allerta-vvf/frontend/src/app/_components/table/table.component.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-12-24 15:21:22 +01:00
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { TableType } from 'src/app/_models/TableType';
import { ApiClientService } from 'src/app/_services/api-client.service';
2021-12-27 19:58:38 +01:00
import { AuthService } from '../../_services/auth.service';
2021-12-22 23:06:58 +01:00
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.scss']
})
export class TableComponent implements OnInit {
@Input() sourceType?: string;
2021-12-24 15:21:22 +01:00
@Output() changeAvailability: EventEmitter<{user: number, newState: 0|1}> = new EventEmitter<{user: number, newState: 0|1}>();
2021-12-22 23:06:58 +01:00
public data: any = [];
2021-12-27 19:58:38 +01:00
constructor(public apiClient: ApiClientService, public auth: AuthService) {}
2021-12-22 23:06:58 +01:00
2021-12-27 14:43:01 +01:00
getTime() {
return Math.floor(Date.now() / 1000);
}
2021-12-24 15:21:22 +01:00
loadTableData() {
2021-12-22 23:06:58 +01:00
this.apiClient.get(this.sourceType || "list").then((data: any) => {
console.log(data);
2021-12-27 13:22:32 +01:00
this.data = data.filter((row: any) => {
if(typeof row.hidden !== 'undefined') return !row.hidden;
return true;
});
2021-12-22 23:06:58 +01:00
});
}
2021-12-24 15:21:22 +01:00
ngOnInit(): void {
console.log(this.sourceType);
this.loadTableData();
}
2021-12-27 19:58:38 +01:00
onChangeAvailability(user: number, newState: 0|1) {
if(this.auth.profile.chief) {
this.changeAvailability.emit({user, newState});
}
}
2021-12-22 23:06:58 +01:00
}