MOBILE-2759 compentecy: Fix completed learning plans view

main
Pau Ferrer Ocaña 2018-11-30 09:46:54 +01:00
parent 62a37720da
commit c94530023a
6 changed files with 100 additions and 69 deletions

View File

@ -19,6 +19,7 @@ import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreSplitViewComponent } from '@components/split-view/split-view';
import { AddonCompetencyProvider } from '../../providers/competency'; import { AddonCompetencyProvider } from '../../providers/competency';
import { AddonCompetencyHelperProvider } from '../../providers/helper';
/** /**
* Page that displays a learning plan. * Page that displays a learning plan.
@ -41,7 +42,8 @@ export class AddonCompetencyCompetencyPage {
constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService, constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService,
private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider, 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.competencyId = navParams.get('competencyId');
this.planId = navParams.get('planId'); this.planId = navParams.get('planId');
this.courseId = navParams.get('courseId'); this.courseId = navParams.get('courseId');
@ -85,11 +87,14 @@ export class AddonCompetencyCompetencyPage {
} }
return promise.then((competency) => { return promise.then((competency) => {
competency.usercompetencysummary.usercompetency = competency.usercompetencysummary.usercompetencyplan ||
competency.usercompetencysummary.usercompetency;
this.competency = competency.usercompetencysummary; this.competency = competency.usercompetencysummary;
if (this.planId) { if (this.planId) {
this.planStatus = competency.plan.status; 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 { } else {
this.competency.usercompetency = this.competency.usercompetencycourse; this.competency.usercompetency = this.competency.usercompetencycourse;
this.coursemodules = competency.coursemodules; 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. * Refreshes the competency.
* *

View File

@ -14,7 +14,6 @@
import { Component, Optional } from '@angular/core'; import { Component, Optional } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app'; import { CoreAppProvider } from '@providers/app';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreSplitViewComponent } from '@components/split-view/split-view';
@ -35,10 +34,9 @@ export class AddonCompetencyPlanPage {
plan: any; plan: any;
user: any; user: any;
constructor(private navCtrl: NavController, navParams: NavParams, private translate: TranslateService, constructor(private navCtrl: NavController, navParams: NavParams, private appProvider: CoreAppProvider,
private appProvider: CoreAppProvider, private domUtils: CoreDomUtilsProvider, private domUtils: CoreDomUtilsProvider, @Optional() private svComponent: CoreSplitViewComponent,
@Optional() private svComponent: CoreSplitViewComponent, private competencyProvider: AddonCompetencyProvider, private competencyProvider: AddonCompetencyProvider, private competencyHelperProvider: AddonCompetencyHelperProvider) {
private competencyHelperProvider: AddonCompetencyHelperProvider) {
this.planId = navParams.get('planId'); this.planId = navParams.get('planId');
} }
@ -58,11 +56,15 @@ export class AddonCompetencyPlanPage {
*/ */
protected fetchLearningPlan(): Promise<void> { protected fetchLearningPlan(): Promise<void> {
return this.competencyProvider.getLearningPlan(this.planId).then((plan) => { 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. // Get the user profile image.
this.competencyHelperProvider.getProfile(plan.plan.userid).then((user) => { this.competencyHelperProvider.getProfile(plan.plan.userid).then((user) => {
this.user = user; this.user = user;
}); });
plan.competencies.forEach((competency) => {
competency.usercompetency = competency.usercompetencyplan || competency.usercompetency;
});
this.plan = plan; this.plan = plan;
}).catch((message) => { }).catch((message) => {
this.domUtils.showErrorModalDefault(message, 'Error getting learning plan data.'); 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. * Refreshes the learning plan.
* *

View File

@ -15,6 +15,7 @@
<a ion-item text-wrap *ngFor="let plan of plans" [title]="plan.name" (click)="openPlan(plan.id)" [class.core-split-item-selected]="plan.id == planId"> <a ion-item text-wrap *ngFor="let plan of plans" [title]="plan.name" (click)="openPlan(plan.id)" [class.core-split-item-selected]="plan.id == planId">
<h2>{{ plan.name }}</h2> <h2>{{ plan.name }}</h2>
<p *ngIf="plan.duedate > 0">{{ 'addon.competency.duedate' | translate }}: {{ plan.duedate | coreToLocaleString }}</p> <p *ngIf="plan.duedate > 0">{{ 'addon.competency.duedate' | translate }}: {{ plan.duedate | coreToLocaleString }}</p>
<ion-badge text-wrap [color]="plan.statuscolor">{{ plan.statusname }}</ion-badge>
</a> </a>
</ion-list> </ion-list>
</core-loading> </core-loading>

View File

@ -17,6 +17,7 @@ import { IonicPage, NavParams } from 'ionic-angular';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreSplitViewComponent } from '@components/split-view/split-view';
import { AddonCompetencyProvider } from '../../providers/competency'; import { AddonCompetencyProvider } from '../../providers/competency';
import { AddonCompetencyHelperProvider } from '../../providers/helper';
/** /**
* Page that displays the list of learning plans. * Page that displays the list of learning plans.
@ -34,7 +35,8 @@ export class AddonCompetencyPlanListPage {
plansLoaded = false; plansLoaded = false;
plans = []; 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'); this.userId = navParams.get('userId');
} }
@ -64,6 +66,20 @@ export class AddonCompetencyPlanListPage {
*/ */
protected fetchLearningPlans(): Promise<void> { protected fetchLearningPlans(): Promise<void> {
return this.competencyProvider.getLearningPlans(this.userId).then((plans) => { 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; this.plans = plans;
}).catch((message) => { }).catch((message) => {
this.domUtils.showErrorModalDefault(message, 'Error getting learning plans data.'); this.domUtils.showErrorModalDefault(message, 'Error getting learning plans data.');

View File

@ -22,14 +22,18 @@ import { CoreSitesProvider } from '@providers/sites';
@Injectable() @Injectable()
export class AddonCompetencyProvider { export class AddonCompetencyProvider {
// Learning plan status.
static STATUS_DRAFT = 0; static STATUS_DRAFT = 0;
static STATUS_ACTIVE = 1; static STATUS_ACTIVE = 1;
static STATUS_COMPLETE = 2; static STATUS_COMPLETE = 2;
static STATUS_WAITIN_GFOR_REVIEW = 3; static STATUS_WAITING_FOR_REVIEW = 3;
static STATUS_IN_REVIEW = 4; static STATUS_IN_REVIEW = 4;
// Competency status.
static REVIEW_STATUS_IDLE = 0; static REVIEW_STATUS_IDLE = 0;
static REVIEW_STATUS_WAITING_FOR_REVIEW = 1; static REVIEW_STATUS_WAITING_FOR_REVIEW = 1;
static REVIEW_STATUS_IN_REVIEW = 2; static REVIEW_STATUS_IN_REVIEW = 2;
protected ROOT_CACHE_KEY = 'mmaCompetency:'; protected ROOT_CACHE_KEY = 'mmaCompetency:';
protected logger; protected logger;

View File

@ -13,8 +13,10 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
import { CoreUserProvider } from '@core/user/providers/user'; import { CoreUserProvider } from '@core/user/providers/user';
import { AddonCompetencyProvider } from './competency';
/** /**
* Service that provides some features regarding learning plans. * Service that provides some features regarding learning plans.
@ -22,7 +24,8 @@ import { CoreUserProvider } from '@core/user/providers/user';
@Injectable() @Injectable()
export class AddonCompetencyHelperProvider { 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; 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);
}
} }