diff --git a/src/app/app.module.ts b/src/app/app.module.ts index bf5da58d2..20b958fd6 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -54,6 +54,7 @@ import { CoreLoginModule } from '../core/login/login.module'; import { CoreMainMenuModule } from '../core/mainmenu/mainmenu.module'; import { CoreCoursesModule } from '../core/courses/courses.module'; import { CoreFileUploaderModule } from '../core/fileuploader/fileuploader.module'; +import { CoreSharedFilesModule } from '../core/sharedfiles/sharedfiles.module'; // For translate loader. AoT requires an exported function for factories. @@ -84,6 +85,7 @@ export function createTranslateLoader(http: HttpClient) { CoreMainMenuModule, CoreCoursesModule, CoreFileUploaderModule, + CoreSharedFilesModule, CoreComponentsModule ], bootstrap: [IonicApp], diff --git a/src/classes/site.ts b/src/classes/site.ts index 235fb8241..b4645cfeb 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -1062,7 +1062,7 @@ export class CoreSite { } if (alertMessage) { - let alert = this.domUtils.showAlert('core.notice', alertMessage, undefined, 3000); + let alert = this.domUtils.showAlert(this.translate.instant('core.notice'), alertMessage, undefined, 3000); alert.onDidDismiss(() => { if (inApp) { resolve(this.utils.openInApp(url, options)); diff --git a/src/core/fileuploader/providers/helper.ts b/src/core/fileuploader/providers/helper.ts index cfd38e40d..07936bb1d 100644 --- a/src/core/fileuploader/providers/helper.ts +++ b/src/core/fileuploader/providers/helper.ts @@ -361,7 +361,7 @@ export class CoreFileUploaderHelperProvider { return this.fileProvider.getFileObjectFromFileEntry(fileEntry).then((file) => { return this.confirmUploadFile(file.size).then(() => { return this.uploadGenericFile(fileEntry.toURL(), file.name, file.type, deleteAfterUpload, siteId).then(() => { - this.domUtils.showAlert('core.success', 'core.fileuploader.fileuploaded'); + this.domUtils.showAlertTranslated('core.success', 'core.fileuploader.fileuploaded'); }); }).catch((err) => { if (err) { diff --git a/src/core/login/pages/email-signup/email-signup.ts b/src/core/login/pages/email-signup/email-signup.ts index dcf5a0f2e..95504c0fe 100644 --- a/src/core/login/pages/email-signup/email-signup.ts +++ b/src/core/login/pages/email-signup/email-signup.ts @@ -236,7 +236,7 @@ export class CoreLoginEmailSignupPage { if (result.success) { // Show alert and ho back. let message = this.translate.instant('core.login.emailconfirmsent', {$a: params.email}); - this.domUtils.showAlert('core.success', message); + this.domUtils.showAlert(this.translate.instant('core.success'), message); this.navCtrl.pop(); } else { if (result.warnings && result.warnings.length) { diff --git a/src/core/sharedfiles/pages/choose-site/choose-site.html b/src/core/sharedfiles/pages/choose-site/choose-site.html new file mode 100644 index 000000000..cb275173d --- /dev/null +++ b/src/core/sharedfiles/pages/choose-site/choose-site.html @@ -0,0 +1,24 @@ + + + {{ 'core.sharedfiles.sharedfiles' | translate }} + + + + + + +

{{ 'core.sharedfiles.chooseaccountstorefile' | translate }}

+

{{fileName}}

+
+ + +

{{site.fullName}}

+

+

{{site.siteUrl}}

