74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import {Component, Inject, OnInit} from '@angular/core';
|
|
import {ToastrService} from "ngx-toastr";
|
|
import {HttpClient} from "@angular/common/http";
|
|
import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from "@angular/material/dialog";
|
|
import {MatTableDataSource} from "@angular/material/table";
|
|
import {Subnet} from "../og-dhcp-subnets.component";
|
|
import {Client} from "../../groups/model/model";
|
|
|
|
@Component({
|
|
selector: 'app-show-clients',
|
|
templateUrl: './show-clients.component.html',
|
|
styleUrl: './show-clients.component.css'
|
|
})
|
|
export class ShowClientsComponent implements OnInit {
|
|
baseUrl: string = import.meta.env.NG_APP_BASE_API_URL;
|
|
dataSource = new MatTableDataSource<Client>([]);
|
|
length = 0;
|
|
itemsPerPage: number = 10;
|
|
pageSizeOptions: number[] = [5, 10, 20];
|
|
page = 0;
|
|
loading: boolean = false;
|
|
filters: { [key: string]: string } = {};
|
|
|
|
columns = [
|
|
{ columnDef: 'id', header: 'ID', cell: (client: Client) => client.id },
|
|
{ columnDef: 'status', header: 'Estado', cell: (client: Client) => client.status },
|
|
{ columnDef: 'name', header: 'Name', cell: (client: Client) => client.name },
|
|
{ columnDef: 'ip', header: 'Ip', cell: (client: Client) => client.ip },
|
|
{ columnDef: 'mac', header: 'Mac', cell: (client: Client) => client.mac },
|
|
{ columnDef: 'ogLive', header: 'OgLive', cell: (client: Client) => client.ogLive?.date },
|
|
];
|
|
|
|
displayedColumns: string[] = ['id', 'status', 'name', 'ip', 'mac', 'ogLive'];
|
|
|
|
constructor(
|
|
private toastService: ToastrService,
|
|
private http: HttpClient,
|
|
public dialogRef: MatDialogRef<ShowClientsComponent>,
|
|
public dialog: MatDialog,
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
) { }
|
|
|
|
ngOnInit(): void {
|
|
if (this.data) {
|
|
this.loadData();
|
|
}
|
|
}
|
|
|
|
loadData() {
|
|
this.loading = true;
|
|
this.http.get<any>(`${this.baseUrl}/clients?page=${this.page + 1}&itemsPerPage=${this.itemsPerPage}&subnet.id=${this.data.subnetId}`, { params: this.filters }).subscribe(
|
|
(data) => {
|
|
this.dataSource.data = data['hydra:member'];
|
|
this.length = data['hydra:totalItems'];
|
|
this.loading = false;
|
|
},
|
|
(error) => {
|
|
this.loading = false;
|
|
}
|
|
);
|
|
console.log(this.dataSource.data)
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
|
|
onPageChange(event: any) {
|
|
this.page = event.pageIndex;
|
|
this.itemsPerPage = event.pageSize;
|
|
this.loadData()
|
|
}
|
|
}
|