Compare commits
	
		
			No commits in common. "f6317d7fbc7fd9fcd83d4fae87335c4149e57c1c" and "e099ff572ff3fddf6ab0bf4eeec2398454e4b4c4" have entirely different histories. 
		
	
	
		
			f6317d7fbc
			...
			e099ff572f
		
	
		|  | @ -6,6 +6,7 @@ import {SquadService} from '../services/army-management/squad.service'; | ||||||
| import {Fraction} from '../utils/fraction.enum'; | import {Fraction} from '../utils/fraction.enum'; | ||||||
| import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service'; | import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service'; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'admin-panel', |   selector: 'admin-panel', | ||||||
|   templateUrl: './admin.component.html', |   templateUrl: './admin.component.html', | ||||||
|  | @ -65,4 +66,5 @@ export class AdminComponent implements OnInit { | ||||||
|       return o1._id === o2._id; |       return o1._id === o2._id; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -22,7 +22,9 @@ export class ArmyComponent implements OnInit { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   ngOnInit() { |   ngOnInit() { | ||||||
|     this.armyService.getArmies().subscribe(army => { |     // init army data
 | ||||||
|  |     this.armyService.getArmy() | ||||||
|  |         .subscribe(army => { | ||||||
|           this.army = army; |           this.army = army; | ||||||
|         }); |         }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  | @ -95,8 +95,8 @@ export class EditUserComponent implements OnInit { | ||||||
|     if (this.user._id) { |     if (this.user._id) { | ||||||
|       this.userService.updateUser(updateObject) |       this.userService.updateUser(updateObject) | ||||||
|           .subscribe(user => { |           .subscribe(user => { | ||||||
|             if (!user.squadId) { |             if (!user.squad) { | ||||||
|               user.squadId = '0'; |               user.squad = '0'; | ||||||
|             } |             } | ||||||
|             this.user = user; |             this.user = user; | ||||||
|             this.snackBarService.showSuccess('generic.save.success'); |             this.snackBarService.showSuccess('generic.save.success'); | ||||||
|  |  | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| import {Component} from '@angular/core'; | import {Component, OnInit} from '@angular/core'; | ||||||
| 
 | 
 | ||||||
| import {FormControl} from '@angular/forms'; | import {FormControl} from '@angular/forms'; | ||||||
| import {ActivatedRoute, Router} from '@angular/router'; | import {ActivatedRoute, Router} from '@angular/router'; | ||||||
| import {Observable} from 'rxjs/Observable'; | import {Observable} from 'rxjs/Observable'; | ||||||
| import {UserService} from '../../../services/army-management/user.service'; | import {UserService} from '../../../services/army-management/user.service'; | ||||||
| import {User} from '../../../models/model-interfaces'; | import {User} from '../../../models/model-interfaces'; | ||||||
| import {ADD_ARRAY, LOAD} from '../../../services/stores/generic-store'; | import {ADD, LOAD} from '../../../services/stores/generic-store'; | ||||||
| import {Fraction} from '../../../utils/fraction.enum'; | import {Fraction} from '../../../utils/fraction.enum'; | ||||||
| import {MatButtonToggleGroup} from '@angular/material'; | import {MatButtonToggleGroup} from '@angular/material'; | ||||||
| import {UIHelpers} from '../../../utils/global.helpers'; | import {UIHelpers} from '../../../utils/global.helpers'; | ||||||
|  | @ -16,7 +16,7 @@ import {TranslateService} from '@ngx-translate/core'; | ||||||
|   templateUrl: './user-list.component.html', |   templateUrl: './user-list.component.html', | ||||||
|   styleUrls: ['./user-list.component.css', '../../../style/select-list.css'] |   styleUrls: ['./user-list.component.css', '../../../style/select-list.css'] | ||||||
| }) | }) | ||||||
| export class UserListComponent { | export class UserListComponent implements OnInit { | ||||||
| 
 | 
 | ||||||
|   selectedUserId: string | number = null; |   selectedUserId: string | number = null; | ||||||
| 
 | 
 | ||||||
|  | @ -26,9 +26,9 @@ export class UserListComponent { | ||||||
| 
 | 
 | ||||||
|   radioModel = ''; |   radioModel = ''; | ||||||
| 
 | 
 | ||||||
|   readonly throttle = 300; |   throttle = 300; | ||||||
| 
 | 
 | ||||||
|   readonly scrollDistance = 1; |   scrollDistance = 1; | ||||||
| 
 | 
 | ||||||
|   offset = 0; |   offset = 0; | ||||||
| 
 | 
 | ||||||
|  | @ -40,6 +40,9 @@ export class UserListComponent { | ||||||
|               private router: Router, |               private router: Router, | ||||||
|               private route: ActivatedRoute, |               private route: ActivatedRoute, | ||||||
|               private translate: TranslateService) { |               private translate: TranslateService) { | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   ngOnInit() { | ||||||
|     this.users$ = this.userService.users$; |     this.users$ = this.userService.users$; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -93,7 +96,7 @@ export class UserListComponent { | ||||||
|     } |     } | ||||||
|     if (this.limit !== 0) { |     if (this.limit !== 0) { | ||||||
|       this.offset += this.limit; |       this.offset += this.limit; | ||||||
|       this.filterUsers(ADD_ARRAY); |       this.filterUsers(ADD); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,7 +7,6 @@ export interface AppUser { | ||||||
|   secret?: string; |   secret?: string; | ||||||
|   activated: boolean; |   activated: boolean; | ||||||
|   permission: number; |   permission: number; | ||||||
|   token?: string; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface User { | export interface User { | ||||||
|  |  | ||||||
|  | @ -18,7 +18,8 @@ export class AppUserService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getUsers() { |   getUsers() { | ||||||
|     this.httpGateway.get<AppUser[]>(this.config.apiAppUserPath) |     this.httpGateway.get(this.config.apiAppUserPath) | ||||||
|  |         .map(res => res.json()) | ||||||
|         .do((users) => { |         .do((users) => { | ||||||
|           this.appUserStore.dispatch({type: LOAD, data: users}); |           this.appUserStore.dispatch({type: LOAD, data: users}); | ||||||
|         }).subscribe(_ => { |         }).subscribe(_ => { | ||||||
|  | @ -28,7 +29,8 @@ export class AppUserService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   updateUser(user: AppUser) { |   updateUser(user: AppUser) { | ||||||
|     return this.httpGateway.patch<AppUser>(this.config.apiAppUserPath + user._id, user) |     return this.httpGateway.patch(this.config.apiAppUserPath + user._id, user) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedUser => { |                .do(savedUser => { | ||||||
|                  const action = {type: EDIT, data: savedUser}; |                  const action = {type: EDIT, data: savedUser}; | ||||||
|                  this.appUserStore.dispatch(action); |                  this.appUserStore.dispatch(action); | ||||||
|  |  | ||||||
|  | @ -1,16 +1,15 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
|  | import {Http, Response} from '@angular/http'; | ||||||
| import 'rxjs/add/operator/map'; | import 'rxjs/add/operator/map'; | ||||||
| 
 | 
 | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {AwardingService} from '../army-management/awarding.service'; | import {AwardingService} from '../army-management/awarding.service'; | ||||||
| import {PromotionService} from '../army-management/promotion.service'; | import {PromotionService} from '../army-management/promotion.service'; | ||||||
| import {CookieService} from 'ngx-cookie-service'; | import {CookieService} from 'ngx-cookie-service'; | ||||||
| import {HttpClient} from '@angular/common/http'; |  | ||||||
| import {AppUser} from '../../models/model-interfaces'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class LoginService { | export class LoginService { | ||||||
|   constructor(private http: HttpClient, |   constructor(private http: Http, | ||||||
|               private config: AppConfig, |               private config: AppConfig, | ||||||
|               private cookieService: CookieService, |               private cookieService: CookieService, | ||||||
|               private awardingService: AwardingService, |               private awardingService: AwardingService, | ||||||
|  | @ -18,10 +17,10 @@ export class LoginService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   login(username: string, password: string) { |   login(username: string, password: string) { | ||||||
|     return this.http.post<AppUser>(this.config.apiAuthenticationPath, {username: username, password: password}) |     return this.http.post(this.config.apiAuthenticationPath, {username: username, password: password}) | ||||||
|                .map((response) => { |                .map((response: Response) => { | ||||||
|                  // login successful if there's a jwt token in the response
 |                  // login successful if there's a jwt token in the response
 | ||||||
|                  const user = response; |                  const user = response.json(); | ||||||
|                  if (user && user.token) { |                  if (user && user.token) { | ||||||
|                    // store user details and jwt token in cookie
 |                    // store user details and jwt token in cookie
 | ||||||
|                    this.cookieService.set('currentUser', JSON.stringify(user)); |                    this.cookieService.set('currentUser', JSON.stringify(user)); | ||||||
|  | @ -35,7 +34,9 @@ export class LoginService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   signUp(username: string, password: string, secret: string) { |   signUp(username: string, password: string, secret: string) { | ||||||
|     return this.http.post(this.config.apiSignupPath, {username: username, password: password, secret: secret}); |     return this.http.post(this.config.apiSignupPath, {username: username, password: password, secret: secret}) | ||||||
|  |                .map((response: Response) => { | ||||||
|  |                }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   logout() { |   logout() { | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ export class AwardingService { | ||||||
|                        .concat('&fractFilter=').concat(fraction) |                        .concat('&fractFilter=').concat(fraction) | ||||||
|                        .concat('&userId=').concat(userId) |                        .concat('&userId=').concat(userId) | ||||||
|                        .concat('&squadId=').concat(squadId); |                        .concat('&squadId=').concat(squadId); | ||||||
|     return this.httpGateway.get<Award[]>(getUrl); |     return this.httpGateway.get(getUrl).map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   addAwarding(award: Award) { |   addAwarding(award: Award) { | ||||||
|  | @ -26,7 +26,8 @@ export class AwardingService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   updateAward(award) { |   updateAward(award) { | ||||||
|     return this.httpGateway.patch(this.config.apiAwardPath + '/' + award._id, award); |     return this.httpGateway.patch(this.config.apiAwardPath + '/' + award._id, award) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   requestAwarding(award: Award) { |   requestAwarding(award: Award) { | ||||||
|  | @ -60,3 +61,4 @@ export class AwardingService { | ||||||
|     return this.getAwardings('', userId); |     return this.getAwardings('', userId); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -1,11 +1,10 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {Decoration} from '../../models/model-interfaces'; | import {Decoration} from '../../models/model-interfaces'; | ||||||
| import {RequestMethod, RequestOptions} from '@angular/http'; | import {RequestMethod, RequestOptions, URLSearchParams} from '@angular/http'; | ||||||
| import {Observable} from 'rxjs/Observable'; | import {Observable} from 'rxjs/Observable'; | ||||||
| import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {HttpGateway} from '../http-gateway'; | import {HttpGateway} from '../http-gateway'; | ||||||
| import {HttpParams} from '@angular/common/http'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class DecorationService { | export class DecorationService { | ||||||
|  | @ -19,13 +18,15 @@ export class DecorationService { | ||||||
|     this.decorations$ = this.decorationStore.items$; |     this.decorations$ = this.decorationStore.items$; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   findDecorations(query = '', fractionFilter?): Observable<Decoration[]> { |   findDecorations(query = '', fractionFilter?) { | ||||||
|     let searchParams = new HttpParams().append('q', query); |     const searchParams = new URLSearchParams(); | ||||||
|  |     searchParams.append('q', query); | ||||||
|     if (fractionFilter) { |     if (fractionFilter) { | ||||||
|       searchParams = searchParams.append('fractFilter', fractionFilter); |       searchParams.append('fractFilter', fractionFilter); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.httpGateway.get<Decoration[]>(this.config.apiDecorationPath, searchParams) |     this.httpGateway.get(this.config.apiDecorationPath, searchParams) | ||||||
|  |         .map(res => res.json()) | ||||||
|         .do((squads) => { |         .do((squads) => { | ||||||
|           this.decorationStore.dispatch({type: LOAD, data: squads}); |           this.decorationStore.dispatch({type: LOAD, data: squads}); | ||||||
|         }).subscribe(_ => { |         }).subscribe(_ => { | ||||||
|  | @ -35,7 +36,8 @@ export class DecorationService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getDecoration(id: number | string): Observable<Decoration> { |   getDecoration(id: number | string): Observable<Decoration> { | ||||||
|     return this.httpGateway.get<Decoration>(this.config.apiDecorationPath + id); |     return this.httpGateway.get(this.config.apiDecorationPath + id) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|  | @ -74,7 +76,8 @@ export class DecorationService { | ||||||
|       method: requestMethod, |       method: requestMethod, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return this.httpGateway.request<Decoration>(requestUrl, options) |     return this.httpGateway.request(requestUrl, options) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedDecoration => { |                .do(savedDecoration => { | ||||||
|                  const action = {type: accessType, data: savedDecoration}; |                  const action = {type: accessType, data: savedDecoration}; | ||||||
|                  this.decorationStore.dispatch(action); |                  this.decorationStore.dispatch(action); | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ import {Injectable} from '@angular/core'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {Promotion} from '../../models/model-interfaces'; | import {Promotion} from '../../models/model-interfaces'; | ||||||
| import {HttpGateway} from '../http-gateway'; | import {HttpGateway} from '../http-gateway'; | ||||||
| import {Observable} from 'rxjs'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class PromotionService { | export class PromotionService { | ||||||
|  | @ -13,9 +12,9 @@ export class PromotionService { | ||||||
|               private config: AppConfig) { |               private config: AppConfig) { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getUnconfirmedPromotions(fraction?: string): Observable<Promotion[]> { |   getUnconfirmedPromotions(fraction?: string) { | ||||||
|     return this.httpGateway.get<Promotion[]>(this.config.apiPromotionPath + |     return this.httpGateway.get(this.config.apiPromotionPath + '?inProgress=true&fractFilter=' + fraction) | ||||||
|       '?inProgress=true&fractFilter=' + fraction); |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   checkUnconfirmedPromotions(fraction?: string) { |   checkUnconfirmedPromotions(fraction?: string) { | ||||||
|  | @ -26,19 +25,23 @@ export class PromotionService { | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getSquadPromotions(squadId: string): Observable<Promotion[]> { |   getSquadPromotions(squadId: string) { | ||||||
|     return this.httpGateway.get<Promotion[]>(this.config.apiPromotionPath + '?squadId=' + squadId); |     return this.httpGateway.get(this.config.apiPromotionPath + '?squadId=' + squadId) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   requestPromotion(promotion: Promotion): Observable<Promotion> { |   requestPromotion(promotion: Promotion) { | ||||||
|     return this.httpGateway.post<Promotion>(this.config.apiPromotionPath, promotion); |     return this.httpGateway.post(this.config.apiPromotionPath, promotion); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   updatePromotion(promotion): Observable<Promotion> { |   updatePromotion(promotion) { | ||||||
|     return this.httpGateway.patch<Promotion>(this.config.apiPromotionPath + '/' + promotion._id, promotion); |     return this.httpGateway.patch(this.config.apiPromotionPath + '/' + promotion._id, promotion) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   deletePromotion(promotionId) { |   deletePromotion(promotionId) { | ||||||
|     return this.httpGateway.delete(this.config.apiPromotionPath + promotionId); |     return this.httpGateway.delete(this.config.apiPromotionPath + promotionId); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -1,11 +1,10 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {Rank} from '../../models/model-interfaces'; | import {Rank} from '../../models/model-interfaces'; | ||||||
| import {RequestMethod, RequestOptions} from '@angular/http'; | import {RequestMethod, RequestOptions, URLSearchParams} from '@angular/http'; | ||||||
| import {Observable} from 'rxjs/Observable'; | import {Observable} from 'rxjs/Observable'; | ||||||
| import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {HttpGateway} from '../http-gateway'; | import {HttpGateway} from '../http-gateway'; | ||||||
| import {HttpParams} from '@angular/common/http'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class RankService { | export class RankService { | ||||||
|  | @ -19,13 +18,15 @@ export class RankService { | ||||||
|     this.ranks$ = this.rankStore.items$; |     this.ranks$ = this.rankStore.items$; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   findRanks(query = '', fractionFilter?): Observable<Rank[]> { |   findRanks(query = '', fractionFilter?) { | ||||||
|     let searchParams = new HttpParams().append('q', query); |     const searchParams = new URLSearchParams(); | ||||||
|  |     searchParams.append('q', query); | ||||||
|     if (fractionFilter) { |     if (fractionFilter) { | ||||||
|       searchParams = searchParams.append('fractFilter', fractionFilter); |       searchParams.append('fractFilter', fractionFilter); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.httpGateway.get<Rank[]>(this.config.apiRankPath, searchParams) |     this.httpGateway.get(this.config.apiRankPath, searchParams) | ||||||
|  |         .map(res => res.json()) | ||||||
|         .do((ranks) => { |         .do((ranks) => { | ||||||
|           this.rankStore.dispatch({type: LOAD, data: ranks}); |           this.rankStore.dispatch({type: LOAD, data: ranks}); | ||||||
|         }).subscribe(_ => { |         }).subscribe(_ => { | ||||||
|  | @ -35,14 +36,15 @@ export class RankService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getRank(id: number | string): Observable<Rank> { |   getRank(id: number | string): Observable<Rank> { | ||||||
|     return this.httpGateway.get<Rank>(this.config.apiRankPath + id); |     return this.httpGateway.get(this.config.apiRankPath + id) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * For creating new data with POST or |    * For creating new data with POST or | ||||||
|    * update existing with patch PATCH |    * update existing with patch PATCH | ||||||
|    */ |    */ | ||||||
|   submitRank(rank: Rank, imageFile?): Observable<Rank> { |   submitRank(rank: Rank, imageFile?) { | ||||||
|     let requestUrl = this.config.apiRankPath; |     let requestUrl = this.config.apiRankPath; | ||||||
|     let requestMethod: RequestMethod; |     let requestMethod: RequestMethod; | ||||||
|     let accessType; |     let accessType; | ||||||
|  | @ -75,10 +77,11 @@ export class RankService { | ||||||
|       method: requestMethod |       method: requestMethod | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return this.httpGateway.request<Rank>(requestUrl, options) |     return this.httpGateway.request(requestUrl, options) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedRank => { |                .do(savedRank => { | ||||||
|                  const action = {type: accessType, data: savedRank}; |                  const action = {type: accessType, data: savedRank}; | ||||||
|                  // leave some time to save image file before accessing it through list view
 |                  // leave some time to save image file before accessing it through listview
 | ||||||
|                  setTimeout(() => { |                  setTimeout(() => { | ||||||
|                    this.rankStore.dispatch(action); |                    this.rankStore.dispatch(action); | ||||||
|                  }, 300); |                  }, 300); | ||||||
|  |  | ||||||
|  | @ -1,11 +1,10 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {Squad} from '../../models/model-interfaces'; | import {Squad} from '../../models/model-interfaces'; | ||||||
| import {RequestMethod, RequestOptions} from '@angular/http'; | import {RequestMethod, RequestOptions, URLSearchParams} from '@angular/http'; | ||||||
| import {Observable} from 'rxjs/Observable'; | import {Observable} from 'rxjs/Observable'; | ||||||
| import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {HttpGateway} from '../http-gateway'; | import {HttpGateway} from '../http-gateway'; | ||||||
| import {HttpParams} from '@angular/common/http'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class SquadService { | export class SquadService { | ||||||
|  | @ -19,11 +18,13 @@ export class SquadService { | ||||||
|     this.squads$ = this.squadStore.items$; |     this.squads$ = this.squadStore.items$; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   findSquads(query = '', fractionFilter = ''): Observable<Squad[]> { |   findSquads(query = '', fractionFilter = '') { | ||||||
|     const searchParams = new HttpParams().append('q', query) |     const searchParams = new URLSearchParams(); | ||||||
|                                          .append('fractFilter', fractionFilter); |     searchParams.append('q', query); | ||||||
|  |     searchParams.append('fractFilter', fractionFilter); | ||||||
| 
 | 
 | ||||||
|     this.httpGateway.get(this.config.apiSquadPath, searchParams) |     this.httpGateway.get(this.config.apiSquadPath, searchParams) | ||||||
|  |         .map(res => res.json()) | ||||||
|         .do((squads) => { |         .do((squads) => { | ||||||
|           this.squadStore.dispatch({type: LOAD, data: squads}); |           this.squadStore.dispatch({type: LOAD, data: squads}); | ||||||
|         }).subscribe(_ => { |         }).subscribe(_ => { | ||||||
|  | @ -33,14 +34,15 @@ export class SquadService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getSquad(id: number | string): Observable<Squad> { |   getSquad(id: number | string): Observable<Squad> { | ||||||
|     return this.httpGateway.get<Squad>(this.config.apiSquadPath + id); |     return this.httpGateway.get(this.config.apiSquadPath + id) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * For creating new data with POST or |    * For creating new data with POST or | ||||||
|    * update existing with patch PATCH |    * update existing with patch PATCH | ||||||
|    */ |    */ | ||||||
|   submitSquad(squad: Squad, imageFile?): Observable<Squad> { |   submitSquad(squad: Squad, imageFile?) { | ||||||
|     let requestUrl = this.config.apiSquadPath; |     let requestUrl = this.config.apiSquadPath; | ||||||
|     let requestMethod: RequestMethod; |     let requestMethod: RequestMethod; | ||||||
|     let accessType; |     let accessType; | ||||||
|  | @ -72,7 +74,8 @@ export class SquadService { | ||||||
|       method: requestMethod |       method: requestMethod | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return this.httpGateway.request<Squad>(requestUrl, options) |     return this.httpGateway.request(requestUrl, options) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedSquad => { |                .do(savedSquad => { | ||||||
|                  const action = {type: accessType, data: savedSquad}; |                  const action = {type: accessType, data: savedSquad}; | ||||||
|                  this.squadStore.dispatch(action); |                  this.squadStore.dispatch(action); | ||||||
|  |  | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {User} from '../../models/model-interfaces'; | import {User} from '../../models/model-interfaces'; | ||||||
|  | import {URLSearchParams} from '@angular/http'; | ||||||
| import {Observable} from 'rxjs/Observable'; | import {Observable} from 'rxjs/Observable'; | ||||||
| import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | import {ADD, EDIT, LOAD, REMOVE, Store} from '../stores/generic-store'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {HttpGateway} from '../http-gateway'; | import {HttpGateway} from '../http-gateway'; | ||||||
| import {HttpParams} from '@angular/common/http'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class UserService { | export class UserService { | ||||||
|  | @ -20,34 +20,32 @@ export class UserService { | ||||||
|     this.users$ = this.userStore.items$; |     this.users$ = this.userStore.items$; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   findUsers(filter, limit?, offset?, action = LOAD): Observable<User[]> { |   findUsers(filter, limit?, offset?, action = LOAD) { | ||||||
|     let searchParams = new HttpParams().append('q', (filter && filter.query) ? filter.query : '') |     const searchParams = new URLSearchParams(); | ||||||
|                                        .append('limit', limit) |  | ||||||
|                                        .append('offset', offset); |  | ||||||
| 
 | 
 | ||||||
|     if (filter) { |     searchParams.append('q', (filter && filter.query) ? filter.query : ''); | ||||||
|       if (filter.fraction) { | 
 | ||||||
|         searchParams = searchParams.append('fractFilter', filter.fraction); |     if (filter && filter.fraction) { | ||||||
|       } |       searchParams.append('fractFilter', filter.fraction); | ||||||
|       if (filter.squadId) { |  | ||||||
|         searchParams = searchParams.append('squadId', filter.squadId); |  | ||||||
|       } |  | ||||||
|       if (filter.decorationId) { |  | ||||||
|         searchParams = searchParams.append('decorationId', filter.decorationId); |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     if (filter && filter.squadId) { | ||||||
|  |       searchParams.append('squadId', filter.squadId); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     this.httpGateway.get<Response>(this.config.apiUserPath, searchParams, true) |     if (filter && filter.decorationId) { | ||||||
|  |       searchParams.append('decorationId', filter.decorationId); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     searchParams.append('limit', limit); | ||||||
|  |     searchParams.append('offset', offset); | ||||||
|  |     this.httpGateway.get(this.config.apiUserPath, searchParams) | ||||||
|         .do((res) => { |         .do((res) => { | ||||||
|           const headerCount = parseInt(res.headers.get('x-total-count'), 10); |           const headerCount = parseInt(res.headers.get('x-total-count'), 10); | ||||||
|           if (headerCount) { |           if (headerCount) { | ||||||
|             this.totalCount = headerCount; |             this.totalCount = headerCount; | ||||||
|           } |           } | ||||||
|         }) |         }).map(res => res.json()).do((users) => { | ||||||
|         .map(res => res.body) |  | ||||||
|         .do((users) => { |  | ||||||
|           console.log(users) |  | ||||||
|       this.userStore.dispatch({type: action, data: users}); |       this.userStore.dispatch({type: action, data: users}); | ||||||
|     }).subscribe(_ => { |     }).subscribe(_ => { | ||||||
|     }); |     }); | ||||||
|  | @ -56,19 +54,22 @@ export class UserService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getUser(_id: number | string): Observable<User> { |   getUser(_id: number | string): Observable<User> { | ||||||
|     return this.httpGateway.get<User>(this.config.apiUserPath + _id); |     return this.httpGateway.get(this.config.apiUserPath + _id) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   submitUser(user): Observable<User> { |   submitUser(user) { | ||||||
|     return this.httpGateway.post<User>(this.config.apiUserPath, user) |     return this.httpGateway.post(this.config.apiUserPath, user) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedUser => { |                .do(savedUser => { | ||||||
|                  const action = {type: ADD, data: savedUser}; |                  const action = {type: ADD, data: savedUser}; | ||||||
|                  this.userStore.dispatch(action); |                  this.userStore.dispatch(action); | ||||||
|                }); |                }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   updateUser(user): Observable<User> { |   updateUser(user) { | ||||||
|     return this.httpGateway.put<User>(this.config.apiUserPath + user._id, user) |     return this.httpGateway.put(this.config.apiUserPath + user._id, user) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedUser => { |                .do(savedUser => { | ||||||
|                  const action = {type: EDIT, data: savedUser}; |                  const action = {type: EDIT, data: savedUser}; | ||||||
|                  this.userStore.dispatch(action); |                  this.userStore.dispatch(action); | ||||||
|  |  | ||||||
|  | @ -1,17 +1,17 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
| import {HttpClient} from '@angular/common/http'; | import {Http} from '@angular/http'; | ||||||
| import {Army} from '../../models/model-interfaces'; |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class ArmyService { | export class ArmyService { | ||||||
| 
 | 
 | ||||||
|   constructor(private http: HttpClient, |   constructor(private http: Http, | ||||||
|               private config: AppConfig) { |               private config: AppConfig) { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getArmies() { |   getArmy() { | ||||||
|     return this.http.get<Army[]>(this.config.apiOverviewPath); |     return this.http.get(this.config.apiOverviewPath) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,15 +1,13 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {RequestMethod} from '@angular/http'; | import {Headers, Http, RequestMethod} from '@angular/http'; | ||||||
| import {Router} from '@angular/router'; | import {Router} from '@angular/router'; | ||||||
| import {CookieService} from 'ngx-cookie-service'; | import {CookieService} from 'ngx-cookie-service'; | ||||||
| import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; |  | ||||||
| import {Observable} from 'rxjs'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class HttpGateway { | export class HttpGateway { | ||||||
| 
 | 
 | ||||||
|   constructor(private router: Router, |   constructor(private router: Router, | ||||||
|               private http: HttpClient, |               private http: Http, | ||||||
|               private cookieService: CookieService) { |               private cookieService: CookieService) { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -18,56 +16,60 @@ export class HttpGateway { | ||||||
|     if (cookieField) { |     if (cookieField) { | ||||||
|       const currentUser = JSON.parse(cookieField); |       const currentUser = JSON.parse(cookieField); | ||||||
|       if (new Date().getTime() <= Date.parse(currentUser.tokenExpireDate)) { |       if (new Date().getTime() <= Date.parse(currentUser.tokenExpireDate)) { | ||||||
|         return { |         const headers = new Headers(); | ||||||
|           headers: new HttpHeaders({ |         headers.append('x-access-token', currentUser.token); | ||||||
|             'x-access-token': currentUser.token |         return headers; | ||||||
|           }) |  | ||||||
|         }; |  | ||||||
|       } else { |       } else { | ||||||
|         // logout
 |         // logout
 | ||||||
|         localStorage.removeItem('currentUser'); |         localStorage.removeItem('currentUser'); | ||||||
|         this.router.navigate(['/login']); |         this.router.navigate(['/login']); | ||||||
|       } |       } | ||||||
|     } else { |  | ||||||
|       return {}; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get<T>(url: string, searchParams?: HttpParams, getFullResponse = false): Observable<T> { |   get(url, searchParams?) { | ||||||
|     const options = this.createAuthorizationHeader(); |     const headers = this.createAuthorizationHeader(); | ||||||
| 
 |     const options: any = {headers: headers}; | ||||||
|     if (searchParams) { |     if (searchParams) { | ||||||
|       options['params'] = searchParams; |       options.search = searchParams; | ||||||
|     } |     } | ||||||
|     if (getFullResponse) { |     return this.http.get(url, options); | ||||||
|       options['observe'] = 'response'; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|     return this.http.get<T>(url, options); |   post(url, data) { | ||||||
|  |     const headers = this.createAuthorizationHeader(); | ||||||
|  |     return this.http.post(url, data, { | ||||||
|  |       headers: headers | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   post<T>(url, data): Observable<T> { |   put(url, data) { | ||||||
|     return this.http.post<T>(url, data, this.createAuthorizationHeader()); |     const headers = this.createAuthorizationHeader(); | ||||||
|  |     return this.http.put(url, data, { | ||||||
|  |       headers: headers | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   put<T>(url, data): Observable<T> { |   patch(url, data) { | ||||||
|     return this.http.put<T>(url, data, this.createAuthorizationHeader()); |     const headers = this.createAuthorizationHeader(); | ||||||
|   } |     return this.http.patch(url, data, { | ||||||
| 
 |       headers: headers | ||||||
|   patch<T>(url, data): Observable<T> { |     }); | ||||||
|     return this.http.patch<T>(url, data, this.createAuthorizationHeader()); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   delete(url) { |   delete(url) { | ||||||
|     return this.http.delete(url, this.createAuthorizationHeader()); |     const headers = this.createAuthorizationHeader(); | ||||||
|  |     return this.http.delete(url, { | ||||||
|  |       headers: headers | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   request<T>(requestUrl, options): Observable<T> { |   request(requestUrl, options) { | ||||||
|     if (options.method === RequestMethod.Post) { |     if (options.method === RequestMethod.Post) { | ||||||
|       return this.post<T>(requestUrl, options.body); |       return this.post(requestUrl, options.body); | ||||||
|     } |     } | ||||||
|     if (options.method === RequestMethod.Patch) { |     if (options.method === RequestMethod.Patch) { | ||||||
|       return this.patch<T>(requestUrl, options.body); |       return this.patch(requestUrl, options.body); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -19,16 +19,19 @@ export class CampaignService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getAllCampaigns() { |   getAllCampaigns() { | ||||||
|     return this.httpGateway.get<Campaign[]>(this.config.apiCampaignPath) |     return this.httpGateway.get(this.config.apiCampaignPath) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do((ranks) => this.campaignStore.dispatch({type: LOAD, data: ranks})); |                .do((ranks) => this.campaignStore.dispatch({type: LOAD, data: ranks})); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getCampaign(id: string) { |   getCampaign(id: string) { | ||||||
|     return this.httpGateway.get(`${this.config.apiCampaignPath}/${id}`); |     return this.httpGateway.get(`${this.config.apiCampaignPath}/${id}`) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getCampaignByWarId(warId) { |   getCampaignByWarId(warId) { | ||||||
|     return this.httpGateway.get(`${this.config.apiCampaignPath}/with/war/${warId}`); |     return this.httpGateway.get(`${this.config.apiCampaignPath}/with/war/${warId}`) | ||||||
|  |                .map((res) => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   submitCampaign(campaign: Campaign) { |   submitCampaign(campaign: Campaign) { | ||||||
|  | @ -51,7 +54,8 @@ export class CampaignService { | ||||||
|       method: requestMethod |       method: requestMethod | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return this.httpGateway.request<Campaign>(requestUrl, options) |     return this.httpGateway.request(requestUrl, options) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do(savedCampaign => { |                .do(savedCampaign => { | ||||||
|                  const action = {type: accessType, data: savedCampaign}; |                  const action = {type: accessType, data: savedCampaign}; | ||||||
|                  this.campaignStore.dispatch(action); |                  this.campaignStore.dispatch(action); | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import {Injectable} from '@angular/core'; | import {Injectable} from '@angular/core'; | ||||||
| import {AppConfig} from '../../app.config'; | import {AppConfig} from '../../app.config'; | ||||||
|  | import {URLSearchParams} from '@angular/http'; | ||||||
| import {HttpGateway} from '../http-gateway'; | import {HttpGateway} from '../http-gateway'; | ||||||
| import {HttpParams} from '@angular/common/http'; |  | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class LogsService { | export class LogsService { | ||||||
|  | @ -11,61 +11,69 @@ export class LogsService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getFullLog(warId: string) { |   getFullLog(warId: string) { | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getBudgetLogs(warId: string, fraction = '') { |   getBudgetLogs(warId: string, fraction = '') { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('fraction', fraction); |     params.append('fraction', fraction); | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/budget', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/budget', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getRespawnLogs(warId: string, playerName = '') { |   getRespawnLogs(warId: string, playerName = '') { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('player', playerName); |     params.append('player', playerName); | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/respawn', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/respawn', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getPointsLogs(warId: string, fraction = '') { |   getPointsLogs(warId: string, fraction = '') { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('fraction', fraction); |     params.append('fraction', fraction); | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/points', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/points', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getReviveLogs(warId: string, medicName = '', patientName = '', fraction = '', stabilizedOnly = false, reviveOnly = false) { |   getReviveLogs(warId: string, medicName = '', patientName = '', fraction = '', stabilizedOnly = false, reviveOnly = false) { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('medic', medicName); |     params.append('medic', medicName); | ||||||
|     params.append('patient', patientName); |     params.append('patient', patientName); | ||||||
|     params.append('fraction', fraction); |     params.append('fraction', fraction); | ||||||
|     params.append('stabilized', stabilizedOnly ? 'true' : ''); |     params.append('stabilized', stabilizedOnly ? 'true' : ''); | ||||||
|     params.append('revive', reviveOnly ? 'true' : ''); |     params.append('revive', reviveOnly ? 'true' : ''); | ||||||
|     return this.httpGateway.get(this.config .apiLogsPath + '/' + warId + '/revive', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/revive', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getKillLogs(warId: string, shooterName = '', targetName = '', fraction = '', friendlyFireOnly = false, notFriendlyFireOnly = false) { |   getKillLogs(warId: string, shooterName = '', targetName = '', fraction = '', friendlyFireOnly = false, notFriendlyFireOnly = false) { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('shooter', shooterName); |     params.append('shooter', shooterName); | ||||||
|     params.append('target', targetName); |     params.append('target', targetName); | ||||||
|     params.append('fraction', fraction); |     params.append('fraction', fraction); | ||||||
|     params.append('friendlyFire', friendlyFireOnly ? 'true' : ''); |     params.append('friendlyFire', friendlyFireOnly ? 'true' : ''); | ||||||
|     params.append('noFriendlyFire', notFriendlyFireOnly ? 'true' : ''); |     params.append('noFriendlyFire', notFriendlyFireOnly ? 'true' : ''); | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/kills', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/kills', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getTransportLogs(warId: string, driverName = '', passengerName = '', fraction = '') { |   getTransportLogs(warId: string, driverName = '', passengerName = '', fraction = '') { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('driver', driverName); |     params.append('driver', driverName); | ||||||
|     params.append('passenger', passengerName); |     params.append('passenger', passengerName); | ||||||
|     params.append('fraction', fraction); |     params.append('fraction', fraction); | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/transport', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/transport', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getFlagLogs(warId: string, playerName = '', fraction = '', captureOnly = false, defendOnly = false) { |   getFlagLogs(warId: string, playerName = '', fraction = '', captureOnly = false, defendOnly = false) { | ||||||
|     const params = new HttpParams(); |     const params = new URLSearchParams(); | ||||||
|     params.append('player', playerName); |     params.append('player', playerName); | ||||||
|     params.append('fraction', fraction); |     params.append('fraction', fraction); | ||||||
|     params.append('capture', captureOnly ? 'true' : ''); |     params.append('capture', captureOnly ? 'true' : ''); | ||||||
|     params.append('defend', defendOnly ? 'true' : ''); |     params.append('defend', defendOnly ? 'true' : ''); | ||||||
|     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/flag', params); |     return this.httpGateway.get(this.config.apiLogsPath + '/' + warId + '/flag', params) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -10,10 +10,12 @@ export class PlayerService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getCampaignPlayer(campaignId: string, playerName: string) { |   getCampaignPlayer(campaignId: string, playerName: string) { | ||||||
|     return this.httpGateway.get(this.config.apiPlayersPath + '/single/' + campaignId + '/' + playerName); |     return this.httpGateway.get(this.config.apiPlayersPath + '/single/' + campaignId + '/' + playerName) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getCampaignHighscore(campaignId: string) { |   getCampaignHighscore(campaignId: string) { | ||||||
|     return this.httpGateway.get(this.config.apiPlayersPath + '/ranking/' + campaignId); |     return this.httpGateway.get(this.config.apiPlayersPath + '/ranking/' + campaignId) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -17,17 +17,19 @@ export class WarService { | ||||||
|     this.wars$ = this.warStore.items$; |     this.wars$ = this.warStore.items$; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getAllWars(campaignId?: string): Observable<War[]> { |   getAllWars(campaignId?: string) { | ||||||
|     let targetUrl = this.config.apiWarPath; |     let targetUrl = this.config.apiWarPath; | ||||||
|     if (campaignId) { |     if (campaignId) { | ||||||
|       targetUrl += `?campaignId=${campaignId}` |       targetUrl += `?campaignId=${campaignId}` | ||||||
|     } |     } | ||||||
|     return this.httpGateway.get<War[]>(targetUrl) |     return this.httpGateway.get(targetUrl) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do((wars) => this.warStore.dispatch({type: LOAD, data: wars})); |                .do((wars) => this.warStore.dispatch({type: LOAD, data: wars})); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getWar(warId: string): Observable<War> { |   getWar(warId: string) { | ||||||
|     return this.httpGateway.get<War>(this.config.apiWarPath + '/' + warId); |     return this.httpGateway.get(this.config.apiWarPath + '/' + warId) | ||||||
|  |                .map(res => res.json()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   submitWar(war: War, logFile?) { |   submitWar(war: War, logFile?) { | ||||||
|  | @ -43,12 +45,14 @@ export class WarService { | ||||||
|       body.append('log', logFile, logFile.name); |       body.append('log', logFile, logFile.name); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return this.httpGateway.post<War>(this.config.apiWarPath, body) |     return this.httpGateway.post(this.config.apiWarPath, body) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do((newWar) => this.warStore.dispatch({type: ADD, data: newWar})); |                .do((newWar) => this.warStore.dispatch({type: ADD, data: newWar})); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   updateWar(war: War) { |   updateWar(war: War) { | ||||||
|     return this.httpGateway.patch<War>(this.config.apiWarPath + '/' + war._id, war) |     return this.httpGateway.patch(this.config.apiWarPath + '/' + war._id, war) | ||||||
|  |                .map(res => res.json()) | ||||||
|                .do((updatedWar) => this.warStore.dispatch({type: EDIT, data: updatedWar})); |                .do((updatedWar) => this.warStore.dispatch({type: EDIT, data: updatedWar})); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ import {BehaviorSubject} from 'rxjs/BehaviorSubject'; | ||||||
| 
 | 
 | ||||||
| export const LOAD = 'LOAD'; | export const LOAD = 'LOAD'; | ||||||
| export const ADD = 'ADD'; | export const ADD = 'ADD'; | ||||||
| export const ADD_ARRAY = 'ADD_ARRAY'; |  | ||||||
| export const EDIT = 'EDIT'; | export const EDIT = 'EDIT'; | ||||||
| export const REMOVE = 'REMOVE'; | export const REMOVE = 'REMOVE'; | ||||||
| 
 | 
 | ||||||
|  | @ -28,8 +27,6 @@ export class Store<T extends Identifiable> { | ||||||
|         return [...action.data]; |         return [...action.data]; | ||||||
|       case ADD: |       case ADD: | ||||||
|         return [...items, action.data]; |         return [...items, action.data]; | ||||||
|       case ADD_ARRAY: |  | ||||||
|         return [...items].concat(action.data); |  | ||||||
|       case EDIT: |       case EDIT: | ||||||
|         return items.map(item => { |         return items.map(item => { | ||||||
|           const editedItem = action.data; |           const editedItem = action.data; | ||||||
|  |  | ||||||
|  | @ -56,8 +56,7 @@ export class WarHeaderComponent implements OnInit { | ||||||
|           this.fractionStatsInitialized = false; |           this.fractionStatsInitialized = false; | ||||||
|           this.fractionFilterSelected = undefined; |           this.fractionFilterSelected = undefined; | ||||||
| 
 | 
 | ||||||
|           this.playerChart = |           this.playerChart = ChartUtils.getSingleDataArray(Fraction.OPFOR, war.playersOpfor, Fraction.BLUFOR, war.playersBlufor); | ||||||
|             ChartUtils.getSingleDataArray(Fraction.OPFOR, war.playersOpfor, Fraction.BLUFOR, war.playersBlufor); |  | ||||||
|           Object.assign(this, [this.playerChart]); |           Object.assign(this, [this.playerChart]); | ||||||
|         }); |         }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue