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