Edit client added oglive select
parent
ad0d0cca67
commit
b4bf55056d
|
@ -15,7 +15,7 @@ export class CreateClientComponent implements OnInit {
|
||||||
clientForm!: FormGroup;
|
clientForm!: FormGroup;
|
||||||
parentUnits: any[] = [];
|
parentUnits: any[] = [];
|
||||||
hardwareProfiles: any[] = [];
|
hardwareProfiles: any[] = [];
|
||||||
ogLives: any[] = []; // Array para almacenar los oglives
|
ogLives: any[] = [];
|
||||||
private errorForm: boolean = false;
|
private errorForm: boolean = false;
|
||||||
protected netifaceTypes = [
|
protected netifaceTypes = [
|
||||||
{ "name": 'Eth0', "value": "eth0" },
|
{ "name": 'Eth0', "value": "eth0" },
|
||||||
|
@ -41,7 +41,7 @@ export class CreateClientComponent implements OnInit {
|
||||||
console.log(this.data);
|
console.log(this.data);
|
||||||
this.loadParentUnits();
|
this.loadParentUnits();
|
||||||
this.loadHardwareProfiles();
|
this.loadHardwareProfiles();
|
||||||
this.loadOgLives(); // Cargar los oglives
|
this.loadOgLives();
|
||||||
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],
|
||||||
|
@ -52,7 +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
|
ogLive: [null, Validators.required]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ export class CreateClientComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOgLives() {
|
loadOgLives() {
|
||||||
// Lógica para cargar ogLives desde la API
|
|
||||||
const url = 'http://127.0.0.1:8080/og-lives?page=1&itemsPerPage=30';
|
const url = 'http://127.0.0.1:8080/og-lives?page=1&itemsPerPage=30';
|
||||||
this.http.get<any>(url).subscribe(
|
this.http.get<any>(url).subscribe(
|
||||||
response => {
|
response => {
|
||||||
|
@ -102,7 +102,7 @@ export class CreateClientComponent implements OnInit {
|
||||||
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
|
formData.ogLive = formData.ogLive;
|
||||||
console.log('Form data:', formData );
|
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 => {
|
||||||
|
|
|
@ -14,6 +14,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.uuid }}
|
||||||
|
</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">
|
||||||
|
|
|
@ -3,19 +3,20 @@ import {Component, Inject} from '@angular/core';
|
||||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { CreateClientComponent } from '../create-client/create-client.component';
|
import { CreateClientComponent } from '../create-client/create-client.component';
|
||||||
import {DataService} from "../../data.service";
|
import { DataService } from '../../data.service';
|
||||||
import {ToastrService} from "ngx-toastr";
|
import { ToastrService } from 'ngx-toastr';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-edit-client',
|
selector: 'app-edit-client',
|
||||||
templateUrl: './edit-client.component.html',
|
templateUrl: './edit-client.component.html',
|
||||||
styleUrl: './edit-client.component.css'
|
styleUrls: ['./edit-client.component.css']
|
||||||
})
|
})
|
||||||
export class EditClientComponent {
|
export class EditClientComponent {
|
||||||
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[] = [];
|
||||||
isEditMode: boolean; // Flag to check if it's edit mode
|
ogLives: any[] = [];
|
||||||
|
isEditMode: boolean;
|
||||||
protected netifaceTypes = [
|
protected netifaceTypes = [
|
||||||
{ "name": 'Eth0', "value": "eth0" },
|
{ "name": 'Eth0', "value": "eth0" },
|
||||||
{ "name": 'Eth1', "value": "eth1" },
|
{ "name": 'Eth1', "value": "eth1" },
|
||||||
|
@ -24,7 +25,7 @@ export class EditClientComponent {
|
||||||
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,
|
||||||
|
@ -32,17 +33,18 @@ export class EditClientComponent {
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
private dataService: DataService,
|
private dataService: DataService,
|
||||||
private toastService: ToastrService,
|
private toastService: ToastrService,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any // Inject data for edit mode
|
@Inject(MAT_DIALOG_DATA) public data: any
|
||||||
) {
|
) {
|
||||||
this.isEditMode = !!data?.uuid; // Check if uuid is passed to determine edit mode
|
this.isEditMode = !!data?.uuid;
|
||||||
if (this.isEditMode) {
|
if (this.isEditMode) {
|
||||||
this.loadData(data.uuid);
|
this.loadData(data.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.loadParentUnits(); // Load parent units when component initializes
|
this.loadParentUnits();
|
||||||
this.loadHardwareProfiles(); // Load hardware profiles when component initializes
|
this.loadHardwareProfiles();
|
||||||
|
this.loadOgLives();
|
||||||
this.clientForm = this.fb.group({
|
this.clientForm = this.fb.group({
|
||||||
organizationalUnit: [null, Validators.required],
|
organizationalUnit: [null, Validators.required],
|
||||||
name: ['', Validators.required],
|
name: ['', Validators.required],
|
||||||
|
@ -53,6 +55,7 @@ export class EditClientComponent {
|
||||||
ip: null,
|
ip: null,
|
||||||
menu: null,
|
menu: null,
|
||||||
hardwareProfile: null,
|
hardwareProfile: null,
|
||||||
|
ogLive: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +83,21 @@ export class EditClientComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadOgLives(): void {
|
||||||
|
const url = 'http://127.0.0.1:8080/og-lives?page=1&itemsPerPage=10000';
|
||||||
|
|
||||||
|
this.http.get<any>(url).subscribe(
|
||||||
|
response => {
|
||||||
|
this.ogLives = response['hydra:member'];
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.error('Error fetching ogLives:', error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
loadData(uuid: string) {
|
loadData(uuid: string) {
|
||||||
this.loading = true
|
this.loading = true;
|
||||||
const url = `http://127.0.0.1:8080/clients/${uuid}`;
|
const url = `http://127.0.0.1:8080/clients/${uuid}`;
|
||||||
|
|
||||||
this.http.get<any>(url).subscribe(
|
this.http.get<any>(url).subscribe(
|
||||||
|
@ -94,9 +110,14 @@ export class EditClientComponent {
|
||||||
netDriver: data.netDriver,
|
netDriver: data.netDriver,
|
||||||
serialNumber: data.serialNumber,
|
serialNumber: data.serialNumber,
|
||||||
hardwareProfile: data.hardwareProfile ? data.hardwareProfile['@id'] : null,
|
hardwareProfile: data.hardwareProfile ? data.hardwareProfile['@id'] : null,
|
||||||
organizationalUnit: data.organizationalUnit ? data.organizationalUnit['@id'] : null
|
organizationalUnit: data.organizationalUnit ? data.organizationalUnit['@id'] : null,
|
||||||
|
ogLive: data.ogLive ? data.ogLive['@id'] : null,
|
||||||
});
|
});
|
||||||
this.loading = false
|
this.loading = false;
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.error('Error al cargar datos del cliente:', error);
|
||||||
|
this.loading = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue