From 6fdb5528ed076e22ea1a67b7a502a0bd363149a0 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 26 Jul 2018 10:42:31 +0200 Subject: [PATCH] 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 --- src/core/course/components/format/format.ts | 3 +++ .../components/course-format/course-format.ts | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/course/components/format/format.ts b/src/core/course/components/format/format.ts index df18d3ef3..9bbb939b8 100644 --- a/src/core/course/components/format/format.ts +++ b/src/core/course/components/format/format.ts @@ -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 && diff --git a/src/core/siteplugins/components/course-format/course-format.ts b/src/core/siteplugins/components/course-format/course-format.ts index 941cdb279..93aaad071 100644 --- a/src/core/siteplugins/components/course-format/course-format.ts +++ b/src/core/siteplugins/components/course-format/course-format.ts @@ -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; // 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 }; } }