MOBILE-2333 siteplugins: Make content functions available in view
parent
eff08198e1
commit
2db7656666
|
@ -63,6 +63,6 @@ export class CoreSitePluginsCourseFormatComponent implements OnInit {
|
|||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
doRefresh(refresher?: any, done?: () => void): Promise<any> {
|
||||
return Promise.resolve(this.content.refreshData());
|
||||
return Promise.resolve(this.content.refreshContent(false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ export class CoreSitePluginsCourseOptionComponent implements OnInit {
|
|||
* @param {any} refresher Refresher.
|
||||
*/
|
||||
refreshData(refresher: any): void {
|
||||
this.content.refreshData().finally(() => {
|
||||
this.content.refreshContent(false).finally(() => {
|
||||
refresher.complete();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
|
|||
if (this.content) {
|
||||
this.refreshIcon = 'spinner';
|
||||
|
||||
return Promise.resolve(this.content.refreshData()).finally(() => {
|
||||
return Promise.resolve(this.content.refreshContent(false)).finally(() => {
|
||||
refresher && refresher.complete();
|
||||
done && done();
|
||||
});
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { Component, OnInit, Input, Output, EventEmitter, Optional } from '@angular/core';
|
||||
import { NavController } from 'ionic-angular';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
|
||||
import { Subject } from 'rxjs';
|
||||
|
@ -39,7 +40,8 @@ export class CoreSitePluginsPluginContentComponent implements OnInit {
|
|||
invalidateObservable: Subject<void>; // An observable to notify observers when to invalidate data.
|
||||
jsData: any; // Data to pass to the component.
|
||||
|
||||
constructor(protected domUtils: CoreDomUtilsProvider, protected sitePluginsProvider: CoreSitePluginsProvider) {
|
||||
constructor(protected domUtils: CoreDomUtilsProvider, protected sitePluginsProvider: CoreSitePluginsProvider,
|
||||
@Optional() protected navCtrl: NavController) {
|
||||
this.onContentLoaded = new EventEmitter();
|
||||
this.onLoadingContent = new EventEmitter();
|
||||
this.invalidateObservable = new Subject<void>();
|
||||
|
@ -67,6 +69,11 @@ export class CoreSitePluginsPluginContentComponent implements OnInit {
|
|||
this.otherData = result.otherdata;
|
||||
this.jsData = this.sitePluginsProvider.createDataForJS(this.initResult, result);
|
||||
|
||||
// Pass some methods as jsData so they can be called from the template too.
|
||||
this.jsData.openContent = this.openContent.bind(this);
|
||||
this.jsData.refreshContent = this.refreshContent.bind(this);
|
||||
this.jsData.updateContent = this.updateContent.bind(this);
|
||||
|
||||
this.onContentLoaded.emit(refresh);
|
||||
}).catch((error) => {
|
||||
this.domUtils.showErrorModalDefault(error, 'core.errorloadingcontent', true);
|
||||
|
@ -75,12 +82,30 @@ export class CoreSitePluginsPluginContentComponent implements OnInit {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a new page with a new content.
|
||||
*
|
||||
* @param {string} title The title to display with the new content.
|
||||
* @param {any} args New params.
|
||||
* @param {string} [component] New component. If not provided, current component
|
||||
* @param {string} [method] New method. If not provided, current method
|
||||
*/
|
||||
openContent(title: string, args: any, component?: string, method?: string): void {
|
||||
this.navCtrl.push('CoreSitePluginsPluginPage', {
|
||||
title: title,
|
||||
component: component || this.component,
|
||||
method: method || this.method,
|
||||
args: args,
|
||||
initResult: this.initResult
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the data.
|
||||
*
|
||||
* @param {boolean} [showSpinner] Whether to show spinner while refreshing.
|
||||
* @param {boolean} [showSpinner=true] Whether to show spinner while refreshing.
|
||||
*/
|
||||
refreshData(showSpinner?: boolean): Promise<any> {
|
||||
refreshContent(showSpinner: boolean = true): Promise<any> {
|
||||
if (showSpinner) {
|
||||
this.dataLoaded = false;
|
||||
}
|
||||
|
@ -95,13 +120,13 @@ export class CoreSitePluginsPluginContentComponent implements OnInit {
|
|||
/**
|
||||
* Update the content, usually with a different method or params.
|
||||
*
|
||||
* @param {string} component New component.
|
||||
* @param {string} method New method.
|
||||
* @param {any} args New params.
|
||||
* @param {string} [component] New component. If not provided, current component
|
||||
* @param {string} [method] New method. If not provided, current method
|
||||
*/
|
||||
updateContent(component: string, method: string, args: any): void {
|
||||
this.component = component;
|
||||
this.method = method;
|
||||
updateContent(args: any, component?: string, method?: string): void {
|
||||
this.component = component || this.component;
|
||||
this.method = method || this.method;
|
||||
this.args = args;
|
||||
this.dataLoaded = false;
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ import { CoreSitePluginsPluginContentComponent } from '../components/plugin-cont
|
|||
selector: '[core-site-plugins-call-ws-new-content]'
|
||||
})
|
||||
export class CoreSitePluginsCallWSNewContentDirective extends CoreSitePluginsCallWSOnClickBaseDirective {
|
||||
@Input() component: string; // The component of the new content.
|
||||
@Input() method: string; // The method to get the new content.
|
||||
@Input() component: string; // The component of the new content. If not provided, use the same component as current page.
|
||||
@Input() method: string; // The method to get the new content. If not provided, use the same method as current page.
|
||||
@Input() args: any; // The params to get the new content.
|
||||
@Input() title: string; // The title to display with the new content. Only if samePage=false.
|
||||
@Input() samePage: boolean | string; // Whether to display the content in same page or open a new one. Defaults to new page.
|
||||
|
@ -84,13 +84,13 @@ export class CoreSitePluginsCallWSNewContentDirective extends CoreSitePluginsCal
|
|||
if (this.utils.isTrueOrOne(this.samePage)) {
|
||||
// Update the parent content (if it exists).
|
||||
if (this.parentContent) {
|
||||
this.parentContent.updateContent(this.component, this.method, args);
|
||||
this.parentContent.updateContent(args, this.component, this.method);
|
||||
}
|
||||
} else {
|
||||
this.navCtrl.push('CoreSitePluginsPluginPage', {
|
||||
title: this.title,
|
||||
component: this.component,
|
||||
method: this.method,
|
||||
component: this.component || (this.parentContent && this.parentContent.component),
|
||||
method: this.method || (this.parentContent && this.parentContent.method),
|
||||
args: args,
|
||||
initResult: this.parentContent && this.parentContent.initResult
|
||||
});
|
||||
|
|
|
@ -74,7 +74,7 @@ export class CoreSitePluginsCallWSDirective extends CoreSitePluginsCallWSOnClick
|
|||
if (this.utils.isTrueOrOne(this.goBackOnSuccess)) {
|
||||
this.navCtrl.pop();
|
||||
} else if (this.utils.isTrueOrOne(this.refreshOnSuccess) && this.parentContent) {
|
||||
this.parentContent.refreshData(true);
|
||||
this.parentContent.refreshContent(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ import { CoreSitePluginsPluginContentComponent } from '../components/plugin-cont
|
|||
selector: '[core-site-plugins-new-content]'
|
||||
})
|
||||
export class CoreSitePluginsNewContentDirective implements OnInit {
|
||||
@Input() component: string; // The component of the new content.
|
||||
@Input() method: string; // The method to get the new content.
|
||||
@Input() component: string; // The component of the new content. If not provided, use the same component as current page.
|
||||
@Input() method: string; // The method to get the new content. If not provided, use the same method as current page.
|
||||
@Input() args: any; // The params to get the new content.
|
||||
@Input() title: string; // The title to display with the new content. Only if samePage=false.
|
||||
@Input() samePage: boolean | string; // Whether to display the content in same page or open a new one. Defaults to new page.
|
||||
|
@ -81,13 +81,13 @@ export class CoreSitePluginsNewContentDirective implements OnInit {
|
|||
if (this.utils.isTrueOrOne(this.samePage)) {
|
||||
// Update the parent content (if it exists).
|
||||
if (this.parentContent) {
|
||||
this.parentContent.updateContent(this.component, this.method, args);
|
||||
this.parentContent.updateContent(args, this.component, this.method);
|
||||
}
|
||||
} else {
|
||||
this.navCtrl.push('CoreSitePluginsPluginPage', {
|
||||
title: this.title,
|
||||
component: this.component,
|
||||
method: this.method,
|
||||
component: this.component || (this.parentContent && this.parentContent.component),
|
||||
method: this.method || (this.parentContent && this.parentContent.method),
|
||||
args: args,
|
||||
initResult: this.parentContent && this.parentContent.initResult
|
||||
});
|
||||
|
|
|
@ -48,7 +48,7 @@ export class CoreSitePluginsPluginPage {
|
|||
* @param {any} refresher Refresher.
|
||||
*/
|
||||
refreshData(refresher: any): void {
|
||||
this.content.refreshData().finally(() => {
|
||||
this.content.refreshContent(false).finally(() => {
|
||||
refresher.complete();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue