Skip to content

Commit

Permalink
ajout des champs supplémentaires issus de la config dans le form user
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrieuclp authored and jacquesfize committed Jan 9, 2024
1 parent 00e83fa commit 7980588
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 64 deletions.
8 changes: 5 additions & 3 deletions backend/geonature/core/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/app/userModule/user.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{{form.value|json}}
{{form.disabled|json}}
<button type="button" (click)="console()">console</button>
<div class="card card-page center-in-div">
<div class="card-header">
<h3 class="underlined main-color">Mes informations</h3>
Expand Down Expand Up @@ -57,8 +54,8 @@ <h3 class="underlined main-color">Mes informations</h3>
</div>
</div>

<pnx-dynamic-form-generator [autoGenerated]="true" [myFormGroup]="form.get('champs_addi')"
[formsDefinition]="FORM_CONFIG">
<pnx-dynamic-form-generator [myFormGroup]="form.get('champs_addi')" [formsDefinition]="additionalFieldsForm"
[autoGenerated]="true">
</pnx-dynamic-form-generator>

<div class="float-right">
Expand Down
71 changes: 15 additions & 56 deletions frontend/src/app/userModule/user.component.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
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',
styleUrls: ['./user.component.scss'],
})
export class UserComponent implements OnInit, AfterViewInit {

private role: BehaviorSubject<Role> = new BehaviorSubject(null);
private roleForm: FormGroup;
private roleForm: UntypedFormGroup;

form: FormGroup;
public FORM_CONFIG = AppConfig.ACCOUNT_MANAGEMENT.ACCOUNT_FORM;
form: UntypedFormGroup;
additionalFieldsForm: Array<any>;

constructor(
private authService: AuthService,
private fb: FormBuilder,
// private roleFormService: RoleFormService,
// private userService: UserDataService,
private fb: UntypedFormBuilder,
private userService: UserDataService,
private dataService: DataFormService
) { }

Expand All @@ -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],
Expand All @@ -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() {
Expand Down

0 comments on commit 7980588

Please sign in to comment.