Fonctionn modifier contact ok
This commit is contained in:
parent
0390c45886
commit
a723a02a56
13 changed files with 80 additions and 32 deletions
|
@ -20,6 +20,7 @@ import { PageUpdateMemberComponent } from './pages/page-update-member/page-updat
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', redirectTo: 'accueil', pathMatch: 'full' },
|
{ path: '', redirectTo: 'accueil', pathMatch: 'full' },
|
||||||
|
{ path: 'modifier-contact/:id', component: PageModifierContactComponent },
|
||||||
{ path: 'compte', component: PageAccountComponent },
|
{ path: 'compte', component: PageAccountComponent },
|
||||||
{ path: 'accueil', component: PageAccueilComponent },
|
{ path: 'accueil', component: PageAccueilComponent },
|
||||||
{ path: 'ajout-membre', component: PageAddMemberComponent },
|
{ path: 'ajout-membre', component: PageAddMemberComponent },
|
||||||
|
@ -35,7 +36,6 @@ const routes: Routes = [
|
||||||
{ path: 'modifier-membre', component: PageUpdateMemberComponent },
|
{ path: 'modifier-membre', component: PageUpdateMemberComponent },
|
||||||
{ path: 'ajouter-contact', component: PageAjoutContactComponent },
|
{ path: 'ajouter-contact', component: PageAjoutContactComponent },
|
||||||
{ path: 'creation-team', component: PageCreationTeamComponent },
|
{ path: 'creation-team', component: PageCreationTeamComponent },
|
||||||
{ path: 'modifier-contact', component: PageModifierContactComponent },
|
|
||||||
{ path: '**', component: PageNotFoundComponent },
|
{ path: '**', component: PageNotFoundComponent },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<button routerLink="../modifier-contact" class="w-100 btn btn-lg btn-rounded btn-secondary">
|
<button routerLink="../modifier-contact/{{personne.id}}" class="w-100 btn btn-lg btn-rounded btn-secondary">
|
||||||
Modifier
|
Modifier
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
export interface Contact {
|
export interface Contact {
|
||||||
|
id: string;
|
||||||
nom: string;
|
nom: string;
|
||||||
prenom: string;
|
prenom: string;
|
||||||
telephone: string;
|
telephone: string;
|
||||||
email: string;
|
email: string;
|
||||||
adresse: string;
|
adresse: string;
|
||||||
dateNaissance: Date;
|
dateNaissance: Date;
|
||||||
|
team: any;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
<label for="floatingInputfirstName">Adresse</label>
|
<label for="floatingInputfirstName">Adresse</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="w-100 btn btn-lg btn-success"
|
<button class="w-100 btn btn-lg btn-secondary"
|
||||||
type="submit"
|
type="submit"
|
||||||
[disabled]="ajoutContactForm.invalid">Valider</button>
|
[disabled]="ajoutContactForm.invalid">Valider</button>
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,8 @@
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
border-bottom-left-radius: 0;
|
border-bottom-left-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
color: #fff;
|
||||||
|
background-color: #5a1e63 !important;
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class PageAjoutContactComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// *********************************pensser a changer group car déprécié********************************
|
// *********************************pensser à changer group car déprécié********************************
|
||||||
this.ajoutContactForm = this.fb.group({
|
this.ajoutContactForm = this.fb.group({
|
||||||
lastNameFc: new FormControl('', [Validators.required]),
|
lastNameFc: new FormControl('', [Validators.required]),
|
||||||
firstNameFc: new FormControl('', [Validators.required]),
|
firstNameFc: new FormControl('', [Validators.required]),
|
||||||
|
@ -52,12 +52,14 @@ export class PageAjoutContactComponent implements OnInit {
|
||||||
const adresseValue = this.ajoutContactForm.value['adresseFc'];
|
const adresseValue = this.ajoutContactForm.value['adresseFc'];
|
||||||
|
|
||||||
const contact: Contact = {
|
const contact: Contact = {
|
||||||
|
id: '',
|
||||||
nom: lastNameValue,
|
nom: lastNameValue,
|
||||||
prenom: firstNameValue,
|
prenom: firstNameValue,
|
||||||
telephone: telephoneValue,
|
telephone: telephoneValue,
|
||||||
email: emailValue,
|
email: emailValue,
|
||||||
dateNaissance: dateNaissanceValue,
|
dateNaissance: dateNaissanceValue,
|
||||||
adresse: adresseValue,
|
adresse: adresseValue,
|
||||||
|
team: { id: '1' }, // changer l'id quand la personne est logé => recuperer l'id de la team du membre
|
||||||
};
|
};
|
||||||
|
|
||||||
if (contact.nom !== '') {
|
if (contact.nom !== '') {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
<app-side-bar></app-side-bar>
|
<app-side-bar></app-side-bar>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modifContact-form text-center">
|
<div class="modifContact-form text-center">
|
||||||
<main class="form-modifContact">
|
<main class="form-modifContact">
|
||||||
<form (ngSubmit)="onSubmit()" [formGroup]="modifContactForm">
|
<form (ngSubmit)="onSubmit()" [formGroup]="modifContactForm">
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
id="floatingInputlastName"
|
id="floatingInputlastName"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="lastName"
|
name="lastName"
|
||||||
formControlName="lastNameFc">
|
formControlName="lastNameFc" value= "{{ listContactInfo.nom }}">
|
||||||
<label for="floatingInputlastName">Nom</label>
|
<label for="floatingInputlastName">Nom</label>
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
id="floatingInputfirstName"
|
id="floatingInputfirstName"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="firstName"
|
name="firstName"
|
||||||
formControlName="firstNameFc">
|
formControlName="firstNameFc" value= "{{ listContactInfo.prenom }}">
|
||||||
<label for="floatingInputfirstName">Prénom</label>
|
<label for="floatingInputfirstName">Prénom</label>
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@
|
||||||
id="floatingInputTelephone"
|
id="floatingInputTelephone"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="telephone"
|
name="telephone"
|
||||||
formControlName="telephoneFc">
|
formControlName="telephoneFc" value= "{{ listContactInfo.telephone }}">
|
||||||
<label for="floatingInputfirstName">Téléphone</label>
|
<label for="floatingInputfirstName">Téléphone</label>
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
id="floatingInput"
|
id="floatingInput"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="email"
|
name="email"
|
||||||
formControlName="emailFc">
|
formControlName="emailFc" value= "{{ listContactInfo.email }}">
|
||||||
<label for="floatingInput">Adresse email</label>
|
<label for="floatingInput">Adresse email</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@
|
||||||
id="floatingInputdateNaissance"
|
id="floatingInputdateNaissance"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="dateNaissance"
|
name="dateNaissance"
|
||||||
formControlName="dateNaissanceFc">
|
formControlName="dateNaissanceFc" value= "{{ listContactInfo.dateNaissance }}">
|
||||||
<label for="floatingInputfirstName">Date de naissance</label>
|
<label for="floatingInputfirstName">Date de naissance</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -69,11 +70,11 @@
|
||||||
id="floatingInputAdresse"
|
id="floatingInputAdresse"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
name="adresse"
|
name="adresse"
|
||||||
formControlName="adresseFc">
|
formControlName="adresseFc" value= "{{ listContactInfo.adresse }}">
|
||||||
<label for="floatingInputfirstName">Adresse</label>
|
<label for="floatingInputfirstName">Adresse</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="w-100 btn btn-lg btn-success"
|
<button class="w-100 btn btn-lg btn-secondary"
|
||||||
type="submit"
|
type="submit"
|
||||||
[disabled]="modifContactForm.invalid">Valider</button>
|
[disabled]="modifContactForm.invalid">Valider</button>
|
||||||
|
|
||||||
|
|
|
@ -24,3 +24,8 @@
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
border-bottom-left-radius: 0;
|
border-bottom-left-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
color: #fff;
|
||||||
|
background-color: #5a1e63 !important;
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
Validators,
|
Validators,
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import { Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { Contact } from '../../models/contact';
|
import { Contact } from '../../models/contact';
|
||||||
import { RepertoireService } from '../../services/repertoire.service';
|
import { RepertoireService } from '../../services/repertoire.service';
|
||||||
|
|
||||||
|
@ -17,22 +17,32 @@ import { RepertoireService } from '../../services/repertoire.service';
|
||||||
export class PageModifierContactComponent implements OnInit {
|
export class PageModifierContactComponent implements OnInit {
|
||||||
public modifContactForm: FormGroup;
|
public modifContactForm: FormGroup;
|
||||||
public contactInfo: FormGroup;
|
public contactInfo: FormGroup;
|
||||||
|
public listContactInfo: any;
|
||||||
|
public personneid: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private repertoireService: RepertoireService,
|
private repertoireService: RepertoireService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private fb: FormBuilder
|
private fb: FormBuilder,
|
||||||
|
private route: ActivatedRoute
|
||||||
) {
|
) {
|
||||||
this.modifContactForm = new FormGroup({});
|
this.modifContactForm = new FormGroup({});
|
||||||
this.contactInfo = this.initForm();
|
this.contactInfo = this.initForm();
|
||||||
|
this.listContactInfo = '';
|
||||||
// this.repertoireService.getContactById()?.subscribe((contact: Contact) => {
|
|
||||||
// this.contactInfo = this.initForm(contact);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// *********************************pensser a changer group car déprécié********************************
|
this.personneid = this.route.snapshot.paramMap.get('id'); // récupère l'id du contact à modifier
|
||||||
|
console.log(this.personneid);
|
||||||
|
|
||||||
|
this.repertoireService
|
||||||
|
.getContactById(this.personneid)
|
||||||
|
.subscribe((listContactInfo: any) => {
|
||||||
|
console.log(listContactInfo);
|
||||||
|
this.listContactInfo = listContactInfo;
|
||||||
|
});
|
||||||
|
|
||||||
|
// *********************************pensser à changer group car déprécié********************************
|
||||||
this.modifContactForm = this.fb.group({
|
this.modifContactForm = this.fb.group({
|
||||||
lastNameFc: new FormControl('', [Validators.required]),
|
lastNameFc: new FormControl('', [Validators.required]),
|
||||||
firstNameFc: new FormControl('', [Validators.required]),
|
firstNameFc: new FormControl('', [Validators.required]),
|
||||||
|
@ -47,6 +57,7 @@ export class PageModifierContactComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Méthode qui initialise les champs du formulaire avec les infos de la BDD
|
||||||
private initForm(contact?: Contact): FormGroup {
|
private initForm(contact?: Contact): FormGroup {
|
||||||
return this.fb.group({
|
return this.fb.group({
|
||||||
firstName: [contact ? contact.nom : ''],
|
firstName: [contact ? contact.nom : ''],
|
||||||
|
@ -58,6 +69,7 @@ export class PageModifierContactComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Méthode qui envoie les champs modifiés pour mise à jour
|
||||||
public onSubmit(): void {
|
public onSubmit(): void {
|
||||||
console.log('value : ', this.modifContactForm.value);
|
console.log('value : ', this.modifContactForm.value);
|
||||||
console.log('form : ', this.modifContactForm);
|
console.log('form : ', this.modifContactForm);
|
||||||
|
@ -69,20 +81,18 @@ export class PageModifierContactComponent implements OnInit {
|
||||||
const adresseValue = this.modifContactForm.value['adresseFc'];
|
const adresseValue = this.modifContactForm.value['adresseFc'];
|
||||||
|
|
||||||
const contact: Contact = {
|
const contact: Contact = {
|
||||||
|
id: this.personneid,
|
||||||
nom: lastNameValue,
|
nom: lastNameValue,
|
||||||
prenom: firstNameValue,
|
prenom: firstNameValue,
|
||||||
telephone: telephoneValue,
|
telephone: telephoneValue,
|
||||||
email: emailValue,
|
email: emailValue,
|
||||||
dateNaissance: dateNaissanceValue,
|
dateNaissance: dateNaissanceValue,
|
||||||
adresse: adresseValue,
|
adresse: adresseValue,
|
||||||
|
team: { id: this.listContactInfo.team.id },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (contact.nom !== '') {
|
|
||||||
this.repertoireService.updateContact(contact).subscribe((resp) => {
|
this.repertoireService.updateContact(contact).subscribe((resp) => {
|
||||||
this.router.navigate(['repertoire/']);
|
this.router.navigate(['repertoire/']);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// affichage erreur
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { Contact } from 'src/app/models/contact';
|
||||||
import { RepertoireService } from 'src/app/services/repertoire.service';
|
import { RepertoireService } from 'src/app/services/repertoire.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -9,12 +11,19 @@ import { RepertoireService } from 'src/app/services/repertoire.service';
|
||||||
export class PageRepertoireComponent implements OnInit {
|
export class PageRepertoireComponent implements OnInit {
|
||||||
public listContact: any[];
|
public listContact: any[];
|
||||||
public listFull: any[];
|
public listFull: any[];
|
||||||
|
public listContactInfo: any;
|
||||||
|
public personneid: any;
|
||||||
keyword: any;
|
keyword: any;
|
||||||
openDetails: any;
|
openDetails: any;
|
||||||
|
|
||||||
constructor(private repertoireService: RepertoireService) {
|
constructor(
|
||||||
|
private repertoireService: RepertoireService,
|
||||||
|
private router: Router,
|
||||||
|
private route: ActivatedRoute
|
||||||
|
) {
|
||||||
this.listContact = [];
|
this.listContact = [];
|
||||||
this.listFull = [];
|
this.listFull = [];
|
||||||
|
this.listContactInfo = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
@ -23,6 +32,16 @@ export class PageRepertoireComponent implements OnInit {
|
||||||
this.listContact = listContact;
|
this.listContact = listContact;
|
||||||
this.listFull = listContact;
|
this.listFull = listContact;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.personneid = this.route.snapshot.paramMap.get('id');
|
||||||
|
console.log(this.personneid);
|
||||||
|
|
||||||
|
this.repertoireService
|
||||||
|
.getContactById(this.personneid)
|
||||||
|
.subscribe((listContactInfo: any) => {
|
||||||
|
console.log(listContactInfo);
|
||||||
|
this.listContactInfo = listContactInfo;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Méthode pour récuper ce qui est saisi dans l'input
|
// Méthode pour récuper ce qui est saisi dans l'input
|
||||||
|
@ -47,4 +66,8 @@ export class PageRepertoireComponent implements OnInit {
|
||||||
console.log(personne);
|
console.log(personne);
|
||||||
this.openDetails = personne;
|
this.openDetails = personne;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this.repertoireService.deleteContact(contact).subscribe((resp) => {
|
||||||
|
// this.router.navigate(['repertoire/']);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ export class RepertoireService {
|
||||||
return this.http.get(`${this.apiUrl}/contacts/team/1`);
|
return this.http.get(`${this.apiUrl}/contacts/team/1`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getContactById(contact: Contact): Observable<any> {
|
getContactById(id: any): Observable<any> {
|
||||||
return this.http.get(`${this.apiUrl}/contacts/{id}`);
|
return this.http.get(`${this.apiUrl}/contacts/` + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
addContact(contact: Contact): Observable<any> {
|
addContact(contact: Contact): Observable<any> {
|
||||||
|
@ -31,8 +31,8 @@ export class RepertoireService {
|
||||||
return this.http.post(`${this.apiUrl}/contacts/add`, contact);
|
return this.http.post(`${this.apiUrl}/contacts/add`, contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteContact() {
|
deleteContact(contact: Contact): Observable<any> {
|
||||||
return this.http.delete(`${this.apiUrl}/contacts/delete`);
|
return this.http.delete(`${this.apiUrl}/contacts/delete/1`);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateContact(contact: Contact): Observable<any> {
|
updateContact(contact: Contact): Observable<any> {
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
Loading…
Add table
Reference in a new issue