Fix update app component and backend.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<div class="title">
|
<div class="title">
|
||||||
<h1>Edit the application {{application?.name}}</h1>
|
<h1>Edit the application {{application?.name}}</h1>
|
||||||
<button class="icon danger">
|
<button class="icon danger" matTooltip="Remove the application">
|
||||||
<mat-icon>delete</mat-icon>
|
<mat-icon>delete</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import { Application } from 'src/app/core/entities/Application';
|
|||||||
import { ReferentialData } from 'src/app/core/entities/ReferentialData';
|
import { ReferentialData } from 'src/app/core/entities/ReferentialData';
|
||||||
import { ApplicationService } from 'src/app/core/services/application.service';
|
import { ApplicationService } from 'src/app/core/services/application.service';
|
||||||
import { ModalService } from 'src/app/core/services/modal.service';
|
import { ModalService } from 'src/app/core/services/modal.service';
|
||||||
|
import { ReferentialDataService } from 'src/app/core/services/referential-data.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-update-application',
|
selector: 'app-update-application',
|
||||||
@@ -23,10 +24,15 @@ export class UpdateApplicationComponent implements OnInit {
|
|||||||
constructor(
|
constructor(
|
||||||
private _formBuilder: FormBuilder,
|
private _formBuilder: FormBuilder,
|
||||||
private _modalService: ModalService,
|
private _modalService: ModalService,
|
||||||
private _applicationService: ApplicationService
|
private _applicationService: ApplicationService,
|
||||||
|
private _referentialDataService: ReferentialDataService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
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.application = this._modalService.data;
|
||||||
this.form.controls.name.setValue(this.application?.name);
|
this.form.controls.name.setValue(this.application?.name);
|
||||||
this.form.controls.serviceName.setValue(this.application?.serviceName);
|
this.form.controls.serviceName.setValue(this.application?.serviceName);
|
||||||
@@ -41,13 +47,18 @@ export class UpdateApplicationComponent implements OnInit {
|
|||||||
|
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
if (this.form.valid) {
|
if (this.form.valid) {
|
||||||
const appToAdd: Application = this.form.value as Application;
|
const appToUpdate = { ...this.application } as Application;
|
||||||
this._applicationService.add(appToAdd)
|
appToUpdate.name = this.form.controls.name.value;
|
||||||
.then(applicationAdded => {
|
appToUpdate.serviceName = this.form.controls.serviceName.value;
|
||||||
console.log('Application added.');
|
// 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();
|
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 {
|
} else {
|
||||||
console.error('Form is invalid');
|
console.error('Form is invalid');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Application } from '../entities/Application';
|
import { Application } from '../entities/Application';
|
||||||
import { ApplicationStatus } from '../entities/ApplicationStatus';
|
import { ApplicationStatus } from '../entities/ApplicationStatus';
|
||||||
@@ -17,6 +17,14 @@ export class ApplicationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add(application: Application): Promise<Application> {
|
add(application: Application): Promise<Application> {
|
||||||
|
const headers = new HttpHeaders()
|
||||||
|
.append('Content-Type', 'application/json');
|
||||||
return this._httpClient.post<Application>('/api/applications', application).toPromise();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
@import "../colors.scss";
|
@import "../colors.scss";
|
||||||
|
|
||||||
|
a.button {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
button, a.button {
|
button, a.button {
|
||||||
background-image: linear-gradient(
|
background-image: linear-gradient(
|
||||||
$btn-primary-background-top,
|
$btn-primary-background-top,
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public class ApplicationController {
|
|||||||
.withName(application.getName())
|
.withName(application.getName())
|
||||||
.withServiceName(application.getServiceName())
|
.withServiceName(application.getServiceName())
|
||||||
.withServiceType(application.getServiceType())
|
.withServiceType(application.getServiceType())
|
||||||
|
.withImage(application.getImage())
|
||||||
.build();
|
.build();
|
||||||
service.update(applicationToUpdate);
|
service.update(applicationToUpdate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class ApplicationService {
|
|||||||
.withName(application.getName())
|
.withName(application.getName())
|
||||||
.withServiceName(application.getServiceName())
|
.withServiceName(application.getServiceName())
|
||||||
.withServiceType(application.getServiceType())
|
.withServiceType(application.getServiceType())
|
||||||
|
.withImage(application.getImage())
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.ifPresentOrElse(this::validateThenSave, NotFoundException::new);
|
.ifPresentOrElse(this::validateThenSave, NotFoundException::new);
|
||||||
|
|||||||
Reference in New Issue
Block a user