MOBILE-2333 siteaddons: Support basic course format site addons
parent
b2c4b65024
commit
52a73f4138
|
@ -21,12 +21,14 @@ import { CoreCompileHtmlComponentModule } from '../../compile/components/compile
|
|||
import { CoreSiteAddonsAddonContentComponent } from './addon-content/addon-content';
|
||||
import { CoreSiteAddonsModuleIndexComponent } from './module-index/module-index';
|
||||
import { CoreSiteAddonsCourseOptionComponent } from './course-option/course-option';
|
||||
import { CoreSiteAddonsCourseFormatComponent } from './course-format/course-format';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
CoreSiteAddonsAddonContentComponent,
|
||||
CoreSiteAddonsModuleIndexComponent,
|
||||
CoreSiteAddonsCourseOptionComponent
|
||||
CoreSiteAddonsCourseOptionComponent,
|
||||
CoreSiteAddonsCourseFormatComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
|
@ -40,11 +42,13 @@ import { CoreSiteAddonsCourseOptionComponent } from './course-option/course-opti
|
|||
exports: [
|
||||
CoreSiteAddonsAddonContentComponent,
|
||||
CoreSiteAddonsModuleIndexComponent,
|
||||
CoreSiteAddonsCourseOptionComponent
|
||||
CoreSiteAddonsCourseOptionComponent,
|
||||
CoreSiteAddonsCourseFormatComponent
|
||||
],
|
||||
entryComponents: [
|
||||
CoreSiteAddonsModuleIndexComponent,
|
||||
CoreSiteAddonsCourseOptionComponent
|
||||
CoreSiteAddonsCourseOptionComponent,
|
||||
CoreSiteAddonsCourseFormatComponent
|
||||
]
|
||||
})
|
||||
export class CoreSiteAddonsComponentsModule {}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<core-site-addons-addon-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [bootstrapResult]="bootstrapResult"></core-site-addons-addon-content>
|
|
@ -0,0 +1,68 @@
|
|||
// (C) Copyright 2015 Martin Dougiamas
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, OnInit, Input, ViewChild } from '@angular/core';
|
||||
import { CoreSiteAddonsProvider } from '../../providers/siteaddons';
|
||||
import { CoreSiteAddonsAddonContentComponent } from '../addon-content/addon-content';
|
||||
|
||||
/**
|
||||
* Component that displays the index of a course format site addon.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'core-site-addons-course-format',
|
||||
templateUrl: 'course-format.html',
|
||||
})
|
||||
export class CoreSiteAddonsCourseFormatComponent implements OnInit {
|
||||
@Input() course: any; // The course to render.
|
||||
@Input() sections: any[]; // List of course sections.
|
||||
@Input() downloadEnabled?: boolean; // Whether the download of sections and modules is enabled.
|
||||
|
||||
@ViewChild(CoreSiteAddonsAddonContentComponent) content: CoreSiteAddonsAddonContentComponent;
|
||||
|
||||
component: string;
|
||||
method: string;
|
||||
args: any;
|
||||
bootstrapResult: any;
|
||||
|
||||
constructor(protected siteAddonsProvider: CoreSiteAddonsProvider) { }
|
||||
|
||||
/**
|
||||
* Component being initialized.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
if (this.course && this.course.format) {
|
||||
const handler = this.siteAddonsProvider.getSiteAddonHandler(this.course.format);
|
||||
if (handler) {
|
||||
this.component = handler.addon.component;
|
||||
this.method = handler.handlerSchema.method;
|
||||
this.args = {
|
||||
courseid: this.course.id,
|
||||
downloadenabled: this.downloadEnabled
|
||||
};
|
||||
this.bootstrapResult = handler.bootstrapResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the data.
|
||||
*
|
||||
* @param {any} [refresher] Refresher.
|
||||
* @param {Function} [done] Function to call when done.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
doRefresh(refresher?: any, done?: () => void): Promise<any> {
|
||||
return Promise.resolve(this.content.refreshData());
|
||||
}
|
||||
}
|
|
@ -27,10 +27,12 @@ import { CoreCourseModulePrefetchDelegate } from '../../course/providers/module-
|
|||
import {
|
||||
CoreCourseOptionsDelegate, CoreCourseOptionsHandler, CoreCourseOptionsHandlerData
|
||||
} from '../../course/providers/options-delegate';
|
||||
import { CoreCourseFormatDelegate, CoreCourseFormatHandler } from '../../course/providers/format-delegate';
|
||||
import { CoreUserDelegate, CoreUserProfileHandler, CoreUserProfileHandlerData } from '../../user/providers/user-delegate';
|
||||
import { CoreDelegateHandler } from '../../../classes/delegate';
|
||||
import { CoreSiteAddonsModuleIndexComponent } from '../components/module-index/module-index';
|
||||
import { CoreSiteAddonsCourseOptionComponent } from '../components/course-option/course-option';
|
||||
import { CoreSiteAddonsCourseFormatComponent } from '../components/course-format/course-format';
|
||||
import { CoreSiteAddonsProvider } from './siteaddons';
|
||||
import { CoreSiteAddonsModulePrefetchHandler } from '../classes/module-prefetch-handler';
|
||||
import { CoreCompileProvider } from '../../compile/providers/compile';
|
||||
|
@ -51,7 +53,8 @@ export class CoreSiteAddonsHelperProvider {
|
|||
private userDelegate: CoreUserDelegate, private langProvider: CoreLangProvider,
|
||||
private siteAddonsProvider: CoreSiteAddonsProvider, private prefetchDelegate: CoreCourseModulePrefetchDelegate,
|
||||
private compileProvider: CoreCompileProvider, private utils: CoreUtilsProvider,
|
||||
private coursesProvider: CoreCoursesProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate) {
|
||||
private coursesProvider: CoreCoursesProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate,
|
||||
private courseFormatDelegate: CoreCourseFormatDelegate) {
|
||||
this.logger = logger.getInstance('CoreSiteAddonsHelperProvider');
|
||||
}
|
||||
|
||||
|
@ -284,6 +287,11 @@ export class CoreSiteAddonsHelperProvider {
|
|||
result.restrict);
|
||||
break;
|
||||
|
||||
case 'CoreCourseFormatDelegate':
|
||||
uniqueName = this.registerCourseFormatHandler(addon, handlerName, handlerSchema, result.jsResult,
|
||||
result.restrict);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Nothing to do.
|
||||
}
|
||||
|
@ -300,6 +308,51 @@ export class CoreSiteAddonsHelperProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a handler in an addon, register it in the course format delegate.
|
||||
*
|
||||
* @param {any} addon Data of the addon.
|
||||
* @param {string} handlerName Name of the handler in the addon.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} [bootstrapResult] Result of executing the bootstrap JS.
|
||||
* @param {any} [restrict] List of users and courses the handler is restricted to.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerCourseFormatHandler(addon: any, handlerName: string, handlerSchema: any, bootstrapResult?: any,
|
||||
restrict?: any): string {
|
||||
if (!handlerSchema) {
|
||||
// Required data not provided, stop.
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the base handler.
|
||||
const formatName = addon.component.replace('format_', ''),
|
||||
baseHandler = this.getBaseHandler(formatName);
|
||||
let handler: CoreCourseFormatHandler;
|
||||
|
||||
// Extend the base handler, adding the properties required by the delegate.
|
||||
handler = Object.assign(baseHandler, {
|
||||
canViewAllSections: (course: any): boolean => {
|
||||
return typeof handlerSchema.canviewallsections != 'undefined' ? handlerSchema.canviewallsections : true;
|
||||
},
|
||||
displayEnableDownload: (course: any): boolean => {
|
||||
return typeof handlerSchema.displayenabledownload != 'undefined' ? handlerSchema.displayenabledownload : true;
|
||||
},
|
||||
displaySectionSelector: (course: any): boolean => {
|
||||
return typeof handlerSchema.displaysectionselector != 'undefined' ? handlerSchema.displaysectionselector : true;
|
||||
},
|
||||
getCourseFormatComponent: (course: any): any => {
|
||||
if (handlerSchema.method) {
|
||||
return CoreSiteAddonsCourseFormatComponent;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.courseFormatDelegate.registerHandler(handler);
|
||||
|
||||
return formatName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a handler in an addon, register it in the course options delegate.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue