67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
import {MatPaginator} from '@angular/material/paginator';
|
|
import {MatSort} from '@angular/material/sort';
|
|
import {LoggingService, UserService} from '@app/_services';
|
|
import {animate, state, style, transition, trigger} from '@angular/animations';
|
|
import {first} from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'app-admin',
|
|
templateUrl: './admin.component.html',
|
|
styleUrls: ['./admin.component.scss'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
animations: [
|
|
trigger('detailExpand', [
|
|
state('collapsed', style({height: '0px', minHeight: 0, visibility: 'hidden'})),
|
|
state('expanded', style({height: '*', visibility: 'visible'})),
|
|
transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
|
|
])
|
|
]
|
|
})
|
|
export class AdminComponent implements OnInit {
|
|
dataSource: MatTableDataSource<any>;
|
|
displayedColumns = ['expand', 'user', 'role', 'action', 'status', 'approve'];
|
|
action: any;
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
constructor(
|
|
private userService: UserService,
|
|
private loggingService: LoggingService
|
|
) {
|
|
this.userService.getActions();
|
|
this.userService.actionsSubject.subscribe(actions => {
|
|
this.dataSource = new MatTableDataSource<any>(actions);
|
|
this.dataSource.paginator = this.paginator;
|
|
this.dataSource.sort = this.sort;
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
doFilter(value: string): void {
|
|
this.dataSource.filter = value.trim().toLocaleLowerCase();
|
|
}
|
|
|
|
approvalStatus(status: boolean): string {
|
|
return status ? 'Approved' : 'Unapproved';
|
|
}
|
|
|
|
approveAction(action: any): void {
|
|
this.userService.approveAction(action.id).pipe(first()).subscribe(res => this.loggingService.sendInfoLevelMessage(res.body));
|
|
this.userService.getActions();
|
|
}
|
|
|
|
revertAction(action: any): void {
|
|
this.userService.revokeAction(action.id).pipe(first()).subscribe(res => this.loggingService.sendInfoLevelMessage(res.body));
|
|
this.userService.getActions();
|
|
}
|
|
|
|
expandCollapse(row): void {
|
|
row.isExpanded = !row.isExpanded;
|
|
}
|
|
}
|