From 46ade52a1a8c215f076da6733206260d9c308863 Mon Sep 17 00:00:00 2001 From: dpalou Date: Wed, 17 Oct 2018 13:00:28 +0200 Subject: [PATCH] MOBILE-2692 siteplugins: Force compilation on PTR --- .../compile/components/compile-html/compile-html.ts | 10 ++++++++-- .../core-siteplugins-plugin-content.html | 2 +- .../components/plugin-content/plugin-content.ts | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/compile/components/compile-html/compile-html.ts b/src/core/compile/components/compile-html/compile-html.ts index d7d9379b0..0fafec013 100644 --- a/src/core/compile/components/compile-html/compile-html.ts +++ b/src/core/compile/components/compile-html/compile-html.ts @@ -19,6 +19,7 @@ import { import { NavController } from 'ionic-angular'; import { CoreCompileProvider } from '../../providers/compile'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreUtilsProvider } from '@providers/utils/utils'; /** * This component has a behaviour similar to $compile for AngularJS. Given an HTML code, it will compile it so all its @@ -45,6 +46,7 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck { @Input() jsData: any; // Data to pass to the fake component. @Input() extraImports: any[] = []; // Extra import modules. @Input() extraProviders: any[] = []; // Extra providers. + @Input() forceCompile: string | boolean; // Set it to true to force compile even if the text/javascript hasn't changed. @Output() created: EventEmitter = new EventEmitter(); // Will emit an event when the component is instantiated. // Get the container where to put the content. @@ -58,7 +60,8 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck { protected differ: any; // To detect changes in the jsData input. constructor(protected compileProvider: CoreCompileProvider, protected cdr: ChangeDetectorRef, element: ElementRef, - @Optional() protected navCtrl: NavController, differs: KeyValueDiffers, protected domUtils: CoreDomUtilsProvider) { + @Optional() protected navCtrl: NavController, differs: KeyValueDiffers, protected domUtils: CoreDomUtilsProvider, + protected utils: CoreUtilsProvider) { this.element = element.nativeElement; this.differ = differs.find([]).create(); } @@ -83,7 +86,10 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck { * Detect changes on input properties. */ ngOnChanges(changes: { [name: string]: SimpleChange }): void { - if ((changes.text || changes.javascript) && this.text) { + // Only compile if text/javascript has changed or the forceCompile flag has been set to true. + if ((changes.text || changes.javascript || (changes.forceCompile && this.utils.isTrueOrOne(this.forceCompile))) && + this.text) { + // Create a new component and a new module. this.compileProvider.createAndCompileComponent(this.text, this.getComponentClass(), this.extraImports) .then((factory) => { diff --git a/src/core/siteplugins/components/plugin-content/core-siteplugins-plugin-content.html b/src/core/siteplugins/components/plugin-content/core-siteplugins-plugin-content.html index a22885173..7088f7a30 100644 --- a/src/core/siteplugins/components/plugin-content/core-siteplugins-plugin-content.html +++ b/src/core/siteplugins/components/plugin-content/core-siteplugins-plugin-content.html @@ -1,3 +1,3 @@ - + diff --git a/src/core/siteplugins/components/plugin-content/plugin-content.ts b/src/core/siteplugins/components/plugin-content/plugin-content.ts index 2342c6566..6ddaf6315 100644 --- a/src/core/siteplugins/components/plugin-content/plugin-content.ts +++ b/src/core/siteplugins/components/plugin-content/plugin-content.ts @@ -41,6 +41,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck { dataLoaded: boolean; invalidateObservable: Subject; // An observable to notify observers when to invalidate data. jsData: any; // Data to pass to the component. + forceCompile: boolean; // Force compilation on PTR. protected differ: any; // To detect changes in the data input. @@ -83,11 +84,14 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck { fetchContent(refresh?: boolean): Promise { this.onLoadingContent.emit(refresh); + this.forceCompile = false; + return this.sitePluginsProvider.getContent(this.component, this.method, this.args, this.preSets).then((result) => { this.content = result.templates.length ? result.templates[0].html : ''; // Load first template. this.javascript = result.javascript; this.otherData = result.otherdata; this.data = this.data || {}; + this.forceCompile = true; this.jsData = Object.assign(this.data, this.sitePluginsProvider.createDataForJS(this.initResult, result));