From 88c05ac1572fae793315b4d0c58d3f6247994303 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 26 Apr 2018 15:59:23 +0200 Subject: [PATCH] MOBILE-2334 assign: Fix errors with file submission plugin --- .../mod/assign/providers/submission-delegate.ts | 2 +- src/app/app.module.ts | 10 +++++++++- src/components/attachments/attachments.ts | 6 +++--- src/components/local-file/local-file.ts | 9 ++------- src/core/emulator/providers/file.ts | 8 ++++++++ src/directives/auto-focus.ts | 16 ++++++++-------- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/addon/mod/assign/providers/submission-delegate.ts b/src/addon/mod/assign/providers/submission-delegate.ts index 8ad8666d5..26d5da2f4 100644 --- a/src/addon/mod/assign/providers/submission-delegate.ts +++ b/src/addon/mod/assign/providers/submission-delegate.ts @@ -224,7 +224,7 @@ export class AddonModAssignSubmissionDelegate extends CoreDelegate { * @param {any} inputData Data entered by the user for the submission. */ clearTmpData(assign: any, submission: any, plugin: any, inputData: any): void { - return this.executeFunctionOnEnabled(plugin.type, 'return', [assign, submission, plugin, inputData]); + return this.executeFunctionOnEnabled(plugin.type, 'clearTmpData', [assign, submission, plugin, inputData]); } /** diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 42107168e..90831a8a8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -212,7 +212,7 @@ export const CORE_PROVIDERS: any[] = [ }) export class AppModule { constructor(platform: Platform, initDelegate: CoreInitDelegate, updateManager: CoreUpdateManagerProvider, - sitesProvider: CoreSitesProvider) { + sitesProvider: CoreSitesProvider, fileProvider: CoreFileProvider) { // Register a handler for platform ready. initDelegate.registerProcess({ name: 'CorePlatformReady', @@ -232,6 +232,14 @@ export class AppModule { load: sitesProvider.restoreSession.bind(sitesProvider) }); + // Register clear app tmp folder. + initDelegate.registerProcess({ + name: 'CoreClearTmpFolder', + priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 150, + blocking: false, + load: fileProvider.clearTmpFolder.bind(fileProvider) + }); + // Execute the init processes. initDelegate.executeInitProcesses(); } diff --git a/src/components/attachments/attachments.ts b/src/components/attachments/attachments.ts index 71f120dc9..79593fcda 100644 --- a/src/components/attachments/attachments.ts +++ b/src/components/attachments/attachments.ts @@ -127,9 +127,9 @@ export class CoreAttachmentsComponent implements OnInit { * A file was renamed. * * @param {number} index Index of the file. - * @param {any} file The new file entry. + * @param {any} data The data received. */ - renamed(index: number, file: any): void { - this.files[index] = file; + renamed(index: number, data: any): void { + this.files[index] = data.file; } } diff --git a/src/components/local-file/local-file.ts b/src/components/local-file/local-file.ts index 47ab54c6e..7695e8871 100644 --- a/src/components/local-file/local-file.ts +++ b/src/components/local-file/local-file.ts @@ -120,11 +120,6 @@ export class CoreLocalFileComponent implements OnInit { e.stopPropagation(); this.editMode = true; this.newFileName = this.file.name; - - // @todo For some reason core-auto-focus isn't working right. Focus the input manually. - // $timeout(function() { - // $mmUtil.focusElement(element[0].querySelector('input')); - // }); } /** @@ -159,8 +154,8 @@ export class CoreLocalFileComponent implements OnInit { this.file = fileEntry; this.loadFileBasicData(); this.onRename.emit({ file: this.file }); - }).catch(() => { - this.domUtils.showErrorModal('core.errorrenamefile', true); + }).catch((error) => { + this.domUtils.showErrorModalDefault(error, 'core.errorrenamefile', true); }); }).finally(() => { modal.dismiss(); diff --git a/src/core/emulator/providers/file.ts b/src/core/emulator/providers/file.ts index d25c69b7a..27a64c645 100644 --- a/src/core/emulator/providers/file.ts +++ b/src/core/emulator/providers/file.ts @@ -74,6 +74,8 @@ export class FileMock extends File { */ private copyMock(srce: Entry, destDir: DirectoryEntry, newName: string): Promise { return new Promise((resolve, reject): void => { + newName = newName.replace(/%20/g, ' '); // Replace all %20 with spaces. + srce.copyTo(destDir, newName, (deste) => { resolve(deste); }, (err) => { @@ -212,6 +214,8 @@ export class FileMock extends File { getDirectory(directoryEntry: DirectoryEntry, directoryName: string, flags: Flags): Promise { return new Promise((resolve, reject): void => { try { + directoryName = directoryName.replace(/%20/g, ' '); // Replace all %20 with spaces. + directoryEntry.getDirectory(directoryName, flags, (de) => { resolve(de); }, (err) => { @@ -235,6 +239,8 @@ export class FileMock extends File { getFile(directoryEntry: DirectoryEntry, fileName: string, flags: Flags): Promise { return new Promise((resolve, reject): void => { try { + fileName = fileName.replace(/%20/g, ' '); // Replace all %20 with spaces. + directoryEntry.getFile(fileName, flags, resolve, (err) => { this.fillErrorMessageMock(err); reject(err); @@ -375,6 +381,8 @@ export class FileMock extends File { */ private moveMock(srce: Entry, destDir: DirectoryEntry, newName: string): Promise { return new Promise((resolve, reject): void => { + newName = newName.replace(/%20/g, ' '); // Replace all %20 with spaces. + srce.moveTo(destDir, newName, (deste) => { resolve(deste); }, (err) => { diff --git a/src/directives/auto-focus.ts b/src/directives/auto-focus.ts index c5f0db88e..5d6e2446d 100644 --- a/src/directives/auto-focus.ts +++ b/src/directives/auto-focus.ts @@ -56,16 +56,16 @@ export class CoreAutoFocusDirective implements OnInit { protected autoFocus(): void { const autoFocus = this.utils.isTrueOrOne(this.coreAutoFocus); if (autoFocus) { - // If it's a ion-input or ion-textarea, search the right input to use. - let element = this.element; - if (this.element.tagName == 'ION-INPUT') { - element = this.element.querySelector('input') || element; - } else if (this.element.tagName == 'ION-TEXTAREA') { - element = this.element.querySelector('textarea') || element; - } - // Wait a bit to make sure the view is loaded. setTimeout(() => { + // If it's a ion-input or ion-textarea, search the right input to use. + let element = this.element; + if (this.element.tagName == 'ION-INPUT') { + element = this.element.querySelector('input') || element; + } else if (this.element.tagName == 'ION-TEXTAREA') { + element = this.element.querySelector('textarea') || element; + } + this.domUtils.focusElement(element); }, 200); }