71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Component } from '@angular/core';
|
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
|
import { MatDialogRef } from '@angular/material/dialog';
|
|
import { CreateClientComponent } from '../create-client/create-client.component';
|
|
|
|
@Component({
|
|
selector: 'app-edit-client',
|
|
templateUrl: './edit-client.component.html',
|
|
styleUrl: './edit-client.component.css'
|
|
})
|
|
export class EditClientComponent {
|
|
clientForm!: FormGroup;
|
|
parentUnits: any[] = []; // Array to store parent units fetched from API
|
|
|
|
constructor(
|
|
private fb: FormBuilder,
|
|
private dialogRef: MatDialogRef<CreateClientComponent>,
|
|
private http: HttpClient
|
|
) { }
|
|
|
|
ngOnInit(): void {
|
|
this.loadParentUnits(); // Load parent units when component initializes
|
|
this.clientForm = this.fb.group({
|
|
organizationalUnit: [''],
|
|
name: ['', Validators.required],
|
|
serialNumber: [''],
|
|
netiface: "eth0",
|
|
netDriver: "e1000e",
|
|
mac: "00:11:22:33:44:55",
|
|
ip: "127.0.0.1",
|
|
status: "test",
|
|
menu: null,
|
|
hardwareProfile: null,
|
|
});
|
|
}
|
|
|
|
loadParentUnits() {
|
|
const url = 'http://127.0.0.1:8080/organizational-units?page=1&itemsPerPage=30';
|
|
|
|
this.http.get<any>(url).subscribe(
|
|
response => {
|
|
this.parentUnits = response['hydra:member'];
|
|
},
|
|
error => {
|
|
console.error('Error fetching parent units:', error);
|
|
}
|
|
);
|
|
}
|
|
|
|
onSubmit() {
|
|
console.log('Form data:', this.clientForm.value);
|
|
if (this.clientForm.valid) {
|
|
const formData = this.clientForm.value;
|
|
this.http.post('http://127.0.0.1:8080/clients', formData).subscribe(
|
|
response => {
|
|
console.log('Response from POST:', response);
|
|
this.dialogRef.close(response);
|
|
},
|
|
error => {
|
|
console.error('Error during POST:', error);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
}
|