Skip to content

Commit

Permalink
modif backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrieuclp committed Mar 22, 2023
1 parent e9f1a8b commit 7843296
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 21 deletions.
2 changes: 2 additions & 0 deletions backend/geonature/core/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
11 changes: 7 additions & 4 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 @@ -78,12 +81,12 @@ <h3 class="underlined main-color">Mes informations</h3>
</div>
</div>

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

<div class="float-right">
<ng-container *ngIf="form.disabled; else validation">
Expand All @@ -93,7 +96,7 @@ <h3 class="underlined main-color">Mes informations</h3>
color="primary"
matTooltip="Editer ces informations"
matTooltipPosition="left"
(click)="form.enable()"
(click)="enableForm()"
>
Editer
<mat-icon>edit</mat-icon>
Expand Down
89 changes: 72 additions & 17 deletions frontend/src/app/userModule/user.component.ts
Original file line number Diff line number Diff line change
@@ -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<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() {
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() {
Expand All @@ -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();
}
}

0 comments on commit 7843296

Please sign in to comment.