cic-staff-client/src/app/pages/settings/settings.component.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-05-10 18:15:25 +02:00
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 { AuthService } from '@app/_services';
import { Staff } from '@app/_models/staff';
import { exportCsv } from '@app/_helpers';
2020-11-25 08:59:48 +01:00
@Component({
selector: 'app-settings',
templateUrl: './settings.component.html',
styleUrls: ['./settings.component.scss'],
2021-05-10 18:15:25 +02:00
changeDetection: ChangeDetectionStrategy.OnPush,
2020-11-25 08:59:48 +01:00
})
export class SettingsComponent implements OnInit {
2020-11-25 08:59:48 +01:00
dataSource: MatTableDataSource<any>;
2021-04-30 14:50:16 +02:00
displayedColumns: Array<string> = ['name', 'email', 'userId'];
trustedUsers: Array<Staff>;
userInfo: Staff;
loading: boolean = true;
2020-11-25 08:59:48 +01:00
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
2021-05-10 18:15:25 +02:00
constructor(private authService: AuthService) {}
2020-11-25 08:59:48 +01:00
ngOnInit(): void {
2021-06-02 09:48:02 +02:00
this.authService.trustedUsersSubject.subscribe((users) => {
this.dataSource = new MatTableDataSource<any>(users);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.trustedUsers = users;
if (users.length > 0) {
this.loading = false;
}
2021-06-02 09:48:02 +02:00
});
this.userInfo = this.authService.getPrivateKeyInfo();
2020-11-25 08:59:48 +01:00
}
doFilter(value: string): void {
this.dataSource.filter = value.trim().toLocaleLowerCase();
}
2021-03-24 14:26:51 +01:00
downloadCsv(): void {
exportCsv(this.trustedUsers, 'users');
}
2021-03-24 17:41:11 +01:00
logout(): void {
this.authService.logout();
}
2020-11-25 08:59:48 +01:00
}