MOBILE-3578 competency: Fix multiple requests when view user profile

main
Pau Ferrer Ocaña 2021-03-16 12:27:28 +01:00
parent e8830eedaf
commit 8689ae76f6
14 changed files with 169 additions and 117 deletions

View File

@ -18,11 +18,11 @@ import { RouterModule, Routes } from '@angular/router';
import { conditionalRoutes } from '@/app/app-routing.module'; import { conditionalRoutes } from '@/app/app-routing.module';
import { CoreScreen } from '@services/screen'; import { CoreScreen } from '@services/screen';
import { CoreSharedModule } from '@/core/shared.module'; import { CoreSharedModule } from '@/core/shared.module';
import { AddonCompetencyPlanPage } from './pages/plan/plan.page'; import { AddonCompetencyPlanPage } from './pages/plan/plan';
import { AddonCompetencyPlanListPage } from './pages/planlist/planlist.page'; import { AddonCompetencyPlanListPage } from './pages/planlist/planlist';
import { AddonCompetencyCompetenciesPage } from './pages/competencies/competencies.page'; import { AddonCompetencyCompetenciesPage } from './pages/competencies/competencies';
import { AddonCompetencyCompetencyPage } from './pages/competency/competency.page'; import { AddonCompetencyCompetencyPage } from './pages/competency/competency';
import { AddonCompetencyCompetencySummaryPage } from './pages/competencysummary/competencysummary.page'; import { AddonCompetencyCompetencySummaryPage } from './pages/competencysummary/competencysummary';
import { AddonCompetencyCourseCompetenciesPage } from './pages/coursecompetencies/coursecompetencies.page'; import { AddonCompetencyCourseCompetenciesPage } from './pages/coursecompetencies/coursecompetencies.page';
import { AddonCompetencyCourseCompetenciesPageModule } from './pages/coursecompetencies/coursecompetencies.module'; import { AddonCompetencyCourseCompetenciesPageModule } from './pages/coursecompetencies/coursecompetencies.module';
@ -33,7 +33,7 @@ const mobileRoutes: Routes = [
component: AddonCompetencyPlanListPage, component: AddonCompetencyPlanListPage,
}, },
{ {
path: 'competencies/', path: 'competencies',
component: AddonCompetencyCompetenciesPage, component: AddonCompetencyCompetenciesPage,
}, },
{ {

View File

@ -91,8 +91,8 @@ export class AddonCompetencyCompetenciesPage implements AfterViewInit, OnDestroy
} else { } else {
throw null; throw null;
} }
} catch (message) { } catch (error) {
CoreDomUtils.showErrorModalDefault(message, 'Error getting competencies data.'); CoreDomUtils.showErrorModalDefault(error, 'Error getting competencies data.');
} }
} }

View File

