MOBILE-3061 dashboard: Pass download enabled as input
parent
fa3a2d3140
commit
007804494d
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit, Input, OnDestroy, ViewChild, Injector } from '@angular/core';
|
import { Component, OnInit, Input, OnDestroy, ViewChild, Injector, OnChanges, SimpleChange } from '@angular/core';
|
||||||
import { Searchbar } from 'ionic-angular';
|
import { Searchbar } from 'ionic-angular';
|
||||||
import { CoreEventsProvider } from '@providers/events';
|
import { CoreEventsProvider } from '@providers/events';
|
||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||||
|
@ -32,7 +32,7 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
|
||||||
selector: 'addon-block-myoverview',
|
selector: 'addon-block-myoverview',
|
||||||
templateUrl: 'addon-block-myoverview.html'
|
templateUrl: 'addon-block-myoverview.html'
|
||||||
})
|
})
|
||||||
export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy {
|
export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
@ViewChild('searchbar') searchbar: Searchbar;
|
@ViewChild('searchbar') searchbar: Searchbar;
|
||||||
@Input() downloadEnabled: boolean;
|
@Input() downloadEnabled: boolean;
|
||||||
|
|
||||||
|
@ -67,7 +67,6 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
|
|
||||||
protected prefetchIconsInitialized = false;
|
protected prefetchIconsInitialized = false;
|
||||||
protected isDestroyed;
|
protected isDestroyed;
|
||||||
protected downloadButtonObserver;
|
|
||||||
protected coursesObserver;
|
protected coursesObserver;
|
||||||
protected updateSiteObserver;
|
protected updateSiteObserver;
|
||||||
protected courseIds = [];
|
protected courseIds = [];
|
||||||
|
@ -87,18 +86,6 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// Refresh the enabled flags if enabled.
|
// Refresh the enabled flags if enabled.
|
||||||
this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED,
|
|
||||||
(data) => {
|
|
||||||
const wasEnabled = this.downloadEnabled;
|
|
||||||
|
|
||||||
this.downloadEnabled = data.enabled;
|
|
||||||
|
|
||||||
if (!wasEnabled && this.downloadEnabled && this.loaded) {
|
|
||||||
// Download all courses is enabled now, initialize it.
|
|
||||||
this.initPrefetchCoursesIcons();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite();
|
this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite();
|
||||||
this.downloadCoursesEnabled = !this.coursesProvider.isDownloadCoursesDisabledInSite();
|
this.downloadCoursesEnabled = !this.coursesProvider.isDownloadCoursesDisabledInSite();
|
||||||
|
|
||||||
|
@ -128,6 +115,16 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect changes on input properties.
|
||||||
|
*/
|
||||||
|
ngOnChanges(changes: {[name: string]: SimpleChange}): void {
|
||||||
|
if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) {
|
||||||
|
// Download all courses is enabled now, initialize it.
|
||||||
|
this.initPrefetchCoursesIcons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the invalidate content function.
|
* Perform the invalidate content function.
|
||||||
*
|
*
|
||||||
|
@ -350,6 +347,5 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
this.isDestroyed = true;
|
this.isDestroyed = true;
|
||||||
this.coursesObserver && this.coursesObserver.off();
|
this.coursesObserver && this.coursesObserver.off();
|
||||||
this.updateSiteObserver && this.updateSiteObserver.off();
|
this.updateSiteObserver && this.updateSiteObserver.off();
|
||||||
this.downloadButtonObserver && this.downloadButtonObserver.off();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit, OnDestroy, Injector, Input } from '@angular/core';
|
import { Component, OnInit, OnDestroy, Injector, Input, OnChanges, SimpleChange } from '@angular/core';
|
||||||
import { CoreEventsProvider } from '@providers/events';
|
import { CoreEventsProvider } from '@providers/events';
|
||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
|
@ -30,7 +30,7 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
|
||||||
selector: 'addon-block-recentlyaccessedcourses',
|
selector: 'addon-block-recentlyaccessedcourses',
|
||||||
templateUrl: 'addon-block-recentlyaccessedcourses.html'
|
templateUrl: 'addon-block-recentlyaccessedcourses.html'
|
||||||
})
|
})
|
||||||
export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy {
|
export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
@Input() downloadEnabled: boolean;
|
@Input() downloadEnabled: boolean;
|
||||||
|
|
||||||
courses = [];
|
courses = [];
|
||||||
|
@ -41,7 +41,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
|
||||||
|
|
||||||
protected prefetchIconsInitialized = false;
|
protected prefetchIconsInitialized = false;
|
||||||
protected isDestroyed;
|
protected isDestroyed;
|
||||||
protected downloadButtonObserver;
|
|
||||||
protected coursesObserver;
|
protected coursesObserver;
|
||||||
protected courseIds = [];
|
protected courseIds = [];
|
||||||
protected fetchContentDefaultError = 'Error getting recent courses data.';
|
protected fetchContentDefaultError = 'Error getting recent courses data.';
|
||||||
|
@ -59,18 +58,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// Refresh the enabled flags if enabled.
|
|
||||||
this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED,
|
|
||||||
(data) => {
|
|
||||||
const wasEnabled = this.downloadEnabled;
|
|
||||||
|
|
||||||
this.downloadEnabled = data.enabled;
|
|
||||||
|
|
||||||
if (!wasEnabled && this.downloadEnabled && this.loaded) {
|
|
||||||
// Download all courses is enabled now, initialize it.
|
|
||||||
this.initPrefetchCoursesIcons();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => {
|
this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => {
|
||||||
this.refreshContent();
|
this.refreshContent();
|
||||||
|
@ -79,6 +66,16 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
|
||||||
super.ngOnInit();
|
super.ngOnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect changes on input properties.
|
||||||
|
*/
|
||||||
|
ngOnChanges(changes: {[name: string]: SimpleChange}): void {
|
||||||
|
if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) {
|
||||||
|
// Download all courses is enabled now, initialize it.
|
||||||
|
this.initPrefetchCoursesIcons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the invalidate content function.
|
* Perform the invalidate content function.
|
||||||
*
|
*
|
||||||
|
@ -155,6 +152,5 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.isDestroyed = true;
|
this.isDestroyed = true;
|
||||||
this.coursesObserver && this.coursesObserver.off();
|
this.coursesObserver && this.coursesObserver.off();
|
||||||
this.downloadButtonObserver && this.downloadButtonObserver.off();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
<h2>{{ 'addon.block_sitemainmenu.pluginname' | translate }}</h2>
|
<h2>{{ 'addon.block_sitemainmenu.pluginname' | translate }}</h2>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
||||||
<ion-item text-wrap *ngIf="block.summary">
|
<ng-container *ngIf="mainMenuBlock">
|
||||||
<core-format-text [text]="block.summary"></core-format-text>
|
<ion-item text-wrap *ngIf="mainMenuBlock.summary">
|
||||||
</ion-item>
|
<core-format-text [text]="mainMenuBlock.summary"></core-format-text>
|
||||||
|
</ion-item>
|
||||||
|
|
||||||
<core-course-module *ngFor="let module of block.modules" [module]="module" [courseId]="siteHomeId" [downloadEnabled]="true" [section]="block"></core-course-module>
|
<core-course-module *ngFor="let module of mainMenuBlock.modules" [module]="module" [courseId]="siteHomeId" [downloadEnabled]="downloadEnabled" [section]="mainMenuBlock"></core-course-module>
|
||||||
|
</ng-container>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit, Injector } from '@angular/core';
|
import { Component, OnInit, Injector, Input } from '@angular/core';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreCourseProvider } from '@core/course/providers/course';
|
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||||
|
@ -28,7 +28,9 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
|
||||||
templateUrl: 'addon-block-sitemainmenu.html'
|
templateUrl: 'addon-block-sitemainmenu.html'
|
||||||
})
|
})
|
||||||
export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent implements OnInit {
|
export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent implements OnInit {
|
||||||
block: any;
|
@Input() downloadEnabled: boolean;
|
||||||
|
|
||||||
|
mainMenuBlock: any;
|
||||||
siteHomeId: number;
|
siteHomeId: number;
|
||||||
|
|
||||||
protected fetchContentDefaultError = 'Error getting main menu data.';
|
protected fetchContentDefaultError = 'Error getting main menu data.';
|
||||||
|
@ -60,9 +62,9 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
|
||||||
promises.push(this.courseProvider.invalidateSections(this.siteHomeId));
|
promises.push(this.courseProvider.invalidateSections(this.siteHomeId));
|
||||||
promises.push(this.siteHomeProvider.invalidateNewsForum(this.siteHomeId));
|
promises.push(this.siteHomeProvider.invalidateNewsForum(this.siteHomeId));
|
||||||
|
|
||||||
if (this.block && this.block.modules) {
|
if (this.mainMenuBlock && this.mainMenuBlock.modules) {
|
||||||
// Invalidate modules prefetch data.
|
// Invalidate modules prefetch data.
|
||||||
promises.push(this.prefetchDelegate.invalidateModules(this.block.modules, this.siteHomeId));
|
promises.push(this.prefetchDelegate.invalidateModules(this.mainMenuBlock.modules, this.siteHomeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
|
@ -75,11 +77,11 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
|
||||||
*/
|
*/
|
||||||
protected fetchContent(): Promise<any> {
|
protected fetchContent(): Promise<any> {
|
||||||
return this.courseProvider.getSections(this.siteHomeId, false, true).then((sections) => {
|
return this.courseProvider.getSections(this.siteHomeId, false, true).then((sections) => {
|
||||||
this.block = sections.find((section) => section.section == 0);
|
this.mainMenuBlock = sections.find((section) => section.section == 0);
|
||||||
|
|
||||||
if (this.block) {
|
if (this.mainMenuBlock) {
|
||||||
this.block.hasContent = this.courseHelper.sectionHasContent(this.block);
|
this.mainMenuBlock.hasContent = this.courseHelper.sectionHasContent(this.mainMenuBlock);
|
||||||
this.courseHelper.addHandlerDataForModules([this.block], this.siteHomeId);
|
this.courseHelper.addHandlerDataForModules([this.mainMenuBlock], this.siteHomeId);
|
||||||
|
|
||||||
// Check if Site Home displays announcements. If so, remove it from the main menu block.
|
// Check if Site Home displays announcements. If so, remove it from the main menu block.
|
||||||
const currentSite = this.sitesProvider.getCurrentSite(),
|
const currentSite = this.sitesProvider.getCurrentSite(),
|
||||||
|
@ -92,15 +94,15 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
|
||||||
hasNewsItem = items.find((item) => { return item == '0'; });
|
hasNewsItem = items.find((item) => { return item == '0'; });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNewsItem && this.block.modules) {
|
if (hasNewsItem && this.mainMenuBlock.modules) {
|
||||||
// Remove forum activity (news one only) from the main menu block to prevent duplicates.
|
// Remove forum activity (news one only) from the main menu block to prevent duplicates.
|
||||||
return this.siteHomeProvider.getNewsForum(this.siteHomeId).then((forum) => {
|
return this.siteHomeProvider.getNewsForum(this.siteHomeId).then((forum) => {
|
||||||
// Search the module that belongs to site news.
|
// Search the module that belongs to site news.
|
||||||
for (let i = 0; i < this.block.modules.length; i++) {
|
for (let i = 0; i < this.mainMenuBlock.modules.length; i++) {
|
||||||
const module = this.block.modules[i];
|
const module = this.mainMenuBlock.modules[i];
|
||||||
|
|
||||||
if (module.modname == 'forum' && module.instance == forum.id) {
|
if (module.modname == 'forum' && module.instance == forum.id) {
|
||||||
this.block.modules.splice(i, 1);
|
this.mainMenuBlock.modules.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit, OnDestroy, Injector, Input } from '@angular/core';
|
import { Component, OnInit, OnDestroy, Injector, Input, OnChanges, SimpleChange } from '@angular/core';
|
||||||
import { CoreEventsProvider } from '@providers/events';
|
import { CoreEventsProvider } from '@providers/events';
|
||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
|
@ -30,7 +30,7 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
|
||||||
selector: 'addon-block-starredcourses',
|
selector: 'addon-block-starredcourses',
|
||||||
templateUrl: 'addon-block-starredcourses.html'
|
templateUrl: 'addon-block-starredcourses.html'
|
||||||
})
|
})
|
||||||
export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnDestroy {
|
export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
@Input() downloadEnabled: boolean;
|
@Input() downloadEnabled: boolean;
|
||||||
|
|
||||||
courses = [];
|
courses = [];
|
||||||
|
@ -41,7 +41,6 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
|
||||||
|
|
||||||
protected prefetchIconsInitialized = false;
|
protected prefetchIconsInitialized = false;
|
||||||
protected isDestroyed;
|
protected isDestroyed;
|
||||||
protected downloadButtonObserver;
|
|
||||||
protected coursesObserver;
|
protected coursesObserver;
|
||||||
protected courseIds = [];
|
protected courseIds = [];
|
||||||
protected fetchContentDefaultError = 'Error getting starred courses data.';
|
protected fetchContentDefaultError = 'Error getting starred courses data.';
|
||||||
|
@ -59,18 +58,6 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// Refresh the enabled flags if enabled.
|
|
||||||
this.downloadButtonObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED,
|
|
||||||
(data) => {
|
|
||||||
const wasEnabled = this.downloadEnabled;
|
|
||||||
|
|
||||||
this.downloadEnabled = data.enabled;
|
|
||||||
|
|
||||||
if (!wasEnabled && this.downloadEnabled && this.loaded) {
|
|
||||||
// Download all courses is enabled now, initialize it.
|
|
||||||
this.initPrefetchCoursesIcons();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => {
|
this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => {
|
||||||
this.refreshContent();
|
this.refreshContent();
|
||||||
|
@ -79,6 +66,16 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
|
||||||
super.ngOnInit();
|
super.ngOnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect changes on input properties.
|
||||||
|
*/
|
||||||
|
ngOnChanges(changes: {[name: string]: SimpleChange}): void {
|
||||||
|
if (changes.downloadEnabled && !changes.downloadEnabled.previousValue && this.downloadEnabled && this.loaded) {
|
||||||
|
// Download all courses is enabled now, initialize it.
|
||||||
|
this.initPrefetchCoursesIcons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the invalidate content function.
|
* Perform the invalidate content function.
|
||||||
*
|
*
|
||||||
|
@ -155,6 +152,5 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.isDestroyed = true;
|
this.isDestroyed = true;
|
||||||
this.coursesObserver && this.coursesObserver.off();
|
this.coursesObserver && this.coursesObserver.off();
|
||||||
this.downloadButtonObserver && this.downloadButtonObserver.off();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, Input, OnInit, Injector, ViewChild, OnDestroy } from '@angular/core';
|
import { Component, Input, OnInit, Injector, ViewChild, OnDestroy, DoCheck, KeyValueDiffers } from '@angular/core';
|
||||||
import { CoreBlockDelegate } from '../../providers/delegate';
|
import { CoreBlockDelegate } from '../../providers/delegate';
|
||||||
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
|
import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-component';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
@ -25,7 +25,7 @@ import { CoreEventsProvider } from '@providers/events';
|
||||||
selector: 'core-block',
|
selector: 'core-block',
|
||||||
templateUrl: 'core-block.html'
|
templateUrl: 'core-block.html'
|
||||||
})
|
})
|
||||||
export class CoreBlockComponent implements OnInit, OnDestroy {
|
export class CoreBlockComponent implements OnInit, OnDestroy, DoCheck {
|
||||||
@ViewChild(CoreDynamicComponent) dynamicComponent: CoreDynamicComponent;
|
@ViewChild(CoreDynamicComponent) dynamicComponent: CoreDynamicComponent;
|
||||||
|
|
||||||
@Input() block: any; // The block to render.
|
@Input() block: any; // The block to render.
|
||||||
|
@ -40,8 +40,12 @@ export class CoreBlockComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
blockSubscription: Subscription;
|
blockSubscription: Subscription;
|
||||||
|
|
||||||
constructor(protected injector: Injector, protected blockDelegate: CoreBlockDelegate,
|
protected differ: any; // To detect changes in the data input.
|
||||||
protected eventsProvider: CoreEventsProvider) { }
|
|
||||||
|
constructor(protected injector: Injector, protected blockDelegate: CoreBlockDelegate, differs: KeyValueDiffers,
|
||||||
|
protected eventsProvider: CoreEventsProvider) {
|
||||||
|
this.differ = differs.find([]).create();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
|
@ -57,6 +61,19 @@ export class CoreBlockComponent implements OnInit, OnDestroy {
|
||||||
this.initBlock();
|
this.initBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect and act upon changes that Angular can’t or won’t detect on its own (objects and arrays).
|
||||||
|
*/
|
||||||
|
ngDoCheck(): void {
|
||||||
|
if (this.data) {
|
||||||
|
// Check if there's any change in the extraData object.
|
||||||
|
const changes = this.differ.diff(this.extraData);
|
||||||
|
if (changes) {
|
||||||
|
this.data = Object.assign(this.data, this.extraData || {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get block display data and initialises the block once this is available. If the block is not
|
* Get block display data and initialises the block once this is available. If the block is not
|
||||||
* supported at the moment, try again if the available blocks are updated (because it comes
|
* supported at the moment, try again if the available blocks are updated (because it comes
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<ion-refresher [enabled]="!!siteHomeComponent && siteHomeComponent.dataLoaded" (ionRefresh)="siteHomeComponent.doRefresh($event)">
|
<ion-refresher [enabled]="!!siteHomeComponent && siteHomeComponent.dataLoaded" (ionRefresh)="siteHomeComponent.doRefresh($event)">
|
||||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||||
</ion-refresher>
|
</ion-refresher>
|
||||||
<core-sitehome-index></core-sitehome-index>
|
<core-sitehome-index [downloadEnabled]="downloadEnabled"></core-sitehome-index>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</core-tab>
|
</core-tab>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<!-- Site home blocks. -->
|
<!-- Site home blocks. -->
|
||||||
<ng-container *ngFor="let block of blocks">
|
<ng-container *ngFor="let block of blocks">
|
||||||
<core-block [block]="block" contextLevel="course" [instanceId]="siteHomeId"></core-block>
|
<core-block [block]="block" contextLevel="course" [instanceId]="siteHomeId" [extraData]="{'downloadEnabled': downloadEnabled}"></core-block>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, OnInit, ViewChildren, QueryList } from '@angular/core';
|
import { Component, OnInit, ViewChildren, QueryList, Input } from '@angular/core';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
import { CoreCourseProvider } from '@core/course/providers/course';
|
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||||
|
@ -31,6 +31,7 @@ import { CoreSite } from '@classes/site';
|
||||||
})
|
})
|
||||||
export class CoreSiteHomeIndexComponent implements OnInit {
|
export class CoreSiteHomeIndexComponent implements OnInit {
|
||||||
@ViewChildren(CoreBlockComponent) blocksComponents: QueryList<CoreBlockComponent>;
|
@ViewChildren(CoreBlockComponent) blocksComponents: QueryList<CoreBlockComponent>;
|
||||||
|
@Input() downloadEnabled: boolean;
|
||||||
|
|
||||||
dataLoaded = false;
|
dataLoaded = false;
|
||||||
section: any;
|
section: any;
|
||||||
|
@ -40,7 +41,6 @@ export class CoreSiteHomeIndexComponent implements OnInit {
|
||||||
siteHomeId: number;
|
siteHomeId: number;
|
||||||
currentSite: CoreSite;
|
currentSite: CoreSite;
|
||||||
blocks = [];
|
blocks = [];
|
||||||
downloadEnabled: boolean;
|
|
||||||
|
|
||||||
constructor(private domUtils: CoreDomUtilsProvider, sitesProvider: CoreSitesProvider,
|
constructor(private domUtils: CoreDomUtilsProvider, sitesProvider: CoreSitesProvider,
|
||||||
private courseProvider: CoreCourseProvider, private courseHelper: CoreCourseHelperProvider,
|
private courseProvider: CoreCourseProvider, private courseHelper: CoreCourseHelperProvider,
|
||||||
|
@ -53,7 +53,6 @@ export class CoreSiteHomeIndexComponent implements OnInit {
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.downloadEnabled = !this.currentSite.isOfflineDisabled();
|
|
||||||
this.loadContent().finally(() => {
|
this.loadContent().finally(() => {
|
||||||
this.dataLoaded = true;
|
this.dataLoaded = true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue