From c94530023a2955d02c472516b14795773eaaabf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 30 Nov 2018 09:46:54 +0100 Subject: [PATCH] MOBILE-2759 compentecy: Fix completed learning plans view --- .../competency/pages/competency/competency.ts | 35 +++-------- src/addon/competency/pages/plan/plan.ts | 46 +++----------- .../competency/pages/planlist/planlist.html | 1 + .../competency/pages/planlist/planlist.ts | 18 +++++- src/addon/competency/providers/competency.ts | 6 +- src/addon/competency/providers/helper.ts | 63 ++++++++++++++++++- 6 files changed, 100 insertions(+), 69 deletions(-) diff --git a/src/addon/competency/pages/competency/competency.ts b/src/addon/competency/pages/competency/competency.ts index 3a20061c3..9552e75a6 100644 --- a/src/addon/competency/pages/competency/competency.ts +++ b/src/addon/competency/pages/competency/competency.ts @@ -19,6 +19,7 @@ import { CoreSitesProvider } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; +import { AddonCompetencyHelperProvider } from '../../providers/helper'; /** * Page that displays a learning plan. @@ -41,7 +42,8 @@ export class AddonCompetencyCompetencyPage { constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService, private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider, - @Optional() private svComponent: CoreSplitViewComponent, private competencyProvider: AddonCompetencyProvider) { + @Optional() private svComponent: CoreSplitViewComponent, private competencyProvider: AddonCompetencyProvider, + private competencyHelperProvider: AddonCompetencyHelperProvider) { this.competencyId = navParams.get('competencyId'); this.planId = navParams.get('planId'); this.courseId = navParams.get('courseId'); @@ -85,11 +87,14 @@ export class AddonCompetencyCompetencyPage { } return promise.then((competency) => { + competency.usercompetencysummary.usercompetency = competency.usercompetencysummary.usercompetencyplan || + competency.usercompetencysummary.usercompetency; this.competency = competency.usercompetencysummary; if (this.planId) { this.planStatus = competency.plan.status; - this.competency.usercompetency.statusname = this.getStatusName(this.competency.usercompetency.status); + this.competency.usercompetency.statusname = + this.competencyHelperProvider.getCompetencyStatusName(this.competency.usercompetency.status); } else { this.competency.usercompetency = this.competency.usercompetencycourse; this.coursemodules = competency.coursemodules; @@ -113,32 +118,6 @@ export class AddonCompetencyCompetencyPage { }); } - /** - * Convenience function to get the review status name translated. - * - * @param {number} status - * @return {string} - */ - protected getStatusName(status: number): string { - let statusTranslateName; - switch (status) { - case AddonCompetencyProvider.REVIEW_STATUS_IDLE: - statusTranslateName = 'idle'; - break; - case AddonCompetencyProvider.REVIEW_STATUS_IN_REVIEW: - statusTranslateName = 'inreview'; - break; - case AddonCompetencyProvider.REVIEW_STATUS_WAITING_FOR_REVIEW: - statusTranslateName = 'waitingforreview'; - break; - default: - // We can use the current status name. - return String(status); - } - - return this.translate.instant('addon.competency.usercompetencystatus_' + statusTranslateName); - } - /** * Refreshes the competency. * diff --git a/src/addon/competency/pages/plan/plan.ts b/src/addon/competency/pages/plan/plan.ts index d82c46dcd..33a01c8b8 100644 --- a/src/addon/competency/pages/plan/plan.ts +++ b/src/addon/competency/pages/plan/plan.ts @@ -14,7 +14,6 @@ import { Component, Optional } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; -import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; @@ -35,10 +34,9 @@ export class AddonCompetencyPlanPage { plan: any; user: any; - constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService, - private appProvider: CoreAppProvider, private domUtils: CoreDomUtilsProvider, - @Optional() private svComponent: CoreSplitViewComponent, private competencyProvider: AddonCompetencyProvider, - private competencyHelperProvider: AddonCompetencyHelperProvider) { + constructor(private navCtrl: NavController, navParams: NavParams, private appProvider: CoreAppProvider, + private domUtils: CoreDomUtilsProvider, @Optional() private svComponent: CoreSplitViewComponent, + private competencyProvider: AddonCompetencyProvider, private competencyHelperProvider: AddonCompetencyHelperProvider) { this.planId = navParams.get('planId'); } @@ -58,11 +56,15 @@ export class AddonCompetencyPlanPage { */ protected fetchLearningPlan(): Promise { return this.competencyProvider.getLearningPlan(this.planId).then((plan) => { - plan.plan.statusname = this.getStatusName(plan.plan.status); + plan.plan.statusname = this.competencyHelperProvider.getPlanStatusName(plan.plan.status); // Get the user profile image. this.competencyHelperProvider.getProfile(plan.plan.userid).then((user) => { this.user = user; }); + + plan.competencies.forEach((competency) => { + competency.usercompetency = competency.usercompetencyplan || competency.usercompetency; + }); this.plan = plan; }).catch((message) => { this.domUtils.showErrorModalDefault(message, 'Error getting learning plan data.'); @@ -83,38 +85,6 @@ export class AddonCompetencyPlanPage { } } - /** - * Convenience function to get the status name translated. - * - * @param {number} status - * @return {string} - */ - protected getStatusName(status: number): string { - let statusTranslateName; - switch (status) { - case AddonCompetencyProvider.STATUS_DRAFT: - statusTranslateName = 'draft'; - break; - case AddonCompetencyProvider.REVIEW_STATUS_IN_REVIEW: - statusTranslateName = 'inreview'; - break; - case AddonCompetencyProvider.REVIEW_STATUS_WAITING_FOR_REVIEW: - statusTranslateName = 'waitingforreview'; - break; - case AddonCompetencyProvider.STATUS_ACTIVE: - statusTranslateName = 'active'; - break; - case AddonCompetencyProvider.STATUS_COMPLETE: - statusTranslateName = 'complete'; - break; - default: - // We can use the current status name. - return String(status); - } - - return this.translate.instant('addon.competency.planstatus' + statusTranslateName); - } - /** * Refreshes the learning plan. * diff --git a/src/addon/competency/pages/planlist/planlist.html b/src/addon/competency/pages/planlist/planlist.html index f5d273ef7..e89eb51c4 100644 --- a/src/addon/competency/pages/planlist/planlist.html +++ b/src/addon/competency/pages/planlist/planlist.html @@ -15,6 +15,7 @@

{{ plan.name }}

{{ 'addon.competency.duedate' | translate }}: {{ plan.duedate | coreToLocaleString }}

+ {{ plan.statusname }}
diff --git a/src/addon/competency/pages/planlist/planlist.ts b/src/addon/competency/pages/planlist/planlist.ts index 52168e7b5..6c05ab924 100644 --- a/src/addon/competency/pages/planlist/planlist.ts +++ b/src/addon/competency/pages/planlist/planlist.ts @@ -17,6 +17,7 @@ import { IonicPage, NavParams } from 'ionic-angular'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { AddonCompetencyProvider } from '../../providers/competency'; +import { AddonCompetencyHelperProvider } from '../../providers/helper'; /** * Page that displays the list of learning plans. @@ -34,7 +35,8 @@ export class AddonCompetencyPlanListPage { plansLoaded = false; plans = []; - constructor(navParams: NavParams, private domUtils: CoreDomUtilsProvider, private competencyProvider: AddonCompetencyProvider) { + constructor(navParams: NavParams, private domUtils: CoreDomUtilsProvider, private competencyProvider: AddonCompetencyProvider, + private competencyHelperProvider: AddonCompetencyHelperProvider) { this.userId = navParams.get('userId'); } @@ -64,6 +66,20 @@ export class AddonCompetencyPlanListPage { */ protected fetchLearningPlans(): Promise { return this.competencyProvider.getLearningPlans(this.userId).then((plans) => { + plans.forEach((plan) => { + plan.statusname = this.competencyHelperProvider.getPlanStatusName(plan.status); + switch (plan.status) { + case AddonCompetencyProvider.STATUS_ACTIVE: + plan.statuscolor = 'success'; + break; + case AddonCompetencyProvider.STATUS_COMPLETE: + plan.statuscolor = 'danger'; + break; + default: + plan.statuscolor = 'warning'; + break; + } + }); this.plans = plans; }).catch((message) => { this.domUtils.showErrorModalDefault(message, 'Error getting learning plans data.'); diff --git a/src/addon/competency/providers/competency.ts b/src/addon/competency/providers/competency.ts index 611f8b492..efbaa2034 100644 --- a/src/addon/competency/providers/competency.ts +++ b/src/addon/competency/providers/competency.ts @@ -22,14 +22,18 @@ import { CoreSitesProvider } from '@providers/sites'; @Injectable() export class AddonCompetencyProvider { + // Learning plan status. static STATUS_DRAFT = 0; static STATUS_ACTIVE = 1; static STATUS_COMPLETE = 2; - static STATUS_WAITIN_GFOR_REVIEW = 3; + static STATUS_WAITING_FOR_REVIEW = 3; static STATUS_IN_REVIEW = 4; + + // Competency status. static REVIEW_STATUS_IDLE = 0; static REVIEW_STATUS_WAITING_FOR_REVIEW = 1; static REVIEW_STATUS_IN_REVIEW = 2; + protected ROOT_CACHE_KEY = 'mmaCompetency:'; protected logger; diff --git a/src/addon/competency/providers/helper.ts b/src/addon/competency/providers/helper.ts index a742218eb..bf95bd3ac 100644 --- a/src/addon/competency/providers/helper.ts +++ b/src/addon/competency/providers/helper.ts @@ -13,8 +13,10 @@ // limitations under the License. import { Injectable } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; import { CoreSitesProvider } from '@providers/sites'; import { CoreUserProvider } from '@core/user/providers/user'; +import { AddonCompetencyProvider } from './competency'; /** * Service that provides some features regarding learning plans. @@ -22,7 +24,8 @@ import { CoreUserProvider } from '@core/user/providers/user'; @Injectable() export class AddonCompetencyHelperProvider { - constructor(private sitesProvider: CoreSitesProvider, private userProvider: CoreUserProvider) { + constructor(private sitesProvider: CoreSitesProvider, private userProvider: CoreUserProvider, + private translate: TranslateService) { } /** @@ -43,4 +46,62 @@ export class AddonCompetencyHelperProvider { return user; }); } + + /** + * Get the review status name translated. + * + * @param {number} status + * @return {string} + */ + getCompetencyStatusName(status: number): string { + let statusTranslateName; + switch (status) { + case AddonCompetencyProvider.REVIEW_STATUS_IDLE: + statusTranslateName = 'idle'; + break; + case AddonCompetencyProvider.REVIEW_STATUS_IN_REVIEW: + statusTranslateName = 'inreview'; + break; + case AddonCompetencyProvider.REVIEW_STATUS_WAITING_FOR_REVIEW: + statusTranslateName = 'waitingforreview'; + break; + default: + // We can use the current status name. + return String(status); + } + + return this.translate.instant('addon.competency.usercompetencystatus_' + statusTranslateName); + } + + /** + * Get the status name translated. + * + * @param {number} status + * @return {string} + */ + getPlanStatusName(status: number): string { + let statusTranslateName; + switch (status) { + case AddonCompetencyProvider.STATUS_DRAFT: + statusTranslateName = 'draft'; + break; + case AddonCompetencyProvider.STATUS_ACTIVE: + statusTranslateName = 'active'; + break; + case AddonCompetencyProvider.STATUS_COMPLETE: + statusTranslateName = 'complete'; + break; + case AddonCompetencyProvider.STATUS_WAITING_FOR_REVIEW: + statusTranslateName = 'waitingforreview'; + break; + case AddonCompetencyProvider.STATUS_IN_REVIEW: + statusTranslateName = 'inreview'; + break; + default: + // We can use the current status name. + return String(status); + } + + return this.translate.instant('addon.competency.planstatus' + statusTranslateName); + } }