Files
mowesta/web-angular/src/app/views-user/user-devices.component.ts
T
handte cb62687016
LocationBasedServices/mowesta/master This commit looks good
Finalized measurement view.
2020-03-10 09:43:12 +01:00

76 lines
2.4 KiB
TypeScript

import { Component, ViewChild, OnInit, OnDestroy, ElementRef, DoCheck } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { DataSource } from '@angular/cdk/table';
import { BehaviorSubject } from 'rxjs';
import { Device, DevicePage } from '../api';
import { DeviceService, ResourceService } from '../services';
import { PaginationHandler, TableHandler, TableColumn } from '../utils';
import { Router } from '@angular/router';
@Component({
selector: 'app-user-devices',
templateUrl: 'user-devices.component.html'
})
export class UserDevicesComponent implements OnInit, OnDestroy, DoCheck {
private static COLUMNS: TableColumn[] = [
{ name: 'id', dropPriority: 2, width: 70, fixedWidth: true },
{ name: 'os', dropPriority: 1, width: 60, fixedWidth: true },
{ name: 'manufacturer', dropPriority: 0, width: 100 },
{ name: 'model', dropPriority: 0, width: 100 },
{ name: 'creationTime', dropPriority: 3, width: 130, fixedWidth: true },
{ name: 'modificationTime', dropPriority: 4, width: 130, fixedWidth: true }
];
@ViewChild('table', { read: ElementRef, static: true }) table: ElementRef;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
dataSource: DataSource<Device>;
private pageHandler: PaginationHandler<Device, DevicePage>;
readonly loading: BehaviorSubject<boolean>;
private tableHandler: TableHandler;
constructor(
public res: ResourceService,
private deviceSerivce: DeviceService,
private router: Router) {
this.dataSource = deviceSerivce;
this.loading = deviceSerivce.loading;
}
ngDoCheck(): void {
this.tableHandler.onCheck();
}
getStyle(column: string): any {
return this.tableHandler.getColumnStyle(column);
}
getColumns(): string[] {
return this.tableHandler.getDisplayColumns();
}
ngOnInit() {
this.tableHandler = new TableHandler(this.table, UserDevicesComponent.COLUMNS);
this.pageHandler = new PaginationHandler(this.paginator, this.deviceSerivce);
this.deviceSerivce.reload();
}
ngOnDestroy() {
this.pageHandler.destroy();
}
getNumber(index: number): number {
if (this.deviceSerivce.page.getValue() != null) {
return this.deviceSerivce.page.getValue().offset + 1 + index;
} else {
return index + 1;
}
}
onClick(device: Device) {
this.router.navigateByUrl(`/${this.res.getLanguage()}/user/devices/${device.id}`);
}
}