MOBILE-3934 competency: Remove deprecated managers
parent
d2b716da8d
commit
7265611dda
|
@ -17,13 +17,16 @@ import { IonRefresher } from '@ionic/angular';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
import {
|
import {
|
||||||
AddonCompetencyDataForPlanPageCompetency, AddonCompetencyDataForCourseCompetenciesPageCompetency, AddonCompetency,
|
AddonCompetencyDataForPlanPageCompetency,
|
||||||
|
AddonCompetencyDataForCourseCompetenciesPageCompetency,
|
||||||
} from '../../services/competency';
|
} from '../../services/competency';
|
||||||
import { ActivatedRoute, Params } from '@angular/router';
|
|
||||||
import { CorePageItemsListManager } from '@classes/page-items-list-manager';
|
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
|
import { AddonCompetencyPlanCompetenciesSource } from '@addons/competency/classes/competency-plan-competencies-source';
|
||||||
|
import { AddonCompetencyCourseCompetenciesSource } from '@addons/competency/classes/competency-course-competencies-source';
|
||||||
|
import { CoreListItemsManager } from '@classes/items-management/list-items-manager';
|
||||||
|
import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the list of competencies of a learning plan.
|
* Page that displays the list of competencies of a learning plan.
|
||||||
|
@ -36,22 +39,32 @@ export class AddonCompetencyCompetenciesPage implements AfterViewInit, OnDestroy
|
||||||
|
|
||||||
@ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent;
|
@ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent;
|
||||||
|
|
||||||
protected planId?: number;
|
competencies: CoreListItemsManager<
|
||||||
protected courseId?: number;
|
AddonCompetencyDataForPlanPageCompetency | AddonCompetencyDataForCourseCompetenciesPageCompetency,
|
||||||
protected userId?: number;
|
AddonCompetencyPlanCompetenciesSource | AddonCompetencyCourseCompetenciesSource
|
||||||
|
>;
|
||||||
|
|
||||||
competenciesLoaded = false;
|
|
||||||
competencies: AddonCompetencyListManager;
|
|
||||||
title = '';
|
title = '';
|
||||||
|
|
||||||
constructor(protected route: ActivatedRoute) {
|
constructor() {
|
||||||
this.planId = CoreNavigator.getRouteNumberParam('planId', { route });
|
const planId = CoreNavigator.getRouteNumberParam('planId');
|
||||||
if (!this.planId) {
|
|
||||||
this.courseId = CoreNavigator.getRouteNumberParam('courseId', { route });
|
if (!planId) {
|
||||||
this.userId = CoreNavigator.getRouteNumberParam('userId', { route });
|
const courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
|
||||||
|
const userId = CoreNavigator.getRouteNumberParam('userId');
|
||||||
|
const source = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource(
|
||||||
|
AddonCompetencyCourseCompetenciesSource,
|
||||||
|
[courseId, userId],
|
||||||
|
);
|
||||||
|
|
||||||
|
this.competencies = new CoreListItemsManager(source, AddonCompetencyCompetenciesPage);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.competencies = new AddonCompetencyListManager(AddonCompetencyCompetenciesPage, this.userId);
|
const source = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource(AddonCompetencyPlanCompetenciesSource, [planId]);
|
||||||
|
|
||||||
|
this.competencies = new CoreListItemsManager(source, AddonCompetencyCompetenciesPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,25 +83,18 @@ export class AddonCompetencyCompetenciesPage implements AfterViewInit, OnDestroy
|
||||||
*/
|
*/
|
||||||
protected async fetchCompetencies(): Promise<void> {
|
protected async fetchCompetencies(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (this.planId) {
|
const source = this.competencies.getSource();
|
||||||
|
|
||||||
const response = await AddonCompetency.getLearningPlan(this.planId);
|
await this.competencies.load();
|
||||||
|
|
||||||
if (response.competencycount <= 0) {
|
if (source instanceof AddonCompetencyPlanCompetenciesSource) {
|
||||||
|
if (!source.plan || source.plan && source.plan.competencycount <= 0) {
|
||||||
throw new CoreError(Translate.instant('addon.competency.errornocompetenciesfound'));
|
throw new CoreError(Translate.instant('addon.competency.errornocompetenciesfound'));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.title = response.plan.name;
|
this.title = source.plan.plan.name;
|
||||||
this.userId = response.plan.userid;
|
|
||||||
|
|
||||||
this.competencies.setItems(response.competencies);
|
|
||||||
} else if (this.courseId) {
|
|
||||||
const response = await AddonCompetency.getCourseCompetencies(this.courseId, this.userId);
|
|
||||||
this.title = Translate.instant('addon.competency.coursecompetencies');
|
|
||||||
|
|
||||||
this.competencies.setItems(response.competencies);
|
|
||||||
} else {
|
} else {
|
||||||
throw null;
|
this.title = Translate.instant('addon.competency.coursecompetencies');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'Error getting competencies data.');
|
CoreDomUtils.showErrorModalDefault(error, 'Error getting competencies data.');
|
||||||
|
@ -101,19 +107,13 @@ export class AddonCompetencyCompetenciesPage implements AfterViewInit, OnDestroy
|
||||||
* @param refresher Refresher.
|
* @param refresher Refresher.
|
||||||
*/
|
*/
|
||||||
async refreshCompetencies(refresher?: IonRefresher): Promise<void> {
|
async refreshCompetencies(refresher?: IonRefresher): Promise<void> {
|
||||||
try {
|
await this.competencies.getSource().invalidateCache();
|
||||||
if (this.planId) {
|
|
||||||
await AddonCompetency.invalidateLearningPlan(this.planId);
|
|
||||||
} else {
|
|
||||||
await AddonCompetency.invalidateCourseCompetencies(this.courseId!, this.userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
this.competencies.getSource().setDirty(true);
|
||||||
this.fetchCompetencies().finally(() => {
|
this.fetchCompetencies().finally(() => {
|
||||||
refresher?.complete();
|
refresher?.complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
@ -123,39 +123,3 @@ export class AddonCompetencyCompetenciesPage implements AfterViewInit, OnDestroy
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddonCompetencyDataForPlanPageCompetencyFormatted =
|
|
||||||
AddonCompetencyDataForPlanPageCompetency | AddonCompetencyDataForCourseCompetenciesPageCompetency;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class to manage competencies list.
|
|
||||||
*/
|
|
||||||
class AddonCompetencyListManager extends CorePageItemsListManager<AddonCompetencyDataForPlanPageCompetencyFormatted> {
|
|
||||||
|
|
||||||
private userId?: number;
|
|
||||||
|
|
||||||
constructor(pageComponent: unknown, userId?: number) {
|
|
||||||
super(pageComponent);
|
|
||||||
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
*/
|
|
||||||
protected getItemPath(competency: AddonCompetencyDataForPlanPageCompetencyFormatted): string {
|
|
||||||
return String(competency.competency.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
*/
|
|
||||||
protected getItemQueryParams(): Params {
|
|
||||||
if (this.userId) {
|
|
||||||
return { userId: this.userId };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ export class AddonCompetencyPlanListPage implements AfterViewInit, OnDestroy {
|
||||||
async refreshLearningPlans(refresher: IonRefresher): Promise<void> {
|
async refreshLearningPlans(refresher: IonRefresher): Promise<void> {
|
||||||
await this.plans.getSource().invalidateCache();
|
await this.plans.getSource().invalidateCache();
|
||||||
|
|
||||||
|
this.plans.getSource().setDirty(true);
|
||||||
this.fetchLearningPlans().finally(() => {
|
this.fetchLearningPlans().finally(() => {
|
||||||
refresher?.complete();
|
refresher?.complete();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue