Compare commits
No commits in common. "TD-4_Admin_kann_spieler_bannen" and "trunk" have entirely different histories.
TD-4_Admin
...
trunk
5 changed files with 17 additions and 61 deletions
4
src/app/core/auth/UserData.d.ts
vendored
4
src/app/core/auth/UserData.d.ts
vendored
|
@ -1,8 +1,6 @@
|
||||||
interface UserData {
|
interface UserData {
|
||||||
username: string,
|
username: string,
|
||||||
verified: boolean,
|
verified: boolean
|
||||||
id: number,
|
|
||||||
banned: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UserData;
|
export default UserData;
|
||||||
|
|
|
@ -22,9 +22,7 @@ export class AuthService implements CanActivate {
|
||||||
const isLoggedIn = isAuthenticated && userData != null && accessToken != '';
|
const isLoggedIn = isAuthenticated && userData != null && accessToken != '';
|
||||||
this.$user.next(isLoggedIn ? {
|
this.$user.next(isLoggedIn ? {
|
||||||
username: userData.preferred_username,
|
username: userData.preferred_username,
|
||||||
verified: userData.email_verified,
|
verified: userData.email_verified
|
||||||
id: userData.id,
|
|
||||||
banned: userData.banned
|
|
||||||
} : undefined);
|
} : undefined);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
<input matInput placeholder="" #searchbar>
|
<input matInput placeholder="" #searchbar>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Filter</mat-label>
|
<mat-label>Banned</mat-label>
|
||||||
<mat-select #filter (selectionChange)="applyFilter(filter.value)">
|
<mat-select>
|
||||||
<mat-option value="all">All</mat-option>
|
<mat-option>Reset</mat-option>
|
||||||
<mat-option value="banned">Banned</mat-option>
|
<mat-option>Banned</mat-option>
|
||||||
<mat-option value="notBanned">Not Banned</mat-option>
|
<mat-option>Not Banned</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<button mat-fab class="shadowless" (click)="onSearch(searchbar)">
|
<button mat-fab class="shadowless" (click)="onSearch(searchbar)">
|
||||||
|
@ -21,27 +21,17 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<mat-table [dataSource]="filteredUsersDataSource" class="dashboard__table">
|
<mat-table [dataSource]="usersDataSource" class="dashboard__table">
|
||||||
<ng-container matColumnDef="username">
|
<ng-container matColumnDef="username">
|
||||||
<th mat-header-cell *matHeaderCellDef>Username</th>
|
<th mat-header-cell *matHeaderCellDef>Username</th>
|
||||||
<td mat-cell *matCellDef="let user"> {{ user.username }}</td>
|
<td mat-cell *matCellDef="let user"> {{ user.username }}</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="banned">
|
|
||||||
<th mat-header-cell *matHeaderCellDef>Banned</th>
|
|
||||||
<td mat-cell *matCellDef="let user"></td>
|
|
||||||
</ng-container>
|
|
||||||
<ng-container matColumnDef="actions">
|
<ng-container matColumnDef="actions">
|
||||||
<th mat-header-cell *matHeaderCellDef>Actions</th>
|
<th mat-header-cell *matHeaderCellDef>Actions</th>
|
||||||
<td mat-cell *matCellDef="let user">
|
<td mat-cell *matCellDef="let user">
|
||||||
@if (user.banned == false) {
|
|
||||||
<button mat-mini-fab class="warn shadowless" (click)="banPlayer(user)">
|
<button mat-mini-fab class="warn shadowless" (click)="banPlayer(user)">
|
||||||
<mat-icon>block</mat-icon>
|
<mat-icon>block</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
} @else {
|
|
||||||
<button mat-mini-fab class="unbanned shadowless" (click)="unbanPlayer(user)">
|
|
||||||
<mat-icon>check</mat-icon>
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
|
|
|
@ -30,8 +30,4 @@
|
||||||
padding: 0.25rem 0;
|
padding: 0.25rem 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.unbanned {
|
|
||||||
color:green;
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import {AsyncPipe} from '@angular/common';
|
import {AsyncPipe} from '@angular/common';
|
||||||
import {ChangeDetectorRef, Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {MatFabButton, MatMiniFabButton} from '@angular/material/button';
|
import {MatFabButton, MatMiniFabButton} from '@angular/material/button';
|
||||||
import {MatFormFieldModule} from '@angular/material/form-field';
|
import {MatFormFieldModule} from '@angular/material/form-field';
|
||||||
import {MatIcon} from '@angular/material/icon';
|
import {MatIcon} from '@angular/material/icon';
|
||||||
|
@ -28,12 +28,10 @@ import {AdministratablePlayer, AdminService, PlayerFilter} from '@core/server';
|
||||||
styleUrl: './dashboard.component.scss'
|
styleUrl: './dashboard.component.scss'
|
||||||
})
|
})
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
displayedColumns: Array<string> = ['username', 'actions', 'banned'];
|
displayedColumns: Array<string> = ['username', 'actions'];
|
||||||
selectedFilter: string = 'all';
|
usersDataSource: MatTableDataSource<AdministratablePlayer> = new MatTableDataSource<AdministratablePlayer>([]);
|
||||||
originalUsersDataSource: MatTableDataSource<AdministratablePlayer> = new MatTableDataSource<AdministratablePlayer>([]);
|
|
||||||
filteredUsersDataSource: MatTableDataSource<AdministratablePlayer> = new MatTableDataSource<AdministratablePlayer>([]);
|
|
||||||
|
|
||||||
constructor(private adminService: AdminService, protected authService: AuthService, private cdr: ChangeDetectorRef) {
|
constructor(private adminService: AdminService, protected authService: AuthService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
@ -44,19 +42,18 @@ export class DashboardComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchPlayers(query: string): void {
|
fetchPlayers(querry: string): void {
|
||||||
const filter: PlayerFilter = {
|
const filter: PlayerFilter = {
|
||||||
page: 0,
|
page: 0,
|
||||||
pageSize: 32,
|
pageSize: 32,
|
||||||
order: PlayerFilter.OrderEnum.Ascending,
|
order: PlayerFilter.OrderEnum.Ascending,
|
||||||
username: query,
|
username: querry,
|
||||||
sortBy: 'username'
|
sortBy: 'username'
|
||||||
};
|
};
|
||||||
|
|
||||||
this.adminService.getAllPlayers(filter).subscribe(
|
this.adminService.getAllPlayers(filter).subscribe(
|
||||||
(players) => {
|
(players) => {
|
||||||
this.originalUsersDataSource.data = players; // Store original data
|
this.usersDataSource = new MatTableDataSource<AdministratablePlayer>(players);
|
||||||
this.filteredUsersDataSource.data = [...players]; // Apply initial filter
|
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
console.error('Error fetching players:', error);
|
console.error('Error fetching players:', error);
|
||||||
|
@ -65,19 +62,8 @@ export class DashboardComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
banPlayer(user: UserData): void {
|
banPlayer(user: UserData): void {
|
||||||
this.adminService.banPlayer(user.id).subscribe(() => {
|
console.log(`Banning user: ${user.username}`);
|
||||||
user.banned = true;
|
// TODO: implement banning logic
|
||||||
this.originalUsersDataSource.data = [...this.originalUsersDataSource.data];
|
|
||||||
this.applyFilter(this.selectedFilter);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
unbanPlayer(user: UserData): void {
|
|
||||||
this.adminService.unbanPlayer(user.id).subscribe(() => {
|
|
||||||
user.banned = false;
|
|
||||||
this.originalUsersDataSource.data = [...this.originalUsersDataSource.data];
|
|
||||||
this.applyFilter(this.selectedFilter);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch(searchbar: HTMLInputElement): void {
|
onSearch(searchbar: HTMLInputElement): void {
|
||||||
|
@ -89,16 +75,4 @@ export class DashboardComponent implements OnInit {
|
||||||
this.fetchPlayers('');
|
this.fetchPlayers('');
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilter(filter: string): void {
|
|
||||||
this.selectedFilter = filter; // Store filter selection
|
|
||||||
let filteredUsers = this.originalUsersDataSource.data;
|
|
||||||
|
|
||||||
if (filter === 'banned') {
|
|
||||||
filteredUsers = filteredUsers.filter(user => user.banned);
|
|
||||||
} else if (filter === 'notBanned') {
|
|
||||||
filteredUsers = filteredUsers.filter(user => !user.banned);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.filteredUsersDataSource.data = [...filteredUsers];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue