diff --git a/src/addon/badges/pages/issued-badge/issued-badge.html b/src/addon/badges/pages/issued-badge/issued-badge.html new file mode 100644 index 000000000..656d54114 --- /dev/null +++ b/src/addon/badges/pages/issued-badge/issued-badge.html @@ -0,0 +1,87 @@ + + + {{badge.name}} + + + + + + + + +
+
+ {{badge.name}} + + {{ 'addon.badges.expired' | translate }} + +
+
+ +
+
+

{{ 'addon.badges.recipientdetails' | translate}}

+
+
+

{{ 'core.name' | translate}}

+

+ +

+
+
+ +
+
+

{{ 'addon.badges.issuerdetails' | translate}}

+
+
+

{{ 'addon.badges.issuername' | translate}}

+

+ +

+
+
+

{{ 'addon.badges.contact' | translate}}

+

+ +

+
+
+ +
+
+

{{ 'addon.badges.badgedetails' | translate}}

+
+
+

{{ 'core.name' | translate}}

+

{{badge.name}}

+
+
+

{{ 'core.description' | translate}}

+

+ +

+
+
+

{{ 'core.course' | translate}}

+

+ +

+
+
+ +
+
+

{{ 'addon.badges.issuancedetails' | translate}}

+
+
+

{{ 'addon.badges.dateawarded' | translate}}

+

{{badge.dateissued | coreToLocaleString }}

+
+
+

{{ 'addon.badges.expirydate' | translate}}

+

{{badge.dateexpire | coreToLocaleString }}

