gestion des retours de l'api via les toasts partie 2, pour les éditions

pull/15/head
Clement FERRERE 2 years ago
parent cc7b99274b
commit 70fde1ce9f
  1. 12
      src/app/components/agence/agence-edit/agence-edit.component.ts
  2. 12
      src/app/components/agence/agence.component.ts
  3. 12
      src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts
  4. 20
      src/app/components/collaborateur/collaborateur-add/collaborateur-add.component.ts
  5. 19
      src/app/components/collaborateur/collaborateur-edit/collaborateur-edit.component.ts
  6. 20
      src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.ts
  7. 12
      src/app/components/periode-essai/periode-essai.component.ts

@ -65,7 +65,13 @@ export class AgenceEditComponent implements OnInit {
this.agence.name = this.registerForm.value.name this.agence.name = this.registerForm.value.name
this.agence.businessUnitId = this.registerForm.value.businessUnitId this.agence.businessUnitId = this.registerForm.value.businessUnitId
this.agenceService.updateAgence(this.agence) this.agenceService.updateAgence(this.agence)
.subscribe(()=>this.goBack()); .subscribe(() => {
this.showSuccess();
this.goBack();
},
() => {
this.showError()
});
} }
} }
@ -77,11 +83,11 @@ export class AgenceEditComponent implements OnInit {
} }
showSuccess() { showSuccess() {
this.toastr.success('Création réussie', 'Business Unit'); this.toastr.success('Modification réussie', 'Business Unit');
} }
showError() { showError() {
this.toastr.error('Création échouée', 'Business Unit'); this.toastr.error('Modification échouée', 'Business Unit');
} }
} }

@ -51,8 +51,12 @@ export class AgenceComponent implements OnInit {
add(agence: Agence): void { add(agence: Agence): void {
this.agenceService.addAgence(agence) this.agenceService.addAgence(agence)
.subscribe(agence => { .subscribe(agence => {
this.agences.push(agence); this.agences.push(agence);
}); this.showSuccess();
},
() => {
this.showError()
});
} }
onSubmit() { onSubmit() {
@ -74,11 +78,11 @@ export class AgenceComponent implements OnInit {
} }
showSuccess() { showSuccess() {
this.toastr.success('Création réussie', 'Business Unit'); this.toastr.success('Création réussie', 'Agence');
} }
showError() { showError() {
this.toastr.error('Création échouée', 'Business Unit'); this.toastr.error('Création échouée', 'Agence');
} }
} }

@ -49,7 +49,13 @@ export class BusinessunitEditComponent implements OnInit {
if (this.businessunit) { if (this.businessunit) {
this.businessunitService.updateBusinessunit(this.bu, this.id) this.businessunitService.updateBusinessunit(this.bu, this.id)
.subscribe(() => this.goBack()); .subscribe(() => {
this.showSuccess();
this.goBack();
},
() => {
this.showError()
});
} }
} }
@ -65,11 +71,11 @@ export class BusinessunitEditComponent implements OnInit {
} }
showSuccess() { showSuccess() {
this.toastr.success('Création réussie', 'Business Unit'); this.toastr.success('Modification réussie', 'Business Unit');
} }
showError() { showError() {
this.toastr.error('Création échouée', 'Business Unit'); this.toastr.error('Modification échouée', 'Business Unit');
} }
} }

@ -76,13 +76,13 @@ export class CollaborateurAddComponent implements OnInit {
} }
this.collaborateur = this.registerForm.value this.collaborateur = this.registerForm.value
if (this.collaborateur) { if (this.collaborateur) {
this.collaborateurService.addCollaborateur(this.collaborateur).subscribe({ this.collaborateurService.addCollaborateur(this.collaborateur).subscribe(collaborateur => {
next: () => { this.collaborateurs.push(collaborateur);
this.showSuccess();
}, },
error: () => { () => {
this.errorValue = 1; this.showError()
} })
})
} }
} }
@ -104,4 +104,12 @@ export class CollaborateurAddComponent implements OnInit {
this.collaborateur.birthDate = new Date($event.target.value); this.collaborateur.birthDate = new Date($event.target.value);
} }
showSuccess() {
this.toastr.success('Création réussie', 'Collaborateur');
}
showError() {
this.toastr.error('Création échouée', 'Collaborateur');
}
} }

