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