MOBILE-2700 dashboard: Get dashboard blocks info

main
Pau Ferrer Ocaña 2018-10-23 12:03:19 +02:00
parent d07cbac9de
commit 0c9af8ee0e
20 changed files with 463 additions and 128 deletions

View File

@ -20,7 +20,9 @@
"addon.block_myoverview.nocoursesinprogress": "block_myoverview",
"addon.block_myoverview.nocoursespast": "block_myoverview",
"addon.block_myoverview.past": "block_myoverview",
"addon.block_myoverview.pluginname": "block_myoverview",
"addon.block_myoverview.title": "block_myoverview",
"addon.block_recentcourses.nocourses": "moodle",
"addon.block_sitemainmenu.pluginname": "block_site_main_menu",
"addon.block_timeline.duedate": "block_timeline",
"addon.block_timeline.next30days": "block_timeline",
@ -30,6 +32,7 @@
"addon.block_timeline.nocoursesinprogress": "block_timeline",
"addon.block_timeline.noevents": "block_timeline",
"addon.block_timeline.overdue": "block_timeline",
"addon.block_timeline.pluginname": "block_timeline",
"addon.block_timeline.sortbycourses": "block_timeline",
"addon.block_timeline.sortbydates": "block_timeline",
"addon.calendar.calendar": "calendar",
@ -1192,7 +1195,6 @@
"core.courses.searchcoursesadvice": "local_moodlemobileapp",
"core.courses.selfenrolment": "local_moodlemobileapp",
"core.courses.sendpaymentbutton": "enrol_paypal",
"core.courses.timeline": "block_dashboard",
"core.courses.totalcoursesearchresults": "local_moodlemobileapp",
"core.currentdevice": "local_moodlemobileapp",
"core.datastoredoffline": "local_moodlemobileapp",

View File

@ -0,0 +1,47 @@
// (C) Copyright 2015 Martin Dougiamas
//
// 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 { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreCoursesComponentsModule } from '@core/courses/components/components.module';
import { AddonBlockMyOverviewComponent } from './myoverview/myoverview';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
@NgModule({
declarations: [
AddonBlockMyOverviewComponent
],
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild(),
CoreComponentsModule,
CoreDirectivesModule,
CoreCoursesComponentsModule,
CoreCourseComponentsModule
],
providers: [
],
exports: [
AddonBlockMyOverviewComponent
],
entryComponents: [
AddonBlockMyOverviewComponent
]
})
export class AddonBlockMyOverviewComponentsModule {}

View File

@ -6,6 +6,9 @@
</core-navbar-buttons>
<core-loading [hideUntil]="loaded" class="core-loading-center">
<ion-item-divider color="light">
<h2>{{ 'addon.block_myoverview.pluginname' | translate }}</h2>
</ion-item-divider>
<div padding ion-row justify-content-end [hidden]="showFilter">
<!-- "Time" selector. -->
<ion-col [hidden]="!showSelectorFilter">

View File

@ -2,11 +2,12 @@
"all": "All",
"future": "Future",
"inprogress": "In progress",
"past": "Past",
"lastaccessed": "Last accessed",
"morecourses": "More courses",
"nocoursesfuture": "No future courses",
"nocoursesinprogress": "No in progress courses",
"nocoursespast": "No past courses",
"lastaccessed": "Last accessed",
"past": "Past",
"pluginname": "Course Overview",
"title": "Title"
}

View File

@ -15,22 +15,26 @@
import { NgModule } from '@angular/core';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreComponentsModule } from '@components/components.module';
import { CoreCoursesComponentsModule } from '@core/courses/components/components.module';
import { AddonBlockMyOverviewComponent } from './component/myoverview';
import { CoreBlockDelegate } from '@core/block/providers/delegate';
import { AddonBlockMyOverviewComponentsModule } from './components/components.module';
import { AddonBlockMyOverviewHandler } from './providers/block-handler';
@NgModule({
declarations: [
AddonBlockMyOverviewComponent
],
imports: [
IonicModule,
CoreComponentsModule,
CoreCoursesComponentsModule,
AddonBlockMyOverviewComponentsModule,
TranslateModule.forChild()
],
exports: [
AddonBlockMyOverviewComponent
],
providers: [
AddonBlockMyOverviewHandler
]
})
export class AddonBlockMyOverviewModule {}
export class AddonBlockMyOverviewModule {
constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockMyOverviewHandler) {
blockDelegate.registerHandler(blockHandler);
}
}