@ -114,14 +114,13 @@ export class CollaborateurEditComponent implements OnInit {
this.collaborateur.status = this.registerForm.value.status this.collaborateur.status = this.registerForm.value.status
if (this.collaborateur) { if (this.collaborateur) {
this.collaborateurService.updateCollaborateur(this.collaborateur).subscribe({ this.collaborateurService.updateCollaborateur(this.collaborateur).subscribe(() => {
next: () => { this.showSuccess();
this.goBack(); this.goBack();
}, },
error: () => { () => {
this.errorValue = 1; this.showError()
} })
})
} }
} }
@ -141,4 +140,12 @@ export class CollaborateurEditComponent implements OnInit {
onBirthDateChange($event: any):void { onBirthDateChange($event: any):void {
this.collaborateur.birthDate = new Date($event.target.value); this.collaborateur.birthDate = new Date($event.target.value);
} }
showSuccess() {
this.toastr.success('Modification réussie', 'Collaborateur');
}
showError() {
this.toastr.error('Modification échouée', 'Collaborateur');
}
} }

@ -8,6 +8,7 @@ import {Observable} from "rxjs";
import {ActivatedRoute} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {take, tap} from "rxjs/operators"; import {take, tap} from "rxjs/operators";
import {Location} from "@angular/common"; import {Location} from "@angular/common";
import {ToastrService} from "ngx-toastr";
@Component({ @Component({
selector: 'app-periode-essai-edit', selector: 'app-periode-essai-edit',
@ -37,7 +38,8 @@ export class PeriodeEssaiEditComponent implements OnInit {
private location: Location, private location: Location,
private collaborateurService: CollaborateurService, private collaborateurService: CollaborateurService,
private periodeEssaiService: PeriodeEssaiService, private periodeEssaiService: PeriodeEssaiService,
private formBuilder: FormBuilder private formBuilder: FormBuilder,
private toastr: ToastrService
) { ) {
this.id = Number(this.route.snapshot.paramMap.get('id')) this.id = Number(this.route.snapshot.paramMap.get('id'))
} }
@ -96,7 +98,13 @@ export class PeriodeEssaiEditComponent implements OnInit {
if (this.periodeEssai){ if (this.periodeEssai){
this.periodeEssaiService.updatePeriodeEssai(this.periodeEssai) this.periodeEssaiService.updatePeriodeEssai(this.periodeEssai)
.subscribe(()=>this.goBack()); .subscribe(() => {
this.showSuccess();
this.goBack();
},
() => {
this.showError()
});
} }
} }
@ -119,6 +127,14 @@ export class PeriodeEssaiEditComponent implements OnInit {
this.periodeEssai.realEndingDate = new Date($event.target.value); this.periodeEssai.realEndingDate = new Date($event.target.value);
} }
showSuccess() {
this.toastr.success('Modification réussie', 'Période d\'essai');
}
showError() {
this.toastr.error('Modification échouée', 'Collaborateur');
}
} }

@ -5,6 +5,7 @@ import {PeriodeEssai} from "../../interfaces/periode-essai";
import {Collaborateur} from "../../interfaces/collaborateur"; import {Collaborateur} from "../../interfaces/collaborateur";
import {CollaborateurService} from "../../services/collaborateur.service"; import {CollaborateurService} from "../../services/collaborateur.service";
import {PeriodeEssaiService} from "../../services/periode-essai.service"; import {PeriodeEssaiService} from "../../services/periode-essai.service";
import {ToastrService} from "ngx-toastr";
@Component({ @Component({
selector: 'app-periode-essai', selector: 'app-periode-essai',
@ -30,7 +31,8 @@ export class PeriodeEssaiComponent implements OnInit {
private http : HttpClient, private http : HttpClient,
private collaborateurService: CollaborateurService, private collaborateurService: CollaborateurService,
private periodeEssaiService: PeriodeEssaiService, private periodeEssaiService: PeriodeEssaiService,
private formBuilder: FormBuilder private formBuilder: FormBuilder,
private toastr: ToastrService
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
@ -104,4 +106,12 @@ export class PeriodeEssaiComponent implements OnInit {
this.periodeEssaiService.getPeriodeEssais() this.periodeEssaiService.getPeriodeEssais()
.subscribe(periodeEssais => this.periodeEssais = periodeEssais); .subscribe(periodeEssais => this.periodeEssais = periodeEssais);
} }
showSuccess() {
this.toastr.success('Création réussie', 'Collaborateur');
}
showError() {
this.toastr.error('Création échouée', 'Collaborateur');
}
} }

Loading…
Cancel
Save