MOBILE-2479 course: Pass course format instance to site plugins

This will allow site plugins to create a view exactly like topics/weeks without having to use Javascript
main
Dani Palou 2018-07-26 10:42:31 +02:00
parent 55682818ff
commit 6fdb5528ed
2 changed files with 11 additions and 1 deletions

View File

@ -77,6 +77,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
this.selectOptions.title = translate.instant('core.course.sections');
this.completionChanged = new EventEmitter();
// Pass this instance to all components so they can use its methods and properties.
this.data.coreCourseFormatComponent = this;
// Listen for section status changes.
this.sectionStatusObserver = eventsProvider.on(CoreEventsProvider.SECTION_STATUS_CHANGED, (data) => {
if (this.downloadEnabled && this.sections && this.sections.length && this.course && data.sectionId &&

View File

@ -15,6 +15,7 @@
import { Component, OnChanges, Input, ViewChild, Output, EventEmitter } from '@angular/core';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsPluginContentComponent } from '../plugin-content/plugin-content';
import { CoreCourseFormatComponent } from '@core/course/components/format/format';
/**
* Component that displays the index of a course format site plugin.
@ -32,6 +33,11 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
@Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section.
@Output() completionChanged?: EventEmitter<void>; // Will emit an event when any module completion changes.
// Special input, allows access to the parent instance properties and methods.
// Please notice that all the other inputs/outputs are also accessible through this instance, so they could be removed.
// However, we decided to keep them to support ngOnChanges and to make templates easier to read.
@Input() coreCourseFormatComponent: CoreCourseFormatComponent;
@ViewChild(CoreSitePluginsPluginContentComponent) content: CoreSitePluginsPluginContentComponent;
component: string;
@ -69,7 +75,8 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
initialSectionId: this.initialSectionId,
initialSectionNumber: this.initialSectionNumber,
moduleId: this.moduleId,
completionChanged: this.completionChanged
completionChanged: this.completionChanged,
coreCourseFormatComponent: this.coreCourseFormatComponent
};
}
}