MOBILE-2325 badges: Issued badges for user page

main
Juan Leyva 2018-02-14 17:21:03 +01:00 committed by Dani Palou
parent 138f83d979
commit 68ff3026e4
4 changed files with 170 additions and 2 deletions

View File

@ -0,0 +1,28 @@
<ion-header>
<ion-navbar>
<ion-title>{{ 'addon.badges.badges' | translate }}</ion-title>
</ion-navbar>
</ion-header>
<core-split-view>
<ion-content>
<ion-refresher [enabled]="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="trophy" [message]="'addon.badges.nobadges' | translate">
</core-empty-box>
<ion-list *ngIf="badges && badges.length" no-margin>
<a ion-item text-wrap *ngFor="let badge of badges" [title]="badge.name" (click)="loadIssuedBadge(badge.uniquehash)" [class.core-split-item-selected]="badge.uniquehash == badgeHash">
<img src="{{badge.badgeurl}}" alt="{{badge.name}}" item-start core-external-content>
<span *ngIf="badge.dateexpire && currentTime >= badge.dateexpire" class="badge badge-assertive">
{{ 'addon.badges.expired' | translate }}
</span>
<h2><core-format-text [text]="badge.name"></core-format-text></h2>
<p>{{ badge.dateissued | coreToLocaleString }}</p>
</a>
</ion-list>
</core-loading>
</ion-content>
</core-split-view>

View File

@ -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 { AddonBadgesUserBadgesPage } from './user-badges';
@NgModule({
declarations: [
AddonBadgesUserBadgesPage,
],
imports: [
CoreComponentsModule,
CoreDirectivesModule,
CorePipesModule,
IonicPageModule.forChild(AddonBadgesUserBadgesPage),
TranslateModule.forChild()
],
})
export class AddonBadgesUserBadgesPageModule {}

View File

@ -0,0 +1,105 @@
// (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, NavParams, NavController } 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 { CoreSplitViewComponent } from '../../../../components/split-view/split-view';
/**
* Page that displays the list of calendar events.
*/
@IonicPage({ segment: 'addon-badges-user-badges' })
@Component({
selector: 'page-addon-badges-user-badges',
templateUrl: 'user-badges.html',
})
export class AddonBadgesUserBadgesPage {
@ViewChild(Content) content: Content;
@ViewChild(CoreSplitViewComponent) splitviewCtrl: CoreSplitViewComponent;
courseId: number;
userId: number;
badgesLoaded = false;
badges = [];
currentTime = 0;
badgeHash = '';
constructor(private translate: TranslateService, private badgesProvider: AddonBadgesProvider, navParams: NavParams,
private domUtils: CoreDomUtilsProvider, private timeUtils: CoreTimeUtilsProvider,
sitesProvider: CoreSitesProvider, private navCtrl: NavController) {
this.courseId = navParams.get('courseId') || 0; // Use 0 for site badges.
this.userId = navParams.get('userId') || sitesProvider.getCurrentSite().getUserId();
}
/**
* View loaded.
*/
ionViewDidLoad(): void {
this.fetchBadges().finally(() => {
this.badgesLoaded = true;
});
}
/**
* Fetch all the badges required for the view.
*
* @return {Promise<any>} Promise resolved when done.
*/
fetchBadges(): Promise<any> {
this.currentTime = this.timeUtils.timestamp();
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);
});
}
/**
* Refresh the badges.
*
* @param {any} refresher Refresher.
*/
refreshBadges(refresher: any): void {
this.badgesProvider.invalidateUserBadges(this.courseId, this.userId).finally(() => {
this.fetchBadges().finally(() => {
refresher.complete();
});
});
}
/**
* Navigate to a particular badge.
*
* @param {string} badgeHash Badge to load.
*/
loadIssuedBadge(badgeHash: string): void {
this.badgeHash = badgeHash;
//this.splitviewCtrl.push('', { id: });
}
}

View File

@ -62,13 +62,13 @@ export class AddonBadgesUserHandler implements CoreUserProfileHandler {
*/
getDisplayData(user: any, courseId: number): CoreUserProfileHandlerData {
return {
icon: 'ion-trophy',
icon: 'trophy',
title: 'addon.badges.badges',
class: '',
action: (event, navCtrl, user, courseId): void => {
event.preventDefault();
event.stopPropagation();
//navCtrl.push();
navCtrl.push('AddonBadgesUserBadgesPage', {courseId: courseId, userId: user.id });
}
};
}