View File

@ -0,0 +1,59 @@
// (C) Copyright 2015 Martin Dougiamas
//
// 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 { Injectable, Injector } from '@angular/core';
import { CoreBlockHandler, CoreBlockHandlerData } from '@core/block/providers/delegate';
import { CoreCoursesProvider } from '@core/courses/providers/courses';
import { AddonBlockMyOverviewComponent } from '../components/myoverview/myoverview';
/**
* Course nav handler.
*/
@Injectable()
export class AddonBlockMyOverviewHandler implements CoreBlockHandler {
name = 'AddonBlockMyOverviewHandler';
blockName = 'myoverview';
constructor(private coursesProvider: CoreCoursesProvider) {
// Nothing to do.
}
/**
* Check if the handler is enabled on a site level.
*
* @return {boolean} Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean | Promise<boolean> {
return !this.coursesProvider.isMyCoursesDisabledInSite();
}
/**
* Returns the data needed to render the block.
*
* @param {Injector} injector Injector.
* @param {any} block The block to render.
* @param {string} contextLevel The context where the block will be used.
* @param {number} instanceId The instance ID associated with the context level.
* @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data.
*/
getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number)
: CoreBlockHandlerData | Promise<CoreBlockHandlerData> {
return {
title: 'addon.block_myoverview.pluginname',
class: 'addon-block-myoverview',
component: AddonBlockMyOverviewComponent
};
}
}

View File

@ -0,0 +1,53 @@
// (C) Copyright 2015 Martin Dougiamas
//
// 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 { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CorePipesModule } from '@pipes/pipes.module';
import { CoreCoursesComponentsModule } from '@core/courses/components/components.module';
import { AddonBlockTimelineComponent } from './timeline/timeline';
import { AddonBlockTimelineEventsComponent } from './events/events';
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
@NgModule({
declarations: [
AddonBlockTimelineComponent,
AddonBlockTimelineEventsComponent
],
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild(),
CoreComponentsModule,
CoreDirectivesModule,
CorePipesModule,
CoreCoursesComponentsModule,
CoreCourseComponentsModule
],
providers: [
],
exports: [
AddonBlockTimelineComponent,
AddonBlockTimelineEventsComponent
],
entryComponents: [
AddonBlockTimelineComponent,
AddonBlockTimelineEventsComponent
]
})
export class AddonBlockTimelineComponentsModule {}

View File

