Add API endpoints for search result counts by name and UUID
Introduced new API paths and backend logic to retrieve total punishment counts based on user search queries using names or UUIDs. Updated the frontend to utilize these endpoints and display the total search results dynamically.
This commit is contained in:
@@ -4,6 +4,7 @@ import {HistoryComponent} from './history/history.component';
|
||||
import {HistoryCount, HistoryService} from '../../api';
|
||||
import {NgClass, NgForOf, NgIf} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {catchError, map, Observable} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bans',
|
||||
@@ -20,18 +21,14 @@ import {FormsModule} from '@angular/forms';
|
||||
})
|
||||
export class BansComponent implements OnInit {
|
||||
|
||||
private PAGE_SIZE: number = 10;
|
||||
|
||||
public getCurrentButtonId(options: 'all' | 'ban' | 'mute' | 'kick' | 'warn') {
|
||||
if (options == this.punishmentType) {
|
||||
return 'currentButton'
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
constructor(public historyApi: HistoryService) {
|
||||
}
|
||||
|
||||
private PAGE_SIZE: number = 10;
|
||||
private uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
||||
private actualPage: number = 0;
|
||||
private totalSearchResults: number = -1;
|
||||
|
||||
public active: string = '';
|
||||
public userType: 'player' | 'staff' = "player";
|
||||
public punishmentType: 'all' | 'ban' | 'mute' | 'kick' | 'warn' = "all";
|
||||
@@ -47,7 +44,6 @@ export class BansComponent implements OnInit {
|
||||
kicks: 0,
|
||||
warnings: 0
|
||||
}
|
||||
private actualPage: number = 0;
|
||||
|
||||
ngOnInit() {
|
||||
this.historyApi.getUserNames(this.userType, this.punishmentType).subscribe(names => {
|
||||
@@ -71,6 +67,13 @@ export class BansComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
public getCurrentButtonId(options: 'all' | 'ban' | 'mute' | 'kick' | 'warn') {
|
||||
if (options == this.punishmentType) {
|
||||
return 'currentButton'
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public filterNames() {
|
||||
if (!this.searchTerm) {
|
||||
this.filteredNames = [];
|
||||
@@ -91,6 +94,26 @@ export class BansComponent implements OnInit {
|
||||
this.pushState()
|
||||
this.finalSearchTerm = this.searchTerm;
|
||||
this.page = 0;
|
||||
if (this.finalSearchTerm.length === 0) {
|
||||
this.totalSearchResults = -1
|
||||
return
|
||||
}
|
||||
|
||||
let totalSearchResultsObservable: Observable<number>;
|
||||
if (this.uuidRegex.test(this.finalSearchTerm)) {
|
||||
totalSearchResultsObservable = this.historyApi.getTotalResultsForUuidSearch(this.userType, this.punishmentType, this.finalSearchTerm);
|
||||
} else {
|
||||
totalSearchResultsObservable = this.historyApi.getTotalResultsForUserSearch(this.userType, this.punishmentType, this.finalSearchTerm);
|
||||
}
|
||||
totalSearchResultsObservable.pipe(
|
||||
map(totalSearchResults => {
|
||||
this.totalSearchResults = totalSearchResults;
|
||||
}),
|
||||
catchError(err => {
|
||||
console.error(err);
|
||||
return [];
|
||||
})
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
public changeHistoryType(type: 'player' | 'staff') {
|
||||
@@ -142,17 +165,20 @@ export class BansComponent implements OnInit {
|
||||
|
||||
public getMaxPage() {
|
||||
const all = this.historyCount.bans + this.historyCount.mutes + this.historyCount.warnings;
|
||||
if (this.finalSearchTerm.length !== 0) {
|
||||
return Math.floor(this.totalSearchResults / this.PAGE_SIZE);
|
||||
}
|
||||
switch (this.punishmentType) {
|
||||
case 'all':
|
||||
return Math.floor(all / this.PAGE_SIZE) - 1;
|
||||
return Math.floor(all / this.PAGE_SIZE);
|
||||
case 'ban':
|
||||
return Math.floor(this.historyCount.bans / this.PAGE_SIZE) - 1;
|
||||
return Math.floor(this.historyCount.bans / this.PAGE_SIZE);
|
||||
case 'mute':
|
||||
return Math.floor(this.historyCount.mutes / this.PAGE_SIZE) - 1;
|
||||
return Math.floor(this.historyCount.mutes / this.PAGE_SIZE);
|
||||
case 'kick':
|
||||
return Math.floor(this.historyCount.kicks / this.PAGE_SIZE) - 1;
|
||||
return Math.floor(this.historyCount.kicks / this.PAGE_SIZE);
|
||||
case 'warn':
|
||||
return Math.floor(this.historyCount.warnings / this.PAGE_SIZE) - 1;
|
||||
return Math.floor(this.historyCount.warnings / this.PAGE_SIZE);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export class HistoryComponent implements OnInit, OnChanges {
|
||||
if (this.uuidRegex.test(this.searchTerm)) {
|
||||
historyObservable = this.historyApi.getHistoryForUuid(this.userType, this.punishmentType, this.searchTerm, this.page);
|
||||
} else {
|
||||
historyObservable = this.historyApi.getHistoryForUsers(this.userType, this.punishmentType, this.searchTerm, this.page)
|
||||
historyObservable = this.historyApi.getHistoryForUsers(this.userType, this.punishmentType, this.searchTerm, this.page);
|
||||
}
|
||||
}
|
||||
historyObservable.pipe(
|
||||
|
||||
Reference in New Issue
Block a user