refs #901 Refactor create-task to select all clients

oggui/calendar
Alvaro Puente Mella 2024-10-07 15:21:15 +02:00
parent 05f7dd603d
commit 6385f4b267
2 changed files with 61 additions and 41 deletions

View File

@ -88,6 +88,9 @@
<mat-form-field appearance="fill" class="full-width">
<mat-label>Selecciona Clientes</mat-label>
<mat-select formControlName="selectedClients" multiple>
<mat-option (click)="toggleSelectAll()" [selected]="areAllSelected()">
Seleccionar todos
</mat-option>
<mat-option *ngFor="let client of selectedClients" [value]="client.uuid">
{{ client.name }} ({{ client.ip }})
</mat-option>
@ -99,6 +102,7 @@
<button mat-raised-button color="primary" (click)="saveTask()">Guardar</button>
</div>
</mat-step>
</mat-horizontal-stepper>
</mat-dialog-content>
</form>

View File

@ -20,6 +20,7 @@ export class CreateTaskComponent implements OnInit {
availableOrganizationalUnits: any[] = [];
selectedUnitChildren: any[] = [];
selectedClients: any[] = [];
selectedClientIds: Set<string> = new Set();
constructor(
private fb: FormBuilder,
@ -124,6 +125,7 @@ export class CreateTaskComponent implements OnInit {
(data) => {
this.selectedClients = data.clients;
this.taskForm.patchValue({ selectedClients: [] });
this.selectedClientIds.clear();
},
(error) => {
this.toastr.error('Error al cargar los detalles del aula seleccionada');
@ -131,6 +133,20 @@ export class CreateTaskComponent implements OnInit {
);
}
toggleSelectAll() {
const allSelected = this.areAllSelected();
if (allSelected) {
this.selectedClientIds.clear();
} else {
this.selectedClients.forEach(client => this.selectedClientIds.add(client.uuid));
}
this.taskForm.get('selectedClients')!.setValue(Array.from(this.selectedClientIds));
}
areAllSelected(): boolean {
return this.selectedClients.length > 0 && this.selectedClients.every(client => this.selectedClientIds.has(client.uuid));
}
saveTask(): void {
if (this.taskForm.invalid) {
this.toastr.error('Por favor, rellene todos los campos obligatorios');
@ -147,7 +163,7 @@ export class CreateTaskComponent implements OnInit {
commandGroups: formData.commandGroup ? [`/command-groups/${formData.commandGroup}`] : null,
dateTime: dateTime,
notes: formData.notes || '',
clients: this.selectedClients.map((client: any) => client['@id']),
clients: Array.from(this.selectedClientIds).map((uuid: string) => `/clients/${uuid}`),
};
if (selectedCommands) {