+
+
+
+
diff --git a/src/addon/badges/pages/issued-badge/issued-badge.module.ts b/src/addon/badges/pages/issued-badge/issued-badge.module.ts new file mode 100644 index 000000000..fc3365801 --- /dev/null +++ b/src/addon/badges/pages/issued-badge/issued-badge.module.ts @@ -0,0 +1,35 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// 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 { IonicPageModule } from 'ionic-angular'; +import { TranslateModule } from '@ngx-translate/core'; +import { CoreComponentsModule } from '../../../../components/components.module'; +import { CoreDirectivesModule } from '../../../../directives/directives.module'; +import { CorePipesModule } from '../../../../pipes/pipes.module'; +import { AddonBadgesIssuedBadgePage } from './issued-badge'; + +@NgModule({ + declarations: [ + AddonBadgesIssuedBadgePage, + ], + imports: [ + CoreComponentsModule, + CoreDirectivesModule, + CorePipesModule, + IonicPageModule.forChild(AddonBadgesIssuedBadgePage), + TranslateModule.forChild() + ], +}) +export class AddonBadgesIssuedBadgePageModule {} diff --git a/src/addon/badges/pages/issued-badge/issued-badge.ts b/src/addon/badges/pages/issued-badge/issued-badge.ts new file mode 100644 index 000000000..8beceaf63 --- /dev/null +++ b/src/addon/badges/pages/issued-badge/issued-badge.ts @@ -0,0 +1,114 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// 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, ViewChild } from '@angular/core'; +import { IonicPage, Content, PopoverController, NavParams } from 'ionic-angular'; +import { TranslateService } from '@ngx-translate/core'; +import { AddonBadgesProvider } from '../../providers/badges'; +import { CoreTimeUtilsProvider } from '../../../../providers/utils/time'; +import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; +import { CoreSitesProvider } from '../../../../providers/sites'; +import { CoreUserProvider } from '../../../../core/user/providers/user'; +import { CoreCoursesProvider } from '../../../../core/courses/providers/courses'; + +/** + * Page that displays the list of calendar events. + */ +@IonicPage({ segment: 'addon-badges-issued-badge' }) +@Component({ + selector: 'page-addon-badges-issued-badge', + templateUrl: 'issued-badge.html', +}) +export class AddonBadgesIssuedBadgePage { + @ViewChild(Content) content: Content; + + courseId: number; + userId: number; + badgeHash: string; + user: any = {}; + course: any = {}; + badge: any = {}; + + badgeLoaded = false; + currentTime = 0; + + constructor(private translate: TranslateService, private badgesProvider: AddonBadgesProvider, navParams: NavParams, + private domUtils: CoreDomUtilsProvider, private timeUtils: CoreTimeUtilsProvider, + private sitesProvider: CoreSitesProvider, private userProvider: CoreUserProvider, + private coursesProvider: CoreCoursesProvider) { + + this.courseId = navParams.get('courseId') || 0; // Use 0 for site badges. + this.userId = navParams.get('userId') || sitesProvider.getCurrentSite().getUserId(); + this.badgeHash = navParams.get('badgeHash'); + } + + /** + * View loaded. + */ + ionViewDidLoad(): void { + + this.fetchIssuedBadge().finally(() => { + this.badgeLoaded = true; + }); + } + + /** + * Fetch the issued badge required for the view. + * + * @return {Promise} Promise resolved when done. + */ + fetchIssuedBadge(): Promise { + const promises = []; + + this.currentTime = this.timeUtils.timestamp(); + let promise = this.userProvider.getProfile(this.userId, this.courseId, true).then((user) => { + this.user = user; + }); + promises.push(promise); + + promise = this.badgesProvider.getUserBadges(this.courseId, this.userId).then((badges) => { + badges.forEach((badge) => { + if (this.badgeHash == badge.uniquehash) { + this.badge = badge; + if (badge.courseid) { + return this.coursesProvider.getUserCourse(badge.courseid, true).then((course) => { + this.course = course; + }).catch(() => { + // Maybe an old deleted course. + this.course = null; + }); + } + } + }); + }).catch((message) => { + this.domUtils.showErrorModalDefault(message, 'Error getting badge data.'); + }); + promises.push(promise); + + return Promise.all(promises); + } + + /** + * Refresh the badges. + * + * @param {any} refresher Refresher. + */ + refreshBadges(refresher: any): void { + this.badgesProvider.invalidateUserBadges(this.courseId, this.userId).finally(() => { + this.fetchIssuedBadge().finally(() => { + refresher.complete(); + }); + }); + } +} diff --git a/src/addon/badges/pages/user-badges/user-badges.ts b/src/addon/badges/pages/user-badges/user-badges.ts index 795f0c304..0855e5346 100644 --- a/src/addon/badges/pages/user-badges/user-badges.ts +++ b/src/addon/badges/pages/user-badges/user-badges.ts @@ -39,11 +39,11 @@ export class AddonBadgesUserBadgesPage { badgesLoaded = false; badges = []; currentTime = 0; - badgeHash = ''; + badgeHash: string; - constructor(private translate: TranslateService, private badgesProvider: AddonBadgesProvider, navParams: NavParams, - private domUtils: CoreDomUtilsProvider, private timeUtils: CoreTimeUtilsProvider, - sitesProvider: CoreSitesProvider, private navCtrl: NavController) { + constructor(private translate: TranslateService, private badgesProvider: AddonBadgesProvider, + navParams: NavParams, private domUtils: CoreDomUtilsProvider, private timeUtils: CoreTimeUtilsProvider, + private sitesProvider: CoreSitesProvider) { this.courseId = navParams.get('courseId') || 0; // Use 0 for site badges. this.userId = navParams.get('userId') || sitesProvider.getCurrentSite().getUserId(); @@ -55,6 +55,10 @@ export class AddonBadgesUserBadgesPage { ionViewDidLoad(): void { this.fetchBadges().finally(() => { + if (!this.badgeHash && this.splitviewCtrl.isOn() && this.badges.length > 0) { + // Take first and load it. + this.loadIssuedBadge(this.badges[0].uniquehash); + } this.badgesLoaded = true; }); } @@ -70,13 +74,7 @@ export class AddonBadgesUserBadgesPage { return this.badgesProvider.getUserBadges(this.courseId, this.userId).then((badges) => { this.badges = badges; }).catch((message) => { - if (message) { - this.domUtils.showErrorModal(message); - } else { - this.domUtils.showErrorModal('Error getting badges data.'); - } - - return Promise.reject(null); + this.domUtils.showErrorModalDefault(message, 'Error getting badges data.'); }); } @@ -100,6 +98,7 @@ export class AddonBadgesUserBadgesPage { */ loadIssuedBadge(badgeHash: string): void { this.badgeHash = badgeHash; - //this.splitviewCtrl.push('', { id: }); + const params = {courseId: this.courseId, userId: this.userId, badgeHash: badgeHash}; + this.splitviewCtrl.push('AddonBadgesIssuedBadgePage', params); } }