|
|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Component, Input, OnInit } from '@angular/core'; |
|
|
|
import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; |
|
|
|
import { CommonModule } from '@angular/common'; |
|
|
|
|
|
|
|
import { MatButtonModule } from '@angular/material/button'; |
|
|
|
@ -7,7 +7,6 @@ import { MatIconModule } from '@angular/material/icon'; |
|
|
|
import { MatTableModule } from '@angular/material/table'; |
|
|
|
|
|
|
|
import { RacesService } from '../../services/races.service'; |
|
|
|
import { RacersService } from '../../services/racers.service'; |
|
|
|
import { RaceResultService } from '../../services/race-result.service'; |
|
|
|
import { Race } from '../../models/race.model'; |
|
|
|
import { Racer } from '../../models/racer.model'; |
|
|
|
@ -27,27 +26,66 @@ import { RaceEntry } from '../../models/raceEntry.model'; |
|
|
|
styleUrl: './race-details.component.scss' |
|
|
|
}) |
|
|
|
|
|
|
|
export class RaceDetailsComponent { |
|
|
|
export class RaceDetailsComponent implements AfterViewInit { |
|
|
|
@Input() race?: Race; |
|
|
|
racers: Map<string, Racer> = new Map<string, Racer>(); |
|
|
|
//raceResults: Map<string, RaceEntry[]> = new Map<string, RaceEntry[]>;
|
|
|
|
raceResults: any; |
|
|
|
blob: Blob = new Blob(); |
|
|
|
|
|
|
|
displayedColumns: string[] = ['position', 'name', 'runTime', 'ghost']; |
|
|
|
sortedResults: RaceEntry[] = []; |
|
|
|
|
|
|
|
openToUploads: boolean = true; |
|
|
|
|
|
|
|
date: any; |
|
|
|
now: any; |
|
|
|
targetDate: Date = new Date(2024, 5, 11); |
|
|
|
targetTime: number = this.targetDate.getTime(); |
|
|
|
difference: number = 0; |
|
|
|
months: Array<string> = [ |
|
|
|
'January', |
|
|
|
'February', |
|
|
|
'March', |
|
|
|
'April', |
|
|
|
'May', |
|
|
|
'June', |
|
|
|
'July', |
|
|
|
'August', |
|
|
|
'September', |
|
|
|
'October', |
|
|
|
'November', |
|
|
|
'December', |
|
|
|
]; |
|
|
|
currentTime: any = `${ |
|
|
|
this.months[this.targetDate.getMonth()] |
|
|
|
} ${this.targetDate.getDate()}, ${this.targetDate.getFullYear()}`;
|
|
|
|
|
|
|
|
@ViewChild('days') days?: ElementRef; |
|
|
|
@ViewChild('hours') hours?: ElementRef; |
|
|
|
@ViewChild('minutes') minutes?: ElementRef; |
|
|
|
@ViewChild('seconds') seconds?: ElementRef; |
|
|
|
|
|
|
|
constructor( |
|
|
|
private racersService: RacersService, |
|
|
|
private raceResultService: RaceResultService, |
|
|
|
private racesService: RacesService, |
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
if( this.race == undefined) { |
|
|
|
console.log("No race in race-details") |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.targetDate = new Date(this.race.endDate); |
|
|
|
this.targetTime = this.targetDate.getTime(); |
|
|
|
|
|
|
|
if(this.targetTime < Date.now()){ |
|
|
|
this.openToUploads = false; |
|
|
|
} |
|
|
|
|
|
|
|
this.currentTime = `${ |
|
|
|
this.months[this.targetDate.getMonth()] |
|
|
|
} ${this.targetDate.getDate()}, ${this.targetDate.getFullYear()}`;
|
|
|
|
|
|
|
|
this.racesService.getRaceResults(this.race.id).subscribe(data => { |
|
|
|
console.log(data) |
|
|
|
this.raceResults = data; |
|
|
|
@ -65,22 +103,33 @@ export class RaceDetailsComponent { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
getBestTimeForRacer(racer_id: string): RaceEntry | undefined { |
|
|
|
let results = this.raceResults.get(racer_id) |
|
|
|
if (results == undefined ){ |
|
|
|
return undefined |
|
|
|
ngAfterViewInit(): void { |
|
|
|
if(this.openToUploads == false) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
let bestTime: number = 0xFFFFFFFF; |
|
|
|
let bestResult = undefined |
|
|
|
for(let result of results){ |
|
|
|
if(result.time < bestTime) { |
|
|
|
bestTime = result.time |
|
|
|
bestResult = result; |
|
|
|
|
|
|
|
setInterval(() => { |
|
|
|
this.tickTock(); |
|
|
|
this.difference = this.targetTime - this.now; |
|
|
|
this.difference = this.difference / (1000 * 60 * 60 * 24); |
|
|
|
|
|
|
|
if(this.days && this.hours && this.minutes && this.seconds){ |
|
|
|
!isNaN(this.days.nativeElement.innerText) |
|
|
|
? (this.days.nativeElement.innerText = Math.floor(this.difference)) |
|
|
|
: (this.days.nativeElement.innerHTML = `<img src="https://i.gifer.com/VAyR.gif" />`); |
|
|
|
} |
|
|
|
} |
|
|
|
}, 1000); |
|
|
|
} |
|
|
|
|
|
|
|
return bestResult |
|
|
|
tickTock() { |
|
|
|
this.date = new Date(); |
|
|
|
this.now = this.date.getTime(); |
|
|
|
if(this.days != undefined && this.hours != undefined && this.minutes != undefined && this.seconds != undefined) { |
|
|
|
this.days.nativeElement.innerText = Math.floor(this.difference); |
|
|
|
this.hours.nativeElement.innerText = 23 - this.date.getHours(); |
|
|
|
this.minutes.nativeElement.innerText = 60 - this.date.getMinutes(); |
|
|
|
this.seconds.nativeElement.innerText = 60 - this.date.getSeconds(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
formatMilliseconds(milliseconds: number) |
|
|
|
@ -104,8 +153,6 @@ export class RaceDetailsComponent { |
|
|
|
return "" |
|
|
|
} |
|
|
|
|
|
|
|
blob: Blob = new Blob(); |
|
|
|
|
|
|
|
onClickDownloadGhost(raceResult: any) { |
|
|
|
console.log(raceResult) |
|
|
|
this.raceResultService.getGhost(raceResult.id).subscribe(data => { |
|
|
|
|