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

84 lines
3.0 KiB
TypeScript
Raw Normal View History

2022-12-11 23:40:16 +01:00
import { HttpClient } from '@angular/common/http';
2023-08-22 19:26:08 +02:00
import { Component, HostListener, OnInit } from '@angular/core';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule } from '@angular/material/table';
2023-08-22 21:13:47 +02:00
import { Layer, LayerType } 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';
2023-06-25 19:08:26 +02:00
import { MatSelectModule } from '@angular/material/select';
import { FormsModule } from '@angular/forms';
2023-08-17 14:52:13 +02:00
import { MatChipsModule} from '@angular/material/chips';
2023-06-25 19:08:26 +02:00
import { MatIconModule } from '@angular/material/icon';
import { NgFor } from '@angular/common';
2022-12-11 23:40:16 +01:00
@Component({
2023-08-22 18:32:17 +02:00
selector: 'diunabi-layers-list',
2023-06-23 15:32:59 +02:00
templateUrl: './layers-list.component.html',
styleUrls: ['./layers-list.component.scss'],
standalone: true,
2023-06-25 19:08:26 +02:00
imports: [MatGridListModule, MatButtonModule, RouterLink, MatFormFieldModule,
MatInputModule, MatTableModule, MatSortModule, MatSelectModule, FormsModule,
MatChipsModule, MatIconModule, NgFor]
2022-12-11 23:40:16 +01:00
})
2023-01-06 11:10:58 +01:00
export class LayersListComponent implements OnInit {
2023-08-22 19:26:08 +02:00
displayedColumns = ['number', 'name', 'type'];
dataSource!: Layer[];
2023-08-22 21:13:47 +02:00
LayerType = LayerType;
2022-12-11 23:40:16 +01:00
2023-08-17 14:52:13 +02:00
start = 0;
2023-10-02 19:59:43 +02:00
limit = 200;
2023-06-25 17:03:17 +02:00
end: number = this.limit + this.start;
2023-08-17 14:52:13 +02:00
loadingInProgress = false;
2023-06-25 17:03:17 +02:00
2023-08-17 14:52:13 +02:00
type = "";
2023-06-25 19:08:26 +02:00
codes: string[] = [];
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-10-02 19:59:43 +02:00
//@HostListener('document:scroll', ['$event'])
2023-08-17 14:52:13 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2023-06-25 17:03:17 +02:00
public async onScroll(event: any) {
2023-08-22 21:37:37 +02:00
console.log('on scrool', event);
2023-06-25 17:03:17 +02:00
if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight - 1 && !this.loadingInProgress) {
this.loadingInProgress = true;
2023-08-22 19:26:08 +02:00
this.dataSource = await Layer.getList(this._http, this.start, this.limit, this.codes);
2023-06-25 17:03:17 +02:00
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-08-22 19:26:08 +02:00
this.dataSource = await Layer.getList(this._http, this.start, this.limit, this.codes);
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
}
2023-06-25 19:08:26 +02:00
async removeCode(code: string) {
const index = this.codes.indexOf(code);
if (index >= 0) {
this.start = 0;
this.end = this.limit + this.start;
this.codes.splice(index, 1);
2023-08-22 19:26:08 +02:00
this.dataSource = await Layer.getList(this._http, this.start, this.limit, this.codes);
2023-06-25 19:08:26 +02:00
}
}
2023-08-21 13:00:05 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2023-06-25 19:08:26 +02:00
async addCode(event: any) {
const value = (event.target.value || '').trim();
if (value) {
this.start = 0;
this.end = this.limit + this.start;
this.codes.push(value);
2023-08-22 19:26:08 +02:00
this.dataSource = await Layer.getList(this._http, this.start, this.limit, this.codes);
2023-06-25 19:08:26 +02:00
}
event.target.value = '';
}
2022-12-11 23:40:16 +01:00
}
2023-06-25 17:03:17 +02:00