Add history page

This commit is contained in:
Teriuihi 2025-04-11 21:20:02 +02:00
parent 4b891dd672
commit 2289b14b5a
16 changed files with 199 additions and 25 deletions

View File

@ -72,7 +72,7 @@ public class HistoryApiController implements HistoryApi {
UserType userTypeEnum = UserType.getUserType(userType);
HistoryType historyTypeEnum = HistoryType.getHistoryType(type);
CompletableFuture<List<String>> playerGroupFuture = new CompletableFuture<>();
Connection.getConnection(Databases.LITE_BANS)
.runQuery(sqlSession -> {
log.debug("Loading user names for type {}", type);
@ -93,9 +93,9 @@ public class HistoryApiController implements HistoryApi {
PunishmentHistoryInnerDto innerDto = new PunishmentHistoryInnerDto()
.uuid(historyRecord.getUuid())
.username(historyRecord.getPunishedName())
.reason(historyRecord.getReason())
.punishmentUserUuid(historyRecord.getBannedByUuid())
.punishmentUser(historyRecord.getBannedByName())
.reason(PunishmentHistoryInnerDto.ReasonEnum.valueOf(historyRecord.getReason()))
.punishedByUuid(historyRecord.getBannedByUuid())
.punishedBy(historyRecord.getBannedByName())
.removedBy(historyRecord.getRemovedByName())
.punishmentTime(historyRecord.getTime())
.expiryTime(historyRecord.getUntil())

View File

@ -2,10 +2,10 @@ package com.alttd.altitudeweb.database.litebans;
public enum HistoryType {
ALL,
BANS,
MUTES,
KICKS,
WARNS;
BAN,
MUTE,
KICK,
WARN;
public static HistoryType getHistoryType(String historyType) {
return HistoryType.valueOf(historyType.toUpperCase());

View File

@ -92,10 +92,10 @@ public interface NameHistoryMapper {
int page) {
return switch (historyType) {
case ALL -> getRecentAll(userType, partialName, page);
case BANS -> getRecentBans(userType, partialName, page);
case MUTES -> getRecentMutes(userType, partialName, page);
case KICKS -> getRecentKicks(userType, partialName, page);
case WARNS -> getRecentWarns(userType, partialName, page);
case BAN -> getRecentBans(userType, partialName, page);
case MUTE -> getRecentMutes(userType, partialName, page);
case KICK -> getRecentKicks(userType, partialName, page);
case WARN -> getRecentWarns(userType, partialName, page);
};
}

View File

@ -20,10 +20,10 @@ public interface RecentNamesMapper {
default List<String> getRecent(HistoryType historyType, UserType userType) {
return switch (historyType) {
case ALL -> getRecentAll(userType);
case BANS -> getRecentBans(userType);
case MUTES -> getRecentMutes(userType);
case KICKS -> getRecentKicks(userType);
case WARNS -> getRecentWarns(userType);
case BAN -> getRecentBans(userType);
case MUTE -> getRecentMutes(userType);
case KICK -> getRecentKicks(userType);
case WARN -> getRecentWarns(userType);
};
}

View File

@ -67,10 +67,10 @@ public interface UUIDHistoryMapper {
default List<HistoryRecord> getRecent(HistoryType historyType, UserType userType, UUID uuid, int page) {
return switch (historyType) {
case ALL -> getRecentAll(userType, uuid, page);
case BANS -> getRecentBans(userType, uuid, page);
case MUTES -> getRecentMutes(userType, uuid, page);
case KICKS -> getRecentKicks(userType, uuid, page);
case WARNS -> getRecentWarns(userType, uuid, page);
case BAN -> getRecentBans(userType, uuid, page);
case MUTE -> getRecentMutes(userType, uuid, page);
case KICK -> getRecentKicks(userType, uuid, page);
case WARN -> getRecentWarns(userType, uuid, page);
};
}

View File

@ -40,6 +40,10 @@ export const routes: Routes = [
{
path: 'privacy',
loadComponent: () => import('./privacy/privacy.component').then(m => m.PrivacyComponent)
},
{
path: 'bans',
loadComponent: () => import('./bans/bans.component').then(m => m.BansComponent)
}
];

View File

@ -0,0 +1,20 @@
<ng-container>
<app-header [current_page]="'bans'" height="200px" background_image="/public/img/backgrounds/staff.png"
[overlay_gradient]="0.5">>
<div class="title" header-content>
<h1>Punishment History</h1>
</div>
</app-header>
<div class="container">
<div class="columnContainer">
<button (click)="punishmentType = 'all'">all</button>
<button (click)="punishmentType = 'ban'">bans</button>
<button (click)="punishmentType = 'mute'">mutes</button>
<button (click)="punishmentType = 'warn'">warnings</button>
</div>
<div class="columnContainer">
<app-history [userType]="userType" [punishmentType]="punishmentType"></app-history>
</div>
</div>
</ng-container>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BansComponent } from './bans.component';
describe('BansComponent', () => {
let component: BansComponent;
let fixture: ComponentFixture<BansComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BansComponent]
})
.compileComponents();
fixture = TestBed.createComponent(BansComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,19 @@
import {Component} from '@angular/core';
import {HeaderComponent} from "../header/header.component";
import {HistoryComponent} from './history/history.component';
@Component({
selector: 'app-bans',
imports: [
HeaderComponent,
HistoryComponent
],
templateUrl: './bans.component.html',
styleUrl: './bans.component.scss'
})
export class BansComponent {
public userType: 'player' | 'staff' = "player";
public punishmentType: 'all' | 'ban' | 'mute' | 'kick' | 'warn' = "all";
}

View File

@ -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>

View File

@ -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();
});
});

View File

@ -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);
}
}

View File

@ -112,7 +112,7 @@ components:
required: true
schema:
type: string
enum: [ all, bans, mutes, kicks ]
enum: [ all, ban, mute, kick, warn ]
description: The type of history to retrieve
User:
name: user
@ -154,7 +154,9 @@ components:
- reason
- type
- punishmentTime
- punishmentUserUuid
- expiryTime
- punishedBy
- punishedByUuid
properties:
username:
type: string
@ -165,6 +167,7 @@ components:
reason:
type: string
description: The reason for the punishment
enum: [ ban, mute, kick, warn ]
type:
type: string
description: The type of punishment
@ -176,10 +179,10 @@ components:
type: integer
format: int64
description: The time when the punishment expires
punishmentUser:
punishedBy:
type: string
description: The username of the punishment issuer
punishmentUserUuid:
punishedByUuid:
type: string
description: The UUID of the punishment issuer
removedBy:

View File

@ -6,7 +6,7 @@ getTeam:
description: Retrieve players who are part of the specified team
operationId: getTeamMembers
parameters:
- name: group
- name: team
in: path
required: true
description: The group name of the team