// (C) Copyright 2015 Moodle Pty Ltd. // // 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 { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreCourse } from '../services/course'; import { CoreCourseModule } from '../services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../services/module-delegate'; /** * Base module handler to be registered. */ export class CoreModuleHandlerBase implements Partial { protected pageName = ''; /** * @inheritdoc */ async isEnabled(): Promise { return true; } /** * @inheritdoc */ async getData( module: CoreCourseModule, courseId: number, // eslint-disable-line @typescript-eslint/no-unused-vars sectionId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars forCoursePage?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars ): Promise { return { icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon), title: module.name, class: 'addon-mod_' + module.modname + '-handler', showDownloadButton: true, action: async ( event: Event, module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions, ): Promise => { await this.openActivityPage(module, courseId, options); }, }; } /** * Opens the activity page. * * @param module The module object. * @param courseId The course ID. * @param options Options for the navigation. * @return Promise resolved when done. */ async openActivityPage(module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions): Promise { if (!CoreCourse.moduleHasView(module)) { return; } options = options || {}; options.params = options.params || {}; Object.assign(options.params, { module }); const routeParams = '/' + courseId + '/' + module.id; await CoreNavigator.navigateToSitePath(this.pageName + routeParams, options); } }