67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
|
|
import {Component, Input, OnChanges, OnInit} from '@angular/core';
|
||
|
|
import {BASE_PATH, HistoryService, PunishmentHistoryInner} from '../../../api';
|
||
|
|
import {map, shareReplay} from 'rxjs';
|
||
|
|
import {NgForOf, NgIf} from '@angular/common';
|
||
|
|
import {CookieService} from 'ngx-cookie-service';
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'app-history',
|
||
|
|
imports: [
|
||
|
|
NgIf,
|
||
|
|
NgForOf
|
||
|
|
],
|
||
|
|
templateUrl: './history.component.html',
|
||
|
|
styleUrl: './history.component.scss',
|
||
|
|
providers: [
|
||
|
|
CookieService,
|
||
|
|
{provide: BASE_PATH, useValue: 'http://localhost:8080/'}
|
||
|
|
],
|
||
|
|
})
|
||
|
|
export class HistoryComponent implements OnInit, OnChanges {
|
||
|
|
|
||
|
|
@Input() userType: 'player' | 'staff' = "player";
|
||
|
|
@Input() punishmentType: 'all' | 'ban' | 'mute' | 'kick' | 'warn' = "all";
|
||
|
|
|
||
|
|
public history: PunishmentHistoryInner[] = []
|
||
|
|
|
||
|
|
constructor(private historyApi: HistoryService) {
|
||
|
|
}
|
||
|
|
|
||
|
|
ngOnChanges(): void {
|
||
|
|
this.reloadHistory();
|
||
|
|
}
|
||
|
|
|
||
|
|
ngOnInit(): void {
|
||
|
|
this.reloadHistory();
|
||
|
|
}
|
||
|
|
|
||
|
|
private reloadHistory(): void {
|
||
|
|
console.log('userType', this.userType);
|
||
|
|
console.log('punishmentType', this.punishmentType);
|
||
|
|
this.historyApi.getHistoryForAll(this.userType, this.punishmentType, 0).pipe(
|
||
|
|
map(history => {
|
||
|
|
this.history = history;
|
||
|
|
console.log("HI");
|
||
|
|
console.log(history);
|
||
|
|
history.forEach(history => {
|
||
|
|
console.log(history);
|
||
|
|
});
|
||
|
|
}),
|
||
|
|
shareReplay(1)
|
||
|
|
).subscribe();
|
||
|
|
}
|
||
|
|
|
||
|
|
public getPunishmentTime(entry: PunishmentHistoryInner) {
|
||
|
|
const date = new Date(entry.punishmentTime);
|
||
|
|
return date.toLocaleDateString(navigator.language);
|
||
|
|
}
|
||
|
|
|
||
|
|
public getExpiredTime(entry: PunishmentHistoryInner) {
|
||
|
|
if (entry.expiryTime === 0) {
|
||
|
|
return "Permanent " + entry.type.charAt(0).toUpperCase() + entry.type.slice(1);
|
||
|
|
}
|
||
|
|
const date = new Date(entry.punishmentTime + entry.expiryTime);
|
||
|
|
return date.toLocaleDateString(navigator.language);
|
||
|
|
}
|
||
|
|
}
|