65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
// src/app/classroom-view/classroom-view.component.ts
|
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
import {
|
|
ChangePasswordModalComponent
|
|
} from "../../pages/admin/users/users/change-password-modal/change-password-modal.component";
|
|
import {MatDialog} from "@angular/material/dialog";
|
|
import {CreateClientComponent} from "../clients/create-client/create-client.component";
|
|
import {ClientViewComponent} from "../client-view/client-view.component";
|
|
|
|
interface GroupedClients {
|
|
organizationalUnitName: string;
|
|
clientRows: any[][];
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-classroom-view',
|
|
templateUrl: './classroom-view.component.html',
|
|
styleUrls: ['./classroom-view.component.css']
|
|
})
|
|
export class ClassroomViewComponent implements OnInit {
|
|
@Input() clients: any[] = [];
|
|
@Input() pcInTable: number = 5;
|
|
groupedClients: GroupedClients[] = [];
|
|
|
|
constructor(public dialog: MatDialog) {}
|
|
|
|
ngOnInit(): void {
|
|
this.groupClientsByOrganizationalUnit();
|
|
}
|
|
|
|
ngOnChanges(): void {
|
|
this.groupClientsByOrganizationalUnit();
|
|
}
|
|
|
|
groupClientsByOrganizationalUnit(): void {
|
|
const grouped = this.clients.reduce((acc, client) => {
|
|
const ouName = client.organizationalUnit.name;
|
|
if (!acc[ouName]) {
|
|
acc[ouName] = [];
|
|
}
|
|
acc[ouName].push(client);
|
|
return acc;
|
|
}, {});
|
|
|
|
console.log(grouped)
|
|
this.groupedClients = Object.keys(grouped).map(ouName => ({
|
|
organizationalUnitName: ouName,
|
|
clientRows: this.chunkArray(grouped[ouName], this.pcInTable)
|
|
}));
|
|
}
|
|
|
|
chunkArray(arr: any[], chunkSize: number): any[][] {
|
|
const chunks = [];
|
|
for (let i = 0; i < arr.length; i += chunkSize) {
|
|
chunks.push(arr.slice(i, i + chunkSize));
|
|
}
|
|
return chunks;
|
|
}
|
|
|
|
handleClientClick(client: any): void {
|
|
const dialogRef = this.dialog.open(ClientViewComponent, { data: { client }, width: '800px', height:'700px'});
|
|
}
|
|
}
|