diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java index c4849c1..d46b398 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/history/HistoryApiController.java @@ -72,7 +72,7 @@ public class HistoryApiController implements HistoryApi { UserType userTypeEnum = UserType.getUserType(userType); HistoryType historyTypeEnum = HistoryType.getHistoryType(type); CompletableFuture> 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()) diff --git a/database/src/main/java/com/alttd/altitudeweb/database/litebans/HistoryType.java b/database/src/main/java/com/alttd/altitudeweb/database/litebans/HistoryType.java index fa708f6..d7692d1 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/litebans/HistoryType.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/litebans/HistoryType.java @@ -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()); diff --git a/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java b/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java index b3d70db..fc1d1bf 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/litebans/NameHistoryMapper.java @@ -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); }; } diff --git a/database/src/main/java/com/alttd/altitudeweb/database/litebans/RecentNamesMapper.java b/database/src/main/java/com/alttd/altitudeweb/database/litebans/RecentNamesMapper.java index a50ddd3..5b8c15c 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/litebans/RecentNamesMapper.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/litebans/RecentNamesMapper.java @@ -20,10 +20,10 @@ public interface RecentNamesMapper { default List 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); }; } diff --git a/database/src/main/java/com/alttd/altitudeweb/database/litebans/UUIDHistoryMapper.java b/database/src/main/java/com/alttd/altitudeweb/database/litebans/UUIDHistoryMapper.java index 81e77dc..37443e2 100644 --- a/database/src/main/java/com/alttd/altitudeweb/database/litebans/UUIDHistoryMapper.java +++ b/database/src/main/java/com/alttd/altitudeweb/database/litebans/UUIDHistoryMapper.java @@ -67,10 +67,10 @@ public interface UUIDHistoryMapper { default List 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); }; } diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index 36ac036..dc58204 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -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) } ]; diff --git a/frontend/src/app/bans/bans.component.html b/frontend/src/app/bans/bans.component.html new file mode 100644 index 0000000..a723943 --- /dev/null +++ b/frontend/src/app/bans/bans.component.html @@ -0,0 +1,20 @@ + + > +
+

Punishment History

+
+
+ +
+
+ + + + +
+
+ +
+
+
diff --git a/frontend/src/app/bans/bans.component.scss b/frontend/src/app/bans/bans.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/bans/bans.component.spec.ts b/frontend/src/app/bans/bans.component.spec.ts new file mode 100644 index 0000000..308d41b --- /dev/null +++ b/frontend/src/app/bans/bans.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BansComponent } from './bans.component'; + +describe('BansComponent', () => { + let component: BansComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [BansComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(BansComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/bans/bans.component.ts b/frontend/src/app/bans/bans.component.ts new file mode 100644 index 0000000..7aa7d17 --- /dev/null +++ b/frontend/src/app/bans/bans.component.ts @@ -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"; + +} diff --git a/frontend/src/app/bans/history/history.component.html b/frontend/src/app/bans/history/history.component.html new file mode 100644 index 0000000..0f22dba --- /dev/null +++ b/frontend/src/app/bans/history/history.component.html @@ -0,0 +1,16 @@ + +

No history found

+
+ + + + + + + + + + +
{{ entry.username }}{{ entry.punishedBy }}{{ entry.reason }}{{ getPunishmentTime(entry) }}{{ getExpiredTime(entry) }}
+
+ diff --git a/frontend/src/app/bans/history/history.component.scss b/frontend/src/app/bans/history/history.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/bans/history/history.component.spec.ts b/frontend/src/app/bans/history/history.component.spec.ts new file mode 100644 index 0000000..fdb7598 --- /dev/null +++ b/frontend/src/app/bans/history/history.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HistoryComponent } from './history.component'; + +describe('HistoryComponent', () => { + let component: HistoryComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [HistoryComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(HistoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/bans/history/history.component.ts b/frontend/src/app/bans/history/history.component.ts new file mode 100644 index 0000000..5efdfc3 --- /dev/null +++ b/frontend/src/app/bans/history/history.component.ts @@ -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); + } +} diff --git a/open_api/src/main/resources/schemas/bans/bans.yml b/open_api/src/main/resources/schemas/bans/bans.yml index 8f73c70..9ac71d1 100644 --- a/open_api/src/main/resources/schemas/bans/bans.yml +++ b/open_api/src/main/resources/schemas/bans/bans.yml @@ -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: diff --git a/open_api/src/main/resources/schemas/team/team.yml b/open_api/src/main/resources/schemas/team/team.yml index 49db31e..23872c8 100644 --- a/open_api/src/main/resources/schemas/team/team.yml +++ b/open_api/src/main/resources/schemas/team/team.yml @@ -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