2021-09-08 14:40:20 +02:00
|
|
|
// (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';
|
2021-09-22 14:25:02 +02:00
|
|
|
import { CoreCourse } from '../services/course';
|
2021-09-08 14:40:20 +02:00
|
|
|
import { CoreCourseModule } from '../services/course-helper';
|
|
|
|
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '../services/module-delegate';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base module handler to be registered.
|
|
|
|
*/
|
|
|
|
export class CoreModuleHandlerBase implements Partial<CoreCourseModuleHandler> {
|
|
|
|
|
|
|
|
protected pageName = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
async isEnabled(): Promise<boolean> {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-27 16:46:43 +02:00
|
|
|
async getData(
|
2021-09-22 14:25:02 +02:00
|
|
|
module: CoreCourseModule,
|
2021-09-08 14:40:20 +02:00
|
|
|
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
|
2021-09-27 16:46:43 +02:00
|
|
|
): Promise<CoreCourseModuleHandlerData> {
|
2021-09-08 14:40:20 +02:00
|
|
|
return {
|
2021-09-22 14:25:02 +02:00
|
|
|
icon: await CoreCourse.getModuleIconSrc(module.modname, module.modicon),
|
2021-09-08 14:40:20 +02:00
|
|
|
title: module.name,
|
|
|
|
class: 'addon-mod_' + module.modname + '-handler',
|
|
|
|
showDownloadButton: true,
|
2021-12-03 13:45:23 +01:00
|
|
|
action: async (
|
|
|
|
event: Event,
|
|
|
|
module: CoreCourseModule,
|
|
|
|
courseId: number,
|
|
|
|
options?: CoreNavigationOptions,
|
|
|
|
): Promise<void> => {
|
2021-12-01 12:26:46 +01:00
|
|
|
await this.openActivityPage(module, courseId, options);
|
2021-09-08 14:40:20 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-12-01 12:26:46 +01:00
|
|
|
/**
|
|
|
|
* 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<void> {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-09-08 14:40:20 +02:00
|
|
|
}
|