From 7980588b4c4bc59530dccdb1396de12338bd6849 Mon Sep 17 00:00:00 2001 From: jbrieuclp Date: Tue, 3 Oct 2023 16:51:57 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20des=20champs=20suppl=C3=A9mentaires=20i?= =?UTF-8?q?ssus=20de=20la=20config=20dans=20le=20form=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/geonature/core/users/routes.py | 8 ++- .../src/app/userModule/user.component.html | 7 +- frontend/src/app/userModule/user.component.ts | 71 ++++--------------- 3 files changed, 22 insertions(+), 64 deletions(-) diff --git a/backend/geonature/core/users/routes.py b/backend/geonature/core/users/routes.py index 2456837f41..a59c2311c6 100644 --- a/backend/geonature/core/users/routes.py +++ b/backend/geonature/core/users/routes.py @@ -135,9 +135,11 @@ 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) + fields = user_fields.copy() + if g.current_user == user: + fields.add("email") + fields.add("champs_addi") + return user.as_dict(fields=fields) @routes.route("/roles", methods=["GET"]) diff --git a/frontend/src/app/userModule/user.component.html b/frontend/src/app/userModule/user.component.html index 0a1a2e132d..56ddbd7f25 100644 --- a/frontend/src/app/userModule/user.component.html +++ b/frontend/src/app/userModule/user.component.html @@ -1,6 +1,3 @@ -{{form.value|json}} -{{form.disabled|json}} -

Mes informations

@@ -57,8 +54,8 @@

Mes informations

- +
diff --git a/frontend/src/app/userModule/user.component.ts b/frontend/src/app/userModule/user.component.ts index 10a119dd12..104bf0acd8 100644 --- a/frontend/src/app/userModule/user.component.ts +++ b/frontend/src/app/userModule/user.component.ts @@ -1,24 +1,10 @@ import { Component, OnInit, AfterViewInit } from '@angular/core'; -import { FormGroup, FormBuilder, Validators, ValidatorFn, AbstractControl } from '@angular/forms'; -import { BehaviorSubject } from 'rxjs'; +import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms'; 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 { AuthService } from '@geonature/components/auth/auth.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', @@ -26,17 +12,15 @@ export interface Role { }) export class UserComponent implements OnInit, AfterViewInit { - private role: BehaviorSubject = new BehaviorSubject(null); - private roleForm: FormGroup; + private roleForm: UntypedFormGroup; - form: FormGroup; - public FORM_CONFIG = AppConfig.ACCOUNT_MANAGEMENT.ACCOUNT_FORM; + form: UntypedFormGroup; + additionalFieldsForm: Array; constructor( private authService: AuthService, - private fb: FormBuilder, - // private roleFormService: RoleFormService, - // private userService: UserDataService, + private fb: UntypedFormBuilder, + private userService: UserDataService, private dataService: DataFormService ) { } @@ -49,26 +33,16 @@ export class UserComponent implements OnInit, AfterViewInit { return form_element; }); this.initForm(); - this.form.disable(); } ngAfterViewInit() { + //patch du formulaire à partir des infos de l'utilisateur connecté this.dataService.getRole(this.authService.getCurrentUser().id_role) - .subscribe((user) => { - this.form.patchValue(user) - console.log(this.form.value) - }); - + .subscribe((user) => this.form.patchValue(user)); } - console() { - console.log(this.form) - this.form.disable(); - } initForm() { - // this.form = this.getForm(this.authService.getCurrentUser().id_role); - this.form = this.fb.group({ identifiant: ['', Validators.required], nom_role: ['', Validators.required], @@ -82,35 +56,20 @@ export class UserComponent implements OnInit, AfterViewInit { }); } - // getForm(role: number): FormGroup { - // return this.roleFormService.getForm(role); - // } - - private getRole(role: number) { - this.dataService.getRole(role).subscribe((res) => { - this.roleForm.patchValue(res); - - }); - } - save() { if (this.form.valid) { - // const finalForm = Object.assign({}, this.form.value); - // // concatenate two forms - // 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(); + this.form.enable(); } enableForm() {