From 129a6327e67cd0a7ce0d776a3e03f46c53d61816 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 4 Jun 2018 10:34:35 +0200 Subject: [PATCH] MOBILE-2376 siteplugins: Parse otherdata and always inject libraries --- .../compile/components/compile-html/compile-html.ts | 10 ++++++---- src/core/siteplugins/providers/siteplugins.ts | 13 ++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/compile/components/compile-html/compile-html.ts b/src/core/compile/components/compile-html/compile-html.ts index 3151f4d29..20bbad32f 100644 --- a/src/core/compile/components/compile-html/compile-html.ts +++ b/src/core/compile/components/compile-html/compile-html.ts @@ -119,10 +119,12 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck { // Store this instance so it can be accessed by the outer component. compileInstance.componentInstance = this; - // If there is some javascript to run, prepare the instance. - if (compileInstance.javascript) { - compileInstance.compileProvider.injectLibraries(this, compileInstance.extraProviders); - } + // Create 2 empty properties that can be used by the template to store data. + this['dataObject'] = {}; + this['dataArray'] = []; + + // Inject the libraries. + compileInstance.compileProvider.injectLibraries(this, compileInstance.extraProviders); // Always add these elements, they could be needed on component init (componentObservable). this['ChangeDetectorRef'] = compileInstance.cdr; diff --git a/src/core/siteplugins/providers/siteplugins.ts b/src/core/siteplugins/providers/siteplugins.ts index ac3f02c10..2dab2bbf2 100644 --- a/src/core/siteplugins/providers/siteplugins.ts +++ b/src/core/siteplugins/providers/siteplugins.ts @@ -20,6 +20,7 @@ import { CoreLangProvider } from '@providers/lang'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSitesProvider } from '@providers/sites'; +import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreConfigConstants } from '../../../configconstants'; import { CoreCoursesProvider } from '@core/courses/providers/courses'; @@ -68,7 +69,8 @@ export class CoreSitePluginsProvider { constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider, private langProvider: CoreLangProvider, private appProvider: CoreAppProvider, private platform: Platform, - private filepoolProvider: CoreFilepoolProvider, private coursesProvider: CoreCoursesProvider) { + private filepoolProvider: CoreFilepoolProvider, private coursesProvider: CoreCoursesProvider, + private textUtils: CoreTextUtilsProvider) { this.logger = logger.getInstance('CoreUserProvider'); } @@ -218,6 +220,15 @@ export class CoreSitePluginsProvider { }).then((result) => { if (result.otherdata) { result.otherdata = this.utils.objectToKeyValueMap(result.otherdata, 'name', 'value'); + + // Try to parse all properties that could be JSON encoded strings. + for (const name in result.otherdata) { + const value = result.otherdata[name]; + + if (typeof value == 'string' && (value[0] == '{' || value[0] == '[')) { + result.otherdata[name] = this.textUtils.parseJSON(value); + } + } } else { result.otherdata = {}; }