@ -1,34 +1,39 @@
<div padding [hidden]="!loaded" ion-row>
<ion-col>
<ion-select text-start [(ngModel)]="filter" (ngModelChange)="switchFilter()" interface="popover" class="core-button-select">
<ion-option value="all">{{ 'core.all' | translate }}</ion-option>
<ion-option value="overdue">{{ 'addon.block_timeline.overdue' | translate }}</ion-option>
<ion-option disabled value="disabled">{{ 'addon.block_timeline.duedate' | translate }}</ion-option>
<ion-option value="next7days">{{ 'addon.block_timeline.next7days' | translate }}</ion-option>
<ion-option value="next30days">{{ 'addon.block_timeline.next30days' | translate }}</ion-option>
<ion-option value="next3months">{{ 'addon.block_timeline.next3months' | translate }}</ion-option>
<ion-option value="next6months">{{ 'addon.block_timeline.next6months' | translate }}</ion-option>
</ion-select>
</ion-col>
<ion-col>
<ion-select text-start [(ngModel)]="sort" (ngModelChange)="switchSort()" interface="popover" class="core-button-select">
<ion-option value="sortbydates">{{ 'addon.block_timeline.sortbydates' | translate }}</ion-option>
<ion-option value="sortbycourses">{{ 'addon.block_timeline.sortbycourses' | translate }}</ion-option>
</ion-select>
</ion-col>
</div>
<core-loading [hideUntil]="loaded && timeline.loaded" [hidden]="sort != 'sortbydates'" class="core-loading-center">
<addon-block-timeline-events [events]="timeline.events" showCourse="true" [canLoadMore]="timeline.canLoadMore" (loadMore)="loadMoreTimeline()" [from]="dataFrom" [to]="dataTo"></addon-block-timeline-events>
</core-loading>
<core-loading [hideUntil]="loaded && timelineCourses.loaded" [hidden]="sort != 'sortbycourses'" class="core-loading-center">
<ion-grid no-padding>
<ion-row no-padding>
<ion-col *ngFor="let course of timelineCourses.courses" no-padding col-12 col-md-6>
<core-courses-course-progress [course]="course">
<addon-block-timeline-events [events]="course.events" [canLoadMore]="course.canLoadMore" (loadMore)="loadMoreCourse(course)" [from]="dataFrom" [to]="dataTo"></addon-block-timeline-events>
</core-courses-course-progress>
</ion-col>
</ion-row>
</ion-grid>
<core-empty-box *ngIf="timelineCourses.courses.length == 0" image="assets/img/icons/courses.svg" [message]="'addon.block_timeline.nocoursesinprogress' | translate"></core-empty-box>
<core-loading [hideUntil]="loaded" class="core-loading-center">
<ion-item-divider color="light">
<h2>{{ 'addon.block_timeline.pluginname' | translate }}</h2>
</ion-item-divider>
<div padding ion-row>
<ion-col>
<ion-select text-start [(ngModel)]="filter" (ngModelChange)="switchFilter()" interface="popover" class="core-button-select">
<ion-option value="all">{{ 'core.all' | translate }}</ion-option>
<ion-option value="overdue">{{ 'addon.block_timeline.overdue' | translate }}</ion-option>
<ion-option disabled value="disabled">{{ 'addon.block_timeline.duedate' | translate }}</ion-option>
<ion-option value="next7days">{{ 'addon.block_timeline.next7days' | translate }}</ion-option>
<ion-option value="next30days">{{ 'addon.block_timeline.next30days' | translate }}</ion-option>
<ion-option value="next3months">{{ 'addon.block_timeline.next3months' | translate }}</ion-option>
<ion-option value="next6months">{{ 'addon.block_timeline.next6months' | translate }}</ion-option>
</ion-select>
</ion-col>
<ion-col>
<ion-select text-start [(ngModel)]="sort" (ngModelChange)="switchSort()" interface="popover" class="core-button-select">
<ion-option value="sortbydates">{{ 'addon.block_timeline.sortbydates' | translate }}</ion-option>
<ion-option value="sortbycourses">{{ 'addon.block_timeline.sortbycourses' | translate }}</ion-option>
</ion-select>
</ion-col>
</div>
<core-loading [hideUntil]="timeline.loaded" [hidden]="sort != 'sortbydates'" class="core-loading-center">
<addon-block-timeline-events [events]="timeline.events" showCourse="true" [canLoadMore]="timeline.canLoadMore" (loadMore)="loadMoreTimeline()" [from]="dataFrom" [to]="dataTo"></addon-block-timeline-events>
</core-loading>
<core-loading [hideUntil]="timelineCourses.loaded" [hidden]="sort != 'sortbycourses'" class="core-loading-center">
<ion-grid no-padding>
<ion-row no-padding>
<ion-col *ngFor="let course of timelineCourses.courses" no-padding col-12 col-md-6>
<core-courses-course-progress [course]="course">
<addon-block-timeline-events [events]="course.events" [canLoadMore]="course.canLoadMore" (loadMore)="loadMoreCourse(course)" [from]="dataFrom" [to]="dataTo"></addon-block-timeline-events>
</core-courses-course-progress>
</ion-col>
</ion-row>
</ion-grid>
<core-empty-box *ngIf="timelineCourses.courses.length == 0" image="assets/img/icons/courses.svg" [message]="'addon.block_timeline.nocoursesinprogress' | translate"></core-empty-box>
</core-loading>
</core-loading>

View File

@ -7,6 +7,7 @@
"nocoursesinprogress": "No in progress courses",
"noevents": "No upcoming activities due",
"overdue": "Overdue",
"pluginname": "Timeline",
"sortbycourses": "Sort by courses",
"sortbydates": "Sort by dates"
}

View File

