2021-03-11 15:55:14 +01:00
|
|
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
|
|
|
//
|
|
|
|
// 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 { Component, OnInit } from '@angular/core';
|
|
|
|
import { CoreDomUtils } from '@services/utils/dom';
|
|
|
|
import { AddonCompetencyDataForPlanPageWSResponse, AddonCompetency } from '../../services/competency';
|
|
|
|
import { AddonCompetencyHelper } from '../../services/competency-helper';
|
|
|
|
import { CoreNavigator } from '@services/navigator';
|
|
|
|
import { CoreUserProfile } from '@features/user/services/user';
|
|
|
|
import { IonRefresher } from '@ionic/angular';
|
2021-09-30 16:35:16 +02:00
|
|
|
import { ADDON_COMPETENCY_MAIN_PAGE_NAME } from '@addons/competency/competency.module';
|
2021-03-11 15:55:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Page that displays a learning plan.
|
|
|
|
*/
|
|
|
|
@Component({
|
|
|
|
selector: 'page-addon-competency-plan',
|
|
|
|
templateUrl: 'plan.html',
|
|
|
|
})
|
|
|
|
export class AddonCompetencyPlanPage implements OnInit {
|
|
|
|
|
|
|
|
protected planId!: number;
|
|
|
|
loaded = false;
|
|
|
|
plan?: AddonCompetencyDataForPlanPageWSResponse;
|
|
|
|
user?: CoreUserProfile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ngOnInit(): void {
|
2021-09-09 16:38:38 +02:00
|
|
|
try {
|
|
|
|
this.planId = CoreNavigator.getRequiredRouteNumberParam('planId');
|
|
|
|
} catch (error) {
|
|
|
|
CoreDomUtils.showErrorModal(error);
|
|
|
|
|
|
|
|
CoreNavigator.back();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2021-03-11 15:55:14 +01:00
|
|
|
|
|
|
|
this.fetchLearningPlan().finally(() => {
|
|
|
|
this.loaded = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the learning plan and updates the view.
|
|
|
|
*
|
|
|
|
* @return Promise resolved when done.
|
|
|
|
*/
|
|
|
|
protected async fetchLearningPlan(): Promise<void> {
|
|
|
|
try {
|
|
|
|
const plan = await AddonCompetency.getLearningPlan(this.planId);
|
|
|
|
plan.plan.statusname = AddonCompetencyHelper.getPlanStatusName(plan.plan.status);
|
|
|
|
|
|
|
|
// Get the user profile image.
|
|
|
|
this.user = await AddonCompetencyHelper.getProfile(plan.plan.userid);
|
|
|
|
|
|
|
|
this.plan = plan;
|
|
|
|
} catch (error) {
|
|
|
|
CoreDomUtils.showErrorModalDefault(error, 'Error getting learning plan data.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Navigates to a particular competency.
|
|
|
|
*
|
|
|
|
* @param competencyId
|
|
|
|
*/
|
|
|
|
openCompetency(competencyId: number): void {
|
|
|
|
CoreNavigator.navigateToSitePath(
|
2021-09-30 16:35:16 +02:00
|
|
|
ADDON_COMPETENCY_MAIN_PAGE_NAME + '/competencies/' + competencyId,
|
2021-03-11 15:55:14 +01:00
|
|
|
{ params: { planId: this.planId } },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refreshes the learning plan.
|
|
|
|
*
|
|
|
|
* @param refresher Refresher.
|
|
|
|
*/
|
|
|
|
refreshLearningPlan(refresher: IonRefresher): void {
|
|
|
|
AddonCompetency.invalidateLearningPlan(this.planId).finally(() => {
|
|
|
|
this.fetchLearningPlan().finally(() => {
|
|
|
|
refresher?.complete();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|