56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import {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 {UserService} from '@app/_services';
|
|
import {first} from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'app-settings',
|
|
templateUrl: './settings.component.html',
|
|
styleUrls: ['./settings.component.scss']
|
|
})
|
|
export class SettingsComponent implements OnInit {
|
|
date: string;
|
|
dataSource: MatTableDataSource<any>;
|
|
displayedColumns = ['name', 'accountType', 'created', 'status', 'options'];
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
constructor(
|
|
private userService: UserService
|
|
) {
|
|
this.userService.getStaff();
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.userService.staffSubject.subscribe(staff => {
|
|
this.dataSource = new MatTableDataSource<any>(staff);
|
|
this.dataSource.paginator = this.paginator;
|
|
this.dataSource.sort = this.sort;
|
|
});
|
|
const d = new Date();
|
|
this.date = `${d.getDate()}/${d.getMonth()}/${d.getFullYear()}`;
|
|
}
|
|
|
|
doFilter(value: string): void {
|
|
this.dataSource.filter = value.trim().toLocaleLowerCase();
|
|
}
|
|
|
|
activateStaff(id: string): void {
|
|
this.userService.activateStaff(id).pipe(first()).subscribe(res => console.log(res));
|
|
this.userService.getStaff();
|
|
}
|
|
|
|
deactivateStaff(id: string): void {
|
|
this.userService.deactivateStaff(id).pipe(first()).subscribe(res => console.log(res));
|
|
this.userService.getStaff();
|
|
}
|
|
|
|
changeStaffType(id: string, type: string): void {
|
|
this.userService.changeStaffType(id, type).pipe(first()).subscribe(res => console.log(res));
|
|
this.userService.getStaff();
|
|
}
|
|
}
|