@ -0,0 +1,59 @@
// (C) Copyright 2015 Martin Dougiamas
//
// 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 { Injectable, Injector } from '@angular/core';
import { CoreBlockHandler, CoreBlockHandlerData } from '@core/block/providers/delegate';
import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline';
import { AddonBlockTimelineComponent } from '../components/timeline/timeline';
/**
* Course nav handler.
*/
@Injectable()
export class AddonBlockTimelineHandler implements CoreBlockHandler {
name = 'AddonBlockTimelineHandler';
blockName = 'timeline';
constructor(private timelineProvider: AddonBlockTimelineProvider) {
// Nothing to do.
}
/**
* Check if the handler is enabled on a site level.
*
* @return {boolean} Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean | Promise<boolean> {
return this.timelineProvider.isAvailable();
}
/**
* Returns the data needed to render the block.
*
* @param {Injector} injector Injector.
* @param {any} block The block to render.
* @param {string} contextLevel The context where the block will be used.
* @param {number} instanceId The instance ID associated with the context level.
* @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data.
*/
getDisplayData?(injector: Injector, block: any, contextLevel: string, instanceId: number)
: CoreBlockHandlerData | Promise<CoreBlockHandlerData> {
return {
title: 'addon.block_timeline.pluginname',
class: 'addon-block-timeline',
component: AddonBlockTimelineComponent
};
}
}

View File

@ -15,33 +15,28 @@
import { NgModule } from '@angular/core';
import { IonicModule } from 'ionic-angular';
import { TranslateModule } from '@ngx-translate/core';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CorePipesModule } from '@pipes/pipes.module';
import { CoreCoursesComponentsModule } from '@core/courses/components/components.module';
import { AddonBlockTimelineComponent } from './components/timeline/timeline';
import { AddonBlockTimelineEventsComponent } from './components/events/events';
import { CoreBlockDelegate } from '@core/block/providers/delegate';
import { AddonBlockTimelineComponentsModule } from './components/components.module';
import { AddonBlockTimelineProvider } from './providers/timeline';
import { AddonBlockTimelineHandler } from './providers/block-handler';
@NgModule({
declarations: [
AddonBlockTimelineComponent,
AddonBlockTimelineEventsComponent
],
imports: [
IonicModule,
CoreComponentsModule,
CoreDirectivesModule,
CorePipesModule,
CoreCoursesComponentsModule,
AddonBlockTimelineComponentsModule,
TranslateModule.forChild()
],
exports: [
AddonBlockTimelineComponent,
AddonBlockTimelineEventsComponent
],
providers: [
AddonBlockTimelineProvider
AddonBlockTimelineProvider,
AddonBlockTimelineHandler
]
})
export class AddonBlockTimelineModule {}
export class AddonBlockTimelineModule {
constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockTimelineHandler) {
blockDelegate.registerHandler(blockHandler);
}
}

View File

@ -20,6 +20,7 @@
"addon.block_myoverview.nocoursesinprogress": "No in progress courses",
"addon.block_myoverview.nocoursespast": "No past courses",
"addon.block_myoverview.past": "Past",
"addon.block_myoverview.pluginname": "Course Overview",
"addon.block_myoverview.title": "Title",
"addon.block_sitemainmenu.pluginname": "Main menu",
"addon.block_timeline.duedate": "Due date",
@ -30,6 +31,7 @@
"addon.block_timeline.nocoursesinprogress": "No in progress courses",
"addon.block_timeline.noevents": "No upcoming activities due",
"addon.block_timeline.overdue": "Overdue",
"addon.block_timeline.pluginname": "Timeline",
"addon.block_timeline.sortbycourses": "Sort by courses",
"addon.block_timeline.sortbydates": "Sort by dates",
"addon.calendar.calendar": "Calendar",
@ -1192,7 +1194,6 @@
"core.courses.searchcoursesadvice": "You can use the search courses button to find courses to access as a guest or enrol yourself in courses that allow it.",
"core.courses.selfenrolment": "Self enrolment",
"core.courses.sendpaymentbutton": "Send payment via PayPal",
"core.courses.timeline": "Timeline",
"core.courses.totalcoursesearchresults": "Total courses: {{$a}}",
"core.currentdevice": "Current device",
"core.datastoredoffline": "Data stored in the device because it couldn't be sent. It will be sent automatically later.",

View File

