Vmeda.Online/src/core/features/course/classes/main-activity-page.ts

91 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-02-16 11:18:12 +01: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 { Component, OnInit } from '@angular/core';
import { CoreNavigator } from '@services/navigator';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreCourseModuleData } from '../services/course-helper';
import { CoreCourseModuleMainResourceComponent } from './main-resource-component';
2021-02-16 11:18:12 +01:00
/**
* Template class to easily create CoreCourseModuleMainComponent of resources (or activities without syncing).
*/
2021-02-16 11:18:12 +01:00
@Component({
template: '',
2021-02-16 11:18:12 +01:00
})
export class CoreCourseModuleMainActivityPage<ActivityType extends CoreCourseModuleMainResourceComponent> implements OnInit {
activityComponent?: ActivityType;
2021-02-16 11:18:12 +01:00
title!: string;
module!: CoreCourseModuleData;
2021-02-16 11:18:12 +01:00
courseId!: number;
/**
* Component being initialized.
2021-02-16 11:18:12 +01:00
*/
ngOnInit(): void {
try {
this.module = CoreNavigator.getRequiredRouteParam<CoreCourseModuleData>('module');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
} catch (error) {
CoreDomUtils.showErrorModal(error);
CoreNavigator.back();
return;
}
2021-02-16 11:18:12 +01:00
this.title = this.module?.name;
}
/**
* Update some data based on the activity instance.
2021-02-16 11:18:12 +01:00
*
* @param activity Activity instance.
*/
updateData(activity: { name: string}): void {
this.title = activity.name || this.title;
}
/**
* User entered the page.
*/
ionViewDidEnter(): void {
this.activityComponent?.ionViewDidEnter();
}
/**
* User left the page.
2021-02-16 11:18:12 +01:00
*/
ionViewDidLeave(): void {
this.activityComponent?.ionViewDidLeave();
2021-02-16 11:18:12 +01:00
}
/**
* User will enter the page.
*/
ionViewWillEnter(): void {
this.activityComponent?.ionViewWillEnter();
}
/**
* User will leave the page.
*/
ionViewWillLeave(): void {
this.activityComponent?.ionViewWillLeave();
}
2021-02-16 11:18:12 +01:00
}