From 7843296bdf9fb6fde81193bf0993f7a7058e99a6 Mon Sep 17 00:00:00 2001 From: jbrieuclp Date: Wed, 22 Mar 2023 14:18:38 +0100 Subject: [PATCH] modif backend --- backend/geonature/core/users/routes.py | 2 + .../src/app/userModule/user.component.html | 11 ++- frontend/src/app/userModule/user.component.ts | 89 +++++++++++++++---- 3 files changed, 81 insertions(+), 21 deletions(-) diff --git a/backend/geonature/core/users/routes.py b/backend/geonature/core/users/routes.py index 7c16d8c03e..7029270b10 100644 --- a/backend/geonature/core/users/routes.py +++ b/backend/geonature/core/users/routes.py @@ -136,6 +136,8 @@ def get_role(id_role): :type id_role: int """ user = User.query.get_or_404(id_role) + user_fields.add('email') + user_fields.add('champs_addi') return user.as_dict(fields=user_fields) diff --git a/frontend/src/app/userModule/user.component.html b/frontend/src/app/userModule/user.component.html index 3b53ec4501..8db7769db4 100644 --- a/frontend/src/app/userModule/user.component.html +++ b/frontend/src/app/userModule/user.component.html @@ -1,3 +1,6 @@ +{{form.value|json}} +{{form.disabled|json}} +

Mes informations

@@ -78,12 +81,12 @@

Mes informations

- +
@@ -93,7 +96,7 @@

Mes informations

color="primary" matTooltip="Editer ces informations" matTooltipPosition="left" - (click)="form.enable()" + (click)="enableForm()" > Editer edit diff --git a/frontend/src/app/userModule/user.component.ts b/frontend/src/app/userModule/user.component.ts index 8b7fe6532a..049bb80cc8 100644 --- a/frontend/src/app/userModule/user.component.ts +++ b/frontend/src/app/userModule/user.component.ts @@ -1,38 +1,89 @@ -import { Component, OnInit } from '@angular/core'; -import { FormGroup } from '@angular/forms'; -import { Observable } from 'rxjs'; +import { Component, OnInit, AfterViewInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, ValidatorFn, AbstractControl } from '@angular/forms'; +import { BehaviorSubject } from 'rxjs'; import { AppConfig } from '@geonature_config/app.config'; import { AuthService, User } from '@geonature/components/auth/auth.service'; -import { Role, RoleFormService } from './services/form.service'; -import { UserDataService } from './services/user-data.service'; +// import { Role, RoleFormService } from './services/form.service'; +// import { UserDataService } from './services/user-data.service'; +import { DataFormService } from '@geonature_common/form/data-form.service'; + +export interface Role { + id_role?: string; + nom_role?: string; + prenom_role?: string; + identifiant?: string; + remarques?: string; + pass_plus?: string; + email?: string; + id_organisme?: string; + nom_complet?: string; +} @Component({ selector: 'pnx-user', templateUrl: './user.component.html', styleUrls: ['./user.component.scss'], }) -export class UserComponent implements OnInit { +export class UserComponent implements OnInit, AfterViewInit { + + private role: BehaviorSubject = new BehaviorSubject(null); + private roleForm: FormGroup; + form: FormGroup; - // dynamicFormGroup: FormGroup; - // public FORM_CONFIG = AppConfig.ACCOUNT_MANAGEMENT.ACCOUNT_FORM; + public FORM_CONFIG = AppConfig.ACCOUNT_MANAGEMENT.ACCOUNT_FORM; constructor( private authService: AuthService, - private roleFormService: RoleFormService, - private userService: UserDataService + private fb: FormBuilder, + // private roleFormService: RoleFormService, + // private userService: UserDataService, + private dataService: DataFormService ) {} ngOnInit() { this.initForm(); + + this.form.disable(); } + ngAfterViewInit() { + this.dataService.getRole(this.authService.getCurrentUser().id_role) + .subscribe((user) => { + this.form.patchValue(user) + console.log(this.form.value) + }); + + } + console() { +console.log(this.form) + this.form.disable(); + + } initForm() { - this.form = this.getForm(this.authService.getCurrentUser().id_role); - // this.dynamicFormGroup = this.fb.group({}); + // this.form = this.getForm(this.authService.getCurrentUser().id_role); + + this.form = this.fb.group({ + identifiant: ['', Validators.required], + nom_role: ['', Validators.required], + prenom_role: ['', Validators.required], + email: [ + '', + [Validators.pattern('^[a-z0-9._-]+@[a-z0-9._-]{2,}.[a-z]{2,4}$'), Validators.required], + ], + remarques: ['', null], + champs_addi: this.fb.group({}) + }); } - getForm(role: number): FormGroup { - return this.roleFormService.getForm(role); + // getForm(role: number): FormGroup { + // return this.roleFormService.getForm(role); + // } + + private getRole(role: number) { + this.dataService.getRole(role).subscribe((res) => { + this.roleForm.patchValue(res); + + }); } save() { @@ -42,12 +93,16 @@ export class UserComponent implements OnInit { // if (AppConfig.ACCOUNT_MANAGEMENT.ACCOUNT_FORM.length > 0) { // finalForm['champs_addi'] = this.dynamicFormGroup.value; // } - this.userService.putRole(this.form.value).subscribe((res) => this.form.disable()); + // this.userService.putRole(this.form.value).subscribe((res) => this.form.disable()); } } cancel() { - this.initForm(); - this.form.disable(); + // this.initForm(); + // this.form.disable(); + } + + enableForm() { + // this.form.enable(); } }