@ -287,6 +287,7 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges, OnDe
this.slideChanged();
setTimeout(() => {
this.calculateTabBarHeight();
this.slides.update();
this.slides.resize();

View File

@ -28,6 +28,5 @@
"searchcoursesadvice": "You can use the search courses button to find courses to access as a guest or enrol yourself in courses that allow it.",
"selfenrolment": "Self enrolment",
"sendpaymentbutton": "Send payment via PayPal",
"timeline": "Timeline",
"totalcoursesearchresults": "Total courses: {{$a}}"
}

View File

@ -23,26 +23,23 @@
</ng-template>
</core-tab>
<!-- Courses tab. -->
<core-tab [show]="coursesEnabled" [title]="'core.courses.courses' | translate">
<!-- Dashboard tab. -->
<core-tab [show]="dashboardEnabled" [title]="'core.courses.mymoodle' | translate">
<ng-template>
<ion-content>
<ion-refresher [enabled]="!!blockMyOverview && blockMyOverview.loaded" (ionRefresh)="blockMyOverview.doRefresh($event)">
<ion-refresher [enabled]="dashboardLoaded" (ionRefresh)="refreshDashboard($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<addon-block-myoverview></addon-block-myoverview>
</ion-content>
</ng-template>
</core-tab>
<core-loading [hideUntil]="dashboardLoaded" class="core-loading-center">
<ion-list>
<!-- Dashboard blocks. -->
<ng-container *ngFor="let block of blocks">
<core-block [block]="block" contextLevel="user" [instanceId]="userId"></core-block>
</ng-container>
</ion-list>
<!-- Timeline tab. -->
<core-tab [show]="timelineEnabled" [title]="'core.courses.timeline' | translate">
<ng-template>
<ion-content>
<ion-refresher [enabled]="!!blockTimeline && blockTimeline.loaded" (ionRefresh)="blockTimeline.doRefresh($event)">
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher>
<addon-block-timeline></addon-block-timeline>
<core-empty-box *ngIf="blocks.length == 0" icon="qr-scanner" [message]="'core.course.nocontentavailable' | translate"></core-empty-box>
</core-loading>
</ion-content>
</ng-template>
</core-tab>

View File

@ -19,9 +19,8 @@ import { CoreCoursesDashboardPage } from './dashboard';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreCoursesComponentsModule } from '../../components/components.module';
import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module';
import { AddonBlockTimelineModule } from '@addon/block/timeline/timeline.module';
import { CoreSiteHomeComponentsModule } from '@core/sitehome/components/components.module';
import { CoreBlockComponentsModule } from '@core/block/components/components.module';
@NgModule({
declarations: [
@ -32,8 +31,7 @@ import { CoreSiteHomeComponentsModule } from '@core/sitehome/components/componen
CoreDirectivesModule,
CoreCoursesComponentsModule,
CoreSiteHomeComponentsModule,
AddonBlockMyOverviewModule,
AddonBlockTimelineModule,
CoreBlockComponentsModule,
IonicPageModule.forChild(CoreCoursesDashboardPage),
TranslateModule.forChild()
],

View File

@ -12,17 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, OnDestroy, ViewChild } from '@angular/core';
import { Component, OnDestroy, ViewChild, ViewChildren, QueryList } from '@angular/core';
import { IonicPage, NavController } from 'ionic-angular';
import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCoursesProvider } from '../../providers/courses';
import { CoreSiteHomeProvider } from '@core/sitehome/providers/sitehome';
import { AddonBlockMyOverviewComponent } from '@addon/block/myoverview/component/myoverview';
import { AddonBlockTimelineComponent } from '@addon/block/timeline/components/timeline/timeline';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTabsComponent } from '@components/tabs/tabs';
import { CoreBlockDelegate } from '@core/block/providers/delegate';
import { CoreBlockComponent } from '@core/block/components/block/block';
import { CoreSiteHomeProvider } from '@core/sitehome/providers/sitehome';
import { CoreSiteHomeIndexComponent } from '@core/sitehome/components/index/index';
import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline';
import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCoursesDashboardProvider } from '../../providers/dashboard';
/**
* Page that displays the dashboard.
@ -35,25 +36,26 @@ import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/time
export class CoreCoursesDashboardPage implements OnDestroy {
@ViewChild(CoreTabsComponent) tabsComponent: CoreTabsComponent;
@ViewChild(CoreSiteHomeIndexComponent) siteHomeComponent: CoreSiteHomeIndexComponent;
@ViewChild(AddonBlockMyOverviewComponent) blockMyOverview: AddonBlockMyOverviewComponent;
@ViewChild(AddonBlockTimelineComponent) blockTimeline: AddonBlockTimelineComponent;
@ViewChildren(CoreBlockComponent) blocksComponents: QueryList<CoreBlockComponent>;
firstSelectedTab: number;
siteHomeEnabled = false;
timelineEnabled = false;
coursesEnabled = false;
tabsReady = false;
searchEnabled: boolean;
tabs = [];
siteName: string;
blocks: any[];
dashboardEnabled = false;
userId: number;
dashboardLoaded = false;
protected isDestroyed;
protected updateSiteObserver;
protected courseIds = '';
constructor(private navCtrl: NavController, private coursesProvider: CoreCoursesProvider,
private sitesProvider: CoreSitesProvider, private siteHomeProvider: CoreSiteHomeProvider,
private eventsProvider: CoreEventsProvider, private timelineProvider: AddonBlockTimelineProvider) {
private eventsProvider: CoreEventsProvider, private dashboardProvider: CoreCoursesDashboardProvider,
private domUtils: CoreDomUtilsProvider, private blockDelegate: CoreBlockDelegate) {
this.loadSiteName();
}
@ -71,25 +73,21 @@ export class CoreCoursesDashboardPage implements OnDestroy {
const promises = [];
// Decide which tab to load first.
promises.push(this.siteHomeProvider.isAvailable().then((enabled) => {
this.siteHomeEnabled = enabled;
}));
promises.push(this.timelineProvider.isAvailable().then((enabled) => {
this.timelineEnabled = enabled;
}));
this.coursesEnabled = !this.coursesProvider.isMyCoursesDisabledInSite();
promises.push(this.loadDashboardContent());
// Decide which tab to load first.
Promise.all(promises).finally(() => {
if (this.siteHomeEnabled && (this.coursesEnabled || this.timelineEnabled)) {
if (this.siteHomeEnabled && this.dashboardEnabled) {
const site = this.sitesProvider.getCurrentSite(),
displaySiteHome = site.getInfo() && site.getInfo().userhomepage === 0;
this.firstSelectedTab = displaySiteHome ? 0 : 1;
} else {
this.firstSelectedTab = this.siteHomeEnabled ? 1 : 0;
this.firstSelectedTab = 0;
}
this.tabsReady = true;
@ -124,6 +122,72 @@ export class CoreCoursesDashboardPage implements OnDestroy {
this.siteName = this.sitesProvider.getCurrentSite().getInfo().sitename;
}
/**
* Convenience function to fetch the dashboard data.
*
* @return {Promise<any>} Promise resolved when done.
*/
protected loadDashboardContent(): Promise<any> {
return this.dashboardProvider.isAvailable().then((enabled) => {
if (enabled) {
this.userId = this.sitesProvider.getCurrentSiteUserId();
return this.dashboardProvider.getDashboardBlocks().then((blocks) => {
this.blocks = blocks;
}).catch((error) => {
this.domUtils.showErrorModal(error);
// Cannot get the blocks, just show dashboard if needed.
this.loadFallbackBlocks();
});
}
// Not enabled, check separated tabs.
this.loadFallbackBlocks();
}).finally(() => {
this.dashboardEnabled = this.blockDelegate.hasSupportedBlock(this.blocks);
this.dashboardLoaded = true;
});
}
/**
* Refresh the dashboard data.
*
* @param {any} refresher Refresher.
*/
refreshDashboard(refresher: any): void {
const promises = [];
promises.push(this.dashboardProvider.invalidateDashboardBlocks());
// Invalidate the blocks.
this.blocksComponents.forEach((blockComponent) => {
promises.push(blockComponent.invalidate().catch(() => {
// Ignore errors.
}));
});
Promise.all(promises).finally(() => {
this.loadDashboardContent().finally(() => {
refresher.complete();
});
});
}
/**
* Load fallback blocks to shown before 3.6 when dashboard blocks are not supported.
*/
protected loadFallbackBlocks(): void {
this.blocks = [
{
name: 'myoverview'
},
{
name: 'timeline'
}
];
}
/**
* Component being destroyed.
*/