@ -4,7 +4,7 @@
<ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button> <ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button>
</ion-buttons> </ion-buttons>
<ion-title *ngIf="competency"> <ion-title *ngIf="competency">
{{ competency!.competency.competency.shortname }} <small>{{ competency.competency.competency.idnumber }}</small> {{ competency.competency.competency.shortname }} <small>{{ competency.competency.competency.idnumber }}</small>
</ion-title> </ion-title>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
@ -16,14 +16,14 @@
<ion-card *ngIf="user"> <ion-card *ngIf="user">
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<core-user-avatar [user]="user" slot="start"></core-user-avatar> <core-user-avatar [user]="user" slot="start"></core-user-avatar>
<ion-label><h2>{{ user!.fullname }}</h2></ion-label> <ion-label><h2>{{ user.fullname }}</h2></ion-label>
</ion-item> </ion-item>
</ion-card> </ion-card>
<ion-card *ngIf="competency"> <ion-card *ngIf="competency">
<ion-item class="ion-text-wrap" *ngIf="competency!.competency.competency.description"> <ion-item class="ion-text-wrap" *ngIf="competency.competency.competency.description">
<ion-label> <ion-label>
<core-format-text [text]="competency!.competency.competency.description" [contextLevel]="contextLevel" <core-format-text [text]="competency.competency.competency.description" [contextLevel]="contextLevel"
[contextInstanceId]="contextInstanceId"> [contextInstanceId]="contextInstanceId">
</core-format-text> </core-format-text>
</ion-label> </ion-label>
@ -31,23 +31,23 @@
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.path' | translate }}</strong> <strong>{{ 'addon.competency.path' | translate }}</strong>
<a *ngIf="competency!.competency.comppath.showlinks" <a *ngIf="competency.competency.comppath.showlinks"
[href]="competency!.competency.comppath.pluginbaseurl + '/competencies.php?competencyframeworkid=' + [href]="competency.competency.comppath.pluginbaseurl + '/competencies.php?competencyframeworkid=' +
competency!.competency.comppath.framework.id + '&pagecontextid=' + competency.competency.comppath.framework.id + '&pagecontextid=' +
competency!.competency.comppath.pagecontextid" competency.competency.comppath.pagecontextid"
core-link [title]="competency!.competency.comppath.framework.name"> core-link [title]="competency.competency.comppath.framework.name">
{{ competency!.competency.comppath.framework.name }} {{ competency.competency.comppath.framework.name }}
</a> </a>
<ng-container *ngIf="!competency!.competency.comppath.showlinks"> <ng-container *ngIf="!competency.competency.comppath.showlinks">
{{ competency!.competency.comppath.framework.name }} {{ competency.competency.comppath.framework.name }}
</ng-container> </ng-container>
&nbsp;/&nbsp; &nbsp;/&nbsp;
<span *ngFor="let ancestor of competency!.competency.comppath.ancestors"> <span *ngFor="let ancestor of competency.competency.comppath.ancestors">
<a *ngIf="competency!.competency.comppath.showlinks" (click)="openCompetencySummary(ancestor.id)" <a *ngIf="competency.competency.comppath.showlinks" (click)="openCompetencySummary(ancestor.id)"
class="core-clickable"> class="core-clickable">
{{ ancestor.name }} {{ ancestor.name }}
</a> </a>
<ng-container *ngIf="!competency!.competency.comppath.showlinks">{{ ancestor.name }}</ng-container> <ng-container *ngIf="!competency.competency.comppath.showlinks">{{ ancestor.name }}</ng-container>
<ng-container *ngIf="!ancestor.last">&nbsp;/&nbsp;</ng-container> <ng-container *ngIf="!ancestor.last">&nbsp;/&nbsp;</ng-container>
</span> </span>
</ion-label> </ion-label>
@ -55,11 +55,11 @@
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.crossreferencedcompetencies' | translate }}</strong>: <strong>{{ 'addon.competency.crossreferencedcompetencies' | translate }}</strong>:
<div *ngIf="!competency!.competency.hasrelatedcompetencies"> <div *ngIf="!competency.competency.hasrelatedcompetencies">
{{ 'addon.competency.nocrossreferencedcompetencies' | translate }} {{ 'addon.competency.nocrossreferencedcompetencies' | translate }}
</div> </div>
<div *ngIf="competency!.competency.hasrelatedcompetencies"> <div *ngIf="competency.competency.hasrelatedcompetencies">
<p *ngFor="let relatedcomp of competency!.competency.relatedcompetencies"> <p *ngFor="let relatedcomp of competency.competency.relatedcompetencies">
<a (click)="openCompetencySummary(relatedcomp.id)" class="core-clickable"> <a (click)="openCompetencySummary(relatedcomp.id)" class="core-clickable">
{{ relatedcomp.shortname }} - {{ relatedcomp.idnumber }} {{ relatedcomp.shortname }} - {{ relatedcomp.idnumber }}
</a> </a>
@ -70,7 +70,7 @@
<ion-item class="ion-text-wrap" *ngIf="coursemodules"> <ion-item class="ion-text-wrap" *ngIf="coursemodules">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.activities' | translate }}</strong> <strong>{{ 'addon.competency.activities' | translate }}</strong>
<p *ngIf="coursemodules!.length == 0"> <p *ngIf="coursemodules.length == 0">
{{ 'addon.competency.noactivities' | translate }} {{ 'addon.competency.noactivities' | translate }}
</p> </p>
<ion-item class="ion-text-wrap" *ngFor="let activity of coursemodules" [href]="activity.url" [title]="activity.name" <ion-item class="ion-text-wrap" *ngFor="let activity of coursemodules" [href]="activity.url" [title]="activity.name"
@ -86,20 +86,20 @@
</ion-label> </ion-label>
</ion-item> </ion-item>
<ng-container *ngIf="userCompetency"> <ng-container *ngIf="userCompetency">
<ion-item class="ion-text-wrap" *ngIf="competency!.usercompetency && competency!.usercompetency!.status"> <ion-item class="ion-text-wrap" *ngIf="competency.usercompetency && competency.usercompetency!.status">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.reviewstatus' | translate }}</strong> <strong>{{ 'addon.competency.reviewstatus' | translate }}</strong>
{{ competency!.usercompetency!.statusname }} {{ competency.usercompetency!.statusname }}
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.proficient' | translate }}</strong> <strong>{{ 'addon.competency.proficient' | translate }}</strong>
</ion-label> </ion-label>
<ion-badge slot="end" color="success" *ngIf="userCompetency!.proficiency"> <ion-badge slot="end" color="success" *ngIf="userCompetency.proficiency">
{{ 'core.yes' | translate }} {{ 'core.yes' | translate }}
</ion-badge> </ion-badge>
<ion-badge slot="end" color="danger" *ngIf="!userCompetency!.proficiency"> <ion-badge slot="end" color="danger" *ngIf="!userCompetency.proficiency">
{{ 'core.no' | translate }} {{ 'core.no' | translate }}
</ion-badge> </ion-badge>
</ion-item> </ion-item>
@ -107,22 +107,22 @@
<ion-label> <ion-label>
<strong>{{ 'addon.competency.rating' | translate }}</strong> <strong>{{ 'addon.competency.rating' | translate }}</strong>
</ion-label> </ion-label>
<ion-badge color="dark" slot="end">{{ userCompetency!.gradename }}</ion-badge> <ion-badge color="dark" slot="end">{{ userCompetency.gradename }}</ion-badge>
</ion-item> </ion-item>
</ng-container> </ng-container>
</ion-card> </ion-card>
<div *ngIf="competency"> <div *ngIf="competency">
<h3 class="ion-margin-horizontal">{{ 'addon.competency.evidence' | translate }}</h3> <h3 class="ion-margin-horizontal">{{ 'addon.competency.evidence' | translate }}</h3>
<p class="ion-margin-horizontal" *ngIf="competency!.evidence.length == 0"> <p class="ion-margin-horizontal" *ngIf="competency.evidence.length == 0">
{{ 'addon.competency.noevidence' | translate }} {{ 'addon.competency.noevidence' | translate }}
</p> </p>
<ion-card *ngFor="let evidence of competency!.evidence"> <ion-card *ngFor="let evidence of competency.evidence">
<ion-item class="ion-text-wrap" *ngIf="evidence.actionuser" core-user-link [userId]="evidence.actionuser!.id" <ion-item class="ion-text-wrap" *ngIf="evidence.actionuser" core-user-link [userId]="evidence.actionuser.id"
[courseId]="courseId"> [courseId]="courseId">
<core-user-avatar [user]="evidence.actionuser" slot="start"></core-user-avatar> <core-user-avatar [user]="evidence.actionuser" slot="start"></core-user-avatar>
<ion-label> <ion-label>
<h2>{{ evidence.actionuser!.fullname }}</h2> <h2>{{ evidence.actionuser.fullname }}</h2>
<p>{{ evidence.timemodified * 1000 | coreFormatDate }}</p> <p>{{ evidence.timemodified * 1000 | coreFormatDate }}</p>
</ion-label> </ion-label>
</ion-item> </ion-item>

