MOBILE-3624 badges: Implement badges feature
parent
003357d19d
commit
7859c8613b
|
@ -39,9 +39,11 @@ import { AddonBlockTagsModule } from './block/tags/tags.module';
|
|||
import { AddonPrivateFilesModule } from './privatefiles/privatefiles.module';
|
||||
import { AddonFilterModule } from './filter/filter.module';
|
||||
import { AddonUserProfileFieldModule } from './userprofilefield/userprofilefield.module';
|
||||
import { AddonBadgesModule } from './badges/badges.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
AddonBadgesModule,
|
||||
AddonPrivateFilesModule,
|
||||
AddonFilterModule,
|
||||
AddonBlockActivityResultsModule,
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
// (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 { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
redirectTo: 'user',
|
||||
pathMatch: 'full',
|
||||
},
|
||||
{
|
||||
path: 'issue',
|
||||
loadChildren: () => import('./pages/issued-badge/issued-badge.module').then( m => m.AddonBadgesIssuedBadgePageModule),
|
||||
},
|
||||
{
|
||||
path: 'user',
|
||||
loadChildren: () => import('./pages/user-badges/user-badges.module').then( m => m.AddonBadgesUserBadgesPageModule),
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
})
|
||||
export class AddonBadgesLazyModule {}
|
|
@ -0,0 +1,54 @@
|
|||
// (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 { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
import { AddonBadgesMyBadgesLinkHandler } from './services/handlers/mybadges-link';
|
||||
import { AddonBadgesBadgeLinkHandler } from './services/handlers/badge-link';
|
||||
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
||||
import { AddonBadgesUserHandler } from './services/handlers/user';
|
||||
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||
// @todo import { CorePushNotificationsDelegate } from '@core/pushnotifications/services/delegate';
|
||||
// import { AddonBadgesPushClickHandler } from './services/push-click-handler';
|
||||
|
||||
const mainMenuHomeSiblingRoutes: Routes = [
|
||||
{
|
||||
path: 'badges',
|
||||
loadChildren: () => import('./badges-lazy.module').then(m => m.AddonBadgesLazyModule),
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CoreMainMenuTabRoutingModule.forChild({
|
||||
siblings: mainMenuHomeSiblingRoutes,
|
||||
}),
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
multi: true,
|
||||
deps: [],
|
||||
useFactory: () => () => {
|
||||
CoreContentLinksDelegate.instance.registerHandler(AddonBadgesMyBadgesLinkHandler.instance);
|
||||
CoreContentLinksDelegate.instance.registerHandler(AddonBadgesBadgeLinkHandler.instance);
|
||||
CoreUserDelegate.instance.registerHandler(AddonBadgesUserHandler.instance);
|
||||
// CorePushNotificationsDelegate.instance.registerHandler(AddonBadgesPushClickHandler.instance);
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
export class AddonBadgesModule {}
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"alignment": "Alignment",
|
||||
"badgedetails": "Badge details",
|
||||
"badges": "Badges",
|
||||
"bendorsement": "Endorsement",
|
||||
"claimcomment": "Endorsement comment",
|
||||
"claimid": "Claim URL",
|
||||
"contact": "Contact",
|
||||
"dateawarded": "Date issued",
|
||||
"expired": "Expired",
|
||||
"expirydate": "Expiry date",
|
||||
"imageauthoremail": "Image author's email",
|
||||
"imageauthorname": "Image author's name",
|
||||
"imageauthorurl": "Image author's URL",
|
||||
"imagecaption": "Image caption",
|
||||
"issuancedetails": "Badge expiry",
|
||||
"issuerdetails": "Issuer details",
|
||||
"issueremail": "Email",
|
||||
"issuername": "Issuer name",
|
||||
"issuerurl": "Issuer URL",
|
||||
"language": "Language",
|
||||
"noalignment": "This badge does not have any external skills or standards specified.",
|
||||
"nobadges": "There are no badges available.",
|
||||
"norelated": "This badge does not have any related badges.",
|
||||
"recipientdetails": "Recipient details",
|
||||
"relatedbages": "Related badges",
|
||||
"version": "Version",
|
||||
"warnexpired": "(This badge has expired!)"
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button>
|
||||
</ion-buttons>
|
||||
<ion-title *ngIf="badge">{{ badge.name }}</ion-title>
|
||||
<ion-title *ngIf="!badge">{{ 'addon.badges.badges' | translate }}</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
<ion-refresher slot="fixed" [disabled]="!badgeLoaded" (ionRefresh)="refreshBadges($event)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<core-loading [hideUntil]="badgeLoaded">
|
||||
<ion-item-group *ngIf="badge">
|
||||
<ion-item class="ion-text-wrap ion-text-center">
|
||||
<ion-label>
|
||||
<img *ngIf="badge.badgeurl" class="large-avatar" [src]="badge.badgeurl" core-external-content [alt]="badge.name" />
|
||||
<ion-badge color="danger" *ngIf="badge.dateexpire && currentTime >= badge.dateexpire">
|
||||
{{ 'addon.badges.expired' | translate }}
|
||||
</ion-badge>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
|
||||
<ion-item-group *ngIf="user">
|
||||
<ion-item-divider>
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.recipientdetails' | translate}}</h2>
|
||||
</ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap">
|
||||
<ion-label>
|
||||
<h2>{{ 'core.name' | translate}}</h2>
|
||||
<p>{{ user.fullname }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
|
||||
<ng-container *ngIf="badge">
|
||||
<ion-item-group>
|
||||
<ion-item-divider>
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.issuerdetails' | translate}}</h2>
|
||||
</ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.issuername">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.issuername' | translate}}</h2>
|
||||
<p>{{ badge.issuername }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.issuercontact">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.contact' | translate}}</h2>
|
||||
<p><a href="mailto:{{badge.issuercontact}}" core-link auto-login="no"> {{ badge.issuercontact }} </a></p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
|
||||
<ion-item-group>
|
||||
<ion-item-divider>
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.badgedetails' | translate}}</h2>
|
||||
</ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.name">
|
||||
<ion-label>
|
||||
<h2>{{ 'core.name' | translate}}</h2>
|
||||
<p>{{ badge.name }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.version">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.version' | translate}}</h2>
|
||||
<p>{{ badge.version }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.language">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.language' | translate}}</h2>
|
||||
<p>{{ badge.language }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.description">
|
||||
<ion-label>
|
||||
<h2>{{ 'core.description' | translate}}</h2>
|
||||
<p>{{ badge.description }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.imageauthorname">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.imageauthorname' | translate}}</h2>
|
||||
<p>{{ badge.imageauthorname }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.imageauthoremail">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.imageauthoremail' | translate}}</h2>
|
||||
<p><a href="mailto:{{badge.imageauthoremail}}" core-link auto-login="no"> {{ badge.imageauthoremail }} </a></p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.imageauthorurl">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.imageauthorurl' | translate}}</h2>
|
||||
<p><a [href]="badge.imageauthorurl" core-link auto-login="no"> {{ badge.imageauthorurl }} </a></p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.imagecaption">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.imagecaption' | translate}}</h2>
|
||||
<p>{{ badge.imagecaption }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="course">
|
||||
<ion-label>
|
||||
<h2>{{ 'core.course' | translate}}</h2>
|
||||
<p>
|
||||
<core-format-text [text]="course.fullname" contextLevel="course" [contextInstanceId]="courseId">
|
||||
</core-format-text>
|
||||
</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<!-- Criteria (not yet avalaible) -->
|
||||
</ion-item-group>
|
||||
|
||||
<ion-item-group>
|
||||
<ion-item-divider>
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.issuancedetails' | translate}}</h2>
|
||||
</ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.dateissued">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.dateawarded' | translate}}</h2>
|
||||
<p>{{badge.dateissued * 1000 | coreFormatDate }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.dateexpire">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.expirydate' | translate}}</h2>
|
||||
<p>
|
||||
{{ badge.dateexpire * 1000 | coreFormatDate }}
|
||||
<span class="text-danger" *ngIf="currentTime >= badge.dateexpire">
|
||||
{{ 'addon.badges.warnexpired' | translate }}
|
||||
</span>
|
||||
</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<!-- Evidence (not yet avalaible) -->
|
||||
</ion-item-group>
|
||||
|
||||
<!-- Endorsement -->
|
||||
<ion-item-group *ngIf="badge.endorsement">
|
||||
<ion-item-divider>
|
||||
<ion-label><h2>{{ 'addon.badges.bendorsement' | translate}}</h2></ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.endorsement.issuername">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.issuername' | translate}}</h2>
|
||||
<p>{{ badge.endorsement.issuername }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.endorsement.issueremail">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.issueremail' | translate}}</h2>
|
||||
<p>
|
||||
<a href="mailto:{{badge.endorsement.issueremail}}" core-link auto-login="no">
|
||||
{{ badge.endorsement.issueremail }}
|
||||
</a>
|
||||
</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.endorsement.issuerurl">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.issuerurl' | translate}}</h2>
|
||||
<p><a [href]="badge.endorsement.issuerurl" core-link auto-login="no"> {{ badge.endorsement.issuerurl }} </a></p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.endorsement.dateissued">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.dateawarded' | translate}}</h2>
|
||||
<p>{{ badge.endorsement.dateissued * 1000 | coreFormatDate }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.endorsement.claimid">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.claimid' | translate}}</h2>
|
||||
<p><a [href]="badge.endorsement.claimid" core-link auto-login="no"> {{ badge.endorsement.claimid }} </a></p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.endorsement.claimcomment">
|
||||
<ion-label>
|
||||
<h2>{{ 'addon.badges.claimcomment' | translate}}</h2>
|
||||
<p>{{ badge.endorsement.claimcomment }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
|
||||
<!-- Related badges -->
|
||||
<ion-item-group *ngIf="badge.relatedbadges">
|
||||
<ion-item-divider>
|
||||
<ion-label><h2>{{ 'addon.badges.relatedbages' | translate}}</h2></ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap" *ngFor="let relatedBadge of badge.relatedbadges">
|
||||
<ion-label><h2>{{ relatedBadge.name }}</h2></ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.relatedbadges.length == 0">
|
||||
<ion-label><h2>{{ 'addon.badges.norelated' | translate}}</h2></ion-label>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
|
||||
<!-- Competencies alignment -->
|
||||
<ion-item-group *ngIf="badge.alignment">
|
||||
<ion-item-divider>
|
||||
<ion-label><h2>{{ 'addon.badges.alignment' | translate}}</h2></ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item class="ion-text-wrap" *ngFor="let alignment of badge.alignment" [href]="alignment.targeturl" core-link
|
||||
auto-login="no">
|
||||
<ion-label><h2>{{ alignment.targetname }}</h2></ion-label>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="badge.alignment.length == 0">
|
||||
<ion-label><h2>{{ 'addon.badges.noalignment' | translate}}</h2></ion-label>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
</ng-container>
|
||||
</core-loading>
|
||||
</ion-content>
|
|
@ -0,0 +1,49 @@
|
|||
// (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 { NgModule } from '@angular/core';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { CoreComponentsModule } from '@components/components.module';
|
||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||
import { CorePipesModule } from '@pipes/pipes.module';
|
||||
|
||||
import { AddonBadgesIssuedBadgePage } from './issued-badge.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: AddonBadgesIssuedBadgePage,
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild(routes),
|
||||
CommonModule,
|
||||
IonicModule,
|
||||
TranslateModule.forChild(),
|
||||
CoreComponentsModule,
|
||||
CoreDirectivesModule,
|
||||
CorePipesModule,
|
||||
],
|
||||
declarations: [
|
||||
AddonBadgesIssuedBadgePage,
|
||||
],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class AddonBadgesIssuedBadgePageModule {}
|
|
@ -0,0 +1,112 @@
|
|||
// (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 { IonRefresher } from '@ionic/angular';
|
||||
import { CoreTimeUtils } from '@services/utils/time';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUser, CoreUserProfile } from '@features/user/services/user';
|
||||
import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
|
||||
|
||||
/**
|
||||
* Page that displays the list of calendar events.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'page-addon-badges-issued-badge',
|
||||
templateUrl: 'issued-badge.html',
|
||||
})
|
||||
export class AddonBadgesIssuedBadgePage implements OnInit {
|
||||
|
||||
protected badgeHash = '';
|
||||
protected userId!: number;
|
||||
|
||||
courseId = 0;
|
||||
user?: CoreUserProfile;
|
||||
course?: CoreEnrolledCourseData;
|
||||
badge?: AddonBadgesUserBadge;
|
||||
badgeLoaded = false;
|
||||
currentTime = 0;
|
||||
|
||||
constructor(
|
||||
protected route: ActivatedRoute,
|
||||
) { }
|
||||
|
||||
/**
|
||||
* View loaded.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.courseId = this.route.snapshot.queryParams['courseId'] || this.courseId; // Use 0 for site badges.
|
||||
this.userId = this.route.snapshot.queryParams['userId'] ||
|
||||
CoreSites.instance.getCurrentSite()?.getUserId();
|
||||
this.badgeHash = this.route.snapshot.queryParams['badgeHash'];
|
||||
|
||||
this.fetchIssuedBadge().finally(() => {
|
||||
this.badgeLoaded = true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the issued badge required for the view.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
async fetchIssuedBadge(): Promise<void> {
|
||||
this.currentTime = CoreTimeUtils.instance.timestamp();
|
||||
|
||||
this.user = await CoreUser.instance.getProfile(this.userId, this.courseId, true);
|
||||
|
||||
try {
|
||||
const badges = await AddonBadges.instance.getUserBadges(this.courseId, this.userId);
|
||||
const badge = badges.find((badge) => this.badgeHash == badge.uniquehash);
|
||||
|
||||
if (!badge) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.badge = badge;
|
||||
if (badge.courseid) {
|
||||
try {
|
||||
this.course = await CoreCourses.instance.getUserCourse(badge.courseid, true);
|
||||
} catch {
|
||||
// Maybe an old deleted course.
|
||||
this.course = undefined;
|
||||
}
|
||||
}
|
||||
} catch (message) {
|
||||
CoreDomUtils.instance.showErrorModalDefault(message, 'Error getting badge data.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the badges.
|
||||
*
|
||||
* @param refresher Refresher.
|
||||
*/
|
||||
async refreshBadges(refresher?: CustomEvent<IonRefresher>): Promise<void> {
|
||||
await CoreUtils.instance.ignoreErrors(Promise.all([
|
||||
AddonBadges.instance.invalidateUserBadges(this.courseId, this.userId),
|
||||
]));
|
||||
|
||||
await CoreUtils.instance.ignoreErrors(Promise.all([
|
||||
this.fetchIssuedBadge(),
|
||||
]));
|
||||
|
||||
refresher?.detail.complete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button>
|
||||
</ion-buttons>
|
||||
<ion-title>{{ 'addon.badges.badges' | translate }}</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<!-- @todo <core-split-view>-->
|
||||
<ion-content>
|
||||
<ion-refresher slot="fixed" [disabled]="!badgesLoaded" (ionRefresh)="refreshBadges($event)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<core-loading [hideUntil]="badgesLoaded">
|
||||
<core-empty-box *ngIf="!badges || badges.length == 0" icon="fas-trophy" [message]="'addon.badges.nobadges' | translate">
|
||||
</core-empty-box>
|
||||
|
||||
<ion-list *ngIf="badges && badges.length" class="ion-no-margin">
|
||||
<ion-item class="ion-text-wrap" *ngFor="let badge of badges" [title]="badge.name"
|
||||
(click)="loadIssuedBadge(badge.uniquehash)" [class.core-split-item-selected]="badge.uniquehash == badgeHash">
|
||||
<ion-avatar slot="start">
|
||||
<img [src]="badge.badgeurl" [alt]="badge.name" core-external-content>
|
||||
</ion-avatar>
|
||||
<ion-label>
|
||||
<h2>{{ badge.name }}</h2>
|
||||
<p>{{ badge.dateissued * 1000 | coreFormatDate :'strftimedatetimeshort' }}</p>
|
||||
</ion-label>
|
||||
<ion-badge slot="end" color="danger" *ngIf="badge.dateexpire && currentTime >= badge.dateexpire">
|
||||
{{ 'addon.badges.expired' | translate }}
|
||||
</ion-badge>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</core-loading>
|
||||
</ion-content>
|
|
@ -0,0 +1,49 @@
|
|||
// (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 { NgModule } from '@angular/core';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { CoreComponentsModule } from '@components/components.module';
|
||||
import { CoreDirectivesModule } from '@directives/directives.module';
|
||||
import { CorePipesModule } from '@pipes/pipes.module';
|
||||
|
||||
import { AddonBadgesUserBadgesPage } from './user-badges.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: AddonBadgesUserBadgesPage,
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild(routes),
|
||||
CommonModule,
|
||||
IonicModule,
|
||||
TranslateModule.forChild(),
|
||||
CoreComponentsModule,
|
||||
CoreDirectivesModule,
|
||||
CorePipesModule,
|
||||
],
|
||||
declarations: [
|
||||
AddonBadgesUserBadgesPage,
|
||||
],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class AddonBadgesUserBadgesPageModule {}
|
|
@ -0,0 +1,113 @@
|
|||
// (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 { IonRefresher } from '@ionic/angular';
|
||||
import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
|
||||
import { CoreTimeUtils } from '@services/utils/time';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreNavHelper } from '@services/nav-helper';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
// @todo import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||
|
||||
/**
|
||||
* Page that displays the list of calendar events.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'page-addon-badges-user-badges',
|
||||
templateUrl: 'user-badges.html',
|
||||
})
|
||||
export class AddonBadgesUserBadgesPage implements OnInit {
|
||||
|
||||
// @ViewChild(CoreSplitViewComponent) splitviewCtrl: CoreSplitViewComponent;
|
||||
|
||||
courseId = 0;
|
||||
userId!: number;
|
||||
|
||||
badgesLoaded = false;
|
||||
badges: AddonBadgesUserBadge[] = [];
|
||||
currentTime = 0;
|
||||
badgeHash!: string;
|
||||
|
||||
constructor(
|
||||
protected route: ActivatedRoute,
|
||||
) { }
|
||||
|
||||
/**
|
||||
* View loaded.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
|
||||
this.courseId = this.route.snapshot.queryParams['courseId'] || this.courseId; // Use 0 for site badges.
|
||||
this.userId = this.route.snapshot.queryParams['userId'] ||
|
||||
CoreSites.instance.getCurrentSite()?.getUserId();
|
||||
|
||||
this.fetchBadges().finally(() => {
|
||||
// @todo splitview
|
||||
/* if (!this.badgeHash && this.splitviewCtrl.isOn() && this.badges.length > 0) {
|
||||
// Take first and load it.
|
||||
this.loadIssuedBadge(this.badges[0].uniquehash);
|
||||
}*/
|
||||
this.badgesLoaded = true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all the badges required for the view.
|
||||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
async fetchBadges(): Promise<void> {
|
||||
this.currentTime = CoreTimeUtils.instance.timestamp();
|
||||
|
||||
try {
|
||||
this.badges = await AddonBadges.instance.getUserBadges(this.courseId, this.userId);
|
||||
} catch (message) {
|
||||
CoreDomUtils.instance.showErrorModalDefault(message, 'Error getting badges data.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the badges.
|
||||
*
|
||||
* @param refresher Refresher.
|
||||
*/
|
||||
async refreshBadges(refresher?: CustomEvent<IonRefresher>): Promise<void> {
|
||||
await CoreUtils.instance.ignoreErrors(Promise.all([
|
||||
AddonBadges.instance.invalidateUserBadges(this.courseId, this.userId),
|
||||
]));
|
||||
|
||||
await CoreUtils.instance.ignoreErrors(Promise.all([
|
||||
this.fetchBadges(),
|
||||
]));
|
||||
|
||||
refresher?.detail.complete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to a particular badge.
|
||||
*
|
||||
* @param badgeHash Badge to load.
|
||||
*/
|
||||
loadIssuedBadge(badgeHash: string): void {
|
||||
this.badgeHash = badgeHash;
|
||||
const params = { courseId: this.courseId, userId: this.userId, badgeHash: badgeHash };
|
||||
// @todo use splitview.
|
||||
// this.splitviewCtrl.push('AddonBadgesIssuedBadgePage', params);
|
||||
CoreNavHelper.instance.goInSite('/badges/issue', params);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
// (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 { Injectable } from '@angular/core';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreWSExternalWarning } from '@services/ws';
|
||||
import { CoreSite } from '@classes/site';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreError } from '@classes/errors/error';
|
||||
|
||||
const ROOT_CACHE_KEY = 'mmaBadges:';
|
||||
|
||||
/**
|
||||
* Service to handle badges.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AddonBadgesProvider {
|
||||
|
||||
/**
|
||||
* Returns whether or not the badge plugin is enabled for a certain site.
|
||||
*
|
||||
* This method is called quite often and thus should only perform a quick
|
||||
* check, we should not be calling WS from here.
|
||||
*
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved with true if enabled, false otherwise.
|
||||
*/
|
||||
async isPluginEnabled(siteId?: string): Promise<boolean> {
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
return site.canUseAdvancedFeature('enablebadges') && site.wsAvailable('core_course_get_user_navigation_options');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key for the get badges call.
|
||||
*
|
||||
* @param courseId ID of the course to get the badges from.
|
||||
* @param userId ID of the user to get the badges from.
|
||||
* @return Cache key.
|
||||
*/
|
||||
protected getBadgesCacheKey(courseId: number, userId: number): string {
|
||||
return ROOT_CACHE_KEY + 'badges:' + courseId + ':' + userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get issued badges for a certain user in a course.
|
||||
*
|
||||
* @param courseId ID of the course to get the badges from.
|
||||
* @param userId ID of the user to get the badges from.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise to be resolved when the badges are retrieved.
|
||||
*/
|
||||
async getUserBadges(courseId: number, userId: number, siteId?: string): Promise<AddonBadgesUserBadge[]> {
|
||||
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
const data: AddonBadgesGetUserBadgesWSParams = {
|
||||
courseid: courseId,
|
||||
userid: userId,
|
||||
};
|
||||
const preSets = {
|
||||
cacheKey: this.getBadgesCacheKey(courseId, userId),
|
||||
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
||||
};
|
||||
|
||||
const response = await site.read<AddonBadgesGetUserBadgesWSResponse>('core_badges_get_user_badges', data, preSets);
|
||||
if (!response || !response.badges) {
|
||||
throw new CoreError('Invalid badges response');
|
||||
}
|
||||
|
||||
// In 3.7, competencies was renamed to alignment. Rename the property in 3.6 too.
|
||||
response.badges.forEach((badge) => {
|
||||
badge.alignment = badge.alignment || badge.competencies;
|
||||
|
||||
// Check that the alignment is valid, they were broken in 3.7.
|
||||
if (badge.alignment && badge.alignment[0] && typeof badge.alignment[0].targetname == 'undefined') {
|
||||
// If any badge lacks targetname it means they are affected by the Moodle bug, don't display them.
|
||||
delete badge.alignment;
|
||||
}
|
||||
});
|
||||
|
||||
return response.badges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate get badges WS call.
|
||||
*
|
||||
* @param courseId Course ID.
|
||||
* @param userId ID of the user to get the badges from.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @return Promise resolved when data is invalidated.
|
||||
*/
|
||||
async invalidateUserBadges(courseId: number, userId: number, siteId?: string): Promise<void> {
|
||||
const site = await CoreSites.instance.getSite(siteId);
|
||||
|
||||
await site.invalidateWsCacheForKey(this.getBadgesCacheKey(courseId, userId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class AddonBadges extends makeSingleton(AddonBadgesProvider) {}
|
||||
|
||||
/**
|
||||
* Params of core_badges_get_user_badges WS.
|
||||
*/
|
||||
type AddonBadgesGetUserBadgesWSParams = {
|
||||
userid?: number; // Badges only for this user id, empty for current user.
|
||||
courseid?: number; // Filter badges by course id, empty all the courses.
|
||||
page?: number; // The page of records to return.
|
||||
perpage?: number; // The number of records to return per page.
|
||||
search?: string; // A simple string to search for.
|
||||
onlypublic?: boolean; // Whether to return only public badges.
|
||||
};
|
||||
|
||||
/**
|
||||
* Data returned by core_badges_get_user_badges WS.
|
||||
*/
|
||||
type AddonBadgesGetUserBadgesWSResponse = {
|
||||
badges: AddonBadgesUserBadge[];
|
||||
warnings?: CoreWSExternalWarning[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Result of WS core_badges_get_user_badges.
|
||||
*/
|
||||
export type AddonBadgesGetUserBadgesResult = {
|
||||
badges: AddonBadgesUserBadge[]; // List of badges.
|
||||
warnings?: CoreWSExternalWarning[]; // List of warnings.
|
||||
};
|
||||
|
||||
/**
|
||||
* Badge data returned by WS core_badges_get_user_badges.
|
||||
*/
|
||||
export type AddonBadgesUserBadge = {
|
||||
id?: number; // Badge id.
|
||||
name: string; // Badge name.
|
||||
description: string; // Badge description.
|
||||
timecreated?: number; // Time created.
|
||||
timemodified?: number; // Time modified.
|
||||
usercreated?: number; // User created.
|
||||
usermodified?: number; // User modified.
|
||||
issuername: string; // Issuer name.
|
||||
issuerurl: string; // Issuer URL.
|
||||
issuercontact: string; // Issuer contact.
|
||||
expiredate?: number; // Expire date.
|
||||
expireperiod?: number; // Expire period.
|
||||
type?: number; // Type.
|
||||
courseid?: number; // Course id.
|
||||
message?: string; // Message.
|
||||
messagesubject?: string; // Message subject.
|
||||
attachment?: number; // Attachment.
|
||||
notification?: number; // @since 3.6. Whether to notify when badge is awarded.
|
||||
nextcron?: number; // @since 3.6. Next cron.
|
||||
status?: number; // Status.
|
||||
issuedid?: number; // Issued id.
|
||||
uniquehash: string; // Unique hash.
|
||||
dateissued: number; // Date issued.
|
||||
dateexpire: number; // Date expire.
|
||||
visible?: number; // Visible.
|
||||
email?: string; // @since 3.6. User email.
|
||||
version?: string; // @since 3.6. Version.
|
||||
language?: string; // @since 3.6. Language.
|
||||
imageauthorname?: string; // @since 3.6. Name of the image author.
|
||||
imageauthoremail?: string; // @since 3.6. Email of the image author.
|
||||
imageauthorurl?: string; // @since 3.6. URL of the image author.
|
||||
imagecaption?: string; // @since 3.6. Caption of the image.
|
||||
badgeurl: string; // Badge URL.
|
||||
endorsement?: { // @since 3.6.
|
||||
id: number; // Endorsement id.
|
||||
badgeid: number; // Badge id.
|
||||
issuername: string; // Endorsement issuer name.
|
||||
issuerurl: string; // Endorsement issuer URL.
|
||||
issueremail: string; // Endorsement issuer email.
|
||||
claimid: string; // Claim URL.
|
||||
claimcomment: string; // Claim comment.
|
||||
dateissued: number; // Date issued.
|
||||
};
|
||||
alignment?: { // @since 3.7. Calculated by the app for 3.6 sites. Badge alignments.
|
||||
id?: number; // Alignment id.
|
||||
badgeid?: number; // Badge id.
|
||||
targetname?: string; // Target name.
|
||||
targeturl?: string; // Target URL.
|
||||
targetdescription?: string; // Target description.
|
||||
targetframework?: string; // Target framework.
|
||||
targetcode?: string; // Target code.
|
||||
}[];
|
||||
competencies?: { // @deprecated from 3.7. @since 3.6. In 3.7 it was renamed to alignment.
|
||||
id?: number; // Alignment id.
|
||||
badgeid?: number; // Badge id.
|
||||
targetname?: string; // Target name.
|
||||
targeturl?: string; // Target URL.
|
||||
targetdescription?: string; // Target description.
|
||||
targetframework?: string; // Target framework.
|
||||
targetcode?: string; // Target code.
|
||||
}[];
|
||||
relatedbadges?: { // @since 3.6. Related badges.
|
||||
id: number; // Badge id.
|
||||
name: string; // Badge name.
|
||||
version?: string; // Version.
|
||||
language?: string; // Language.
|
||||
type?: number; // Type.
|
||||
}[];
|
||||
};
|
|
@ -0,0 +1,71 @@
|
|||
// (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 { Injectable } from '@angular/core';
|
||||
import { Params } from '@angular/router';
|
||||
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreNavHelper } from '@services/nav-helper';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { AddonBadges } from '../badges';
|
||||
|
||||
|
||||
/**
|
||||
* Handler to treat links to user participants page.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AddonBadgesBadgeLinkHandlerService extends CoreContentLinksHandlerBase {
|
||||
|
||||
name = 'AddonBadgesBadgeLinkHandler';
|
||||
pattern = /\/badges\/badge\.php.*([?&]hash=)/;
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @param siteIds List of sites the URL belongs to.
|
||||
* @param url The URL to treat.
|
||||
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param courseId Course ID related to the URL. Optional but recommended.
|
||||
* @return List of (or promise resolved with list of) actions.
|
||||
*/
|
||||
getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] {
|
||||
|
||||
return [{
|
||||
action: (siteId: string): void => {
|
||||
CoreNavHelper.instance.goInSite(
|
||||
'/badges/issue',
|
||||
{ courseId: 0, badgeHash: params.hash },
|
||||
siteId,
|
||||
);
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param siteId The site ID.
|
||||
* @param url The URL to treat.
|
||||
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param courseId Course ID related to the URL. Optional but recommended.
|
||||
* @return Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string): Promise<boolean> {
|
||||
return AddonBadges.instance.isPluginEnabled(siteId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class AddonBadgesBadgeLinkHandler extends makeSingleton(AddonBadgesBadgeLinkHandlerService) {}
|
|
@ -0,0 +1,58 @@
|
|||
// (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 { Injectable } from '@angular/core';
|
||||
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreNavHelper } from '@services/nav-helper';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { AddonBadges } from '../badges';
|
||||
|
||||
/**
|
||||
* Handler to treat links to user badges page.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AddonBadgesMyBadgesLinkHandlerService extends CoreContentLinksHandlerBase {
|
||||
|
||||
name = 'AddonBadgesMyBadgesLinkHandler';
|
||||
featureName = 'CoreUserDelegate_AddonBadges';
|
||||
pattern = /\/badges\/mybadges\.php/;
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @return List of (or promise resolved with list of) actions.
|
||||
*/
|
||||
getActions(): CoreContentLinksAction[] {
|
||||
return [{
|
||||
action: (siteId: string): void => {
|
||||
CoreNavHelper.instance.goInSite('/badges/user', {}, siteId);
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param siteId The site ID.
|
||||
* @return Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string): boolean | Promise<boolean> {
|
||||
return AddonBadges.instance.isPluginEnabled(siteId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class AddonBadgesMyBadgesLinkHandler extends makeSingleton(AddonBadgesMyBadgesLinkHandlerService) {}
|
|
@ -0,0 +1,82 @@
|
|||
// (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 { Injectable } from '@angular/core';
|
||||
import { CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/services/courses';
|
||||
import { CoreUserProfile } from '@features/user/services/user';
|
||||
import { CoreUserDelegateService, CoreUserProfileHandler, CoreUserProfileHandlerData } from '@features/user/services/user-delegate';
|
||||
import { CoreNavHelper } from '@services/nav-helper';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { AddonBadges } from '../badges';
|
||||
|
||||
/**
|
||||
* Profile badges handler.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AddonBadgesUserHandlerService implements CoreUserProfileHandler {
|
||||
|
||||
name = 'AddonBadges';
|
||||
priority = 50;
|
||||
type = CoreUserDelegateService.TYPE_NEW_PAGE;
|
||||
|
||||
/**
|
||||
* Check if handler is enabled.
|
||||
*
|
||||
* @return Always enabled.
|
||||
*/
|
||||
isEnabled(): Promise<boolean> {
|
||||
return AddonBadges.instance.isPluginEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if handler is enabled for this user in this context.
|
||||
*
|
||||
* @param user User to check.
|
||||
* @param courseId Course ID.
|
||||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @return True if enabled, false otherwise.
|
||||
*/
|
||||
async isEnabledForUser(
|
||||
user: CoreUserProfile,
|
||||
courseId: number,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
if (navOptions && typeof navOptions.badges != 'undefined') {
|
||||
return navOptions.badges;
|
||||
}
|
||||
|
||||
// If we reach here, it means we are opening the user site profile.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data needed to render the handler.
|
||||
*
|
||||
* @return Data needed to render the handler.
|
||||
*/
|
||||
getDisplayData(): CoreUserProfileHandlerData {
|
||||
return {
|
||||
icon: 'fas-trophy',
|
||||
title: 'addon.badges.badges',
|
||||
action: (event, user, courseId): void => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
CoreNavHelper.instance.goInSite('/badges/user', { courseId: courseId || 0, userId: user.id });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class AddonBadgesUserHandler extends makeSingleton(AddonBadgesUserHandlerService) {}
|
|
@ -49,7 +49,7 @@
|
|||
</ion-grid>
|
||||
|
||||
<ion-item button class="ion-text-wrap core-user-profile-handler" (click)="openUserDetails()"
|
||||
title="{{ 'core.user.details' | translate }}">
|
||||
title="{{ 'core.user.details' | translate }}" detail>
|
||||
<ion-icon name="fa-user" slot="start"></ion-icon>
|
||||
<ion-label>
|
||||
<h2>{{ 'core.user.details' | translate }}</h2>
|
||||
|
@ -61,9 +61,9 @@
|
|||
|
||||
<ion-item button *ngFor="let handler of newPageHandlers" class="ion-text-wrap" (click)="handlerClicked($event, handler)"
|
||||
[ngClass]="['core-user-profile-handler', handler.class]" [hidden]="handler.hidden"
|
||||
title="{{ handler.title | translate }}">
|
||||
title="{{ handler.title | translate }}" detail>
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start"></ion-icon>
|
||||
<ion-label>
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start"></ion-icon>
|
||||
<h2>{{ handler.title | translate }}</h2>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
@ -72,8 +72,8 @@
|
|||
<ion-button *ngFor="let handler of actionHandlers" expand="block" fill="outline"
|
||||
[ngClass]="['core-user-profile-handler', handler.class]" (click)="handlerClicked($event, handler)"
|
||||
[hidden]="handler.hidden" title="{{ handler.title | translate }}" [disabled]="handler.spinner">
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start"></ion-icon>
|
||||
<ion-label>
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start"></ion-icon>
|
||||
<span>{{ handler.title | translate }}</span>
|
||||
</ion-label>
|
||||
<ion-spinner *ngIf="handler.spinner"></ion-spinner>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
--core-avatar-size: var(--core-large-avatar-size);
|
||||
|
||||
img {
|
||||
margin: 0;
|
||||
margin: 8px auto;
|
||||
}
|
||||
|
||||
.contact-status {
|
||||
|
|
|
@ -20,6 +20,7 @@ import { CoreUtils } from '@services/utils/utils';
|
|||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreUserProfile } from './user';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/services/courses';
|
||||
|
||||
/**
|
||||
* Interface that all user profile handlers must implement.
|
||||
|
@ -48,7 +49,12 @@ export interface CoreUserProfileHandler extends CoreDelegateHandler {
|
|||
* @param admOptions Admin options for the course.
|
||||
* @return Whether or not the handler is enabled for a user.
|
||||
*/
|
||||
isEnabledForUser(user: CoreUserProfile, courseId: number, navOptions?: unknown, admOptions?: unknown): Promise<boolean>;
|
||||
isEnabledForUser(
|
||||
user: CoreUserProfile,
|
||||
courseId: number,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Returns the data needed to render the handler.
|
||||
|
|
|
@ -93,19 +93,20 @@ export class CoreNavHelperService {
|
|||
* Goes to a certain page in a certain site. If the site is current site it will perform a regular navigation,
|
||||
* otherwise it will load the other site and open the page in main menu.
|
||||
*
|
||||
* @param pageName Name of the page to go.
|
||||
* @param path Path to go.
|
||||
* @param pageParams Params to send to the page.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @param checkMenu If true, check if the root page of a main menu tab. Only the page name will be checked.
|
||||
* @param checkMenu If true, check if the root page is on a main menu tab. Only the path will be checked.
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
async goInSite(pageName: string, pageParams: Params, siteId?: string, checkMenu?: boolean): Promise<void> {
|
||||
async goInSite(path: string, pageParams: Params, siteId?: string, checkMenu?: boolean): Promise<void> {
|
||||
|
||||
siteId = siteId || CoreSites.instance.getCurrentSiteId();
|
||||
|
||||
// @todo: When this function was in ContentLinksHelper, this code was inside NgZone. Check if it's needed.
|
||||
|
||||
if (!CoreSites.instance.isLoggedIn() || siteId != CoreSites.instance.getCurrentSiteId()) {
|
||||
await this.openInSiteMainMenu(pageName, pageParams, siteId);
|
||||
await this.openInSiteMainMenu(path, pageParams, siteId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -114,20 +115,20 @@ export class CoreNavHelperService {
|
|||
let isInMenu = false;
|
||||
// Check if the page is in the main menu.
|
||||
try {
|
||||
isInMenu = await CoreMainMenu.instance.isCurrentMainMenuHandler(pageName);
|
||||
isInMenu = await CoreMainMenu.instance.isCurrentMainMenuHandler(path);
|
||||
} catch {
|
||||
isInMenu = false;
|
||||
}
|
||||
|
||||
if (isInMenu) {
|
||||
// Just select the tab. @todo test.
|
||||
CoreNavHelper.instance.loadPageInMainMenu(pageName, pageParams);
|
||||
CoreNavHelper.instance.loadPageInMainMenu(path, pageParams);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await this.goInCurrentMainMenuTab(pageName, pageParams);
|
||||
await this.goInCurrentMainMenuTab(path, pageParams);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -205,7 +205,7 @@ ion-card.core-danger-card {
|
|||
img.large-avatar,
|
||||
.large-avatar img {
|
||||
display: block;
|
||||
margin: auto;
|
||||
margin: 8px auto;
|
||||
width: var(--core-large-avatar-size);
|
||||
height: var(--core-large-avatar-size);
|
||||
max-width: var(--core-large-avatar-size);
|
||||
|
|
Loading…
Reference in New Issue