View File

@ -13,8 +13,7 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { CoreCoursesProvider } from './courses';
import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline';
import { CoreSitesProvider } from '@providers/sites';
/**
* Service that provides some features regarding course overview.
@ -22,30 +21,69 @@ import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/time
@Injectable()
export class CoreCoursesDashboardProvider {
constructor(private coursesProvider: CoreCoursesProvider, private timelineProvider: AddonBlockTimelineProvider) { }
constructor(private sitesProvider: CoreSitesProvider) { }
protected ROOT_CACHE_KEY = 'CoreCoursesDashboard:';
/**
* Returns whether or not My Overview is available for a certain site.
* Get cache key for dashboard blocks WS calls.
*
* @param {number} [userId] User ID. Default, 0 means current user.
* @return {string} Cache key.
*/
protected getDashboardBlocksCacheKey(userId: number = 0): string {
return this.ROOT_CACHE_KEY + 'blocks:' + userId;
}
/**
* Get dashboard blocks.
*
* @param {number} [userId] User ID. Default, current user.
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<any[]>} Promise resolved with the list of blocks.
* @since 3.6
*/
getDashboardBlocks(userId?: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
const params = {
},
preSets = {
cacheKey: this.getDashboardBlocksCacheKey(userId)
};
if (userId) {
params['userid'] = userId;
}
return site.read('core_block_get_dashboard_blocks', params, preSets).then((result) => {
return result.blocks || [];
});
});
}
/**
* Invalidates dashboard blocks WS call.
*
* @param {number} [userId] User ID. Default, current user.
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<any>} Promise resolved when the data is invalidated.
*/
invalidateDashboardBlocks(userId?: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.invalidateWsCacheForKey(this.getDashboardBlocksCacheKey(userId));
});
}
/**
* Returns whether or not block based Dashboard is available for a certain site.
*
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<boolean>} Promise resolved with true if available, resolved with false or rejected otherwise.
* @since 3.6
*/
isAvailable(siteId?: string): Promise<boolean> {
return this.timelineProvider.isAvailable(siteId);
}
/**
* Check if My Overview is available and not disabled.
*
* @return {Promise<boolean>} Promise resolved with true if enabled, resolved with false otherwise.
*/
isEnabled(): Promise<boolean> {
if (!this.coursesProvider.isMyCoursesDisabledInSite()) {
return this.isAvailable().catch(() => {
return false;
});
}
return Promise.resolve(false);
return this.sitesProvider.getSite(siteId).then((site) => {
return site.wsAvailable('core_block_get_dashboard_blocks');
});
}
}

