diff --git a/src/app/_services/pilots.service.ts b/src/app/_services/pilots.service.ts index 9beec26..cba61cc 100644 --- a/src/app/_services/pilots.service.ts +++ b/src/app/_services/pilots.service.ts @@ -1,141 +1,134 @@ import {Injectable} from '@angular/core'; import { HttpClient } from '@angular/common/http'; import {Observable} from 'rxjs'; import {WebSocketAPI} from '../_helpers/WebSocketAPI'; @Injectable({ providedIn: 'root' }) export class PilotsService { public currentPilots: Array; public passedPilots: Array; public setApiButton = false; public API = '//' + location.hostname + ':8080'; public apiAdress = ''; public webSocketAPI: WebSocketAPI; constructor(private http: HttpClient) { this.webSocketAPI = new WebSocketAPI(this); this.webSocketAPI._connect(); this.updatePilots(); } updatePilots() { this.updatePassedPilots(); this.updateCurrentPilots(); } getCurrentPilots(): Observable { return this.http.get(this.API + '/getCurrentPilots'); } updateCurrentPilots() { this.getCurrentPilots().subscribe(data => { this.currentPilots = data.sort((n1, n2) => { if (n1.seat > n2.seat) { return 1; } if (n1.seat < n2.seat) { return -1; } return 0; }); - - console.log('update current'); - console.log(this.currentPilots); }); } getPassedPilots(): Observable { return this.http.get(this.API + '/getPassedPilots'); } updatePassedPilots() { this.getPassedPilots().subscribe(data => { this.passedPilots = data; - console.log('update passed'); - console.log(this.passedPilots); }); } save(pilot: any): Observable { return this.http.post(this.API + '/savePilot', pilot); } setApi(apiAdress: string) { this.apiAdress = apiAdress; } updateNewPilots() { if (this.apiAdress != '') { this.setApiButton = false; this.getNewPilots().subscribe(data => { data[0].pilotResults.forEach(pilot => { pilot.falseStart = false; pilot.obstructedGate = 0; pilot.collisionRecovery = 0; pilot.circuitExit = 0; pilot.crash = 0; pilot.definitiveCrash = false; pilot.videoProblems = 0; pilot.celebratoryManoeuvre = 0; pilot.dangerousPiloting = 0; pilot.missedGate = 0; pilot.circuitCut = 0; pilot.failsafe = 0; pilot.missedGateButton = false; pilot.circuitCutButton = false; pilot.current = 'current'; pilot.run = data[0].name; pilot.race = data[0].sessionName; }); let newRun = true; if (this.currentPilots) { this.currentPilots.forEach(pilot => { if (pilot.run == data[0].name) { newRun = false; } else { pilot.current = "passed"; this.save(pilot).subscribe(data => { }); } }); } if (newRun) { this.currentPilots = data[0].pilotResults.sort((n1, n2) => { if (n1.seat > n2.seat) { return 1; } if (n1.seat < n2.seat) { return -1; } return 0; }); - console.log(this.currentPilots); - this.currentPilots.forEach(pilot => { this.save(pilot).subscribe(data => { this.webSocketAPI._send('updateCurrent'); this.webSocketAPI._send('updatePassed'); }); }); } }); } else { this.setApiButton = true; } } getNewPilots(): Observable { return this.http.get(this.apiAdress); } } diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index a875e1b..fa3a79d 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -1,76 +1,74 @@ import { Component, OnInit } from '@angular/core'; import {AuthenticationService} from '../_services'; import {Router} from '@angular/router'; import {UserBackEnd} from '../_helpers'; import {DialogAddUserComponent, DialogData} from '../dialog-add-user/dialog-add-user.component'; import {MatDialog} from '@angular/material'; import {PilotsService} from '../_services/pilots.service'; @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.css'] }) export class AdminComponent implements OnInit { - currentUserValue: any; users: any; apiAdress = ''; nameNewUser: string; constructor(private pilotService: PilotsService, private router: Router, private authenticationService: AuthenticationService, private userBackEnd: UserBackEnd,public dialog: MatDialog) { - this.currentUserValue = this.authenticationService.currentUserValue; } ngOnInit() { - if (this.currentUserValue.role != 'admin') { + if (this.authenticationService.currentUserValue.role != 'admin') { this.router.navigate(['home']); } else { this.users = this.userBackEnd.getUsers(); } } updateUsers() { this.userBackEnd.updateUsers(this.users); } delete(name: any) { let i = 0; let index = -1; this.users.forEach(function(user) { if (user.name == name) { index = i; } i++; }); this.users.splice(index, 1); this.userBackEnd.updateUsers(this.users); } addUser(): void { const dialogRef = this.dialog.open(DialogAddUserComponent, { data: {name: this.nameNewUser, } }); dialogRef.afterClosed().subscribe(result => { if (result != null) { this.addUserToTheList(result); } }); } addUserToTheList(user: DialogData) { let i = 0; this.users.forEach(function(user) { i = user.id; }); var newUser = { id: i++, name: user.name, username: user.username, password: user.password , role: user.role}; this.users.push(newUser); this.updateUsers(); } setApi() { this.pilotService.setApi('//' + this.apiAdress + '/api/currentrun'); } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 287f06c..0f4238f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,25 +1,18 @@ import {Component, OnInit} from '@angular/core'; -import { Router } from '@angular/router'; - -import {AuthenticationService} from './_services'; -import {WebSocketAPI} from './_helpers/WebSocketAPI'; - @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { ngOnInit() { - } constructor() { - } } diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 85fe927..6b2ea5b 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,65 +1,65 @@
-

Current pilots azd

+

Current pilots

{{pilot.nickname}} Run : {{pilot.run}}
Run n°{{pilot.run}}
Id : {{pilot.pilotId}}

Old run pilots

{{pilot.nickname}} Run : {{pilot.run}}
Run n°{{pilot.run}}
Id : {{pilot.pilotId}}

No pilots for the moment...

diff --git a/src/app/toolbar-menu/toolbar-menu.component.html b/src/app/toolbar-menu/toolbar-menu.component.html index abf0623..6e087df 100644 --- a/src/app/toolbar-menu/toolbar-menu.component.html +++ b/src/app/toolbar-menu/toolbar-menu.component.html @@ -1,21 +1,22 @@
{{authenticationService.currentUserValue.name}}
diff --git a/src/app/toolbar-menu/toolbar-menu.component.ts b/src/app/toolbar-menu/toolbar-menu.component.ts index 84f5ac6..bcff904 100644 --- a/src/app/toolbar-menu/toolbar-menu.component.ts +++ b/src/app/toolbar-menu/toolbar-menu.component.ts @@ -1,35 +1,24 @@ import { Component, OnInit } from '@angular/core'; -import {WebSocketAPI} from '../_helpers/WebSocketAPI'; import {AuthenticationService} from '../_services'; import {Router} from '@angular/router'; @Component({ selector: 'app-toolbar-menu', templateUrl: './toolbar-menu.component.html', styleUrls: ['./toolbar-menu.component.css'] }) export class ToolbarMenuComponent implements OnInit { - currentUser: any; - currentUserValue: any; - webSocketAPI: WebSocketAPI; - greeting: any; name: string; constructor(private authenticationService: AuthenticationService, private router: Router) { } ngOnInit() { - this.authenticationService.currentUser.subscribe(x => this.currentUser = x); - this.currentUserValue = this.authenticationService.currentUserValue; - } - - refresh(x) { - this.currentUser = x; } logout() { this.authenticationService.logout(); this.router.navigate(['/']); } }