MOBILE-2692 siteplugins: Force compilation on PTR
parent
409bb0fde3
commit
46ade52a1a
|
@ -19,6 +19,7 @@ import {
|
||||||
import { NavController } from 'ionic-angular';
|
import { NavController } from 'ionic-angular';
|
||||||
import { CoreCompileProvider } from '../../providers/compile';
|
import { CoreCompileProvider } from '../../providers/compile';
|
||||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
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
|
* 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() jsData: any; // Data to pass to the fake component.
|
||||||
@Input() extraImports: any[] = []; // Extra import modules.
|
@Input() extraImports: any[] = []; // Extra import modules.
|
||||||
@Input() extraProviders: any[] = []; // Extra providers.
|
@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<any> = new EventEmitter(); // Will emit an event when the component is instantiated.
|
@Output() created: EventEmitter<any> = new EventEmitter(); // Will emit an event when the component is instantiated.
|
||||||
|
|
||||||
// Get the container where to put the content.
|
// 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.
|
protected differ: any; // To detect changes in the jsData input.
|
||||||
|
|
||||||
constructor(protected compileProvider: CoreCompileProvider, protected cdr: ChangeDetectorRef, element: ElementRef,
|
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.element = element.nativeElement;
|
||||||
this.differ = differs.find([]).create();
|
this.differ = differs.find([]).create();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +86,10 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
|
||||||
* Detect changes on input properties.
|
* Detect changes on input properties.
|
||||||
*/
|
*/
|
||||||
ngOnChanges(changes: { [name: string]: SimpleChange }): void {
|
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.
|
// Create a new component and a new module.
|
||||||
this.compileProvider.createAndCompileComponent(this.text, this.getComponentClass(), this.extraImports)
|
this.compileProvider.createAndCompileComponent(this.text, this.getComponentClass(), this.extraImports)
|
||||||
.then((factory) => {
|
.then((factory) => {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<core-loading [hideUntil]="dataLoaded">
|
<core-loading [hideUntil]="dataLoaded">
|
||||||
<core-compile-html [text]="content" [javascript]="javascript" [jsData]="jsData"></core-compile-html>
|
<core-compile-html [text]="content" [javascript]="javascript" [jsData]="jsData" [forceCompile]="forceCompile"></core-compile-html>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
|
@ -41,6 +41,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
|
||||||
dataLoaded: boolean;
|
dataLoaded: boolean;
|
||||||
invalidateObservable: Subject<void>; // An observable to notify observers when to invalidate data.
|
invalidateObservable: Subject<void>; // An observable to notify observers when to invalidate data.
|
||||||
jsData: any; // Data to pass to the component.
|
jsData: any; // Data to pass to the component.
|
||||||
|
forceCompile: boolean; // Force compilation on PTR.
|
||||||
|
|
||||||
protected differ: any; // To detect changes in the data input.
|
protected differ: any; // To detect changes in the data input.
|
||||||
|
|
||||||
|
@ -83,11 +84,14 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
|
||||||
fetchContent(refresh?: boolean): Promise<any> {
|
fetchContent(refresh?: boolean): Promise<any> {
|
||||||
this.onLoadingContent.emit(refresh);
|
this.onLoadingContent.emit(refresh);
|
||||||
|
|
||||||
|
this.forceCompile = false;
|
||||||
|
|
||||||
return this.sitePluginsProvider.getContent(this.component, this.method, this.args, this.preSets).then((result) => {
|
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.content = result.templates.length ? result.templates[0].html : ''; // Load first template.
|
||||||
this.javascript = result.javascript;
|
this.javascript = result.javascript;
|
||||||
this.otherData = result.otherdata;
|
this.otherData = result.otherdata;
|
||||||
this.data = this.data || {};
|
this.data = this.data || {};
|
||||||
|
this.forceCompile = true;
|
||||||
|
|
||||||
this.jsData = Object.assign(this.data, this.sitePluginsProvider.createDataForJS(this.initResult, result));
|
this.jsData = Object.assign(this.data, this.sitePluginsProvider.createDataForJS(this.initResult, result));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue