|
| 1 | +// (C) Copyright 2015 Moodle Pty Ltd. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import { Component, Optional, Injector } from '@angular/core'; |
| 16 | +import { Content } from 'ionic-angular'; |
| 17 | +import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component'; |
| 18 | +import { AddonModH5PActivity, AddonModH5PActivityProvider, AddonModH5PActivityData } from '../../providers/h5pactivity'; |
| 19 | + |
| 20 | +/** |
| 21 | + * Component that displays an H5P activity entry page. |
| 22 | + */ |
| 23 | +@Component({ |
| 24 | + selector: 'addon-mod-h5pactivity-index', |
| 25 | + templateUrl: 'addon-mod-h5pactivity-index.html', |
| 26 | +}) |
| 27 | +export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActivityComponent { |
| 28 | + component = AddonModH5PActivityProvider.COMPONENT; |
| 29 | + moduleName = 'h5pactivity'; |
| 30 | + |
| 31 | + h5pActivity: AddonModH5PActivityData; // The H5P activity object. |
| 32 | + |
| 33 | + protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity'; |
| 34 | + |
| 35 | + constructor(injector: Injector, |
| 36 | + @Optional() protected content: Content) { |
| 37 | + super(injector, content); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Component being initialized. |
| 42 | + */ |
| 43 | + ngOnInit(): void { |
| 44 | + super.ngOnInit(); |
| 45 | + |
| 46 | + this.loadContent(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Check the completion. |
| 51 | + */ |
| 52 | + protected checkCompletion(): void { |
| 53 | + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Get the activity data. |
| 58 | + * |
| 59 | + * @param refresh If it's refreshing content. |
| 60 | + * @param sync If it should try to sync. |
| 61 | + * @param showErrors If show errors to the user of hide them. |
| 62 | + * @return Promise resolved when done. |
| 63 | + */ |
| 64 | + protected async fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<void> { |
| 65 | + try { |
| 66 | + this.h5pActivity = await AddonModH5PActivity.instance.getH5PActivity(this.courseId, this.module.id); |
| 67 | + |
| 68 | + this.description = this.h5pActivity.intro; |
| 69 | + this.dataRetrieved.emit(this.h5pActivity); |
| 70 | + } finally { |
| 71 | + this.fillContextMenu(refresh); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Perform the invalidate content function. |
| 77 | + * |
| 78 | + * @return Resolved when done. |
| 79 | + */ |
| 80 | + protected invalidateContent(): Promise<any> { |
| 81 | + return AddonModH5PActivity.instance.invalidateActivityData(this.courseId); |
| 82 | + } |
| 83 | +} |
0 commit comments