2017-11-10 17:15:11 +00:00
import { Component , OnInit , Input , Output , EventEmitter } from '@angular/core' ;
import { ApiService } from '../providers/api-service' ;
// import { PaginatePipe } from 'ngx-pagination';
import { PaginationInstance } from 'ngx-pagination' ;
// import { PaginationControlsComponent } from 'ngx-pagination';
// import { PaginationControlsDirective } from 'ngx-pagination';
// import { TransactionResultComponent } from '../shared/transaction-result.component';
import 'rxjs/add/operator/map' ;
@Component ( {
2017-11-10 17:17:04 +00:00
templateUrl : 'leaderboard.component.html' ,
2017-11-10 17:15:11 +00:00
} )
export class LeaderboardComponent implements OnInit {
2017-11-10 18:41:35 +00:00
leaderboardList ;
2017-11-10 17:15:11 +00:00
noLeaderboardList = false ;
public p : any ;
leaderboardData : Array < any > ;
currentPos : number ;
listType : any = 'weekly_total' ;
public paginateConfig : PaginationInstance = {
id : 'leadpaginate' ,
itemsPerPage : 10 ,
currentPage : 1 ,
totalItems : 0
} ;
constructor (
private api : ApiService ,
2017-11-10 18:41:35 +00:00
) { }
2017-11-10 17:15:11 +00:00
ngOnInit ( ) : void {
this . loadLeaderboard ( 0 ) ;
}
// private fetchLeaderboard() {
// this.peopleService.leaderboard(this.listType)
// .subscribe(
// result => {
// this.leaderboardData = result.leaderboard;
// this.currentPos = result.user_position;
// }
// );
// }
public changeLeaderboard ( event ) {
2017-11-10 18:41:35 +00:00
this . loadLeaderboard ( 0 ) ;
2017-11-10 17:15:11 +00:00
}
loadLeaderboard ( leadPage : number ) {
2017-11-10 18:41:35 +00:00
console . log ( leadPage , this . listType ) ;
this . api . leaderboard_fetch ( this . listType , leadPage ) . subscribe (
2017-11-10 17:15:11 +00:00
result = > {
2017-11-10 18:41:35 +00:00
if ( result . leaderboard . length > 0 ) {
this . leaderboardList = result . leaderboard ;
2017-11-10 17:15:11 +00:00
// TODO Rename in server
2017-11-10 18:41:35 +00:00
this . paginateConfig . totalItems = result . count ;
2017-11-10 17:15:11 +00:00
this . paginateConfig . currentPage = result . page ;
this . noLeaderboardList = false ;
} else {
2017-11-10 18:41:35 +00:00
// handle the case when the leaderboardList is empty
2017-11-10 17:15:11 +00:00
this . leaderboardList = null ;
this . noLeaderboardList = true ;
}
} ,
error = > {
console . log ( error ) ;
}
) ;
}
// // dynamically changes the row style based on player's position
// // for instance, top three player and the player him/herself should
// // be hightlighted
// public getClass(item) {
// if( item.position < 4 ) {
// return "topThree";
// } else if( item.position == this.currentPos ) {
// return "user";
// }
// return "otherUsers";
// }
//
// // show changes by using icon, trending up and trending down or no trend.
// public getTrendIcon(item){
// if( item.trend < 0 ){
// return "md-trending-up";
// } else if( item.trend > 0 ){
// return "md-trending-down";
// }
// return "md-remove";
// }
//
// // need to merge this function with getIcon
// // this function shows different icon color based on the direction of the position shifted
// public getTrendIconColor(item){
// if( item.trend < 0 ) {
// return "secondary";
// } else if( item.trend > 0 ){
// return "danger";
// }
// return "dark";
// }
}