Create client added oglive select
parent
151808fd29
commit
ad0d0cca67
|
@ -16,6 +16,14 @@
|
|||
<mat-label i18n="@@name-label">Nombre</mat-label>
|
||||
<input matInput formControlName="name">
|
||||
</mat-form-field>
|
||||
<mat-form-field class="form-field">
|
||||
<mat-label i18n="@@oglive-label">OgLive</mat-label>
|
||||
<mat-select formControlName="ogLive">
|
||||
<mat-option *ngFor="let oglive of ogLives" [value]="oglive['@id']">
|
||||
{{ oglive.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="form-field">
|
||||
<mat-label i18n="@@serial-number-label">Número de Serie</mat-label>
|
||||
<input matInput formControlName="serialNumber">
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
|
||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
import {ToastrService} from "ngx-toastr";
|
||||
import {DataService} from "../../data.service";
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { DataService } from '../../data.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-client',
|
||||
|
@ -13,18 +13,19 @@ import {DataService} from "../../data.service";
|
|||
})
|
||||
export class CreateClientComponent implements OnInit {
|
||||
clientForm!: FormGroup;
|
||||
parentUnits: any[] = []; // Array to store parent units fetched from API
|
||||
hardwareProfiles: any[] = []; // Array to store hardware profiles fetched from API
|
||||
parentUnits: any[] = [];
|
||||
hardwareProfiles: any[] = [];
|
||||
ogLives: any[] = []; // Array para almacenar los oglives
|
||||
private errorForm: boolean = false;
|
||||
protected netifaceTypes = [
|
||||
{"name": 'Eth0', "value": "eth0"},
|
||||
{"name": 'Eth1', "value": "eth1"},
|
||||
{"name": 'Eth2', "value": "eth2"},
|
||||
{ "name": 'Eth0', "value": "eth0" },
|
||||
{ "name": 'Eth1', "value": "eth1" },
|
||||
{ "name": 'Eth2', "value": "eth2" },
|
||||
];
|
||||
protected netDriverTypes = [
|
||||
{"name": 'Generic', "value": "generic"},
|
||||
{ "name": 'Generic', "value": "generic" },
|
||||
];
|
||||
loading:boolean = false
|
||||
loading: boolean = false;
|
||||
|
||||
constructor(
|
||||
private fb: FormBuilder,
|
||||
|
@ -33,14 +34,14 @@ export class CreateClientComponent implements OnInit {
|
|||
private snackBar: MatSnackBar,
|
||||
private toastService: ToastrService,
|
||||
private dataService: DataService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any // Inject data for edit mode
|
||||
) {
|
||||
}
|
||||
@Inject(MAT_DIALOG_DATA) public data: any
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
console.log(this.data);
|
||||
this.loadParentUnits(); // Load parent units when component initializes
|
||||
this.loadParentUnits();
|
||||
this.loadHardwareProfiles();
|
||||
this.loadOgLives(); // Cargar los oglives
|
||||
this.clientForm = this.fb.group({
|
||||
organizationalUnit: [this.data.organizationalUnit ? this.data.organizationalUnit['@id'] : null, Validators.required],
|
||||
name: ['', Validators.required],
|
||||
|
@ -51,6 +52,7 @@ export class CreateClientComponent implements OnInit {
|
|||
ip: ['', Validators.required],
|
||||
menu: [this.data.organizationalUnit && this.data.organizationalUnit.networkSettings && this.data.organizationalUnit.networkSettings.menu ? this.data.organizationalUnit.networkSettings.menu['@id'] : null],
|
||||
hardwareProfile: [this.data.organizationalUnit && this.data.organizationalUnit.networkSettings && this.data.organizationalUnit.networkSettings.hardwareProfile ? this.data.organizationalUnit.networkSettings.hardwareProfile['@id'] : null],
|
||||
ogLive: [null, Validators.required] // Nuevo campo para ogLive
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -58,35 +60,50 @@ export class CreateClientComponent implements OnInit {
|
|||
this.dataService.getHardwareProfiles().subscribe(
|
||||
(data: any[]) => {
|
||||
this.hardwareProfiles = data;
|
||||
this.loading = false
|
||||
this.loading = false;
|
||||
},
|
||||
(error: any) => {
|
||||
console.error('Error fetching hardware profiles', error);
|
||||
this.loading = false
|
||||
this.loading = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
loadParentUnits() {
|
||||
this.loading = true
|
||||
this.loading = true;
|
||||
const url = 'http://127.0.0.1:8080/organizational-units?page=1&itemsPerPage=10000';
|
||||
|
||||
this.http.get<any>(url).subscribe(
|
||||
response => {
|
||||
this.parentUnits = response['hydra:member'];
|
||||
this.loading = false
|
||||
this.loading = false;
|
||||
},
|
||||
error => {
|
||||
console.error('Error fetching parent units:', error);
|
||||
this.loading = false
|
||||
this.loading = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
loadOgLives() {
|
||||
// Lógica para cargar ogLives desde la API
|
||||
const url = 'http://127.0.0.1:8080/og-lives?page=1&itemsPerPage=30';
|
||||
this.http.get<any>(url).subscribe(
|
||||
response => {
|
||||
this.ogLives = response['hydra:member'];
|
||||
},
|
||||
error => {
|
||||
console.error('Error fetching ogLives:', error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
if (this.clientForm.valid) {
|
||||
this.errorForm = false
|
||||
this.errorForm = false;
|
||||
const formData = this.clientForm.value;
|
||||
formData.ogLive = formData.ogLive; // Asegurar que se envía el UUID de ogLive
|
||||
console.log('Form data:', formData );
|
||||
this.http.post('http://127.0.0.1:8080/clients', formData).subscribe(
|
||||
response => {
|
||||
this.dialogRef.close(response);
|
||||
|
@ -94,7 +111,7 @@ export class CreateClientComponent implements OnInit {
|
|||
},
|
||||
error => {
|
||||
console.error('Error during POST:', error);
|
||||
this.errorForm = true
|
||||
this.errorForm = true;
|
||||
this.openSnackBar(true, 'Error al crear el cliente: ' + error.error['hydra:description']);
|
||||
}
|
||||
);
|
||||
|
@ -108,7 +125,8 @@ export class CreateClientComponent implements OnInit {
|
|||
openSnackBar(isError: boolean, message: string) {
|
||||
if (isError) {
|
||||
this.toastService.error(' Error al crear el cliente: ' + message, 'Error');
|
||||
} else
|
||||
} else {
|
||||
this.toastService.success(message, 'Éxito');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue