refs #1065 Bug fix on edit software profiles
testing/ogGui-multibranch/pipeline/head There was a failure building this commit Details

oggui/translations
Alvaro Puente Mella 2024-11-07 12:16:37 +01:00
parent 0d403d8b8e
commit 7a0e13b829
3 changed files with 40 additions and 50 deletions

View File

@ -2,7 +2,6 @@
<mat-dialog-content class="form-container">
<mat-tab-group>
<!-- Primer tab: formulario de comandos -->
<mat-tab label="Formulario">
<form [formGroup]="formGroup" (ngSubmit)="onSubmit()" class="form-group">
<mat-form-field appearance="fill" class="full-width" >

View File

@ -1,21 +1,21 @@
import {Component, Inject} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
import {HttpClient} from "@angular/common/http";
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {ToastrService} from "ngx-toastr";
import {DataService as SoftwareService} from "../../software/data.service";
import {DataService} from "../data.service";
import {Observable, startWith} from "rxjs";
import { Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ToastrService } from 'ngx-toastr';
import { DataService as SoftwareService } from '../../software/data.service';
import { DataService } from '../data.service';
import { Observable, startWith } from 'rxjs';
import { debounceTime, switchMap, map } from 'rxjs/operators';
@Component({
selector: 'app-create-software-profile',
templateUrl: './create-software-profile.component.html',
styleUrl: './create-software-profile.component.css'
styleUrls: ['./create-software-profile.component.css']
})
export class CreateSoftwareProfileComponent {
export class CreateSoftwareProfileComponent implements OnInit {
baseUrl: string = import.meta.env.NG_APP_BASE_API_URL;
formGroup: FormGroup<any>;
formGroup: FormGroup;
private apiUrl = `${this.baseUrl}/software-profiles`;
softwareCollection: any[] = [];
organizationalUnits: any[] = [];
@ -45,11 +45,13 @@ export class CreateSoftwareProfileComponent {
ngOnInit(): void {
if (this.data) {
this.load()
this.softwareProfileId = this.data['@id'];
this.patchFormData();
}
this.loadSoftware();
this.loadOrganizationalUnits()
this.loadOperativeSystems()
this.loadOrganizationalUnits();
this.loadOperativeSystems();
this.filteredSoftware = this.softwareControl.valueChanges.pipe(
startWith(''),
@ -58,42 +60,50 @@ export class CreateSoftwareProfileComponent {
);
}
patchFormData(): void {
this.formGroup.patchValue({
description: this.data.description || '',
comments: this.data.comments || '',
organizationalUnit: this.data.organizationalUnit ? this.data.organizationalUnit['@id'] : null,
operativeSystem: this.data.operativeSystem ? this.data.operativeSystem['@id'] : null,
});
}
loadSoftware() {
this.http.get<any>( `${this.baseUrl}/software?&page=1&itemsPerPage=10`).subscribe(
this.http.get<any>(`${this.baseUrl}/software?page=1&itemsPerPage=10`).subscribe(
response => {
this.softwareCollection = response['hydra:member'];
},
error => {
console.error('Error fetching parent units:', error);
console.error('Error fetching software:', error);
}
);
}
loadOrganizationalUnits() {
this.http.get<any>( `${this.baseUrl}/organizational-units?&page=1&itemsPerPage=10000`).subscribe(
this.http.get<any>(`${this.baseUrl}/organizational-units?page=1&itemsPerPage=10000`).subscribe(
response => {
this.organizationalUnits = response['hydra:member'];
},
error => {
console.error('Error fetching parent units:', error);
console.error('Error fetching organizational units:', error);
}
);
}
loadOperativeSystems() {
this.http.get<any>( `${this.baseUrl}/operative-systems?&page=1&itemsPerPage=10000`).subscribe(
this.http.get<any>(`${this.baseUrl}/operative-systems?page=1&itemsPerPage=10000`).subscribe(
response => {
this.operativeSystems = response['hydra:member'];
},
error => {
console.error('Error fetching parent units:', error);
console.error('Error fetching operative systems:', error);
}
);
}
private _filterSoftware(value: string): Observable<any[]> {
return this.softwareDataService.getSoftwareCollection({ 'name': value}).pipe(
return this.softwareDataService.getSoftwareCollection({ name: value }).pipe(
map(response => response || [])
);
}
@ -109,23 +119,6 @@ export class CreateSoftwareProfileComponent {
this.softwareControl.setValue('');
}
load(): void {
this.dataService.getSoftwareProfile(this.data).subscribe({
next: (response) => {
this.formGroup = this.fb.group({
description: [response.description],
comments: [response.comments],
organizationalUnit: [response.organizationalUnit ? response.organizationalUnit['@id'] : null],
operativeSystem: [response.operativeSystem ? response.operativeSystem['@id'] : null],
});
this.softwareProfileId = response['@id'];
},
error: (err) => {
console.error('Error fetching software:', err);
}
});
}
addSoftware() {
const software = this.softwareCollection.find(s => s.id === this.selectedSoftware);
if (software && !this.selectedSoftwares.includes(software)) {
@ -144,7 +137,6 @@ export class CreateSoftwareProfileComponent {
onSubmit(): void {
if (this.formGroup.valid) {
const payload = {
description: this.formGroup.value.description,
comments: this.formGroup.value.comments,
@ -155,24 +147,24 @@ export class CreateSoftwareProfileComponent {
if (this.softwareProfileId) {
this.http.put(`${this.baseUrl}${this.softwareProfileId}`, payload).subscribe(
(response) => {
() => {
this.toastService.success('Software editado correctamente');
this.dialogRef.close();
},
(error) => {
this.toastService.error(error['error']['hydra:description']);
console.error('Error al editar el comando', error);
this.toastService.error(error.error['hydra:description']);
console.error('Error al editar el software', error);
}
);
} else {
this.http.post(`${this.baseUrl}/software-profiles`, payload).subscribe(
(response) => {
this.http.post(`${this.apiUrl}`, payload).subscribe(
() => {
this.toastService.success('Software añadido correctamente');
this.dialogRef.close();
},
(error) => {
this.toastService.error(error['error']['hydra:description']);
console.error('Error al añadir comando', error);
this.toastService.error(error.error['hydra:description']);
console.error('Error al añadir software', error);
}
);
}

View File

@ -5,7 +5,6 @@ import {MatDialog} from "@angular/material/dialog";
import {HttpClient} from "@angular/common/http";
import {DataService} from "../software/data.service";
import {ToastrService} from "ngx-toastr";
import {CreateSoftwareComponent} from "../software/create-software/create-software.component";
import {DeleteModalComponent} from "../../shared/delete_modal/delete-modal/delete-modal.component";
import {PageEvent} from "@angular/material/paginator";
import {CreateSoftwareProfileComponent} from "./create-software-profile/create-software-profile.component";
@ -90,7 +89,7 @@ export class SoftwareProfileComponent {
editSoftware(softwareProfile: any): void {
const dialogRef = this.dialog.open(CreateSoftwareProfileComponent, {
width: '600px',
data: softwareProfile['@id']
data: softwareProfile
});
dialogRef.afterClosed().subscribe(result => {