Fix update app component and backend.

This commit is contained in:
2021-08-08 00:09:31 +02:00
parent 84d66ec45a
commit e2d9983e21
7 changed files with 51 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
<div class="title">
<h1>Edit the application {{application?.name}}</h1>
<button class="icon danger">
<button class="icon danger" matTooltip="Remove the application">
<mat-icon>delete</mat-icon>
</button>
</div>

View File

@@ -0,0 +1,18 @@
.title {
position: relative;
display: flex;
align-items: center;
&:hover {
button {
opacity: 1;
}
}
button {
position: absolute;
right: 5px;
opacity: 0;
transition: opacity .2s ease;
}
}

View File

@@ -4,6 +4,7 @@ import { Application } from 'src/app/core/entities/Application';
import { ReferentialData } from 'src/app/core/entities/ReferentialData';
import { ApplicationService } from 'src/app/core/services/application.service';
import { ModalService } from 'src/app/core/services/modal.service';
import { ReferentialDataService } from 'src/app/core/services/referential-data.service';
@Component({
selector: 'app-update-application',
@@ -23,10 +24,15 @@ export class UpdateApplicationComponent implements OnInit {
constructor(
private _formBuilder: FormBuilder,
private _modalService: ModalService,
private _applicationService: ApplicationService
private _applicationService: ApplicationService,
private _referentialDataService: ReferentialDataService
) {}
ngOnInit(): void {
this._referentialDataService.getServiceTypes()
.then(serviceTypes => this.serviceTypes = serviceTypes)
.catch(error => console.error('An error occured while loading service types.'));
this.application = this._modalService.data;
this.form.controls.name.setValue(this.application?.name);
this.form.controls.serviceName.setValue(this.application?.serviceName);
@@ -41,13 +47,18 @@ export class UpdateApplicationComponent implements OnInit {
onSubmit(): void {
if (this.form.valid) {
const appToAdd: Application = this.form.value as Application;
this._applicationService.add(appToAdd)
.then(applicationAdded => {
console.log('Application added.');
const appToUpdate = { ...this.application } as Application;
appToUpdate.name = this.form.controls.name.value;
appToUpdate.serviceName = this.form.controls.serviceName.value;
// appToUpdate.serviceType = this.form.controls.serviceType.value;
appToUpdate.image = this.form.controls.image.value;
this._applicationService.update(appToUpdate)
.then(() => {
console.log('Application uodated.');
this._modalService.close();
})
.catch(error => console.error('An error occured while adding the new application.'));
.catch(error => console.error('An error occured while updating the application.'));
} else {
console.error('Form is invalid');
}

View File

@@ -1,4 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Application } from '../entities/Application';
import { ApplicationStatus } from '../entities/ApplicationStatus';
@@ -17,6 +17,14 @@ export class ApplicationService {
}
add(application: Application): Promise<Application> {
const headers = new HttpHeaders()
.append('Content-Type', 'application/json');
return this._httpClient.post<Application>('/api/applications', application).toPromise();
}
update(application: Application): Promise<void> {
const headers = new HttpHeaders()
.append('Content-Type', 'application/json');
return this._httpClient.put<void>(`/api/applications/${application.id}`, application, { headers }).toPromise();
}
}

View File

@@ -1,5 +1,9 @@
@import "../colors.scss";
a.button {
text-decoration: none;
}
button, a.button {
background-image: linear-gradient(
$btn-primary-background-top,