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