+
+
+
+
+ + + diff --git a/src/core/sharedfiles/pages/choose-site/choose-site.module.ts b/src/core/sharedfiles/pages/choose-site/choose-site.module.ts new file mode 100644 index 000000000..2436ede4b --- /dev/null +++ b/src/core/sharedfiles/pages/choose-site/choose-site.module.ts @@ -0,0 +1,33 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; +import { CoreSharedFilesChooseSitePage } from './choose-site'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreComponentsModule } from '../../../../components/components.module'; +import { CoreDirectivesModule } from '../../../../directives/directives.module'; + +@NgModule({ + declarations: [ + CoreSharedFilesChooseSitePage + ], + imports: [ + CoreComponentsModule, + CoreDirectivesModule, + IonicPageModule.forChild(CoreSharedFilesChooseSitePage), + TranslateModule.forChild() + ] +}) +export class CoreSharedFilesChooseSitePageModule {} diff --git a/src/core/sharedfiles/pages/choose-site/choose-site.ts b/src/core/sharedfiles/pages/choose-site/choose-site.ts new file mode 100644 index 000000000..68896cc94 --- /dev/null +++ b/src/core/sharedfiles/pages/choose-site/choose-site.ts @@ -0,0 +1,89 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, OnInit } from '@angular/core'; +import { IonicPage, NavController, NavParams } from 'ionic-angular'; +import { CoreFileProvider } from '../../../../providers/file'; +import { CoreSitesProvider } from '../../../../providers/sites'; +import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; +import { CoreSharedFilesHelperProvider } from '../../providers/helper'; + +/** + * Modal to display the list of sites to choose one to store a shared file. + */ +@IonicPage() +@Component({ + selector: 'page-core-shared-files-choose-site', + templateUrl: 'choose-site.html', +}) +export class CoreSharedFilesChooseSitePage implements OnInit { + + fileName: string; + sites: any[]; + loaded: boolean; + + protected filePath: string; + protected fileEntry: any; + + constructor(private navCtrl: NavController, navParams: NavParams, private sharedFilesHelper: CoreSharedFilesHelperProvider, + private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider, + private fileProvider: CoreFileProvider) { + this.filePath = navParams.get('filePath'); + } + + /** + * Component being initialized. + */ + ngOnInit() { + if (!this.filePath) { + this.domUtils.showErrorModal('Error reading file.'); + this.navCtrl.pop(); + return; + } + + let fileAndDir = this.fileProvider.getFileAndDirectoryFromPath(this.filePath); + this.fileName = fileAndDir.name; + + // Get the file. + this.fileProvider.getFile(this.filePath).then((fe) => { + this.fileEntry = fe; + this.fileName = this.fileEntry.name; + }).catch(() => { + this.domUtils.showErrorModal('Error reading file.'); + this.navCtrl.pop(); + }); + + // Get the sites. + this.sitesProvider.getSites().then((sites) => { + this.sites = sites; + }).finally(() => { + this.loaded = true; + }); + } + + /** + * Store the file in a certain site. + * + * @param {string} siteId Site ID. + */ + storeInSite(siteId: string) : void { + this.loaded = false; + this.sharedFilesHelper.storeSharedFileInSite(this.fileEntry, siteId).then(() => { + this.navCtrl.pop(); + }).finally(() => { + this.loaded = true; + }); + }; + +} \ No newline at end of file diff --git a/src/core/sharedfiles/pages/list/list.html b/src/core/sharedfiles/pages/list/list.html new file mode 100644 index 000000000..ee14a99a6 --- /dev/null +++ b/src/core/sharedfiles/pages/list/list.html @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + +
+ + + {{ 'core.folder' | translate }} +

{{ file.name }}

+
+
+
+ + +
+
diff --git a/src/core/sharedfiles/pages/list/list.module.ts b/src/core/sharedfiles/pages/list/list.module.ts new file mode 100644 index 000000000..af48247d6 --- /dev/null +++ b/src/core/sharedfiles/pages/list/list.module.ts @@ -0,0 +1,33 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; +import { CoreSharedFilesListPage } from './list'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreComponentsModule } from '../../../../components/components.module'; +import { CoreDirectivesModule } from '../../../../directives/directives.module'; + +@NgModule({ + declarations: [ + CoreSharedFilesListPage + ], + imports: [ + CoreComponentsModule, + CoreDirectivesModule, + IonicPageModule.forChild(CoreSharedFilesListPage), + TranslateModule.forChild() + ] +}) +export class CoreSharedFilesListPageModule {} diff --git a/src/core/sharedfiles/pages/list/list.ts b/src/core/sharedfiles/pages/list/list.ts new file mode 100644 index 000000000..dc285979e --- /dev/null +++ b/src/core/sharedfiles/pages/list/list.ts @@ -0,0 +1,181 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { IonicPage, ViewController, NavParams, NavController } from 'ionic-angular'; +import { TranslateService } from '@ngx-translate/core'; +import { CoreEventsProvider } from '../../../../providers/events'; +import { CoreFileProvider } from '../../../../providers/file'; +import { CoreSitesProvider } from '../../../../providers/sites'; +import { CoreTextUtilsProvider } from '../../../../providers/utils/text'; +import { CoreSharedFilesProvider } from '../../providers/sharedfiles'; + +/** + * Modal to display the list of shared files. + */ +@IonicPage() +@Component({ + selector: 'page-core-shared-files-list', + templateUrl: 'list.html', +}) +export class CoreSharedFilesListPage implements OnInit, OnDestroy { + + siteId: string; + isModal: boolean; + manage: boolean; + pick: boolean; // To pick a file you MUST use a modal. + path: string = ''; + title: string; + filesLoaded: boolean; + files: any[]; + + protected mimetypes: string[]; + protected shareObserver; + + constructor(private viewCtrl: ViewController, navParams: NavParams, private sharedFilesProvider: CoreSharedFilesProvider, + private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, private translate: TranslateService, + private fileProvider: CoreFileProvider, private eventsProvider: CoreEventsProvider, private navCtrl: NavController) { + this.siteId = navParams.get('siteId') || this.sitesProvider.getCurrentSiteId(); + this.mimetypes = navParams.get('mimetypes'); + this.isModal = !!navParams.get('isModal'); + this.manage = !!navParams.get('manage'); + this.pick = !!navParams.get('pick'); + this.path = navParams.get('path') || ''; + } + + /** + * Component being initialized. + */ + ngOnInit() { + this.loadFiles(); + + // Listen for new files shared with the app. + this.shareObserver = this.eventsProvider.on(CoreEventsProvider.FILE_SHARED, (data) => { + if (data.siteId == this.siteId) { + // File was stored in current site, refresh the list. + this.filesLoaded = false; + this.loadFiles().finally(() => { + this.filesLoaded = true; + }); + } + }); + } + + /** + * Load the files. + */ + protected loadFiles() { + if (this.path) { + this.title = this.fileProvider.getFileAndDirectoryFromPath(this.path).name; + } else { + this.title = this.translate.instant('core.sharedfiles.sharedfiles'); + } + + return this.sharedFilesProvider.getSiteSharedFiles(this.siteId, this.path, this.mimetypes).then((files) => { + this.files = files; + this.filesLoaded = true; + }); + } + + /** + * Close modal. + */ + closeModal() : void { + this.viewCtrl.dismiss(); + } + + /** + * Refresh the list of files. + * + * @param {any} refresher Refresher. + */ + refreshFiles(refresher: any) : void { + this.loadFiles().finally(() => { + refresher.complete(); + }); + } + + /** + * Called when a file is deleted. Remove the file from the list. + * + * @param {number} index Position of the file. + */ + fileDeleted(index: number) : void { + this.files.splice(index, 1); + } + + /** + * Called when a file is renamed. Update the list. + * + * @param {number} index Position of the file. + * @param {any} file New FileEntry. + */ + fileRenamed(index: number, file: any) : void { + this.files[index] = file; + } + + /** + * Open a subfolder. + * + * @param {any} folder The folder to open. + */ + openFolder(folder: any) : void { + let path = this.textUtils.concatenatePaths(this.path, folder.name); + if (this.isModal) { + // In Modal we don't want to open a new page because we cannot dismiss the modal from the new page. + this.path = path; + this.filesLoaded = false; + this.loadFiles(); + } else { + this.navCtrl.push('CoreSharedFilesListPage', { + path: path, + manage: this.manage, + pick: this.pick, + siteId: this.siteId, + mimetypes: this.mimetypes, + isModal: this.isModal + }); + } + } + + /** + * Change site loaded. + * + * @param {string} id Site to load. + */ + changeSite(id: string) : void { + this.siteId = id; + this.path = ''; + this.filesLoaded = false; + this.loadFiles(); + } + + /** + * A file was picked. + * + * @param {any} file Picked file. + */ + filePicked(file: any) : void { + this.viewCtrl.dismiss(file); + } + + /** + * Component destroyed. + */ + ngOnDestroy() { + if (this.shareObserver) { + this.shareObserver.off(); + } + } +} \ No newline at end of file diff --git a/src/core/sharedfiles/providers/helper.ts b/src/core/sharedfiles/providers/helper.ts new file mode 100644 index 000000000..22f76e6b7 --- /dev/null +++ b/src/core/sharedfiles/providers/helper.ts @@ -0,0 +1,176 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { AlertController, ModalController } from 'ionic-angular'; +import { TranslateService } from '@ngx-translate/core'; +import { CoreAppProvider } from '../../../providers/app'; +import { CoreFileProvider } from '../../../providers/file'; +import { CoreLoggerProvider } from '../../../providers/logger'; +import { CoreInitDelegate } from '../../../providers/init'; +import { CoreSitesProvider } from '../../../providers/sites'; +import { CoreDomUtilsProvider } from '../../../providers/utils/dom'; +import { CoreUtilsProvider } from '../../../providers/utils/utils'; +import { CoreSharedFilesProvider } from './sharedfiles'; +import { CoreFileUploaderProvider } from '../../fileuploader/providers/fileuploader'; + +/** + * Helper service to share files with the app. + */ +@Injectable() +export class CoreSharedFilesHelperProvider { + protected logger; + + constructor(logger: CoreLoggerProvider, private alertCtrl: AlertController, private translate: TranslateService, + private utils: CoreUtilsProvider, private sitesProvider: CoreSitesProvider, private modalCtrl: ModalController, + private fileUploaderProvider: CoreFileUploaderProvider, private initDelegate: CoreInitDelegate, + private sharedFilesProvider: CoreSharedFilesProvider, private domUtils: CoreDomUtilsProvider, + private fileProvider: CoreFileProvider, private appProvider: CoreAppProvider) { + this.logger = logger.getInstance('CoreSharedFilesHelperProvider'); + } + + /** + * Ask a user if he wants to replace a file (using originalName) or rename it (using newName). + * + * @param {string} originalName Original name. + * @param {string} newName New name. + * @return {Promise} Promise resolved with the name to use when the user chooses. Rejected if user cancels. + */ + askRenameReplace(originalName: string, newName: string) : Promise { + const deferred = this.utils.promiseDefer(), + alert = this.alertCtrl.create({ + title: this.translate.instant('core.sharedfiles.sharedfiles'), + message: this.translate.instant('core.sharedfiles.chooseactionrepeatedfile', {$a: newName}), + buttons: [ + { + text: this.translate.instant('core.sharedfiles.rename'), + handler: () => { + deferred.resolve(newName); + } + }, + { + text: this.translate.instant('core.sharedfiles.replace'), + handler: () => { + deferred.resolve(originalName); + } + } + ] + }); + + alert.present(); + return deferred.promise; + } + + /** + * Go to the choose site view. + * + * @param {string} filePath File path to send to the view. + */ + goToChooseSite(filePath: string) : void { + let navCtrl = this.appProvider.getRootNavController(); + navCtrl.push('CoreSharedFilesChooseSitePage', {filePath: filePath}); + } + + /** + * Open the view to select a shared file. + * + * @param {string[]} [mimetypes] List of supported mimetypes. If undefined, all mimetypes supported. + * @return {Promise} Promise resolved when a file is picked, rejected if file picker is closed without selecting a file. + */ + pickSharedFile(mimetypes?: string[]) : Promise { + return new Promise((resolve, reject) => { + let modal = this.modalCtrl.create('CoreSharedFilesListPage', {mimetypes: mimetypes, isModal: true, pick: true}); + modal.present(); + + modal.onDidDismiss((file: any) => { + if (!file) { + // User cancelled. + reject(); + return; + } + + const error = this.fileUploaderProvider.isInvalidMimetype(mimetypes, file.fullPath); + if (error) { + reject(error); + } else { + resolve({ + path: file.fullPath, + treated: false + }); + } + }) + }); + } + + /** + * Checks if there is a new file received in iOS and move it to the shared folder of current site. + * If more than one site is found, the user will have to choose the site where to store it in. + * If more than one file is found, treat only the first one. + * + * @return {Promise} Promise resolved when done. + */ + searchIOSNewSharedFiles() : Promise { + return this.initDelegate.ready().then(() => { + let navCtrl = this.appProvider.getRootNavController(); + if (navCtrl && navCtrl.getActive().id == 'CoreSharedFilesChooseSite') { + // We're already treating a shared file. Abort. + return Promise.reject(null); + } + + return this.sharedFilesProvider.checkIOSNewFiles().then((fileEntry) => { + return this.sitesProvider.getSitesIds().then((siteIds) => { + if (!siteIds.length) { + // No sites stored, show error and delete the file. + this.domUtils.showErrorModal('core.sharedfiles.errorreceivefilenosites', true); + return this.sharedFilesProvider.deleteInboxFile(fileEntry); + } else if (siteIds.length == 1) { + return this.storeSharedFileInSite(fileEntry, siteIds[0]); + } else { + this.goToChooseSite(fileEntry.fullPath); + } + }); + }); + }); + } + + /** + * Store a shared file in a site's shared files folder. + * + * @param {any} fileEntry Shared file entry. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when done. + */ + storeSharedFileInSite(fileEntry: any, siteId?: string) : Promise { + siteId = siteId || this.sitesProvider.getCurrentSiteId(); + + // First of all check if there's already a file with the same name in the shared files folder. + const sharedFilesDirPath = this.sharedFilesProvider.getSiteSharedFilesDirPath(siteId); + return this.fileProvider.getUniqueNameInFolder(sharedFilesDirPath, fileEntry.name).then((newName) => { + if (newName == fileEntry.name) { + // No file with the same name. Use the original file name. + return newName; + } else { + // Repeated name. Ask the user what he wants to do. + return this.askRenameReplace(fileEntry.name, newName); + } + }).then((name) => { + return this.sharedFilesProvider.storeFileInSite(fileEntry, name, siteId).catch(function(err) { + this.domUtils.showErrorModal(err || 'Error moving file.'); + }).finally(() => { + this.sharedFilesProvider.deleteInboxFile(fileEntry); + this.domUtils.showAlertTranslated('core.success', 'core.sharedfiles.successstorefile'); + }); + }); + } +} diff --git a/src/core/sharedfiles/providers/sharedfiles.ts b/src/core/sharedfiles/providers/sharedfiles.ts index 14f838f40..5a653f442 100644 --- a/src/core/sharedfiles/providers/sharedfiles.ts +++ b/src/core/sharedfiles/providers/sharedfiles.ts @@ -225,7 +225,7 @@ export class CoreSharedFilesProvider { // Create dir if it doesn't exist already. return this.fileProvider.createDir(sharedFilesFolder).then(() => { return this.fileProvider.moveFile(entry.fullPath, newPath).then((newFile) => { - this.eventsProvider.trigger(CoreEventsProvider.FILE_SHARED, {siteid: siteId, name: newName}); + this.eventsProvider.trigger(CoreEventsProvider.FILE_SHARED, {siteId: siteId, name: newName}); return newFile; }); }); diff --git a/src/core/sharedfiles/providers/upload-handler.ts b/src/core/sharedfiles/providers/upload-handler.ts new file mode 100644 index 000000000..1337dd4f2 --- /dev/null +++ b/src/core/sharedfiles/providers/upload-handler.ts @@ -0,0 +1,64 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { Platform } from 'ionic-angular'; +import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from '../../fileuploader/providers/delegate'; +import { CoreSharedFilesHelperProvider } from './helper'; +/** + * Handler to upload files from the album. + */ +@Injectable() +export class CoreSharedFilesUploadHandler implements CoreFileUploaderHandler { + name = 'CoreSharedFilesUpload'; + priority = 1300; + + constructor(private sharedFilesHelper: CoreSharedFilesHelperProvider, private platform: Platform) {} + + /** + * Whether or not the handler is enabled on a site level. + * + * @return {boolean|Promise} True or promise resolved with true if enabled. + */ + isEnabled(): boolean|Promise { + return this.platform.is('ios'); + } + + /** + * Given a list of mimetypes, return the ones that are supported by the handler. + * + * @param {string[]} [mimetypes] List of mimetypes. + * @return {string[]} Supported mimetypes. + */ + getSupportedMimetypes(mimetypes: string[]) : string[] { + return mimetypes; + } + + /** + * Get the data to display the handler. + * + * @return {CoreFileUploaderHandlerData} Data. + */ + getData() : CoreFileUploaderHandlerData { + return { + title: 'core.sharedfiles.sharedfiles', + class: 'core-sharedfiles-fileuploader-handler', + icon: 'folder', + action: (maxSize?: number, upload?: boolean, allowOffline?: boolean, mimetypes?: string[]) => { + // Don't use the params because the file won't be uploaded, it is returned to the fileuploader. + return this.sharedFilesHelper.pickSharedFile(mimetypes); + } + }; + } +} diff --git a/src/core/sharedfiles/sharedfiles.module.ts b/src/core/sharedfiles/sharedfiles.module.ts index eee25251a..e58bbd904 100644 --- a/src/core/sharedfiles/sharedfiles.module.ts +++ b/src/core/sharedfiles/sharedfiles.module.ts @@ -13,7 +13,11 @@ // limitations under the License. import { NgModule } from '@angular/core'; +import { Platform } from 'ionic-angular'; import { CoreSharedFilesProvider } from './providers/sharedfiles'; +import { CoreSharedFilesHelperProvider } from './providers/helper'; +import { CoreSharedFilesUploadHandler } from './providers/upload-handler'; +import { CoreFileUploaderDelegate } from '../fileuploader/providers/delegate'; @NgModule({ declarations: [ @@ -21,7 +25,23 @@ import { CoreSharedFilesProvider } from './providers/sharedfiles'; imports: [ ], providers: [ - CoreSharedFilesProvider + CoreSharedFilesProvider, + CoreSharedFilesHelperProvider, + CoreSharedFilesUploadHandler ] }) -export class CoreSharedFilesModule {} +export class CoreSharedFilesModule { + constructor(platform: Platform, delegate: CoreFileUploaderDelegate, handler: CoreSharedFilesUploadHandler, + helper: CoreSharedFilesHelperProvider) { + // Register the handler. + delegate.registerHandler(handler); + + if (platform.is('ios')) { + // Check if there are new files at app start and when the app is resumed. + helper.searchIOSNewSharedFiles(); + platform.resume.subscribe(() => { + helper.searchIOSNewSharedFiles(); + }); + } + } +}