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

80 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-12-11 23:40:16 +01:00
import { HttpClient } from '@angular/common/http';
2023-10-20 13:56:40 +02:00
import { Component, OnInit } from '@angular/core';
2023-08-22 19:26:08 +02:00
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';
2023-11-07 00:19:21 +01:00
import { Router, RouterLink } from '@angular/router';
2023-06-23 15:32:59 +02:00
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';
2023-10-20 13:56:40 +02:00
import { KeyValuePipe, NgFor } from '@angular/common';
import { ScrollEndDirective } from 'src/app/directives/scroll-end.directive';
import { Subject, debounceTime, distinctUntilChanged } from 'rxjs';
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,
2023-10-20 13:56:40 +02:00
MatChipsModule, MatIconModule, NgFor, ScrollEndDirective, KeyValuePipe]
2022-12-11 23:40:16 +01:00
})
2023-01-06 11:10:58 +01:00
export class LayersListComponent implements OnInit {
2023-11-07 00:19:21 +01:00
displayedColumns = ['number', 'name', 'type', 'opt'];
2023-08-22 19:26:08 +02:00
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-20 09:28:42 +02:00
limit = 50;
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-10-20 13:56:40 +02:00
type: LayerType | '' = '';
name: string = '';
nameUpdate = new Subject<string>();
2023-06-25 19:08:26 +02:00
2022-12-11 23:40:16 +01:00
constructor(
2023-06-23 15:53:55 +02:00
private _http: HttpClient,
2023-11-07 00:19:21 +01:00
private _router: Router
2023-01-06 11:10:58 +01:00
) { }
2022-12-11 23:40:16 +01:00
async ngOnInit() {
2023-10-20 13:56:40 +02:00
this.nameUpdate.pipe(
debounceTime(400),
distinctUntilChanged())
.subscribe(() => {
this.loadList();
});
await this.loadList();
2022-12-11 23:40:16 +01:00
}
2023-10-20 13:56:40 +02:00
async loadList() {
this.start = 0;
this.end = this.limit;
this.dataSource = await Layer.getList(this._http, this.start, this.limit, this.name, this.type);
2023-06-25 19:08:26 +02:00
}
2023-10-20 13:56:40 +02:00
async loadMore() {
this.start = this.end;
this.end += this.limit;
this.dataSource = this.dataSource.concat(
await Layer.getList(this._http, this.start, this.limit, this.name, this.type)
);
2023-06-25 19:08:26 +02:00
}
2023-11-07 00:19:21 +01:00
openInNewTab(element: Layer) {
console.log(element);
const url = this._router.serializeUrl(
this._router.createUrlTree([`/app/layers/Detail/${element.id}`])
);
window.open(url, '_blank');
}
2022-12-11 23:40:16 +01:00
}
2023-06-25 17:03:17 +02:00