diff --git a/src/app/views/dashboard/dashboard.component.html b/src/app/views/dashboard/dashboard.component.html index 1badaea..cf0c27f 100644 --- a/src/app/views/dashboard/dashboard.component.html +++ b/src/app/views/dashboard/dashboard.component.html @@ -6,11 +6,11 @@ - Banned - - Reset - Banned - Not Banned + Filter + + All + Banned + Not Banned - + Username {{ user.username }} diff --git a/src/app/views/dashboard/dashboard.component.ts b/src/app/views/dashboard/dashboard.component.ts index 02a1192..ab847d3 100644 --- a/src/app/views/dashboard/dashboard.component.ts +++ b/src/app/views/dashboard/dashboard.component.ts @@ -29,7 +29,9 @@ import {AdministratablePlayer, AdminService, PlayerFilter} from '@core/server'; }) export class DashboardComponent implements OnInit { displayedColumns: Array = ['username', 'actions', 'banned']; - usersDataSource: MatTableDataSource = new MatTableDataSource([]); + selectedFilter: string = 'all'; + originalUsersDataSource: MatTableDataSource = new MatTableDataSource([]); + filteredUsersDataSource: MatTableDataSource = new MatTableDataSource([]); constructor(private adminService: AdminService, protected authService: AuthService, private cdr: ChangeDetectorRef) { } @@ -42,18 +44,19 @@ export class DashboardComponent implements OnInit { }); } - fetchPlayers(querry: string): void { + fetchPlayers(query: string): void { const filter: PlayerFilter = { page: 0, pageSize: 32, order: PlayerFilter.OrderEnum.Ascending, - username: querry, + username: query, sortBy: 'username' }; this.adminService.getAllPlayers(filter).subscribe( (players) => { - this.usersDataSource = new MatTableDataSource(players); + this.originalUsersDataSource.data = players; // Store original data + this.filteredUsersDataSource.data = [...players]; // Apply initial filter }, (error) => { console.error('Error fetching players:', error); @@ -64,18 +67,19 @@ export class DashboardComponent implements OnInit { banPlayer(user: UserData): void { this.adminService.banPlayer(user.id).subscribe(() => { user.banned = true; - this.usersDataSource.data = [...this.usersDataSource.data]; + this.originalUsersDataSource.data = [...this.originalUsersDataSource.data]; + this.applyFilter(this.selectedFilter); }); } unbanPlayer(user: UserData): void { this.adminService.unbanPlayer(user.id).subscribe(() => { user.banned = false; - this.usersDataSource.data = [...this.usersDataSource.data]; + this.originalUsersDataSource.data = [...this.originalUsersDataSource.data]; + this.applyFilter(this.selectedFilter); }); } - onSearch(searchbar: HTMLInputElement): void { this.fetchPlayers(searchbar.value); } @@ -84,4 +88,17 @@ export class DashboardComponent implements OnInit { searchbar.value = ''; 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]; + } }