oggui/ogWebconsole/src/app/components/groups/shared/change-parent/change-parent.component.ts

64 lines
1.8 KiB
TypeScript

import {Component, Inject, OnInit} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {ToastrService} from "ngx-toastr";
import {Router} from "@angular/router";
import {ConfigService} from "@services/config.service";
@Component({
selector: 'app-change-parent',
templateUrl: './change-parent.component.html',
styleUrl: './change-parent.component.css'
})
export class ChangeParentComponent implements OnInit {
baseUrl: string;
loading: boolean = true;
units: any[] = [];
newOU: any;
constructor(
private http: HttpClient,
public dialogRef: MatDialogRef<ChangeParentComponent>,
private toastService: ToastrService,
private router: Router,
private configService: ConfigService,
@Inject(MAT_DIALOG_DATA) public data: { clients: any}
) {
this.baseUrl = this.configService.apiUrl;
}
ngOnInit(): void {
this.loading = true;
this.loadUnits();
}
loadUnits() {
this.http.get<any>(`${this.baseUrl}/organizational-units?page=1&itemsPerPage=500`).subscribe(
response => {
this.units = response['hydra:member'];
this.loading = false;
},
error => console.error('Error fetching organizational units:', error)
);
}
save() {
this.http.post<any>(`${this.baseUrl}/clients/change-organizational-unit`, {
clients: this.data.clients.map((client: any) => client['@id']),
organizationalUnit: this.newOU['@id']
}).subscribe({
next: (response) => {
this.toastService.success('Parent changed successfully');
this.dialogRef.close(true);
},
error: error => {
this.toastService.error(error.error['hydra:description']);
}
})
}
close() {
this.dialogRef.close();
}
}