View File

@ -17,6 +17,7 @@ import { CoreCoursesProvider } from './courses';
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate';
import { CoreCoursesDashboardProvider } from '../providers/dashboard';
import { CoreSiteHomeProvider } from '@core/sitehome/providers/sitehome';
import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline';
/**
* Handler to add Dashboard into main menu.
@ -27,7 +28,7 @@ export class CoreDashboardMainMenuHandler implements CoreMainMenuHandler {
priority = 1100;
constructor(private coursesProvider: CoreCoursesProvider, private dashboardProvider: CoreCoursesDashboardProvider,
private siteHomeProvider: CoreSiteHomeProvider) { }
private siteHomeProvider: CoreSiteHomeProvider, private timelineProvider: AddonBlockTimelineProvider) { }
/**
* Check if the handler is enabled on a site level.
@ -35,20 +36,27 @@ export class CoreDashboardMainMenuHandler implements CoreMainMenuHandler {
* @return {boolean | Promise<boolean>} Whether or not the handler is enabled on a site level.
*/
isEnabled(): boolean | Promise<boolean> {
// Check if my overview is enabled.
return this.dashboardProvider.isEnabled().then((enabled) => {
// Check if 3.6 dashboard is enabled.
return this.dashboardProvider.isAvailable().then((enabled) => {
if (enabled) {
return true;
}
return this.siteHomeProvider.isAvailable().then((enabled) => {
// Show in case siteHome is enabled.
// Check if my overview is enabled.
return this.timelineProvider.isAvailable().then((enabled) => {
if (enabled) {
return true;
}
// My overview not enabled, check if my courses is enabled.
return !this.coursesProvider.isMyCoursesDisabledInSite();
return this.siteHomeProvider.isAvailable().then((enabled) => {
// Show in case siteHome is enabled.
if (enabled) {
return true;
}
// My overview not enabled, check if my courses is enabled.
return !this.coursesProvider.isMyCoursesDisabledInSite();
});
});
});
}