refs #1065 Bug fix on edit software profiles
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
parent
0d403d8b8e
commit
7a0e13b829
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
<mat-dialog-content class="form-container">
|
<mat-dialog-content class="form-container">
|
||||||
<mat-tab-group>
|
<mat-tab-group>
|
||||||
<!-- Primer tab: formulario de comandos -->
|
|
||||||
<mat-tab label="Formulario">
|
<mat-tab label="Formulario">
|
||||||
<form [formGroup]="formGroup" (ngSubmit)="onSubmit()" class="form-group">
|
<form [formGroup]="formGroup" (ngSubmit)="onSubmit()" class="form-group">
|
||||||
<mat-form-field appearance="fill" class="full-width" >
|
<mat-form-field appearance="fill" class="full-width" >
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
import {Component, Inject} from '@angular/core';
|
import { Component, Inject, OnInit } from '@angular/core';
|
||||||
import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
|
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
import {HttpClient} from "@angular/common/http";
|
import { HttpClient } from '@angular/common/http';
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import {ToastrService} from "ngx-toastr";
|
import { ToastrService } from 'ngx-toastr';
|
||||||
import {DataService as SoftwareService} from "../../software/data.service";
|
import { DataService as SoftwareService } from '../../software/data.service';
|
||||||
import {DataService} from "../data.service";
|
import { DataService } from '../data.service';
|
||||||
import {Observable, startWith} from "rxjs";
|
import { Observable, startWith } from 'rxjs';
|
||||||
import { debounceTime, switchMap, map } from 'rxjs/operators';
|
import { debounceTime, switchMap, map } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-create-software-profile',
|
selector: 'app-create-software-profile',
|
||||||
templateUrl: './create-software-profile.component.html',
|
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;
|
baseUrl: string = import.meta.env.NG_APP_BASE_API_URL;
|
||||||
formGroup: FormGroup<any>;
|
formGroup: FormGroup;
|
||||||
private apiUrl = `${this.baseUrl}/software-profiles`;
|
private apiUrl = `${this.baseUrl}/software-profiles`;
|
||||||
softwareCollection: any[] = [];
|
softwareCollection: any[] = [];
|
||||||
organizationalUnits: any[] = [];
|
organizationalUnits: any[] = [];
|
||||||
|
@ -45,11 +45,13 @@ export class CreateSoftwareProfileComponent {
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
this.load()
|
this.softwareProfileId = this.data['@id'];
|
||||||
|
this.patchFormData();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loadSoftware();
|
this.loadSoftware();
|
||||||
this.loadOrganizationalUnits()
|
this.loadOrganizationalUnits();
|
||||||
this.loadOperativeSystems()
|
this.loadOperativeSystems();
|
||||||
|
|
||||||
this.filteredSoftware = this.softwareControl.valueChanges.pipe(
|
this.filteredSoftware = this.softwareControl.valueChanges.pipe(
|
||||||
startWith(''),
|
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() {
|
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 => {
|
response => {
|
||||||
this.softwareCollection = response['hydra:member'];
|
this.softwareCollection = response['hydra:member'];
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.error('Error fetching parent units:', error);
|
console.error('Error fetching software:', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOrganizationalUnits() {
|
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 => {
|
response => {
|
||||||
this.organizationalUnits = response['hydra:member'];
|
this.organizationalUnits = response['hydra:member'];
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.error('Error fetching parent units:', error);
|
console.error('Error fetching organizational units:', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOperativeSystems() {
|
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 => {
|
response => {
|
||||||
this.operativeSystems = response['hydra:member'];
|
this.operativeSystems = response['hydra:member'];
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.error('Error fetching parent units:', error);
|
console.error('Error fetching operative systems:', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _filterSoftware(value: string): Observable<any[]> {
|
private _filterSoftware(value: string): Observable<any[]> {
|
||||||
|
return this.softwareDataService.getSoftwareCollection({ name: value }).pipe(
|
||||||
return this.softwareDataService.getSoftwareCollection({ 'name': value}).pipe(
|
|
||||||
map(response => response || [])
|
map(response => response || [])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -109,23 +119,6 @@ export class CreateSoftwareProfileComponent {
|
||||||
this.softwareControl.setValue('');
|
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() {
|
addSoftware() {
|
||||||
const software = this.softwareCollection.find(s => s.id === this.selectedSoftware);
|
const software = this.softwareCollection.find(s => s.id === this.selectedSoftware);
|
||||||
if (software && !this.selectedSoftwares.includes(software)) {
|
if (software && !this.selectedSoftwares.includes(software)) {
|
||||||
|
@ -144,7 +137,6 @@ export class CreateSoftwareProfileComponent {
|
||||||
|
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
if (this.formGroup.valid) {
|
if (this.formGroup.valid) {
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
description: this.formGroup.value.description,
|
description: this.formGroup.value.description,
|
||||||
comments: this.formGroup.value.comments,
|
comments: this.formGroup.value.comments,
|
||||||
|
@ -155,24 +147,24 @@ export class CreateSoftwareProfileComponent {
|
||||||
|
|
||||||
if (this.softwareProfileId) {
|
if (this.softwareProfileId) {
|
||||||
this.http.put(`${this.baseUrl}${this.softwareProfileId}`, payload).subscribe(
|
this.http.put(`${this.baseUrl}${this.softwareProfileId}`, payload).subscribe(
|
||||||
(response) => {
|
() => {
|
||||||
this.toastService.success('Software editado correctamente');
|
this.toastService.success('Software editado correctamente');
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toastService.error(error['error']['hydra:description']);
|
this.toastService.error(error.error['hydra:description']);
|
||||||
console.error('Error al editar el comando', error);
|
console.error('Error al editar el software', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.http.post(`${this.baseUrl}/software-profiles`, payload).subscribe(
|
this.http.post(`${this.apiUrl}`, payload).subscribe(
|
||||||
(response) => {
|
() => {
|
||||||
this.toastService.success('Software añadido correctamente');
|
this.toastService.success('Software añadido correctamente');
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toastService.error(error['error']['hydra:description']);
|
this.toastService.error(error.error['hydra:description']);
|
||||||
console.error('Error al añadir comando', error);
|
console.error('Error al añadir software', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import {MatDialog} from "@angular/material/dialog";
|
||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import {DataService} from "../software/data.service";
|
import {DataService} from "../software/data.service";
|
||||||
import {ToastrService} from "ngx-toastr";
|
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 {DeleteModalComponent} from "../../shared/delete_modal/delete-modal/delete-modal.component";
|
||||||
import {PageEvent} from "@angular/material/paginator";
|
import {PageEvent} from "@angular/material/paginator";
|
||||||
import {CreateSoftwareProfileComponent} from "./create-software-profile/create-software-profile.component";
|
import {CreateSoftwareProfileComponent} from "./create-software-profile/create-software-profile.component";
|
||||||
|
@ -90,7 +89,7 @@ export class SoftwareProfileComponent {
|
||||||
editSoftware(softwareProfile: any): void {
|
editSoftware(softwareProfile: any): void {
|
||||||
const dialogRef = this.dialog.open(CreateSoftwareProfileComponent, {
|
const dialogRef = this.dialog.open(CreateSoftwareProfileComponent, {
|
||||||
width: '600px',
|
width: '600px',
|
||||||
data: softwareProfile['@id']
|
data: softwareProfile
|
||||||
});
|
});
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe(result => {
|
dialogRef.afterClosed().subscribe(result => {
|
||||||
|
|
Loading…
Reference in New Issue