Add history page

This commit is contained in:
2025-04-11 21:20:02 +02:00
parent 4b891dd672
commit 2289b14b5a
16 changed files with 199 additions and 25 deletions
@@ -0,0 +1,16 @@
<ng-container *ngIf="history.length === 0">
<p>No history found</p>
</ng-container>
<ng-container *ngIf="history.length > 0">
<table>
<tr *ngFor="let entry of history">
<td>{{ entry.username }}</td>
<td>{{ entry.punishedBy }}</td>
<td>{{ entry.reason }}</td>
<td>{{ getPunishmentTime(entry) }}</td>
<td>{{ getExpiredTime(entry) }}</td>
</tr>
</table>
</ng-container>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HistoryComponent } from './history.component';
describe('HistoryComponent', () => {
let component: HistoryComponent;
let fixture: ComponentFixture<HistoryComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HistoryComponent]
})
.compileComponents();
fixture = TestBed.createComponent(HistoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,66 @@
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);
}
}