View File

@ -35,7 +35,7 @@ import { CoreUtils } from '@services/utils/utils';
import { AddonCompetencyMainMenuHandlerService } from '@addons/competency/services/handlers/mainmenu'; import { AddonCompetencyMainMenuHandlerService } from '@addons/competency/services/handlers/mainmenu';
/** /**
* Page that displays a learning plan. * Page that displays the competency information.
*/ */
@Component({ @Component({
selector: 'page-addon-competency-competency', selector: 'page-addon-competency-competency',

View File

@ -4,7 +4,7 @@
<ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button> <ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button>
</ion-buttons> </ion-buttons>
<ion-title *ngIf="competency"> <ion-title *ngIf="competency">
{{ competency!.competency.shortname }} <small>{{ competency!.competency.idnumber }}</small> {{ competency.competency.shortname }} <small>{{ competency.competency.idnumber }}</small>
</ion-title> </ion-title>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
@ -14,9 +14,9 @@
</ion-refresher> </ion-refresher>
<core-loading [hideUntil]="competencyLoaded"> <core-loading [hideUntil]="competencyLoaded">
<ion-card *ngIf="competency"> <ion-card *ngIf="competency">
<ion-item class="ion-text-wrap" *ngIf="competency!.competency.description"> <ion-item class="ion-text-wrap" *ngIf="competency.competency.description">
<ion-label> <ion-label>
<core-format-text [text]="competency!.competency.description" [contextLevel]="contextLevel" <core-format-text [text]="competency.competency.description" [contextLevel]="contextLevel"
[contextInstanceId]="contextInstanceId"> [contextInstanceId]="contextInstanceId">
</core-format-text> </core-format-text>
</ion-label> </ion-label>
@ -24,8 +24,8 @@
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.path' | translate }}</strong> <strong>{{ 'addon.competency.path' | translate }}</strong>
{{ competency!.comppath.framework.name }} {{ competency.comppath.framework.name }}
<span *ngFor="let ancestor of competency!.comppath.ancestors"> <span *ngFor="let ancestor of competency.comppath.ancestors">
&nbsp;/&nbsp;<a (click)="openCompetencySummary(ancestor.id)">{{ ancestor.name }}</a> &nbsp;/&nbsp;<a (click)="openCompetencySummary(ancestor.id)">{{ ancestor.name }}</a>
</span> </span>
</ion-label> </ion-label>

View File

@ -22,7 +22,7 @@ import { CoreUtils } from '@services/utils/utils';
import { AddonCompetencyMainMenuHandlerService } from '@addons/competency/services/handlers/mainmenu'; import { AddonCompetencyMainMenuHandlerService } from '@addons/competency/services/handlers/mainmenu';
/** /**
* Page that displays a learning plan. * Page that displays the competency summary.
*/ */
@Component({ @Component({
selector: 'page-addon-competency-competency-summary', selector: 'page-addon-competency-competency-summary',

View File

@ -11,27 +11,27 @@
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content> <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher> </ion-refresher>
<core-loading [hideUntil]="competenciesLoaded"> <core-loading [hideUntil]="competenciesLoaded">
<ion-card *ngIf="!user && competencies && competencies!.statistics.competencycount > 0"> <ion-card *ngIf="!user && competencies && competencies.statistics.competencycount > 0">
<ng-container *ngIf="competencies!.cangradecompetencies"> <ng-container *ngIf="competencies.cangradecompetencies">
<ion-item class="ion-text-wrap" *ngIf="competencies!.settings.pushratingstouserplans"> <ion-item class="ion-text-wrap" *ngIf="competencies.settings.pushratingstouserplans">
<ion-label>{{ 'addon.competency.coursecompetencyratingsarepushedtouserplans' | translate }}</ion-label> <ion-label>{{ 'addon.competency.coursecompetencyratingsarepushedtouserplans' | translate }}</ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" *ngIf="!competencies!.settings.pushratingstouserplans" color="danger"> <ion-item class="ion-text-wrap" *ngIf="!competencies.settings.pushratingstouserplans" color="danger">
<ion-label>{{ 'addon.competency.coursecompetencyratingsarenotpushedtouserplans' | translate }}</ion-label> <ion-label>{{ 'addon.competency.coursecompetencyratingsarenotpushedtouserplans' | translate }}</ion-label>
</ion-item> </ion-item>
</ng-container> </ng-container>
<ion-item class="ion-text-wrap" *ngIf="competencies!.statistics.canbegradedincourse"> <ion-item class="ion-text-wrap" *ngIf="competencies.statistics.canbegradedincourse">
<ion-label> <ion-label>
{{ 'addon.competency.xcompetenciesproficientoutofyincourse' | translate: {$a: {{ 'addon.competency.xcompetenciesproficientoutofyincourse' | translate: {$a:
{x: competencies!.statistics.proficientcompetencycount, y: competencies!.statistics.competencycount} } }} {x: competencies.statistics.proficientcompetencycount, y: competencies.statistics.competencycount} } }}
<core-progress-bar [progress]="competencies!.statistics.proficientcompetencypercentage"></core-progress-bar> <core-progress-bar [progress]="competencies.statistics.proficientcompetencypercentage"></core-progress-bar>
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" <ion-item class="ion-text-wrap"
*ngIf="competencies!.statistics.canmanagecoursecompetencies && competencies!.statistics.leastproficientcount > 0"> *ngIf="competencies.statistics.canmanagecoursecompetencies && competencies.statistics.leastproficientcount > 0">
<ion-label> <ion-label>
<strong>{{ 'addon.competency.competenciesmostoftennotproficientincourse' | translate }}</strong>: <strong>{{ 'addon.competency.competenciesmostoftennotproficientincourse' | translate }}</strong>:
<p *ngFor="let comp of competencies!.statistics.leastproficient"> <p *ngFor="let comp of competencies.statistics.leastproficient">
<a (click)="openCompetencySummary(comp.id)"> <a (click)="openCompetencySummary(comp.id)">
{{ comp.shortname }} - {{ comp.idnumber }} {{ comp.shortname }} - {{ comp.idnumber }}
</a> </a>
@ -40,29 +40,29 @@
</ion-item> </ion-item>
</ion-card> </ion-card>
<h3 class="ion-margin-horizontal" *ngIf="competencies && competencies!.statistics.competencycount > 0"> <h3 class="ion-margin-horizontal" *ngIf="competencies && competencies.statistics.competencycount > 0">
{{ 'addon.competency.coursecompetencies' | translate }} {{ 'addon.competency.coursecompetencies' | translate }}
</h3> </h3>
<ion-card *ngIf="user"> <ion-card *ngIf="user">
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<core-user-avatar [user]="user" slot="start"></core-user-avatar> <core-user-avatar [user]="user" slot="start"></core-user-avatar>
<ion-label><h2>{{ user!.fullname }}</h2></ion-label> <ion-label><h2>{{ user.fullname }}</h2></ion-label>
</ion-item> </ion-item>
</ion-card> </ion-card>
<core-empty-box *ngIf="competencies && competencies!.statistics.competencycount == 0" <core-empty-box *ngIf="competencies && competencies.statistics.competencycount == 0"
icon="fas-award" message="{{ 'addon.competency.nocompetenciesincourse' | translate }}"> icon="fas-award" message="{{ 'addon.competency.nocompetenciesincourse' | translate }}">
</core-empty-box> </core-empty-box>
<div *ngIf="competencies"> <div *ngIf="competencies">
<ion-card *ngFor="let competency of competencies!.competencies"> <ion-card *ngFor="let competency of competencies.competencies">
<ion-item class="ion-text-wrap" (click)="openCompetency(competency.competency.id)" <ion-item class="ion-text-wrap" (click)="openCompetency(competency.competency.id)"
[title]="competency.competency.shortname" detail="true"> [title]="competency.competency.shortname" detail="true">
<ion-label> <ion-label>
<h2><strong>{{competency.competency.shortname}} <em>{{competency.competency.idnumber}}</em></strong></h2> <h2><strong>{{competency.competency.shortname}} <em>{{competency.competency.idnumber}}</em></strong></h2>
</ion-label> </ion-label>
<ion-badge slot="end" *ngIf="competency.usercompetencycourse && competency.usercompetencycourse!.gradename" <ion-badge slot="end" *ngIf="competency.usercompetencycourse && competency.usercompetencycourse.gradename"
[color]="competency.usercompetencycourse!.proficiency ? 'success' : 'danger'"> [color]="competency.usercompetencycourse.proficiency ? 'success' : 'danger'">
{{ competency.usercompetencycourse!.gradename }} {{ competency.usercompetencycourse.gradename }}
</ion-badge> </ion-badge>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
@ -92,7 +92,7 @@
<ng-container *ngIf="!ancestor.last">&nbsp;/&nbsp;</ng-container> <ng-container *ngIf="!ancestor.last">&nbsp;/&nbsp;</ng-container>
</span> </span>
</div> </div>
<div *ngIf="competencies!.statistics.canmanagecoursecompetencies"> <div *ngIf="competencies.statistics.canmanagecoursecompetencies">
<strong>{{ 'addon.competency.uponcoursecompletion' | translate }}</strong> <strong>{{ 'addon.competency.uponcoursecompletion' | translate }}</strong>
<ng-container *ngFor="let ruleoutcome of competency.ruleoutcomeoptions"> <ng-container *ngFor="let ruleoutcome of competency.ruleoutcomeoptions">
<span *ngIf="ruleoutcome.selected">{{ ruleoutcome.text }}</span> <span *ngIf="ruleoutcome.selected">{{ ruleoutcome.text }}</span>

View File

@ -3,7 +3,7 @@
<ion-buttons slot="start"> <ion-buttons slot="start">
<ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button> <ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button>
</ion-buttons> </ion-buttons>
<ion-title *ngIf="plan">{{plan!.plan.name}}</ion-title> <ion-title *ngIf="plan">{{plan.plan.name}}</ion-title>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content> <ion-content>
@ -15,27 +15,27 @@
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<ion-label> <ion-label>
<core-user-avatar [user]="user" slot="start"></core-user-avatar> <core-user-avatar [user]="user" slot="start"></core-user-avatar>
<h2>{{ user!.fullname }}</h2> <h2>{{ user.fullname }}</h2>
</ion-label> </ion-label>
</ion-item> </ion-item>
</ion-card> </ion-card>
<ion-card *ngIf="plan"> <ion-card *ngIf="plan">
<ion-list> <ion-list>
<ion-item class="ion-text-wrap" *ngIf="plan!.plan.description" lines="none"> <ion-item class="ion-text-wrap" *ngIf="plan.plan.description" lines="none">
<ion-label> <ion-label>
<core-format-text [text]="plan!.plan.description" contextLevel="user" <core-format-text [text]="plan.plan.description" contextLevel="user"
[contextInstanceId]="plan!.plan.userid"> [contextInstanceId]="plan.plan.userid">
</core-format-text> </core-format-text>
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" lines="none"> <ion-item class="ion-text-wrap" lines="none">
<ion-label> <ion-label>
<p> <p>
<strong>{{ 'addon.competency.status' | translate }}</strong>: {{ plan!.plan.statusname }} <strong>{{ 'addon.competency.status' | translate }}</strong>: {{ plan.plan.statusname }}
</p> </p>
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" *ngIf="plan!.plan.duedate > 0" lines="none"> <ion-item class="ion-text-wrap" *ngIf="plan.plan.duedate > 0" lines="none">
<ion-label> <ion-label>
<p> <p>
<strong>{{ 'addon.competency.duedate' | translate }}</strong>: <strong>{{ 'addon.competency.duedate' | translate }}</strong>:
@ -43,10 +43,10 @@
</p> </p>
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" *ngIf="plan!.plan.template" lines="none"> <ion-item class="ion-text-wrap" *ngIf="plan.plan.template" lines="none">
<ion-label> <ion-label>
<p> <p>
<strong>{{ 'addon.competency.template' | translate }}</strong>: {{ plan!.plan.template!.shortname }} <strong>{{ 'addon.competency.template' | translate }}</strong>: {{ plan.plan.template.shortname }}
</p> </p>
</ion-label> </ion-label>
</ion-item> </ion-item>

View File

@ -56,6 +56,41 @@ export class AddonCompetencyProvider {
site.isFeatureDisabled('CoreUserDelegate_AddonCompetency'); site.isFeatureDisabled('CoreUserDelegate_AddonCompetency');
} }
/**
* Returns whether current user can see another user competencies in a course.
*
* @param courseId Course ID.
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved with boolean: whether the user can view the competencies.
*/
async canViewUserCompetenciesInCourse(courseId: number, userId?: number, siteId?: string): Promise<boolean> {
if (!CoreSites.isLoggedIn()) {
return false;
}
try {
const response = await this.getCourseCompetenciesPage(courseId, siteId);
if (!response.competencies.length) {
// No competencies.
return false;
}
if (!userId || userId == CoreSites.getCurrentSiteUserId()) {
// Current user.
return true;
}
// Check if current user can view any competency of the user.
await this.getCompetencyInCourse(courseId, response.competencies[0].competency.id, userId, siteId);
return true;
} catch {
return false;
}
}
/** /**
* Get cache key for user learning plans data WS calls. * Get cache key for user learning plans data WS calls.
* *
@ -290,7 +325,7 @@ export class AddonCompetencyProvider {
} }
/** /**
* Get all competencies in a course. * Get all competencies in a course for a certain user.
* *
* @param courseId ID of the course. * @param courseId ID of the course.
* @param userId ID of the user. * @param userId ID of the user.
@ -304,6 +339,38 @@ export class AddonCompetencyProvider {
siteId?: string, siteId?: string,
ignoreCache = false, ignoreCache = false,
): Promise<AddonCompetencyDataForCourseCompetenciesPageWSResponse> { ): Promise<AddonCompetencyDataForCourseCompetenciesPageWSResponse> {
const courseCompetencies = await this.getCourseCompetenciesPage(courseId, siteId, ignoreCache);
if (!userId || userId == CoreSites.getCurrentSiteUserId()) {
return courseCompetencies;
}
const userCompetenciesSumaries: AddonCompetencyDataForUserCompetencySummaryInCourseWSResponse[] =
await Promise.all(courseCompetencies.competencies.map((competency) =>
this.getCompetencyInCourse(courseId, competency.competency.id, userId, siteId)));
userCompetenciesSumaries.forEach((userCompetenciesSumary, index) => {
courseCompetencies.competencies[index].usercompetencycourse =
userCompetenciesSumary.usercompetencysummary.usercompetencycourse;
});
return courseCompetencies;
}
/**
* Get all competencies in a course.
*
* @param courseId ID of the course.
* @param siteId Site ID. If not defined, current site.
* @param ignoreCache True if it should ignore cached data (it will always fail in offline or server down).
* @return Promise to be resolved when the course competencies are retrieved.
*/
async getCourseCompetenciesPage(
courseId: number,
siteId?: string,
ignoreCache = false,
): Promise<AddonCompetencyDataForCourseCompetenciesPageWSResponse> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const params: AddonCompetencyDataForCourseCompetenciesPageWSParams = { const params: AddonCompetencyDataForCourseCompetenciesPageWSParams = {
@ -320,26 +387,11 @@ export class AddonCompetencyProvider {
preSets.emergencyCache = false; preSets.emergencyCache = false;
} }
const courseCompetencies = await site.read<AddonCompetencyDataForCourseCompetenciesPageWSResponse>( return site.read<AddonCompetencyDataForCourseCompetenciesPageWSResponse>(
'tool_lp_data_for_course_competencies_page', 'tool_lp_data_for_course_competencies_page',
params, params,
preSets, preSets,
); );
if (!userId || userId == CoreSites.getCurrentSiteUserId()) {
return courseCompetencies;
}
const userCompetenciesSumaries: AddonCompetencyDataForUserCompetencySummaryInCourseWSResponse[] =
await Promise.all(courseCompetencies.competencies.map((competency) =>
this.getCompetencyInCourse(courseId, competency.competency.id, userId, siteId)));
userCompetenciesSumaries.forEach((userCompetenciesSumary, index) => {
courseCompetencies.competencies[index].usercompetencycourse =
userCompetenciesSumary.usercompetencysummary.usercompetencycourse;
});
return courseCompetencies;
} }
/** /**

View File

@ -98,39 +98,41 @@ export class AddonCompetencyCourseOptionHandlerService implements CoreCourseOpti
// Get the competencies in the course. // Get the competencies in the course.
const competencies = await AddonCompetency.getCourseCompetencies(course.id, undefined, undefined, true); const competencies = await AddonCompetency.getCourseCompetencies(course.id, undefined, undefined, true);
if (!competencies || !competencies.competencies) {
return;
}
const promises: Promise<unknown>[] = []; const promises: Promise<unknown>[] = [];
// Prefetch all the competencies. // Prefetch all the competencies.
if (competencies && competencies.competencies) { competencies.competencies.forEach((competency) => {
competencies.competencies.forEach((competency) => { promises.push(AddonCompetency.getCompetencyInCourse(
promises.push(AddonCompetency.getCompetencyInCourse( course.id,
course.id, competency.competency.id,
competency.competency.id, undefined,
undefined, undefined,
undefined, true,
true, ));
));
promises.push(AddonCompetency.getCompetencySummary( promises.push(AddonCompetency.getCompetencySummary(
competency.competency.id, competency.competency.id,
undefined, undefined,
undefined, undefined,
true, true,
)); ));
if (competency.coursemodules) { if (competency.coursemodules) {
competency.coursemodules.forEach((module) => { competency.coursemodules.forEach((module) => {
promises.push(CoreFilterHelper.getFilters(ContextLevel.MODULE, module.id, { courseId: course.id })); promises.push(CoreFilterHelper.getFilters(ContextLevel.MODULE, module.id, { courseId: course.id }));
}); });
} }
if (competency.plans) { if (competency.plans) {
competency.plans.forEach((plan) => { competency.plans.forEach((plan) => {
promises.push(CoreFilterHelper.getFilters(ContextLevel.USER, plan.userid)); promises.push(CoreFilterHelper.getFilters(ContextLevel.USER, plan.userid));
}); });
} }
}); });
}
await Promise.all(promises); await Promise.all(promises);
} }

View File

@ -54,7 +54,7 @@ export class AddonCompetencyPushClickHandlerService implements CorePushNotificat
// Open the learning plan. // Open the learning plan.
const planId = Number(contextUrlParams.id); const planId = Number(contextUrlParams.id);
await CoreUtils.ignoreErrors(AddonCompetency.invalidateLearningPlan(planId, notification.site)); await CoreUtils.ignoreErrors(AddonCompetency.invalidateLearningPlan(planId, notification.site));
await CoreNavigator.navigateToSitePath('/' + AddonCompetencyMainMenuHandlerService.PAGE_NAME + '/' + planId, { await CoreNavigator.navigateToSitePath('/' + AddonCompetencyMainMenuHandlerService.PAGE_NAME + '/' + planId, {
siteId: notification.site, siteId: notification.site,

View File

@ -44,9 +44,7 @@ export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler
async isEnabledForUser(user: CoreUserProfile, courseId?: number): Promise<boolean> { async isEnabledForUser(user: CoreUserProfile, courseId?: number): Promise<boolean> {
try { try {
if (courseId) { if (courseId) {
const response = await AddonCompetency.getCourseCompetencies(courseId, user.id); return AddonCompetency.canViewUserCompetenciesInCourse(courseId, user.id);
return response.competencies.length > 0;
} else { } else {
const plans = await AddonCompetency.getLearningPlans(user.id); const plans = await AddonCompetency.getLearningPlans(user.id);