Skip to content

Commit

Permalink
modif backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrieuclp authored and jacquesfize committed Jan 9, 2024
1 parent eed9859 commit 00e83fa
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 29 deletions.
10 changes: 4 additions & 6 deletions backend/geonature/core/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,10 @@ def get_role(id_role):
:param id_role: the id user
:type id_role: int
"""
user = DB.get_or_404(User, id_role)
fields = user_fields.copy()
if g.current_user == user:
fields.add("email")
fields.add("champs_addi")
return user.as_dict(fields=fields)
user = User.query.get_or_404(id_role)
user_fields.add("email")
user_fields.add("champs_addi")
return user.as_dict(fields=user_fields)


@routes.route("/roles", methods=["GET"])
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/app/userModule/user.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{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 @@ -54,12 +57,9 @@ <h3 class="underlined main-color">Mes informations</h3>
</div>
</div>

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

<div class="float-right">
<ng-container *ngIf="form.disabled; else validation">
Expand Down
83 changes: 66 additions & 17 deletions frontend/src/app/userModule/user.component.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
import { Component, OnInit, AfterViewInit } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
import { FormGroup, FormBuilder, Validators, ValidatorFn, AbstractControl } from '@angular/forms';
import { BehaviorSubject } from 'rxjs';
import { AppConfig } from '@geonature_config/app.config';
import { AuthService } from '@geonature/components/auth/auth.service';
import { UserDataService } from './services/user-data.service';
import { AuthService, User } from '@geonature/components/auth/auth.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<Role> = 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() {
Expand All @@ -30,22 +49,48 @@ export class UserComponent implements OnInit {
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));
.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): UntypedFormGroup {
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() {
Expand All @@ -55,13 +100,17 @@ 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();
}

enableForm() {
Expand Down

0 comments on commit 00e83fa

Please sign in to comment.