Files
DiunaBI/Frontend/src/app/modules/layers/layers-list/layers-list.component.ts

63 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-12-11 23:40:16 +01:00
import { HttpClient } from '@angular/common/http';
2023-06-25 17:03:17 +02:00
import { Component, HostListener, OnInit, ViewChild } from '@angular/core';
2023-06-23 15:32:59 +02:00
import { MatSort, MatSortable, MatSortModule } from '@angular/material/sort';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
2023-01-06 11:10:58 +01:00
import { Layer } from 'src/app/models/layer.model';
2023-06-23 15:32:59 +02:00
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
import { RouterLink } from '@angular/router';
import { MatButtonModule } from '@angular/material/button';
import { MatGridListModule } from '@angular/material/grid-list';
2022-12-11 23:40:16 +01:00
@Component({
2023-06-23 15:32:59 +02:00
selector: 'app-layers-list',
templateUrl: './layers-list.component.html',
styleUrls: ['./layers-list.component.scss'],
standalone: true,
2023-06-25 17:03:17 +02:00
imports: [MatGridListModule, MatButtonModule, RouterLink, MatFormFieldModule, MatInputModule, MatTableModule, MatSortModule]
2022-12-11 23:40:16 +01:00
})
2023-01-06 11:10:58 +01:00
export class LayersListComponent implements OnInit {
2022-12-21 18:35:26 +01:00
displayedColumns = ['number', 'name', 'source'];
2023-01-06 11:10:58 +01:00
dataSource!: MatTableDataSource<Layer>;
2022-12-11 23:40:16 +01:00
@ViewChild(MatSort) sort!: MatSort;
2023-06-25 17:03:17 +02:00
start: number = 0;
limit: number = 50;
end: number = this.limit + this.start;
loadingInProgress: boolean = false;
2022-12-11 23:40:16 +01:00
constructor(
2023-06-23 15:53:55 +02:00
private _http: HttpClient,
2023-01-06 11:10:58 +01:00
) { }
2022-12-11 23:40:16 +01:00
2023-06-25 17:03:17 +02:00
@HostListener('document:scroll', ['$event'])
public async onScroll(event: any) {
if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight - 1 && !this.loadingInProgress) {
this.loadingInProgress = true;
let data: Layer[] = await Layer.getList(this._http, this.start, this.limit);
this.dataSource.data = this.dataSource.data.concat(data);
this.start = this.end;
this.end = this.limit + this.start;
setTimeout(() => {
this.loadingInProgress = false;
}, 500);
}
}
2022-12-11 23:40:16 +01:00
async ngOnInit() {
2023-06-25 17:03:17 +02:00
this.dataSource = new MatTableDataSource(await Layer.getList(this._http, this.start, this.limit));
2022-12-11 23:40:16 +01:00
this.dataSource.sort = this.sort;
2022-12-27 22:22:21 +01:00
this.dataSource.sort.sort({ id: 'number', start: 'desc' } as MatSortable);
2023-06-25 17:03:17 +02:00
this.start = this.end;
this.end = this.limit + this.start;
2022-12-11 23:40:16 +01:00
}
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
}
2023-01-06 11:10:58 +01:00
trackByUid(index : number, item : Layer) {
2022-12-11 23:40:16 +01:00
return item.id;
}
}
2023-06-25 17:03:17 +02:00