Migrate main gateway from Http to HttpClient - 1st iteration (CC-63)
parent
2291ec20bf
commit
f6317d7fbc
|
@ -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.squad) {
|
if (!user.squadId) {
|
||||||
user.squad = '0';
|
user.squadId = '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, OnInit} from '@angular/core';
|
import {Component} 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, LOAD} from '../../../services/stores/generic-store';
|
import {ADD_ARRAY, 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 implements OnInit {
|
export class UserListComponent {
|
||||||
|
|
||||||
selectedUserId: string | number = null;
|
selectedUserId: string | number = null;
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ export class UserListComponent implements OnInit {
|
||||||
|
|
||||||
radioModel = '';
|
radioModel = '';
|
||||||
|
|
||||||
throttle = 300;
|
readonly throttle = 300;
|
||||||
|
|
||||||
scrollDistance = 1;
|
readonly scrollDistance = 1;
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
|
@ -40,9 +40,6 @@ export class UserListComponent implements OnInit {
|
||||||
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$;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +93,7 @@ export class UserListComponent implements OnInit {
|
||||||
}
|
}
|
||||||
if (this.limit !== 0) {
|
if (this.limit !== 0) {
|
||||||
this.offset += this.limit;
|
this.offset += this.limit;
|
||||||
this.filterUsers(ADD);
|
this.filterUsers(ADD_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ export class AppUserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getUsers() {
|
getUsers() {
|
||||||
this.httpGateway.get(this.config.apiAppUserPath)
|
this.httpGateway.get<AppUser[]>(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(_ => {
|
||||||
|
@ -29,8 +28,7 @@ export class AppUserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUser(user: AppUser) {
|
updateUser(user: AppUser) {
|
||||||
return this.httpGateway.patch(this.config.apiAppUserPath + user._id, user)
|
return this.httpGateway.patch<AppUser>(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);
|
||||||
|
|
|
@ -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(getUrl).map(res => res.json());
|
return this.httpGateway.get<Award[]>(getUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
addAwarding(award: Award) {
|
addAwarding(award: Award) {
|
||||||
|
@ -26,8 +26,7 @@ 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) {
|
||||||
|
@ -61,4 +60,3 @@ export class AwardingService {
|
||||||
return this.getAwardings('', userId);
|
return this.getAwardings('', userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
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, URLSearchParams} from '@angular/http';
|
import {RequestMethod, RequestOptions} 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 {
|
||||||
|
@ -18,15 +19,13 @@ export class DecorationService {
|
||||||
this.decorations$ = this.decorationStore.items$;
|
this.decorations$ = this.decorationStore.items$;
|
||||||
}
|
}
|
||||||
|
|
||||||
findDecorations(query = '', fractionFilter?) {
|
findDecorations(query = '', fractionFilter?): Observable<Decoration[]> {
|
||||||
const searchParams = new URLSearchParams();
|
let searchParams = new HttpParams().append('q', query);
|
||||||
searchParams.append('q', query);
|
|
||||||
if (fractionFilter) {
|
if (fractionFilter) {
|
||||||
searchParams.append('fractFilter', fractionFilter);
|
searchParams = searchParams.append('fractFilter', fractionFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.httpGateway.get(this.config.apiDecorationPath, searchParams)
|
this.httpGateway.get<Decoration[]>(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(_ => {
|
||||||
|
@ -36,8 +35,7 @@ export class DecorationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getDecoration(id: number | string): Observable<Decoration> {
|
getDecoration(id: number | string): Observable<Decoration> {
|
||||||
return this.httpGateway.get(this.config.apiDecorationPath + id)
|
return this.httpGateway.get<Decoration>(this.config.apiDecorationPath + id);
|
||||||
.map(res => res.json());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,8 +74,7 @@ export class DecorationService {
|
||||||
method: requestMethod,
|
method: requestMethod,
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.httpGateway.request(requestUrl, options)
|
return this.httpGateway.request<Decoration>(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,6 +2,7 @@ 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 {
|
||||||
|
@ -12,9 +13,9 @@ export class PromotionService {
|
||||||
private config: AppConfig) {
|
private config: AppConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getUnconfirmedPromotions(fraction?: string) {
|
getUnconfirmedPromotions(fraction?: string): Observable<Promotion[]> {
|
||||||
return this.httpGateway.get(this.config.apiPromotionPath + '?inProgress=true&fractFilter=' + fraction)
|
return this.httpGateway.get<Promotion[]>(this.config.apiPromotionPath +
|
||||||
.map(res => res.json());
|
'?inProgress=true&fractFilter=' + fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkUnconfirmedPromotions(fraction?: string) {
|
checkUnconfirmedPromotions(fraction?: string) {
|
||||||
|
@ -25,23 +26,19 @@ export class PromotionService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getSquadPromotions(squadId: string) {
|
getSquadPromotions(squadId: string): Observable<Promotion[]> {
|
||||||
return this.httpGateway.get(this.config.apiPromotionPath + '?squadId=' + squadId)
|
return this.httpGateway.get<Promotion[]>(this.config.apiPromotionPath + '?squadId=' + squadId);
|
||||||
.map(res => res.json());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requestPromotion(promotion: Promotion) {
|
requestPromotion(promotion: Promotion): Observable<Promotion> {
|
||||||
return this.httpGateway.post(this.config.apiPromotionPath, promotion);
|
return this.httpGateway.post<Promotion>(this.config.apiPromotionPath, promotion);
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePromotion(promotion) {
|
updatePromotion(promotion): Observable<Promotion> {
|
||||||
return this.httpGateway.patch(this.config.apiPromotionPath + '/' + promotion._id, promotion)
|
return this.httpGateway.patch<Promotion>(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,10 +1,11 @@
|
||||||
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, URLSearchParams} from '@angular/http';
|
import {RequestMethod, RequestOptions} 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 {
|
||||||
|
@ -18,15 +19,13 @@ export class RankService {
|
||||||
this.ranks$ = this.rankStore.items$;
|
this.ranks$ = this.rankStore.items$;
|
||||||
}
|
}
|
||||||
|
|
||||||
findRanks(query = '', fractionFilter?) {
|
findRanks(query = '', fractionFilter?): Observable<Rank[]> {
|
||||||
const searchParams = new URLSearchParams();
|
let searchParams = new HttpParams().append('q', query);
|
||||||
searchParams.append('q', query);
|
|
||||||
if (fractionFilter) {
|
if (fractionFilter) {
|
||||||
searchParams.append('fractFilter', fractionFilter);
|
searchParams = searchParams.append('fractFilter', fractionFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.httpGateway.get(this.config.apiRankPath, searchParams)
|
this.httpGateway.get<Rank[]>(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(_ => {
|
||||||
|
@ -36,15 +35,14 @@ export class RankService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getRank(id: number | string): Observable<Rank> {
|
getRank(id: number | string): Observable<Rank> {
|
||||||
return this.httpGateway.get(this.config.apiRankPath + id)
|
return this.httpGateway.get<Rank>(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?) {
|
submitRank(rank: Rank, imageFile?): Observable<Rank> {
|
||||||
let requestUrl = this.config.apiRankPath;
|
let requestUrl = this.config.apiRankPath;
|
||||||
let requestMethod: RequestMethod;
|
let requestMethod: RequestMethod;
|
||||||
let accessType;
|
let accessType;
|
||||||
|
@ -77,8 +75,7 @@ export class RankService {
|
||||||
method: requestMethod
|
method: requestMethod
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.httpGateway.request(requestUrl, options)
|
return this.httpGateway.request<Rank>(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 list view
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
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, URLSearchParams} from '@angular/http';
|
import {RequestMethod, RequestOptions} 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 {
|
||||||
|
@ -18,13 +19,11 @@ export class SquadService {
|
||||||
this.squads$ = this.squadStore.items$;
|
this.squads$ = this.squadStore.items$;
|
||||||
}
|
}
|
||||||
|
|
||||||
findSquads(query = '', fractionFilter = '') {
|
findSquads(query = '', fractionFilter = ''): Observable<Squad[]> {
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new HttpParams().append('q', query)
|
||||||
searchParams.append('q', query);
|
.append('fractFilter', fractionFilter);
|
||||||
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(_ => {
|
||||||
|
@ -34,15 +33,14 @@ export class SquadService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSquad(id: number | string): Observable<Squad> {
|
getSquad(id: number | string): Observable<Squad> {
|
||||||
return this.httpGateway.get(this.config.apiSquadPath + id)
|
return this.httpGateway.get<Squad>(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?) {
|
submitSquad(squad: Squad, imageFile?): Observable<Squad> {
|
||||||
let requestUrl = this.config.apiSquadPath;
|
let requestUrl = this.config.apiSquadPath;
|
||||||
let requestMethod: RequestMethod;
|
let requestMethod: RequestMethod;
|
||||||
let accessType;
|
let accessType;
|
||||||
|
@ -74,8 +72,7 @@ export class SquadService {
|
||||||
method: requestMethod
|
method: requestMethod
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.httpGateway.request(requestUrl, options)
|
return this.httpGateway.request<Squad>(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,32 +20,34 @@ export class UserService {
|
||||||
this.users$ = this.userStore.items$;
|
this.users$ = this.userStore.items$;
|
||||||
}
|
}
|
||||||
|
|
||||||
findUsers(filter, limit?, offset?, action = LOAD) {
|
findUsers(filter, limit?, offset?, action = LOAD): Observable<User[]> {
|
||||||
const searchParams = new URLSearchParams();
|
let searchParams = new HttpParams().append('q', (filter && filter.query) ? filter.query : '')
|
||||||
|
.append('limit', limit)
|
||||||
|
.append('offset', offset);
|
||||||
|
|
||||||
searchParams.append('q', (filter && filter.query) ? filter.query : '');
|
if (filter) {
|
||||||
|
if (filter.fraction) {
|
||||||
if (filter && filter.fraction) {
|
searchParams = searchParams.append('fractFilter', 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter && filter.decorationId) {
|
this.httpGateway.get<Response>(this.config.apiUserPath, searchParams, true)
|
||||||
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(_ => {
|
||||||
});
|
});
|
||||||
|
@ -54,22 +56,19 @@ export class UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser(_id: number | string): Observable<User> {
|
getUser(_id: number | string): Observable<User> {
|
||||||
return this.httpGateway.get(this.config.apiUserPath + _id)
|
return this.httpGateway.get<User>(this.config.apiUserPath + _id);
|
||||||
.map(res => res.json());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
submitUser(user) {
|
submitUser(user): Observable<User> {
|
||||||
return this.httpGateway.post(this.config.apiUserPath, user)
|
return this.httpGateway.post<User>(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) {
|
updateUser(user): Observable<User> {
|
||||||
return this.httpGateway.put(this.config.apiUserPath + user._id, user)
|
return this.httpGateway.put<User>(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,13 +1,15 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Headers, Http, RequestMethod} from '@angular/http';
|
import {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: Http,
|
private http: HttpClient,
|
||||||
private cookieService: CookieService) {
|
private cookieService: CookieService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,60 +18,56 @@ 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)) {
|
||||||
const headers = new Headers();
|
return {
|
||||||
headers.append('x-access-token', currentUser.token);
|
headers: new HttpHeaders({
|
||||||
return headers;
|
'x-access-token': currentUser.token
|
||||||
|
})
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
// logout
|
// logout
|
||||||
localStorage.removeItem('currentUser');
|
localStorage.removeItem('currentUser');
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url, searchParams?) {
|
get<T>(url: string, searchParams?: HttpParams, getFullResponse = false): Observable<T> {
|
||||||
const headers = this.createAuthorizationHeader();
|
const options = this.createAuthorizationHeader();
|
||||||
const options: any = {headers: headers};
|
|
||||||
if (searchParams) {
|
if (searchParams) {
|
||||||
options.search = searchParams;
|
options['params'] = searchParams;
|
||||||
}
|
}
|
||||||
return this.http.get(url, options);
|
if (getFullResponse) {
|
||||||
|
options['observe'] = 'response';
|
||||||
}
|
}
|
||||||
|
|
||||||
post(url, data) {
|
return this.http.get<T>(url, options);
|
||||||
const headers = this.createAuthorizationHeader();
|
|
||||||
return this.http.post(url, data, {
|
|
||||||
headers: headers
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
put(url, data) {
|
post<T>(url, data): Observable<T> {
|
||||||
const headers = this.createAuthorizationHeader();
|
return this.http.post<T>(url, data, this.createAuthorizationHeader());
|
||||||
return this.http.put(url, data, {
|
|
||||||
headers: headers
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
patch(url, data) {
|
put<T>(url, data): Observable<T> {
|
||||||
const headers = this.createAuthorizationHeader();
|
return this.http.put<T>(url, data, 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) {
|
||||||
const headers = this.createAuthorizationHeader();
|
return this.http.delete(url, this.createAuthorizationHeader());
|
||||||
return this.http.delete(url, {
|
|
||||||
headers: headers
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request(requestUrl, options) {
|
request<T>(requestUrl, options): Observable<T> {
|
||||||
if (options.method === RequestMethod.Post) {
|
if (options.method === RequestMethod.Post) {
|
||||||
return this.post(requestUrl, options.body);
|
return this.post<T>(requestUrl, options.body);
|
||||||
}
|
}
|
||||||
if (options.method === RequestMethod.Patch) {
|
if (options.method === RequestMethod.Patch) {
|
||||||
return this.patch(requestUrl, options.body);
|
return this.patch<T>(requestUrl, options.body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,19 +19,16 @@ export class CampaignService {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllCampaigns() {
|
getAllCampaigns() {
|
||||||
return this.httpGateway.get(this.config.apiCampaignPath)
|
return this.httpGateway.get<Campaign[]>(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) {
|
||||||
|
@ -54,8 +51,7 @@ export class CampaignService {
|
||||||
method: requestMethod
|
method: requestMethod
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.httpGateway.request(requestUrl, options)
|
return this.httpGateway.request<Campaign>(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,69 +11,61 @@ 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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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 URLSearchParams();
|
const params = new HttpParams();
|
||||||
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,12 +10,10 @@ 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,19 +17,17 @@ export class WarService {
|
||||||
this.wars$ = this.warStore.items$;
|
this.wars$ = this.warStore.items$;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllWars(campaignId?: string) {
|
getAllWars(campaignId?: string): Observable<War[]> {
|
||||||
let targetUrl = this.config.apiWarPath;
|
let targetUrl = this.config.apiWarPath;
|
||||||
if (campaignId) {
|
if (campaignId) {
|
||||||
targetUrl += `?campaignId=${campaignId}`
|
targetUrl += `?campaignId=${campaignId}`
|
||||||
}
|
}
|
||||||
return this.httpGateway.get(targetUrl)
|
return this.httpGateway.get<War[]>(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) {
|
getWar(warId: string): Observable<War> {
|
||||||
return this.httpGateway.get(this.config.apiWarPath + '/' + warId)
|
return this.httpGateway.get<War>(this.config.apiWarPath + '/' + warId);
|
||||||
.map(res => res.json());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
submitWar(war: War, logFile?) {
|
submitWar(war: War, logFile?) {
|
||||||
|
@ -45,14 +43,12 @@ export class WarService {
|
||||||
body.append('log', logFile, logFile.name);
|
body.append('log', logFile, logFile.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.httpGateway.post(this.config.apiWarPath, body)
|
return this.httpGateway.post<War>(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(this.config.apiWarPath + '/' + war._id, war)
|
return this.httpGateway.patch<War>(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,6 +2,7 @@ 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';
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@ 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,7 +56,8 @@ export class WarHeaderComponent implements OnInit {
|
||||||
this.fractionStatsInitialized = false;
|
this.fractionStatsInitialized = false;
|
||||||
this.fractionFilterSelected = undefined;
|
this.fractionFilterSelected = undefined;
|
||||||
|
|
||||||
this.playerChart = ChartUtils.getSingleDataArray(Fraction.OPFOR, war.playersOpfor, Fraction.BLUFOR, war.playersBlufor);
|
this.playerChart =
|
||||||
|
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