From 0c59a6c7c4c7a9afc675814e6110794342314f71 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 1 Jun 2018 12:32:22 +0200 Subject: [PATCH] MOBILE-2404 pluginfile: Fix plugin file handlers --- .../folder/providers/pluginfile-handler.ts | 1 + .../mod/imscp/providers/pluginfile-handler.ts | 1 + .../mod/page/providers/pluginfile-handler.ts | 1 + .../resource/providers/pluginfile-handler.ts | 1 + .../mod/scorm/providers/pluginfile-handler.ts | 3 ++- src/providers/plugin-file-delegate.ts | 24 ++++++++++++------- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/addon/mod/folder/providers/pluginfile-handler.ts b/src/addon/mod/folder/providers/pluginfile-handler.ts index b35efe663..943d2b0d4 100644 --- a/src/addon/mod/folder/providers/pluginfile-handler.ts +++ b/src/addon/mod/folder/providers/pluginfile-handler.ts @@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate'; @Injectable() export class AddonModFolderPluginFileHandler implements CorePluginFileHandler { name = 'AddonModFolderPluginFileHandler'; + component = 'mod_folder'; /** * Return the RegExp to match the revision on pluginfile URLs. diff --git a/src/addon/mod/imscp/providers/pluginfile-handler.ts b/src/addon/mod/imscp/providers/pluginfile-handler.ts index e64e9b44f..f3cd322d6 100644 --- a/src/addon/mod/imscp/providers/pluginfile-handler.ts +++ b/src/addon/mod/imscp/providers/pluginfile-handler.ts @@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate'; @Injectable() export class AddonModImscpPluginFileHandler implements CorePluginFileHandler { name = 'AddonModImscpPluginFileHandler'; + component = 'mod_imscp'; /** * Return the RegExp to match the revision on pluginfile URLs. diff --git a/src/addon/mod/page/providers/pluginfile-handler.ts b/src/addon/mod/page/providers/pluginfile-handler.ts index 63719c389..4fa49fcdc 100644 --- a/src/addon/mod/page/providers/pluginfile-handler.ts +++ b/src/addon/mod/page/providers/pluginfile-handler.ts @@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate'; @Injectable() export class AddonModPagePluginFileHandler implements CorePluginFileHandler { name = 'AddonModPagePluginFileHandler'; + component = 'mod_page'; /** * Return the RegExp to match the revision on pluginfile URLs. diff --git a/src/addon/mod/resource/providers/pluginfile-handler.ts b/src/addon/mod/resource/providers/pluginfile-handler.ts index daa3da78b..ecd7154f1 100644 --- a/src/addon/mod/resource/providers/pluginfile-handler.ts +++ b/src/addon/mod/resource/providers/pluginfile-handler.ts @@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate'; @Injectable() export class AddonModResourcePluginFileHandler implements CorePluginFileHandler { name = 'AddonModResourcePluginFileHandler'; + component = 'mod_resource'; /** * Return the RegExp to match the revision on pluginfile URLs. diff --git a/src/addon/mod/scorm/providers/pluginfile-handler.ts b/src/addon/mod/scorm/providers/pluginfile-handler.ts index 6910b67b4..58e16d725 100644 --- a/src/addon/mod/scorm/providers/pluginfile-handler.ts +++ b/src/addon/mod/scorm/providers/pluginfile-handler.ts @@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate'; @Injectable() export class AddonModScormPluginFileHandler implements CorePluginFileHandler { name = 'AddonModScormPluginFileHandler'; + component = 'mod_scorm'; /** * Return the RegExp to match the revision on pluginfile URLs. @@ -32,7 +33,7 @@ export class AddonModScormPluginFileHandler implements CorePluginFileHandler { // Check filearea. if (args[2] == 'content') { // Component + Filearea + Revision - return new RegExp('/mod_resource/content/([0-9]+)/'); + return new RegExp('/mod_scorm/content/([0-9]+)/'); } } diff --git a/src/providers/plugin-file-delegate.ts b/src/providers/plugin-file-delegate.ts index b504a0ee8..6f1e3e902 100644 --- a/src/providers/plugin-file-delegate.ts +++ b/src/providers/plugin-file-delegate.ts @@ -20,11 +20,17 @@ import { CoreLoggerProvider } from './logger'; */ export interface CorePluginFileHandler { /** - * A name to identify the handler. It should match the "component" of pluginfile URLs. + * A name to identify the handler. * @type {string} */ name: string; + /** + * The "component" of the handler. It should match the "component" of pluginfile URLs. + * @type {string} + */ + component: string; + /** * Return the RegExp to match the revision on pluginfile URLs. * @@ -57,12 +63,12 @@ export class CorePluginFileDelegate { /** * Get the handler for a certain pluginfile url. * - * @param {string} pluginType Type of the plugin. + * @param {string} component Component of the plugin. * @return {CorePluginFileHandler} Handler. Undefined if no handler found for the plugin. */ - protected getPluginHandler(pluginType: string): CorePluginFileHandler { - if (typeof this.handlers[pluginType] != 'undefined') { - return this.handlers[pluginType]; + protected getPluginHandler(component: string): CorePluginFileHandler { + if (typeof this.handlers[component] != 'undefined') { + return this.handlers[component]; } } @@ -88,14 +94,14 @@ export class CorePluginFileDelegate { * @return {boolean} True if registered successfully, false otherwise. */ registerHandler(handler: CorePluginFileHandler): boolean { - if (typeof this.handlers[handler.name] !== 'undefined') { - this.logger.log(`Addon '${handler.name}' already registered`); + if (typeof this.handlers[handler.component] !== 'undefined') { + this.logger.log(`Handler '${handler.component}' already registered`); return false; } - this.logger.log(`Registered addon '${handler.name}'`); - this.handlers[handler.name] = handler; + this.logger.log(`Registered handler '${handler.component}'`); + this.handlers[handler.component] = handler; return true; }