refs #985 clasroom-group select fix
parent
8eef8cd8ec
commit
5bd9db1618
|
@ -63,15 +63,20 @@
|
|||
|
||||
<ng-container matColumnDef="ogLive">
|
||||
<mat-header-cell *matHeaderCellDef> Plantilla </mat-header-cell>
|
||||
<mat-cell *matCellDef="let element">
|
||||
<mat-form-field>
|
||||
<mat-select [(value)]="element.ogLive">
|
||||
<mat-option *ngFor="let option of ogLiveOptions" [value]="option['@id']">{{ option.name }}</mat-option>
|
||||
<mat-cell *matCellDef="let client">
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Seleccione una plantilla</mat-label>
|
||||
<mat-select [(ngModel)]="client.ogLive" [name]="'ogLive' + client.id">
|
||||
<mat-option [value]="null">Ninguna</mat-option>
|
||||
<mat-option *ngFor="let template of ogLiveOptions" [value]="template['@id']">
|
||||
{{ template.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
|
|
|
@ -15,22 +15,15 @@ export class PxeBootFilesComponent implements OnInit {
|
|||
availableOrganizationalUnits: any[] = [];
|
||||
selectedUnitChildren: any[] = [];
|
||||
dataSource: any[] = [];
|
||||
|
||||
taskForm: FormGroup;
|
||||
|
||||
loadingUnits: boolean = false;
|
||||
|
||||
ogLiveOptions: any[] = [];
|
||||
|
||||
globalOgLive: string | null = null;
|
||||
|
||||
length: number = 0;
|
||||
itemsPerPage: number = 10;
|
||||
page: number = 0;
|
||||
pageSizeOptions: number[] = [5, 10, 20, 40, 100];
|
||||
|
||||
filters: any = {};
|
||||
|
||||
displayedColumns: string[] = ['id', 'name', 'ogLive'];
|
||||
|
||||
constructor(
|
||||
|
@ -80,23 +73,42 @@ export class PxeBootFilesComponent implements OnInit {
|
|||
onOrganizationalUnitChange(): void {
|
||||
const selectedUnitId = this.taskForm.get('organizationalUnit')?.value;
|
||||
const selectedUnit = this.availableOrganizationalUnits.find(unit => unit['@id'] === selectedUnitId);
|
||||
if (selectedUnit && selectedUnit.children) {
|
||||
this.selectedUnitChildren = selectedUnit.children.filter((child: any) => child.type === 'classroom');
|
||||
|
||||
if (selectedUnit) {
|
||||
this.selectedUnitChildren = this.getAllClassrooms(selectedUnit);
|
||||
} else {
|
||||
this.selectedUnitChildren = [];
|
||||
}
|
||||
}
|
||||
|
||||
getAllClassrooms(unit: any): any[] {
|
||||
let classrooms: any[] = [];
|
||||
if (unit.type === 'classroom') {
|
||||
classrooms.push(unit);
|
||||
}
|
||||
if (unit.children) {
|
||||
for (const child of unit.children) {
|
||||
classrooms = classrooms.concat(this.getAllClassrooms(child));
|
||||
}
|
||||
}
|
||||
return classrooms;
|
||||
}
|
||||
|
||||
|
||||
onChildChange(): void {
|
||||
const selectedChildId = this.taskForm.get('selectedChild')?.value;
|
||||
const selectedChild = this.selectedUnitChildren.find(child => child['@id'] === selectedChildId);
|
||||
if (selectedChild && selectedChild.clients) {
|
||||
this.dataSource = selectedChild.clients;
|
||||
this.dataSource = selectedChild.clients.map((client: { template: { [x: string]: any; }; }) => ({
|
||||
...client,
|
||||
ogLive: client.template ? client.template['@id'] : null
|
||||
}));
|
||||
} else {
|
||||
this.dataSource = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
applyToAll(): void {
|
||||
this.dataSource = this.dataSource.map(client => ({
|
||||
...client,
|
||||
|
@ -124,7 +136,6 @@ export class PxeBootFilesComponent implements OnInit {
|
|||
clients: clients
|
||||
};
|
||||
|
||||
console.log('Payload:', url);
|
||||
this.http.post(url, payload).subscribe({
|
||||
next: () => {
|
||||
this.toastService.success(`Clientes guardados correctamente para la plantilla ${templateId}`);
|
||||
|
|
Loading…
Reference in New Issue