From 4f70fe212482c5d0557a9db4ac088bac2a24b949 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Tue, 5 Jan 2021 11:35:24 +0100 Subject: [PATCH 01/21] fix(claimStructure) : add logic to show claim button --- src/app/services/structure.service.ts | 3 ++ .../structure-details.component.html | 5 ++- .../structure-details.component.ts | 43 ++++++++++++------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index f881eb0a6..9c7857106 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -23,6 +23,9 @@ export class StructureService { return this.http.post('/api/structures/' + id, structure).pipe(map((item: Structure) => new Structure(item))); } + public isClaimed(id: number): Observable<any> { + return this.http.get('/api/structures/isClaimed/' + id); + } public getStructure(id: number): Observable<Structure> { return this.http.get('/api/structures/' + id).pipe(map((item: any) => new Structure(item))); } diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index 77524b636..6f78bd201 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -4,8 +4,11 @@ (closeEvent)="updateStructure($event)" (clickOutside)="displayForm()" ></app-structureForm> -<div class="structrue-details-container" *ngIf="structure"> +<div class="structrue-details-container" *ngIf="structure && !isLoading"> <!-- Header info --> + <div fxLayout="row" fxLayoutAlign="center center" *ngIf="!isClaimed"> + <button>Revendiquer</button> + </div> <div fxLayout="row" fxLayoutAlign="end center"> <div (click)="close()" class="ico-close-details"></div> </div> diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index db1de038c..a7760778f 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -9,6 +9,7 @@ import { ActivatedRoute } from '@angular/router'; import { PrintService } from '../../../shared/service/print.service'; import { Equipment } from '../../enum/equipment.enum'; import { typeStructureEnum } from '../../../shared/enum/typeStructure.enum'; +import { StructureService } from '../../../services/structure.service'; @Component({ selector: 'app-structure-details', templateUrl: './structure-details.component.html', @@ -27,8 +28,15 @@ export class StructureDetailsComponent implements OnInit { public printMode = false; public isOtherSection = false; public showForm = false; + public isClaimed: boolean = null; + public isLoading: boolean = false; - constructor(route: ActivatedRoute, private printService: PrintService, private searchService: SearchService) { + constructor( + route: ActivatedRoute, + private printService: PrintService, + private searchService: SearchService, + private structureService: StructureService + ) { route.url.subscribe((url) => { if (url[0].path === 'structure') { this.structure = this.printService.structure; @@ -38,24 +46,29 @@ export class StructureDetailsComponent implements OnInit { } ngOnInit(): void { - this.searchService.getCategoriesTraining().subscribe((referentiels) => { - referentiels.forEach((referentiel) => { - if (referentiel.isBaseSkills()) { - this.baseSkillssReferentiel = referentiel; - } else if (referentiel.isRigthtsAccess()) { - this.accessRightsReferentiel = referentiel; + this.isLoading = true; + this.structureService.isClaimed(this.structure.id).subscribe((boolean) => { + this.isClaimed = boolean; + this.searchService.getCategoriesTraining().subscribe((referentiels) => { + referentiels.forEach((referentiel) => { + if (referentiel.isBaseSkills()) { + this.baseSkillssReferentiel = referentiel; + } else if (referentiel.isRigthtsAccess()) { + this.accessRightsReferentiel = referentiel; + } + }); + this.setServiceCategories(); + if (this.printMode) { + this.printService.onDataReady(); } + this.isLoading = false; }); - this.setServiceCategories(); - if (this.printMode) { - this.printService.onDataReady(); + const index = this.structure.proceduresAccompaniment.indexOf('autres'); + if (index > -1) { + this.structure.proceduresAccompaniment.splice(index, 1); + this.isOtherSection = true; } }); - const index = this.structure.proceduresAccompaniment.indexOf('autres'); - if (index > -1) { - this.structure.proceduresAccompaniment.splice(index, 1); - this.isOtherSection = true; - } } public getLabelTypeStructure(typeStructure: string[]): string { -- GitLab From 385b2c31fbe91c3ead3590da27304dcc4f897433 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Wed, 6 Jan 2021 14:27:42 +0100 Subject: [PATCH 02/21] feat(claimStructure) : create an register account component to put form inside --- .../create-account-form.component.html | 0 .../create-account-form.component.scss | 0 .../create-account-form.component.spec.ts | 24 +++++++++++++++++++ .../create-account-form.component.ts | 12 ++++++++++ src/app/shared/components/index.ts | 3 +++ 5 files changed, 39 insertions(+) create mode 100644 src/app/shared/components/create-account-form/create-account-form.component.html create mode 100644 src/app/shared/components/create-account-form/create-account-form.component.scss create mode 100644 src/app/shared/components/create-account-form/create-account-form.component.spec.ts create mode 100644 src/app/shared/components/create-account-form/create-account-form.component.ts diff --git a/src/app/shared/components/create-account-form/create-account-form.component.html b/src/app/shared/components/create-account-form/create-account-form.component.html new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/shared/components/create-account-form/create-account-form.component.scss b/src/app/shared/components/create-account-form/create-account-form.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/shared/components/create-account-form/create-account-form.component.spec.ts b/src/app/shared/components/create-account-form/create-account-form.component.spec.ts new file mode 100644 index 000000000..66d5e6023 --- /dev/null +++ b/src/app/shared/components/create-account-form/create-account-form.component.spec.ts @@ -0,0 +1,24 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateAccountFormComponent } from './create-account-form.component'; + +describe('ModalComponent', () => { + let component: CreateAccountFormComponent; + let fixture: ComponentFixture<CreateAccountFormComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [CreateAccountFormComponent], + }).compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateAccountFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/components/create-account-form/create-account-form.component.ts b/src/app/shared/components/create-account-form/create-account-form.component.ts new file mode 100644 index 000000000..f4cb4cea8 --- /dev/null +++ b/src/app/shared/components/create-account-form/create-account-form.component.ts @@ -0,0 +1,12 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-create-account-form', + templateUrl: './create-account-form.component.html', + styleUrls: ['./create-account-form.component.scss'], +}) +export class CreateAccountFormComponent implements OnInit { + constructor() {} + + ngOnInit(): void {} +} diff --git a/src/app/shared/components/index.ts b/src/app/shared/components/index.ts index 7eb5744bb..89b310d72 100644 --- a/src/app/shared/components/index.ts +++ b/src/app/shared/components/index.ts @@ -5,6 +5,7 @@ import { SignUpModalComponent } from './signup-modal/signup-modal.component'; import { SignInModalComponent } from './signin-modal/signin-modal.component'; import { SvgIconComponent } from './svg-icon/svg-icon.component'; import { ValidatorFormComponent } from './validator-form/validator-form.component'; +import { CreateAccountFormComponent } from './create-account-form/create-account-form.component'; // tslint:disable-next-line: max-line-length export { @@ -15,6 +16,7 @@ export { ValidatorFormComponent, SignUpModalComponent, SignInModalComponent, + CreateAccountFormComponent, }; // tslint:disable-next-line:variable-name @@ -26,4 +28,5 @@ export const SharedComponents = [ ValidatorFormComponent, SignUpModalComponent, SignInModalComponent, + CreateAccountFormComponent, ]; -- GitLab From b20376b6687f00873363db8239bff5782400631a Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Wed, 6 Jan 2021 16:16:43 +0100 Subject: [PATCH 03/21] feat(claimStructure) : fix account form --- .../create-account-form.component.html | 29 ++++++++++ .../create-account-form.component.ts | 33 ++++++++++- .../signin-modal/signin-modal.component.html | 57 +------------------ .../signin-modal/signin-modal.component.ts | 31 ++-------- .../validator-form.component.ts | 17 +++++- 5 files changed, 82 insertions(+), 85 deletions(-) diff --git a/src/app/shared/components/create-account-form/create-account-form.component.html b/src/app/shared/components/create-account-form/create-account-form.component.html index e69de29bb..d92f345c2 100644 --- a/src/app/shared/components/create-account-form/create-account-form.component.html +++ b/src/app/shared/components/create-account-form/create-account-form.component.html @@ -0,0 +1,29 @@ +<form [formGroup]="accountForm" *ngIf="accountForm" (ngSubmit)="onSubmit(accountForm)"> + <div class="form-group"> + <label for="email">Email</label> + <input type="email" autocomplete="on" formControlName="email" class="form-control" /> + <app-validator-form *ngIf="submitted" [control]="getAccountControl('email')"></app-validator-form> + </div> + <div class="form-group"> + <label for="password">Mot de passe</label> + <input type="password" autocomplete="on" formControlName="password" class="form-control" /> + <app-validator-form + *ngIf="submitted" + [nameControl]="'password'" + [control]="getAccountControl('password')" + ></app-validator-form> + </div> + <div class="form-group"> + <label for="confirmPassword">Confirmation du mot de passe</label> + <input type="password" autocomplete="on" formControlName="confirmPassword" class="form-control" /> + <app-validator-form + *ngIf="submitted" + [nameControl]="'password'" + [control]="getAccountControl('confirmPassword')" + ></app-validator-form> + </div> + + <div class="form-group"> + <button class="btn btn-primary" type="submit">{{ buttonName }}</button> + </div> +</form> diff --git a/src/app/shared/components/create-account-form/create-account-form.component.ts b/src/app/shared/components/create-account-form/create-account-form.component.ts index f4cb4cea8..8a793868d 100644 --- a/src/app/shared/components/create-account-form/create-account-form.component.ts +++ b/src/app/shared/components/create-account-form/create-account-form.component.ts @@ -1,4 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms'; +import { MustMatch } from '../../validator/form'; @Component({ selector: 'app-create-account-form', @@ -7,6 +9,33 @@ import { Component, OnInit } from '@angular/core'; }) export class CreateAccountFormComponent implements OnInit { constructor() {} + public accountForm: FormGroup; + public submitted: boolean = false; + @Input() public buttonName; + @Output() public submitForm = new EventEmitter<FormGroup>(); - ngOnInit(): void {} + ngOnInit(): void { + this.accountForm = new FormGroup( + { + email: new FormControl('', Validators.required), + password: new FormControl('', [ + Validators.required, + Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/), + ]), + confirmPassword: new FormControl(''), + }, + [MustMatch('password', 'confirmPassword')] + ); + } + + public onSubmit(accountForm: FormGroup) { + this.submitted = true; + if (accountForm.valid) { + this.submitForm.emit(accountForm); + } + } + + public getAccountControl(nameControl: string): AbstractControl { + return this.accountForm.get(nameControl); + } } diff --git a/src/app/shared/components/signin-modal/signin-modal.component.html b/src/app/shared/components/signin-modal/signin-modal.component.html index 4d0b4c3de..fec631fc0 100644 --- a/src/app/shared/components/signin-modal/signin-modal.component.html +++ b/src/app/shared/components/signin-modal/signin-modal.component.html @@ -5,62 +5,9 @@ </div> <h4>Inscription</h4> <div *ngIf="!success"> - <form [formGroup]="form" (ngSubmit)="onSubmit()"> - <div class="form-group"> - <label for="email">Email</label> - <input - type="email" - autocomplete="on" - formControlName="email" - class="form-control" - [ngClass]="{ 'is-invalid': submitted && f.email.errors }" - /> - <div *ngIf="submitted && f.email.errors" class="invalid-feedback"> - <div *ngIf="f.email.errors.required">Email is required</div> - </div> - </div> - <div class="form-group"> - <label for="password">Mot de passe</label> - <input - type="password" - autocomplete="on" - formControlName="password" - class="form-control" - [ngClass]="{ 'is-invalid': submitted && f.password.errors }" - /> - <div *ngIf="submitted && f.password.errors" class="invalid-feedback"> - <div *ngIf="f.password.errors.required">Le mot de passe est obligatoire</div> - <div *ngIf="f.password.errors.pattern"> - Le mot de passe doit avoir au minimun 8 caractères, une majuscule, une minuscule, un chiffre et un - caractère spécial. - </div> - </div> - </div> - <div class="form-group"> - <label for="confirmPassword">Confirmation du mot de passe</label> - <input - type="password" - autocomplete="on" - formControlName="confirmPassword" - class="form-control" - [ngClass]="{ 'is-invalid': submitted && f.confirmPassword.errors }" - /> - <div *ngIf="submitted && f.confirmPassword.errors" class="invalid-feedback"> - <div *ngIf="f.confirmPassword.errors.required">La confirmation du mot de passe est obligatoire</div> - <div *ngIf="f.confirmPassword.errors.mustMatch">Les mot de passe ne sont pas les mêmes</div> - </div> - </div> - - <div *ngIf="userAlreadyExist">Cette addresse mail est déjà utilisée</div> - <div class="form-group"> - <button [disabled]="loading" class="btn btn-primary"> - <span *ngIf="loading" class="spinner-border spinner-border-sm mr-1"></span> - Register - </button> - <a routerLink="../login" class="btn btn-link">Cancel</a> - </div> - </form> + <app-create-account-form [buttonName]="'Valider'" (submitForm)="onSubmit($event)"></app-create-account-form> </div> + <div *ngIf="userAlreadyExist">Cette addresse mail est déjà utilisée</div> <div *ngIf="success"> <p> Un mail de confirmation vous a été envoyé. Merci de valider votre addresse mail avant de pouvoir vous connecter. diff --git a/src/app/shared/components/signin-modal/signin-modal.component.ts b/src/app/shared/components/signin-modal/signin-modal.component.ts index 253ec9136..d76097a7b 100644 --- a/src/app/shared/components/signin-modal/signin-modal.component.ts +++ b/src/app/shared/components/signin-modal/signin-modal.component.ts @@ -1,8 +1,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { FormGroup, FormBuilder, Validators, AbstractControl } from '@angular/forms'; +import { FormGroup } from '@angular/forms'; import { first } from 'rxjs/operators'; import { AuthService } from '../../../services/auth.service'; -import { MustMatch } from '../../validator/form'; @Component({ selector: 'app-signin-modal', @@ -10,51 +9,33 @@ import { MustMatch } from '../../validator/form'; styleUrls: ['./signin-modal.component.scss'], }) export class SignInModalComponent implements OnInit { - public form: FormGroup; public loading = false; public submitted = false; public success = false; public userAlreadyExist = false; - constructor(private formBuilder: FormBuilder, private authService: AuthService) {} + constructor(private authService: AuthService) {} @Input() public openned: boolean; @Output() closed = new EventEmitter(); - ngOnInit(): void { - this.form = this.formBuilder.group( - { - email: ['', Validators.required], - password: [ - '', - [Validators.required, Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/)], - ], - confirmPassword: [''], - }, - { validator: MustMatch('password', 'confirmPassword') } - ); - } - - // getter for form fields - get f(): { [key: string]: AbstractControl } { - return this.form.controls; - } + ngOnInit(): void {} public closeModal(): void { this.closed.emit(); } - public onSubmit(): void { + public onSubmit(form: FormGroup): void { this.submitted = true; // stop here if form is invalid - if (this.form.invalid) { + if (form.invalid) { return; } this.loading = true; this.authService - .register(this.form.value) + .register(form.value) .pipe(first()) .subscribe( () => { diff --git a/src/app/shared/components/validator-form/validator-form.component.ts b/src/app/shared/components/validator-form/validator-form.component.ts index f226ca915..cc10fe185 100644 --- a/src/app/shared/components/validator-form/validator-form.component.ts +++ b/src/app/shared/components/validator-form/validator-form.component.ts @@ -1,12 +1,23 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; +import { Component, Input, OnInit } from '@angular/core'; +import { FormControl } from '@angular/forms'; @Component({ selector: 'app-validator-form', templateUrl: './validator-form.component.html', styleUrls: ['./validator-form.component.scss'], }) -export class ValidatorFormComponent { +export class ValidatorFormComponent implements OnInit { @Input() public control: FormControl; + @Input() public nameControl?: string; + public errorPattern = 'Champ mal renseigné'; + public errorMustMatch = 'Champ non identique'; constructor() {} + + ngOnInit() { + if (this.nameControl == 'password') { + this.errorPattern = + 'Le mot de passe doit avoir au minimun 8 caractères, une majuscule, une minuscule, un chiffre et un caractère spécial.'; + this.errorMustMatch = 'Les mots de passe doivent être identiques'; + } + } } -- GitLab From eb0c3a5b83fbe8590d6b0ee9c1e884dcf69cdfbf Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Wed, 6 Jan 2021 17:04:34 +0100 Subject: [PATCH 04/21] feat(claimStructure) : fix edit/claim mode for Form --- src/app/form/form.component.html | 463 +++++++++--------- src/app/form/form.component.scss | 4 +- src/app/form/form.component.ts | 39 +- src/app/models/user.model.ts | 1 + src/app/profile/profile.component.html | 6 + src/app/profile/services/profile.service.ts | 4 + .../create-account-form.component.html | 2 +- .../create-account-form.component.ts | 1 - .../signin-modal/signin-modal.component.html | 2 +- .../validator-form.component.html | 3 +- .../structure-details.component.html | 6 +- .../structure-details.component.ts | 15 +- 12 files changed, 306 insertions(+), 240 deletions(-) diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index 7d4eae895..506f4bcfc 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -1,247 +1,260 @@ -<form [formGroup]="structureForm" *ngIf="structureForm" (ngSubmit)="onSubmit(structureForm)"> - <p>Votre structure est-elle ?*</p> - <input type="radio" formControlName="structureRepresentation" value="principal" /> Un établissement principal (siège - social)<br /> - <input type="radio" formControlName="structureRepresentation" value="antenne" /> Une permanence (antenne) - <app-validator-form [control]="getStructureControl('structureRepresentation')"></app-validator-form> - <p>Nom de votre structure*</p> - <input type="text" formControlName="structureName" /> - <app-validator-form [control]="getStructureControl('structureName')"></app-validator-form> - <p>Type de structure*</p> - <div *ngFor="let choice of typeStructure | keyvalue"> - <label> - <input - type="checkbox" - [value]="choice.key" - (change)="onCheckChange($event, 'structureType')" - [checked]="isInArray(choice.key, 'structureType')" - /> - {{ choice.value }} - </label> - </div> - <app-validator-form [control]="getStructureControl('structureType')"></app-validator-form> - <p>Démarche</p> - <div *ngIf="proceduresAccompaniment"> - <p>{{ proceduresAccompaniment.name }}</p> - <div *ngFor="let module of proceduresAccompaniment.modules"> +<div class="form"> + <form [formGroup]="structureForm" *ngIf="structureForm" (ngSubmit)="onSubmit(structureForm)"> + <p>Votre structure est-elle ?*</p> + <input type="radio" formControlName="structureRepresentation" value="principal" /> Un établissement principal (siège + social)<br /> + <input type="radio" formControlName="structureRepresentation" value="antenne" /> Une permanence (antenne) + <app-validator-form [control]="getStructureControl('structureRepresentation')"></app-validator-form> + <p>Nom de votre structure*</p> + <input type="text" formControlName="structureName" /> + <app-validator-form [control]="getStructureControl('structureName')"></app-validator-form> + <p>Type de structure*</p> + <div *ngFor="let choice of typeStructure | keyvalue"> <label> <input type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, proceduresAccompaniment.id)" - [checked]="isInArray(module.id, proceduresAccompaniment.id)" + [value]="choice.key" + (change)="onCheckChange($event, 'structureType')" + [checked]="isInArray(choice.key, 'structureType')" + [disabled]="getStructureControl('structureType').disabled" /> - {{ module.text }} + {{ choice.value }} </label> </div> - </div> - <p>Description</p> - <textarea rows="4" style="width: 100%" maxlength="500" formControlName="description"></textarea> - <p> - Afin de rendre visible l'offre de formation numérique proposée lors de ce nouveau confinement, merci d'indiquer ici, - les activités que vous avez pu maintenir - </p> - <textarea rows="4" style="width: 100%" maxlength="1000" formControlName="lockdownActivity"></textarea> - <div formGroupName="address"> - <p>ADRESSE</p> - <p>Numéro</p> - <input type="text" autocomplete="street-address" formControlName="numero" /> - <p>Voie*</p> - <input type="text" formControlName="street" /> - <app-validator-form [control]="getAddressControl('street')"></app-validator-form> - <p>Commune*</p> - <input type="text" formControlName="commune" /> - <app-validator-form [control]="getAddressControl('commune')"></app-validator-form> - </div> - <p>VOUS JOINDRE</p> - <p>Téléphone*</p> - <input type="text" formControlName="contactPhone" (input)="modifyPhoneInput($event.target.value)" /> - <app-validator-form [control]="getStructureControl('contactPhone')"></app-validator-form> - <p>Courriel*</p> - <input type="email" formControlName="contactMail" /> - <app-validator-form [control]="getStructureControl('contactMail')"></app-validator-form> - <p>Site web</p> - <input type="text" formControlName="website" /> - <p>Présence sur les réseaux sociaux</p> - <p>Facebook</p> - <input type="text" formControlName="facebook" /> - <p>Twitter</p> - <input type="text" formControlName="twitter" /> - <p>Instagram</p> - <input type="text" formControlName="instagram" /> - <p>Personne à contacter</p> - <p>Civilité</p> - <input type="radio" formControlName="gender" value="Madame" />Madame <br /> - <input type="radio" formControlName="gender" value="Monsieur" />Monsieur - <p>Nom</p> - <input type="text" formControlName="contactName" /> - <p>Prénom</p> - <input type="text" formControlName="contactSurname" /> - <p>Courriel*</p> - <input type="email" formControlName="contactMail" /> - <app-validator-form [control]="getStructureControl('contactMail')"></app-validator-form> - <p>Fonction</p> - <select formControlName="fonction"> - <option value="">---Sélectionner---</option> - <option *ngFor="let fonction of fonctions | keyvalue" [value]="fonction.key"> - {{ fonction.value }} - </option> - </select> - <p>Accessibilité</p> - <input type="checkbox" formControlName="pmrAccess" />Accessibilité personnes à mobilité réduite (PMR) <br /> - <div *ngIf="accessModality"> - <p>{{ accessModality.name }}*</p> - <div *ngFor="let module of accessModality.modules"> - <label> - <input - type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, accessModality.id)" - [checked]="isInArray(module.id, accessModality.id)" - /> - {{ module.text }} - </label> + <app-validator-form [control]="getStructureControl('structureType')"></app-validator-form> + <p>Démarche</p> + <div *ngIf="proceduresAccompaniment"> + <p>{{ proceduresAccompaniment.name }}</p> + <div *ngFor="let module of proceduresAccompaniment.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, proceduresAccompaniment.id)" + [checked]="isInArray(module.id, proceduresAccompaniment.id)" + [disabled]="getStructureControl(proceduresAccompaniment.id).disabled" + /> + {{ module.text }} + </label> + </div> </div> - <app-validator-form [control]="getStructureControl('accessModality')"></app-validator-form> - </div> - <p>Pour les RDV, merci de préciser s'il est nécessaire d'apporter des pièces justificatives ou du matériel.</p> - <textarea rows="4" style="width: 100%" maxlength="500" formControlName="documentsMeeting"></textarea> - <div *ngIf="labelsQualifications"> - <p>{{ labelsQualifications.name }}</p> - <div *ngFor="let module of labelsQualifications.modules"> - <label> - <input - type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, labelsQualifications.id)" - [checked]="isInArray(module.id, labelsQualifications.id)" - /> - {{ module.text }} - </label> + <p>Description</p> + <textarea rows="4" style="width: 100%" maxlength="500" formControlName="description"></textarea> + <p> + Afin de rendre visible l'offre de formation numérique proposée lors de ce nouveau confinement, merci d'indiquer + ici, les activités que vous avez pu maintenir + </p> + <textarea rows="4" style="width: 100%" maxlength="1000" formControlName="lockdownActivity"></textarea> + <div formGroupName="address"> + <p>ADRESSE</p> + <p>Numéro</p> + <input type="text" autocomplete="street-address" formControlName="numero" /> + <p>Voie*</p> + <input type="text" formControlName="street" /> + <app-validator-form [control]="getAddressControl('street')"></app-validator-form> + <p>Commune*</p> + <input type="text" formControlName="commune" /> + <app-validator-form [control]="getAddressControl('commune')"></app-validator-form> </div> - </div> - <div *ngIf="publics"> - <p>{{ publics.name }}*</p> - <div *ngFor="let module of publics.modules"> - <label> - <input - type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, publics.id)" - [checked]="isInArray(module.id, publics.id)" - /> - {{ module.text }} - </label> + <p>VOUS JOINDRE</p> + <p>Téléphone*</p> + <input type="text" formControlName="contactPhone" (input)="modifyPhoneInput($event.target.value)" /> + <app-validator-form [control]="getStructureControl('contactPhone')"></app-validator-form> + <p>Courriel*</p> + <input type="email" formControlName="contactMail" /> + <app-validator-form [control]="getStructureControl('contactMail')"></app-validator-form> + <p>Site web</p> + <input type="text" formControlName="website" /> + <p>Présence sur les réseaux sociaux</p> + <p>Facebook</p> + <input type="text" formControlName="facebook" /> + <p>Twitter</p> + <input type="text" formControlName="twitter" /> + <p>Instagram</p> + <input type="text" formControlName="instagram" /> + <p>Personne à contacter</p> + <p>Civilité</p> + <input type="radio" formControlName="gender" value="Madame" />Madame <br /> + <input type="radio" formControlName="gender" value="Monsieur" />Monsieur + <p>Nom</p> + <input type="text" formControlName="contactName" /> + <p>Prénom</p> + <input type="text" formControlName="contactSurname" /> + <p>Courriel*</p> + <input type="email" formControlName="contactMail" /> + <app-validator-form [control]="getStructureControl('contactMail')"></app-validator-form> + <p>Fonction</p> + <select formControlName="fonction"> + <option value="">---Sélectionner---</option> + <option *ngFor="let fonction of fonctions | keyvalue" [value]="fonction.key"> + {{ fonction.value }} + </option> + </select> + <p>Accessibilité</p> + <input type="checkbox" formControlName="pmrAccess" />Accessibilité personnes à mobilité réduite (PMR) <br /> + <div *ngIf="accessModality"> + <p>{{ accessModality.name }}*</p> + <div *ngFor="let module of accessModality.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, accessModality.id)" + [checked]="isInArray(module.id, accessModality.id)" + [disabled]="getStructureControl(accessModality.id).disabled" + /> + {{ module.text }} + </label> + </div> + <app-validator-form [control]="getStructureControl('accessModality')"></app-validator-form> </div> - <app-validator-form [control]="getStructureControl('publics')"></app-validator-form> - </div> - <div formGroupName="hours"> - <p>Heures</p> - <div *ngFor="let day of weekDay | keyvalue"> - <div [formGroupName]="day.key"> - <p>Ouvert le {{ day.value }} ? :</p> - <input type="radio" formControlName="open" (click)="addTime(day.key)" [value]="true" />Oui <br /> - <input type="radio" formControlName="open" (click)="removeTime(day.key)" [value]="false" />Non - <div formArrayName="time" *ngIf="isOpen(day.key)"> - <div *ngFor="let time of getTime(day.key).controls; index as i"> - <div [formGroupName]="i"> - <input type="number" formControlName="openning" /> - <input type="number" formControlName="closing" /> - </div> - <div *ngIf="i < 1"> - <input - type="checkbox" - [value]="false" - (change)="onCheckPlageHoursChange($event, day.key, time)" - [checked]="getTime(day.key).controls.length == 2" - />Ajouter une plage + <p>Pour les RDV, merci de préciser s'il est nécessaire d'apporter des pièces justificatives ou du matériel.</p> + <textarea rows="4" style="width: 100%" maxlength="500" formControlName="documentsMeeting"></textarea> + <div *ngIf="labelsQualifications"> + <p>{{ labelsQualifications.name }}</p> + <div *ngFor="let module of labelsQualifications.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, labelsQualifications.id)" + [checked]="isInArray(module.id, labelsQualifications.id)" + [disabled]="getStructureControl(labelsQualifications.id).disabled" + /> + {{ module.text }} + </label> + </div> + </div> + <div *ngIf="publics"> + <p>{{ publics.name }}*</p> + <div *ngFor="let module of publics.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, publics.id)" + [checked]="isInArray(module.id, publics.id)" + [disabled]="getStructureControl(publics.id).disabled" + /> + {{ module.text }} + </label> + </div> + <app-validator-form [control]="getStructureControl('publics')"></app-validator-form> + </div> + <div formGroupName="hours"> + <p>Heures</p> + <div *ngFor="let day of weekDay | keyvalue"> + <div [formGroupName]="day.key"> + <p>Ouvert le {{ day.value }} ? :</p> + <input type="radio" formControlName="open" (click)="addTime(day.key)" [value]="true" />Oui <br /> + <input type="radio" formControlName="open" (click)="removeTime(day.key)" [value]="false" />Non + <div formArrayName="time" *ngIf="isOpen(day.key)"> + <div *ngFor="let time of getTime(day.key).controls; index as i"> + <div [formGroupName]="i"> + <input type="number" formControlName="openning" /> + <input type="number" formControlName="closing" /> + </div> + <div *ngIf="i < 1"> + <input + type="checkbox" + [value]="false" + (change)="onCheckPlageHoursChange($event, day.key, time)" + [checked]="getTime(day.key).controls.length == 2" + [disabled]="getStructureControl('hours').disabled" + />Ajouter une plage + </div> </div> </div> </div> </div> </div> - </div> - <p>Fermetures exceptionnelles</p> - <input type="text" formControlName="exceptionalClosures" /> - <div *ngIf="publicsAccompaniment"> - <p>{{ publicsAccompaniment.name }}</p> - <div *ngFor="let module of publicsAccompaniment.modules"> - <label> - <input - type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, publicsAccompaniment.id)" - [checked]="isInArray(module.id, publicsAccompaniment.id)" - /> - {{ module.text }} - </label> + <p>Fermetures exceptionnelles</p> + <input type="text" formControlName="exceptionalClosures" /> + <div *ngIf="publicsAccompaniment"> + <p>{{ publicsAccompaniment.name }}</p> + <div *ngFor="let module of publicsAccompaniment.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, publicsAccompaniment.id)" + [checked]="isInArray(module.id, publicsAccompaniment.id)" + [disabled]="getStructureControl(publicsAccompaniment.id).disabled" + /> + {{ module.text }} + </label> + </div> </div> - </div> - <p>Formations au numérique proposées</p> - <p> - Ces modules de compétences sont issus du référentiel national et identifiés dans le cadre du déploiement du Pass - numérique sur la Métropole (pour en savoir +) - </p> - <div *ngFor="let c of categoryTraining"> - <p>{{ c.name }}</p> - <div *ngFor="let module of c.modules"> - <label> - <input - type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, c.id)" - [checked]="isInArray(module.id, c.id)" - /> - {{ module.text }} - </label> + <p>Formations au numérique proposées</p> + <p> + Ces modules de compétences sont issus du référentiel national et identifiés dans le cadre du déploiement du Pass + numérique sur la Métropole (pour en savoir +) + </p> + <div *ngFor="let c of categoryTraining"> + <p>{{ c.name }}</p> + <div *ngFor="let module of c.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, c.id)" + [checked]="isInArray(module.id, c.id)" + [disabled]="getStructureControl(c.id).disabled" + /> + {{ module.text }} + </label> + </div> </div> - </div> - <div *ngIf="equipmentsAndServices"> - <p>{{ equipmentsAndServices.name }}</p> - <div *ngFor="let module of equipmentsAndServices.modules"> + <div *ngIf="equipmentsAndServices"> + <p>{{ equipmentsAndServices.name }}</p> + <div *ngFor="let module of equipmentsAndServices.modules"> + <label> + <input + type="checkbox" + [value]="module.id" + (change)="onCheckChange($event, equipmentsAndServices.id)" + [checked]="isInArray(module.id, equipmentsAndServices.id)" + [disabled]="getStructureControl(equipmentsAndServices.id).disabled" + /> + {{ module.text }} + </label> + <div *ngIf="isInArray(module.id, equipmentsAndServices.id)"> + <div *ngIf="module.id == 'ordinateurs'"> + <span>Nombre</span> + <input type="number" formControlName="nbComputers" /> + </div> + <div *ngIf="module.id == 'tablettes'"> + <span>Nombre</span> + <input type="number" formControlName="nbTablets" /> + </div> + <div *ngIf="module.id == 'bornesNumeriques'"> + <span>Nombre</span> + <input type="number" formControlName="nbNumericTerminal" /> + </div> + <div *ngIf="module.id == 'imprimantes'"> + <span>Nombre</span> + <input type="number" formControlName="nbPrinters" /> + </div> + </div> + </div> + </div> + <p>Précisions si nécessaire</p> + <textarea rows="4" style="width: 100%" maxlength="500" formControlName="equipmentsDetails"></textarea> + <p>L'accès à ce matériel est</p> + <div *ngFor="let equipment of equipmentAccess | keyvalue"> <label> <input type="checkbox" - [value]="module.id" - (change)="onCheckChange($event, equipmentsAndServices.id)" - [checked]="isInArray(module.id, equipmentsAndServices.id)" + [value]="equipment.key" + (change)="onCheckChange($event, 'equipmentsAccessType')" + [checked]="isInArray(equipment.key, 'equipmentsAccessType')" + [disabled]="getStructureControl('equipmentsAccessType').disabled" /> - {{ module.text }} + {{ equipment.value }} </label> - <div *ngIf="isInArray(module.id, equipmentsAndServices.id)"> - <div *ngIf="module.id == 'ordinateurs'"> - <span>Nombre</span> - <input type="number" formControlName="nbComputers" /> - </div> - <div *ngIf="module.id == 'tablettes'"> - <span>Nombre</span> - <input type="number" formControlName="nbTablets" /> - </div> - <div *ngIf="module.id == 'bornesNumeriques'"> - <span>Nombre</span> - <input type="number" formControlName="nbNumericTerminal" /> - </div> - <div *ngIf="module.id == 'imprimantes'"> - <span>Nombre</span> - <input type="number" formControlName="nbPrinters" /> - </div> - </div> </div> - </div> - <p>Précisions si nécessaire</p> - <textarea rows="4" style="width: 100%" maxlength="500" formControlName="equipmentsDetails"></textarea> - <p>L'accès à ce matériel est</p> - <div *ngFor="let equipment of equipmentAccess | keyvalue"> - <label> - <input - type="checkbox" - [value]="equipment.key" - (change)="onCheckChange($event, 'equipmentsAccessType')" - [checked]="isInArray(equipment.key, 'equipmentsAccessType')" - /> - {{ equipment.value }} - </label> - </div> - <br /> - <button type="submit" [disabled]="structureForm.invalid">OK</button> -</form> + <br /> + <button *ngIf="isEditMode" type="submit">Modifier</button> + </form> + <app-create-account-form *ngIf="!isEditMode" (submitForm)="onSubmitClaim($event)"></app-create-account-form> +</div> diff --git a/src/app/form/form.component.scss b/src/app/form/form.component.scss index 14dbd367d..8db71778c 100644 --- a/src/app/form/form.component.scss +++ b/src/app/form/form.component.scss @@ -1,7 +1,7 @@ -form { +.form { position: fixed; background: white; - width: 100vh; + width: 50vw; height: 100vh; top: 0; z-index: 9999; diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 85485bd4a..8ee5f1df8 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms'; +import { AbstractControl, Form, FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { Structure } from '../models/structure.model'; import { Time } from '../models/time.model'; import { Day } from '../models/day.model'; @@ -11,6 +11,9 @@ import { EquipmentAccess } from '../shared/enum/equipmentAccess.enum'; import { WeekDayEnum } from '../shared/enum/weekDay.enum'; import { typeStructureEnum } from '../shared/enum/typeStructure.enum'; import { FonctionContactEnum } from '../shared/enum/fonctionContact.enum'; +import { MustMatch } from '../shared/validator/form'; +import { ProfileService } from '../profile/services/profile.service'; +import { User } from '../models/user.model'; @Component({ selector: 'app-structureForm', @@ -19,8 +22,12 @@ import { FonctionContactEnum } from '../shared/enum/fonctionContact.enum'; }) export class FormComponent implements OnInit { @Input() public idStructure: number; + @Input() public isEditMode: boolean; @Output() closeEvent = new EventEmitter<Structure>(); public structureForm: FormGroup; + + public userAlreadyExist = false; + public equipmentAccess = EquipmentAccess; public weekDay = WeekDayEnum; public typeStructure = typeStructureEnum; @@ -33,7 +40,12 @@ export class FormComponent implements OnInit { public equipmentsAndServices: Category; public proceduresAccompaniment: Category; public structureId: number; - constructor(private structureService: StructureService, private searchService: SearchService) {} + constructor( + private structureService: StructureService, + private searchService: SearchService, + private formBuilder: FormBuilder, + private profileService: ProfileService + ) {} ngOnInit(): void { this.structureService.getStructure(this.idStructure).subscribe((structure) => { @@ -69,6 +81,7 @@ export class FormComponent implements OnInit { } }); }); + this.searchService.getCategoriesTraining().subscribe((t) => { this.categoryTraining = t; }); @@ -135,6 +148,14 @@ export class FormComponent implements OnInit { equipmentsDetails: new FormControl(structure.equipmentsDetails), equipmentsAccessType: this.loadArrayForCheckbox(structure.equipmentsAccessType, false), }); + + // Disable form when it's to claim. + console.log(this.isEditMode); + if (!this.isEditMode) { + Object.keys(this.structureForm.controls).forEach((controlName) => { + this.structureForm.controls[controlName].disable(); + }); + } } private loadArrayForCheckbox(array: string[], isRequired: boolean): FormArray { @@ -143,7 +164,6 @@ export class FormComponent implements OnInit { isRequired ? Validators.required : Validators.nullValidator ); } - public getStructureControl(nameControl: string): AbstractControl { return this.structureForm.get(nameControl); } @@ -178,8 +198,8 @@ export class FormComponent implements OnInit { } private createTime(time: Time): FormGroup { return new FormGroup({ - openning: new FormControl(time.openning, Validators.required), - closing: new FormControl(time.closing, Validators.required), + openning: new FormControl(time.openning), + closing: new FormControl(time.closing), }); } @@ -220,7 +240,15 @@ export class FormComponent implements OnInit { } return false; } + public onSubmitClaim(accountForm: FormGroup): void { + if (!this.structureForm.invalid && accountForm.valid) { + this.profileService.claimStructure(this.structureId, accountForm.value).subscribe((user) => { + this.closeEvent.emit(this.structureForm.value); + }); + } + } public onSubmit(structureForm: FormGroup): void { + console.log(structureForm); if (structureForm.valid) { this.structureService.postStructure(this.structureId, structureForm.value).subscribe( (structure: Structure) => { @@ -228,7 +256,6 @@ export class FormComponent implements OnInit { }, (err) => {} ); - } else { } } } diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index aa2391853..a60ee2247 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -5,4 +5,5 @@ export class User { emailVerified: boolean; role: number; validationToken: string; + structuresLink: number[]; } diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html index d85790c5f..f50087732 100644 --- a/src/app/profile/profile.component.html +++ b/src/app/profile/profile.component.html @@ -4,6 +4,12 @@ <div *ngIf="userProfile" fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px"> <p>Id: {{ userProfile._id }}</p> <p>Email: {{ userProfile.email }}</p> + <p> + Mes structures : + <span *ngFor="let structureId of userProfile.structuresLink"> + <b>{{ structureId }}</b> + </span> + </p> <button (click)="toogleChangeEmail()">Changer d'email</button> <form *ngIf="changeEmail" diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index ef4d4537a..6be0626c8 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -15,6 +15,10 @@ export class ProfileService { return this.http.get<User>(`${this.baseUrl}/profile`); } + public claimStructure(id: number, body: User): Observable<User> { + return this.http.post<any>(`${this.baseUrl}/claim/` + id, body); + } + public changePassword(newPassword: string, oldPassword: string): Observable<User> { return this.http.post<any>(`${this.baseUrl}/change-password`, { newPassword, oldPassword }); } diff --git a/src/app/shared/components/create-account-form/create-account-form.component.html b/src/app/shared/components/create-account-form/create-account-form.component.html index d92f345c2..e8a4bd045 100644 --- a/src/app/shared/components/create-account-form/create-account-form.component.html +++ b/src/app/shared/components/create-account-form/create-account-form.component.html @@ -24,6 +24,6 @@ </div> <div class="form-group"> - <button class="btn btn-primary" type="submit">{{ buttonName }}</button> + <button class="btn btn-primary" type="submit">Valider</button> </div> </form> diff --git a/src/app/shared/components/create-account-form/create-account-form.component.ts b/src/app/shared/components/create-account-form/create-account-form.component.ts index 8a793868d..2ae7b4136 100644 --- a/src/app/shared/components/create-account-form/create-account-form.component.ts +++ b/src/app/shared/components/create-account-form/create-account-form.component.ts @@ -11,7 +11,6 @@ export class CreateAccountFormComponent implements OnInit { constructor() {} public accountForm: FormGroup; public submitted: boolean = false; - @Input() public buttonName; @Output() public submitForm = new EventEmitter<FormGroup>(); ngOnInit(): void { diff --git a/src/app/shared/components/signin-modal/signin-modal.component.html b/src/app/shared/components/signin-modal/signin-modal.component.html index fec631fc0..d8d32764a 100644 --- a/src/app/shared/components/signin-modal/signin-modal.component.html +++ b/src/app/shared/components/signin-modal/signin-modal.component.html @@ -5,7 +5,7 @@ </div> <h4>Inscription</h4> <div *ngIf="!success"> - <app-create-account-form [buttonName]="'Valider'" (submitForm)="onSubmit($event)"></app-create-account-form> + <app-create-account-form (submitForm)="onSubmit($event)"></app-create-account-form> </div> <div *ngIf="userAlreadyExist">Cette addresse mail est déjà utilisée</div> <div *ngIf="success"> diff --git a/src/app/shared/components/validator-form/validator-form.component.html b/src/app/shared/components/validator-form/validator-form.component.html index a1494a2df..4cc6696be 100644 --- a/src/app/shared/components/validator-form/validator-form.component.html +++ b/src/app/shared/components/validator-form/validator-form.component.html @@ -1,4 +1,5 @@ <div *ngIf="control.invalid" class="alert"> <div *ngIf="control.errors.required">Champ obligatoire</div> - <div *ngIf="control.errors.pattern">Champ mal renseigné</div> + <div *ngIf="control.errors.pattern">{{ errorPattern }}</div> + <div *ngIf="control.errors.mustMatch">{{ errorMustMatch }}</div> </div> diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index 6f78bd201..7b9cd7fb1 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -1,13 +1,17 @@ <app-structureForm *ngIf="showForm" [idStructure]="structure.id" + [isEditMode]="isEditMode" (closeEvent)="updateStructure($event)" (clickOutside)="displayForm()" ></app-structureForm> <div class="structrue-details-container" *ngIf="structure && !isLoading"> <!-- Header info --> <div fxLayout="row" fxLayoutAlign="center center" *ngIf="!isClaimed"> - <button>Revendiquer</button> + <button (click)="claimStructure()">Revendiquer</button> + </div> + <div fxLayout="row" fxLayoutAlign="center center"> + <button (click)="editStructure()">Modifier</button> </div> <div fxLayout="row" fxLayoutAlign="end center"> <div (click)="close()" class="ico-close-details"></div> diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index a7760778f..5996b9a98 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -30,6 +30,7 @@ export class StructureDetailsComponent implements OnInit { public showForm = false; public isClaimed: boolean = null; public isLoading: boolean = false; + public isEditMode: boolean = false; constructor( route: ActivatedRoute, @@ -124,15 +125,25 @@ export class StructureDetailsComponent implements OnInit { this.printService.printDocument('structure', this.structure); } - // Show/hide editForm structure + public editStructure(): void { + this.isEditMode = true; + this.displayForm(); + } + + public claimStructure(): void { + this.isEditMode = false; + this.displayForm(); + } + // Show/hide form structure public displayForm(): void { this.showForm = !this.showForm; } public updateStructure(s: Structure): void { this.structure = new Structure({ ...this.structure, ...s }); - this.displayForm(); this.updatedStructure.emit(this.structure); + this.displayForm(); + this.ngOnInit(); } public getAccessIcon(accessModality: AccessModality): string { switch (accessModality) { -- GitLab From 08637a58eef15278bbcbffdf8dec0a8c87dd616d Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Thu, 7 Jan 2021 11:50:55 +0100 Subject: [PATCH 05/21] fix(claimStructure) : fix edit and new structure --- src/app/app.component.ts | 11 ++--------- src/app/form/form.component.html | 6 +++++- src/app/form/form.component.ts | 3 +-- src/app/profile/services/profile.service.ts | 8 +++++++- .../structure-details.component.html | 7 +++---- .../structure-details/structure-details.component.ts | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9b9e30d8d..0bda1e50e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,5 @@ import { Component } from '@angular/core'; import { ProfileService } from './profile/services/profile.service'; -import { AuthService } from './services/auth.service'; import { PrintService } from './shared/service/print.service'; @Component({ @@ -11,13 +10,7 @@ import { PrintService } from './shared/service/print.service'; export class AppComponent { title = 'pamn'; - constructor( - public printService: PrintService, - private authService: AuthService, - private profilService: ProfileService - ) { - if (this.authService.isLoggedIn()) { - this.profilService.getProfile(); - } + constructor(public printService: PrintService, private profilService: ProfileService) { + this.profilService.getProfile(); } } diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index 506f4bcfc..8d492c99a 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -255,6 +255,10 @@ </div> <br /> <button *ngIf="isEditMode" type="submit">Modifier</button> + <button *ngIf="!structureId" [disabled]="structureForm.invalid" type="submit">Ajouter</button> </form> - <app-create-account-form *ngIf="!isEditMode" (submitForm)="onSubmitClaim($event)"></app-create-account-form> + <app-create-account-form + *ngIf="!isEditMode && structureId" + (submitForm)="onSubmitClaim($event)" + ></app-create-account-form> </div> diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 0efdf8bdd..b767b0f83 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -156,8 +156,7 @@ export class FormComponent implements OnInit { }); // Disable form when it's to claim. - console.log(this.isEditMode); - if (!this.isEditMode) { + if (!this.isEditMode && this.idStructure) { Object.keys(this.structureForm.controls).forEach((controlName) => { this.structureForm.controls[controlName].disable(); }); diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index 703710b0a..d91009403 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -14,7 +14,7 @@ export class ProfileService { public async getProfile(): Promise<User> { // Get profil by API only on first time - if (!this.currentProfile) { + if (!this.currentProfile && this.authService.isLoggedIn()) { const profile = await this.http.get<User>(`${this.baseUrl}/profile`).toPromise(); this.currentProfile = profile; } @@ -22,6 +22,12 @@ export class ProfileService { } public isLinkedToStructure(idStructure: number): boolean { + if (!this.authService.isLoggedIn()) { + this.currentProfile = null; + } + if (!this.currentProfile) { + return false; + } return this.currentProfile.structuresLink.includes(idStructure); } diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index 80302915f..ec6286ea6 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -11,12 +11,11 @@ <button (click)="claimStructure()">Revendiquer</button> </div> <div fxLayout="row" fxLayoutAlign="center center"> - <button (click)="editStructure()">Modifier</button> + <button *ngIf="profileService.isLinkedToStructure(structure.id)" (click)="editStructure()"> + Modifier ma structure + </button> </div> <div fxLayout="row" fxLayoutAlign="end center"> - <button *ngIf="profileService.isLinkedToStructure(structure.id)" (click)="displayForm()"> - Modifier la structure - </button> <div (click)="close()" class="ico-close-details"></div> </div> <div fxLayout="row" class="structure-details-block" fxLayoutAlign="baseline baseline" fxLayoutGap="8px"> diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index 951da51fc..dad0636d6 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -52,7 +52,7 @@ export class StructureDetailsComponent implements OnInit { ngOnInit(): void { this.isLoading = true; - this.profileService.getProfile().subscribe((p: User) => { + this.profileService.getProfile().then((p: User) => { this.currentProfile = p; }); this.structureService.isClaimed(this.structure.id).subscribe((boolean) => { -- GitLab From 974f76d19007dae69484aedbc38efaa090c3ac4d Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Thu, 7 Jan 2021 12:49:03 +0100 Subject: [PATCH 06/21] feat(claimStructure) : feat claim structure when connected --- src/app/app.component.ts | 11 ++++++++-- src/app/form/form.component.html | 9 +++++++- src/app/form/form.component.ts | 13 +++++++++-- src/app/profile/services/profile.service.ts | 22 +++++++++++++------ .../structure-details.component.html | 1 + .../structure-details.component.ts | 12 ++++++---- 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0bda1e50e..9b9e30d8d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; import { ProfileService } from './profile/services/profile.service'; +import { AuthService } from './services/auth.service'; import { PrintService } from './shared/service/print.service'; @Component({ @@ -10,7 +11,13 @@ import { PrintService } from './shared/service/print.service'; export class AppComponent { title = 'pamn'; - constructor(public printService: PrintService, private profilService: ProfileService) { - this.profilService.getProfile(); + constructor( + public printService: PrintService, + private authService: AuthService, + private profilService: ProfileService + ) { + if (this.authService.isLoggedIn()) { + this.profilService.getProfile(); + } } } diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html index 8d492c99a..780499151 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -257,8 +257,15 @@ <button *ngIf="isEditMode" type="submit">Modifier</button> <button *ngIf="!structureId" [disabled]="structureForm.invalid" type="submit">Ajouter</button> </form> + <button + *ngIf="!isEditMode && structureId && profile" + [disabled]="structureForm.invalid" + (click)="onSubmitClaimWithAccount()" + > + Revendiquer + </button> <app-create-account-form - *ngIf="!isEditMode && structureId" + *ngIf="!isEditMode && structureId && !profile" (submitForm)="onSubmitClaim($event)" ></app-create-account-form> </div> diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index b767b0f83..29871f36b 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -247,13 +247,22 @@ export class FormComponent implements OnInit { } public onSubmitClaim(accountForm: FormGroup): void { if (!this.structureForm.invalid && accountForm.valid) { - this.profileService.claimStructure(this.structureId, accountForm.value).subscribe((user) => { + this.profileService.claimStructureWithoutAccount(this.structureId, accountForm.value).subscribe((user) => { this.closeEvent.emit(this.structureForm.value); }); } } + + public onSubmitClaimWithAccount(): void { + this.profileService + .claimStructureWithAccount(this.structureId, this.profile.email) + .subscribe((structuresLinked) => { + this.profile.structuresLink = structuresLinked; + this.profileService.setProfile(this.profile); + this.closeEvent.emit(this.structureForm.value); + }); + } public onSubmit(structureForm: FormGroup): void { - console.log(structureForm); if (structureForm.valid) { if (this.structureId) { this.structureService.postStructure(this.structureId, structureForm.value).subscribe( diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index d91009403..cf7dc2c81 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -2,7 +2,6 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { User } from '../../models/user.model'; -import { AuthService } from '../../services/auth.service'; @Injectable({ providedIn: 'root', @@ -10,31 +9,40 @@ import { AuthService } from '../../services/auth.service'; export class ProfileService { private readonly baseUrl = 'api/users'; private currentProfile: User = null; - constructor(private http: HttpClient, private authService: AuthService) {} + constructor(private http: HttpClient) {} public async getProfile(): Promise<User> { // Get profil by API only on first time - if (!this.currentProfile && this.authService.isLoggedIn()) { + if (!this.currentProfile) { const profile = await this.http.get<User>(`${this.baseUrl}/profile`).toPromise(); this.currentProfile = profile; } return this.currentProfile; } + public setProfile(profile: User): void { + this.currentProfile = profile; + } + public isLinkedToStructure(idStructure: number): boolean { - if (!this.authService.isLoggedIn()) { - this.currentProfile = null; - } if (!this.currentProfile) { return false; } return this.currentProfile.structuresLink.includes(idStructure); } - public claimStructure(id: number, body: User): Observable<User> { + public removeProfile(): void { + this.currentProfile = null; + } + + public claimStructureWithoutAccount(id: number, body: User): Observable<User> { return this.http.post<any>(`${this.baseUrl}/claim/` + id, body); } + public claimStructureWithAccount(id: number, email: string): Observable<number[]> { + return this.http.post<any>(`${this.baseUrl}/claimWithAccount/` + id, { email }); + } + public changePassword(newPassword: string, oldPassword: string): Observable<User> { return this.http.post<any>(`${this.baseUrl}/change-password`, { newPassword, oldPassword }); } diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index ec6286ea6..d78d68677 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -2,6 +2,7 @@ *ngIf="showForm" [idStructure]="structure.id" [isEditMode]="isEditMode" + [profile]="currentProfile" (closeEvent)="updateStructure($event)" (clickOutside)="displayForm()" ></app-structureForm> diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index dad0636d6..2e16a534b 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -12,6 +12,7 @@ import { typeStructureEnum } from '../../../shared/enum/typeStructure.enum'; import { StructureService } from '../../../services/structure.service'; import { ProfileService } from '../../../profile/services/profile.service'; import { User } from '../../../models/user.model'; +import { AuthService } from '../../../services/auth.service'; @Component({ selector: 'app-structure-details', templateUrl: './structure-details.component.html', @@ -40,7 +41,8 @@ export class StructureDetailsComponent implements OnInit { private printService: PrintService, private searchService: SearchService, private structureService: StructureService, - private profileService: ProfileService + private profileService: ProfileService, + private authService: AuthService ) { route.url.subscribe((url) => { if (url[0].path === 'structure') { @@ -52,9 +54,11 @@ export class StructureDetailsComponent implements OnInit { ngOnInit(): void { this.isLoading = true; - this.profileService.getProfile().then((p: User) => { - this.currentProfile = p; - }); + if (this.authService.isLoggedIn()) { + this.profileService.getProfile().then((p: User) => { + this.currentProfile = p; + }); + } this.structureService.isClaimed(this.structure.id).subscribe((boolean) => { this.isClaimed = boolean; this.searchService.getCategoriesTraining().subscribe((referentiels) => { -- GitLab From 436357678f1d675b973bc25782155c72d69b057e Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 10:31:26 +0100 Subject: [PATCH 07/21] fix error TU form --- src/app/form/form.component.spec.ts | 7 ++++--- src/app/structure-list/structure-list.component.spec.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/form/form.component.spec.ts b/src/app/form/form.component.spec.ts index 54eeeb118..83f6d5e3d 100644 --- a/src/app/form/form.component.spec.ts +++ b/src/app/form/form.component.spec.ts @@ -1,18 +1,19 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms'; +import { FormArray, FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; import { Time } from '../models/time.model'; +import { SharedModule } from '../shared/shared.module'; import { FormComponent } from './form.component'; -fdescribe('FormComponent', () => { +describe('FormComponent', () => { let component: FormComponent; let fixture: ComponentFixture<FormComponent>; beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [FormComponent], - imports: [HttpClientTestingModule], + imports: [HttpClientTestingModule, FormsModule, ReactiveFormsModule, SharedModule], }).compileComponents(); }); diff --git a/src/app/structure-list/structure-list.component.spec.ts b/src/app/structure-list/structure-list.component.spec.ts index 45ed7ac0e..793f39969 100644 --- a/src/app/structure-list/structure-list.component.spec.ts +++ b/src/app/structure-list/structure-list.component.spec.ts @@ -202,7 +202,7 @@ describe('StructureListComponent', () => { it('should emit undefined id structure to remove map marker', () => { spyOn(component.displayMapMarkerId, 'emit'); - component.mouseOut(); + component.mouseLeave(); expect(component.displayMapMarkerId.emit).toHaveBeenCalled(); expect(component.displayMapMarkerId.emit).toHaveBeenCalledWith([undefined]); }); -- GitLab From 7cdd2c4d26248f23b9df46d9bfaa0571e2a34544 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 10:32:02 +0100 Subject: [PATCH 08/21] fix error TU --- src/app/map/services/map.service.spec.ts | 6 +++--- .../logo-card/logo-card.component.spec.ts | 14 ++++++-------- .../modal-filter/modal-filter.component.spec.ts | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/map/services/map.service.spec.ts b/src/app/map/services/map.service.spec.ts index ca4b202d0..ae117847d 100644 --- a/src/app/map/services/map.service.spec.ts +++ b/src/app/map/services/map.service.spec.ts @@ -27,17 +27,17 @@ describe('MapService', () => { }); it('should cerate marker with tooltip', () => { - const marker = service.createMarker(45.764043, 4.835659, 1, '<p>Hello <br/>World !</p>'); + const marker = service.createMarker(45.764043, 4.835659, 1, null, '<p>Hello <br/>World !</p>'); expect(marker.getTooltip().getContent()).toEqual('<p>Hello <br/>World !</p>'); }); it('should get marker', () => { - const marker = service.createMarker(45.764043, 4.835659, 1, '<p>Hello <br/>World !</p>'); + const marker = service.createMarker(45.764043, 4.835659, 1, null, '<p>Hello <br/>World !</p>'); expect(marker).toEqual(service.getMarker(1)); }); it('should not get marker, with missing id', () => { - service.createMarker(45.764043, 4.835659, 1, '<p>Hello <br/>World !</p>'); + service.createMarker(45.764043, 4.835659, 1, null, '<p>Hello <br/>World !</p>'); expect(service.getMarker(2)).toEqual(null); }); it('should not get marker, empty', () => { diff --git a/src/app/shared/components/logo-card/logo-card.component.spec.ts b/src/app/shared/components/logo-card/logo-card.component.spec.ts index 32b67d9f0..e0083e172 100644 --- a/src/app/shared/components/logo-card/logo-card.component.spec.ts +++ b/src/app/shared/components/logo-card/logo-card.component.spec.ts @@ -24,13 +24,11 @@ describe('LogoCardComponent', () => { }); it('should return logo name with a string input', () => { - const logoCaf = component.getLogoKey(Demarches.caf); - const logoCarsat = component.getLogoKey(Demarches.carsat); - const logoCpam = component.getLogoKey(Demarches.cpam); - const logoOther = component.getLogoKey(Demarches.other); - expect(logoCaf).toEqual('caf'); - expect(logoCarsat).toEqual('carsat'); - expect(logoCpam).toEqual('cpam'); - expect(logoOther).toEqual('other'); + const logoCaf = component.getName(Demarches.accompagnantCaf); + const logoCarsat = component.getName(Demarches.carsat); + const logoCpam = component.getName(Demarches.cpam); + expect(logoCaf).toEqual('Caf'); + expect(logoCarsat).toEqual('Carsat'); + expect(logoCpam).toEqual('Cpam'); }); }); diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts index d81c0bea5..8a8c3cd40 100644 --- a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts +++ b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts @@ -50,7 +50,7 @@ describe('ModalFilterComponent', () => { ]; component.checkedModules = modules; const evt = { target: { checked: true, value: '175' } }; - component.onCheckboxChange(evt, 'training', false); + component.onCheckboxChange(evt, 'training'); expect(component.checkedModules.length).toEqual(4); }); it('should remove a module to checkedModule array', () => { @@ -61,7 +61,7 @@ describe('ModalFilterComponent', () => { ]; component.checkedModules = modules; const evt = { target: { checked: false, value: '173' } }; - component.onCheckboxChange(evt, 'training', false); + component.onCheckboxChange(evt, 'training'); expect(component.checkedModules.length).toEqual(2); }); -- GitLab From 28437522d0b2a6ef8add74b16510b0c0c2d419d6 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 10:32:14 +0100 Subject: [PATCH 09/21] fix TU card --- .../components/card/card.component.spec.ts | 27 ++++++------------- .../components/card/card.component.ts | 6 ++--- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/app/structure-list/components/card/card.component.spec.ts b/src/app/structure-list/components/card/card.component.spec.ts index 37156feec..00dd7f4ad 100644 --- a/src/app/structure-list/components/card/card.component.spec.ts +++ b/src/app/structure-list/components/card/card.component.spec.ts @@ -5,7 +5,7 @@ import { HttpClientModule } from '@angular/common/http'; import { Structure } from '../../../models/structure.model'; import { OpeningDay } from '../../../models/openingDay.model'; -describe('CardComponent', () => { +fdescribe('CardComponent', () => { let component: CardComponent; let fixture: ComponentFixture<CardComponent>; let structure: Structure; @@ -23,13 +23,16 @@ describe('CardComponent', () => { id: 1, numero: '26-63', updatedAt: '2020-10-08T15:17:00.000Z', - nomDeLusager: 'Erwan Le luron', structureRepresentation: 'Un établissement principal (siège social)', structureName: 'Régie de Quartier Armstrong', structureType: 'Tiers-lieu & coworking, FabLab', description: "Association loi 1901 dont l'objet est l'insertion par l'économie social et solidaire", - n: 2, - adressWay: 21356, + address: { + numero: 2, + street: 'rue du test', + commune: 'villeurbanne', + }, + contactPhone: '04 72 21 03 07', contactMail: 'sguillet@rqa.fr', website: '', @@ -41,7 +44,7 @@ describe('CardComponent', () => { contactSurname: 'Séverine', fonction: 'Autres', pmrAccess: '', - choixMultiples: 'Tout public', + publicsAccompaniment: 'Tout public', exceptionalClosures: '', proceduresAccompaniment: 'Accompagnant CAF', autresAccompagnements: '', @@ -50,20 +53,6 @@ describe('CardComponent', () => { socialAndProfessional: 254, parentingHelp: '', digitalCultureSecurity: 264, - wifiEnAccesLibre: 'True', - nbComputers: '', - nombre: '', - tablettes: '', - bornesNumeriques: '', - imprimantes: '', - autresEspacesProposesParLaStructure: 'Espace libre service', - statutJuridique: '', - appartenezVousAUnReseauDeMediation: '', - precisezLequel: '', - idDeLitemStructureDansDirectus: 123, - statutDeLitemStructureDansDirectus: '', - idDeLitemOffreDansDirectus: '', - statut: 'Erreur lors du versement des données offre', hours: { monday: { open: true, diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts index ade585e5d..be8bff0b6 100644 --- a/src/app/structure-list/components/card/card.component.ts +++ b/src/app/structure-list/components/card/card.component.ts @@ -33,12 +33,12 @@ export class CardComponent implements OnInit { public getLabelTypeStructure(typeStructure: string[]): string { let label = ''; - typeStructure.forEach((type) => { + for (var i = 0; i < typeStructure.length; i++) { if (label) { label += ', '; } - label += typeStructureEnum[type]; - }); + label += typeStructureEnum[typeStructure[i]]; + } return label; } public cardHover(): void { -- GitLab From cdd9ee250e1630b5d0207f6efa911ee0c2af0272 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 11:25:42 +0100 Subject: [PATCH 10/21] fix error TU --- src/app/structure-list/components/card/card.component.spec.ts | 2 +- src/app/structure-list/components/card/card.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/structure-list/components/card/card.component.spec.ts b/src/app/structure-list/components/card/card.component.spec.ts index 00dd7f4ad..6550c1cfb 100644 --- a/src/app/structure-list/components/card/card.component.spec.ts +++ b/src/app/structure-list/components/card/card.component.spec.ts @@ -5,7 +5,7 @@ import { HttpClientModule } from '@angular/common/http'; import { Structure } from '../../../models/structure.model'; import { OpeningDay } from '../../../models/openingDay.model'; -fdescribe('CardComponent', () => { +describe('CardComponent', () => { let component: CardComponent; let fixture: ComponentFixture<CardComponent>; let structure: Structure; diff --git a/src/app/structure-list/components/card/card.component.ts b/src/app/structure-list/components/card/card.component.ts index be8bff0b6..e97788372 100644 --- a/src/app/structure-list/components/card/card.component.ts +++ b/src/app/structure-list/components/card/card.component.ts @@ -33,7 +33,7 @@ export class CardComponent implements OnInit { public getLabelTypeStructure(typeStructure: string[]): string { let label = ''; - for (var i = 0; i < typeStructure.length; i++) { + for (let i = 0; i < typeStructure.length; i++) { if (label) { label += ', '; } -- GitLab From 6fb51be0003d035902a563eb85ae36d6f838218d Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 11:34:43 +0100 Subject: [PATCH 11/21] fix tu --- .../structure-details.component.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/structure-list/components/structure-details/structure-details.component.spec.ts b/src/app/structure-list/components/structure-details/structure-details.component.spec.ts index 6254b606e..c11a13d30 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.spec.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.spec.ts @@ -1,29 +1,34 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; import { Structure } from '../../../models/structure.model'; import { AccessModality } from '../../enum/access-modality.enum'; import { Category } from '../../models/category.model'; import { Module } from '../../models/module.model'; import { StructureDetailsComponent } from './structure-details.component'; -describe('StructureDetailsComponent', () => { +fdescribe('StructureDetailsComponent', () => { let component: StructureDetailsComponent; let fixture: ComponentFixture<StructureDetailsComponent>; + const fakeActivatedRoute = { + snapshot: { data: {} }, + } as ActivatedRoute; beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [StructureDetailsComponent], - imports: [HttpClientTestingModule], + imports: [HttpClientTestingModule, RouterTestingModule], }).compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(StructureDetailsComponent); component = fixture.componentInstance; - fixture.detectChanges(); let structure: Structure = new Structure(); structure.baseSkills = ['123', '234', '817']; component.structure = structure; + fixture.detectChanges(); }); it('should create', () => { -- GitLab From c9247f8dcfa9e2df0a50a53e3664c7726ac87a9f Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 11:35:08 +0100 Subject: [PATCH 12/21] clean code --- .../structure-details/structure-details.component.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/app/structure-list/components/structure-details/structure-details.component.spec.ts b/src/app/structure-list/components/structure-details/structure-details.component.spec.ts index c11a13d30..d1e70665c 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.spec.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.spec.ts @@ -1,6 +1,5 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { ActivatedRoute } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { Structure } from '../../../models/structure.model'; import { AccessModality } from '../../enum/access-modality.enum'; @@ -8,12 +7,9 @@ import { Category } from '../../models/category.model'; import { Module } from '../../models/module.model'; import { StructureDetailsComponent } from './structure-details.component'; -fdescribe('StructureDetailsComponent', () => { +describe('StructureDetailsComponent', () => { let component: StructureDetailsComponent; let fixture: ComponentFixture<StructureDetailsComponent>; - const fakeActivatedRoute = { - snapshot: { data: {} }, - } as ActivatedRoute; beforeEach(async () => { await TestBed.configureTestingModule({ -- GitLab From f12d6a4575e96b61ab6781e953924c0fa3a25b2c Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 11:37:19 +0100 Subject: [PATCH 13/21] fix error tu --- .../components/logo-card/logo-card.component.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/shared/components/logo-card/logo-card.component.spec.ts b/src/app/shared/components/logo-card/logo-card.component.spec.ts index e0083e172..6ee59acff 100644 --- a/src/app/shared/components/logo-card/logo-card.component.spec.ts +++ b/src/app/shared/components/logo-card/logo-card.component.spec.ts @@ -24,11 +24,11 @@ describe('LogoCardComponent', () => { }); it('should return logo name with a string input', () => { - const logoCaf = component.getName(Demarches.accompagnantCaf); - const logoCarsat = component.getName(Demarches.carsat); - const logoCpam = component.getName(Demarches.cpam); - expect(logoCaf).toEqual('Caf'); - expect(logoCarsat).toEqual('Carsat'); - expect(logoCpam).toEqual('Cpam'); + const logoCaf = component.getName('accompagnantCaf'); + const logoCarsat = component.getName('carsat'); + const logoCpam = component.getName('cpam'); + expect(logoCaf).toEqual(Demarches.accompagnantCaf); + expect(logoCarsat).toEqual(Demarches.carsat); + expect(logoCpam).toEqual(Demarches.cpam); }); }); -- GitLab From 850c7a9fcb887ade0f29cd51b0c06cb643671493 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 11:40:48 +0100 Subject: [PATCH 14/21] fix error TU --- .../components/validator-form/validator-form.component.html | 2 +- .../components/validator-form/validator-form.component.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/components/validator-form/validator-form.component.html b/src/app/shared/components/validator-form/validator-form.component.html index 4cc6696be..55e0bf989 100644 --- a/src/app/shared/components/validator-form/validator-form.component.html +++ b/src/app/shared/components/validator-form/validator-form.component.html @@ -1,4 +1,4 @@ -<div *ngIf="control.invalid" class="alert"> +<div *ngIf="control && control.invalid" class="alert"> <div *ngIf="control.errors.required">Champ obligatoire</div> <div *ngIf="control.errors.pattern">{{ errorPattern }}</div> <div *ngIf="control.errors.mustMatch">{{ errorMustMatch }}</div> diff --git a/src/app/shared/components/validator-form/validator-form.component.spec.ts b/src/app/shared/components/validator-form/validator-form.component.spec.ts index 7e5ecc4cb..43a26651f 100644 --- a/src/app/shared/components/validator-form/validator-form.component.spec.ts +++ b/src/app/shared/components/validator-form/validator-form.component.spec.ts @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ValidatorFormComponent } from './validator-form.component'; -describe('button', () => { +fdescribe('validatorForm', () => { let component: ValidatorFormComponent; let fixture: ComponentFixture<ValidatorFormComponent>; -- GitLab From 6dd3eb18fb9badb28f301066710e2dccb5838deb Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 11:54:37 +0100 Subject: [PATCH 15/21] fix error TU --- .../validator-form/validator-form.component.spec.ts | 2 +- .../components/modal-filter/modal-filter.component.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/shared/components/validator-form/validator-form.component.spec.ts b/src/app/shared/components/validator-form/validator-form.component.spec.ts index 43a26651f..85f448156 100644 --- a/src/app/shared/components/validator-form/validator-form.component.spec.ts +++ b/src/app/shared/components/validator-form/validator-form.component.spec.ts @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ValidatorFormComponent } from './validator-form.component'; -fdescribe('validatorForm', () => { +describe('validatorForm', () => { let component: ValidatorFormComponent; let fixture: ComponentFixture<ValidatorFormComponent>; diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts index 8a8c3cd40..63f7e84f6 100644 --- a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts +++ b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts @@ -7,7 +7,7 @@ import { Module } from '../../models/module.model'; import { ModalFilterComponent } from './modal-filter.component'; -describe('ModalFilterComponent', () => { +fdescribe('ModalFilterComponent', () => { let component: ModalFilterComponent; let fixture: ComponentFixture<ModalFilterComponent>; @@ -76,7 +76,7 @@ describe('ModalFilterComponent', () => { { id: '167', text: 'training', count: 0 }, ]; component.checkedModules = modules; - const category: Category = new Category({ name: 'morefilters', modules: [modules[0], modules[1], modules[2]] }); + const category: Category = new Category({ id: 'morefilters', modules: [modules[0], modules[1], modules[2]] }); component.categories = [category]; component.clearFilters(); expect(component.checkedModules.length).toEqual(3); -- GitLab From a511172ed43761465b962d7e20685e788486205a Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 12:01:52 +0100 Subject: [PATCH 16/21] fix error TU --- src/app/app.component.spec.ts | 3 ++- src/app/profile/profile.component.spec.ts | 8 +++++--- src/app/reset-password/reset-password.component.spec.ts | 9 ++++++--- .../signin-modal/signin-modal.component.spec.ts | 2 ++ .../signup-modal/signup-modal.component.spec.ts | 4 ++++ .../modal-filter/modal-filter.component.spec.ts | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 3ccaf52ed..1a1d0edd2 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,3 +1,4 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; @@ -5,7 +6,7 @@ import { AppComponent } from './app.component'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [RouterTestingModule], + imports: [RouterTestingModule, HttpClientTestingModule], declarations: [AppComponent], }).compileComponents(); }); diff --git a/src/app/profile/profile.component.spec.ts b/src/app/profile/profile.component.spec.ts index e88012e7a..855f40fa1 100644 --- a/src/app/profile/profile.component.spec.ts +++ b/src/app/profile/profile.component.spec.ts @@ -1,4 +1,6 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; import { ProfileComponent } from './profile.component'; @@ -8,9 +10,9 @@ describe('ProfileComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ ProfileComponent ] - }) - .compileComponents(); + declarations: [ProfileComponent], + imports: [HttpClientTestingModule, ReactiveFormsModule], + }).compileComponents(); }); beforeEach(() => { diff --git a/src/app/reset-password/reset-password.component.spec.ts b/src/app/reset-password/reset-password.component.spec.ts index 92e44ad45..921329cb4 100644 --- a/src/app/reset-password/reset-password.component.spec.ts +++ b/src/app/reset-password/reset-password.component.spec.ts @@ -1,4 +1,7 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { RouterTestingModule } from '@angular/router/testing'; import { ResetPasswordComponent } from './reset-password.component'; @@ -8,9 +11,9 @@ describe('ResetPasswordComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ ResetPasswordComponent ] - }) - .compileComponents(); + declarations: [ResetPasswordComponent], + imports: [ReactiveFormsModule, HttpClientTestingModule, RouterTestingModule], + }).compileComponents(); }); beforeEach(() => { diff --git a/src/app/shared/components/signin-modal/signin-modal.component.spec.ts b/src/app/shared/components/signin-modal/signin-modal.component.spec.ts index d7bcc9ccb..45e193fe1 100644 --- a/src/app/shared/components/signin-modal/signin-modal.component.spec.ts +++ b/src/app/shared/components/signin-modal/signin-modal.component.spec.ts @@ -1,3 +1,4 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { SignInModalComponent } from './signin-modal.component'; @@ -9,6 +10,7 @@ describe('SignInModalComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [SignInModalComponent], + imports: [HttpClientTestingModule], }).compileComponents(); }); diff --git a/src/app/shared/components/signup-modal/signup-modal.component.spec.ts b/src/app/shared/components/signup-modal/signup-modal.component.spec.ts index dfc6badbb..af1e49062 100644 --- a/src/app/shared/components/signup-modal/signup-modal.component.spec.ts +++ b/src/app/shared/components/signup-modal/signup-modal.component.spec.ts @@ -1,4 +1,7 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { RouterTestingModule } from '@angular/router/testing'; import { SignUpModalComponent } from './signup-modal.component'; @@ -9,6 +12,7 @@ describe('SignUpModalComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [SignUpModalComponent], + imports: [ReactiveFormsModule, RouterTestingModule, HttpClientTestingModule], }).compileComponents(); }); diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts index 63f7e84f6..085835199 100644 --- a/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts +++ b/src/app/structure-list/components/modal-filter/modal-filter.component.spec.ts @@ -7,7 +7,7 @@ import { Module } from '../../models/module.model'; import { ModalFilterComponent } from './modal-filter.component'; -fdescribe('ModalFilterComponent', () => { +describe('ModalFilterComponent', () => { let component: ModalFilterComponent; let fixture: ComponentFixture<ModalFilterComponent>; -- GitLab From b95a779cb4a96e20d99051af0d1d512d564d6d8d Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 12:06:52 +0100 Subject: [PATCH 17/21] fix error TU imports --- src/app/header/header.component.spec.ts | 3 ++- src/app/reset-email/reset-email.component.spec.ts | 3 +++ src/app/services/auth.service.spec.ts | 5 ++++- .../user-verification/user-verification.component.spec.ts | 8 +++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts index 6e760707f..bd80c9e4d 100644 --- a/src/app/header/header.component.spec.ts +++ b/src/app/header/header.component.spec.ts @@ -1,3 +1,4 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; @@ -9,7 +10,7 @@ describe('HeaderComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [RouterTestingModule], + imports: [RouterTestingModule, HttpClientTestingModule], declarations: [HeaderComponent], }).compileComponents(); }); diff --git a/src/app/reset-email/reset-email.component.spec.ts b/src/app/reset-email/reset-email.component.spec.ts index 126ebbac5..0f79540dd 100644 --- a/src/app/reset-email/reset-email.component.spec.ts +++ b/src/app/reset-email/reset-email.component.spec.ts @@ -1,4 +1,6 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { ResetEmailComponent } from './reset-email.component'; @@ -9,6 +11,7 @@ describe('ResetEmailComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ResetEmailComponent], + imports: [RouterTestingModule, HttpClientTestingModule], }).compileComponents(); }); diff --git a/src/app/services/auth.service.spec.ts b/src/app/services/auth.service.spec.ts index f1251cacf..85272789d 100644 --- a/src/app/services/auth.service.spec.ts +++ b/src/app/services/auth.service.spec.ts @@ -1,3 +1,4 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; import { AuthService } from './auth.service'; @@ -6,7 +7,9 @@ describe('AuthService', () => { let service: AuthService; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + }); service = TestBed.inject(AuthService); }); diff --git a/src/app/user-verification/user-verification.component.spec.ts b/src/app/user-verification/user-verification.component.spec.ts index 241a7b6ad..48c1ec0b0 100644 --- a/src/app/user-verification/user-verification.component.spec.ts +++ b/src/app/user-verification/user-verification.component.spec.ts @@ -1,4 +1,6 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; import { UserVerificationComponent } from './user-verification.component'; @@ -8,9 +10,9 @@ describe('UserVerificationComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ UserVerificationComponent ] - }) - .compileComponents(); + declarations: [UserVerificationComponent], + imports: [RouterTestingModule, HttpClientTestingModule], + }).compileComponents(); }); beforeEach(() => { -- GitLab From 8d429181c1577f067efc6342b7053c590cc6d032 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 12:10:19 +0100 Subject: [PATCH 18/21] fix error TU --- src/app/map/services/map.service.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/map/services/map.service.spec.ts b/src/app/map/services/map.service.spec.ts index ae117847d..e4d405c3f 100644 --- a/src/app/map/services/map.service.spec.ts +++ b/src/app/map/services/map.service.spec.ts @@ -22,19 +22,19 @@ describe('MapService', () => { }); it('should add marker to map with icon ic_marker.png', () => { const marker = service.createMarker(45.764043, 4.835659, 1); - expect(marker.getIcon().options.iconSize).toEqual([35, 41]); - expect(marker.getIcon().options.iconAnchor).toEqual([13, 41]); + expect(marker.getIcon().options.iconSize).toEqual([19, 24]); + expect(marker.getIcon().options.iconAnchor).toEqual([9, 0]); }); - it('should cerate marker with tooltip', () => { + it('should cerate marker with popup', () => { const marker = service.createMarker(45.764043, 4.835659, 1, null, '<p>Hello <br/>World !</p>'); - expect(marker.getTooltip().getContent()).toEqual('<p>Hello <br/>World !</p>'); + expect(marker.getPopup().getContent()).toEqual('<p>Hello <br/>World !</p>'); }); it('should get marker', () => { - const marker = service.createMarker(45.764043, 4.835659, 1, null, '<p>Hello <br/>World !</p>'); - expect(marker).toEqual(service.getMarker(1)); + const marker = service.createMarker(45.764043, 4.835659, 1, 53, '<p>Hello <br/>World !</p>'); + expect(marker).toEqual(service.getMarker(53)); }); it('should not get marker, with missing id', () => { service.createMarker(45.764043, 4.835659, 1, null, '<p>Hello <br/>World !</p>'); -- GitLab From d6d87e4d880b8bb4d394477443d1efc55574572a Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Fri, 8 Jan 2021 12:31:35 +0100 Subject: [PATCH 19/21] feat(claimStructure) : add TU --- .../create-account-form.component.spec.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/app/shared/components/create-account-form/create-account-form.component.spec.ts b/src/app/shared/components/create-account-form/create-account-form.component.spec.ts index 66d5e6023..259b99060 100644 --- a/src/app/shared/components/create-account-form/create-account-form.component.spec.ts +++ b/src/app/shared/components/create-account-form/create-account-form.component.spec.ts @@ -1,11 +1,23 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { MustMatch } from '../../validator/form'; import { CreateAccountFormComponent } from './create-account-form.component'; -describe('ModalComponent', () => { +describe('CreateAccountFormComponent', () => { let component: CreateAccountFormComponent; let fixture: ComponentFixture<CreateAccountFormComponent>; - + const accountForm = new FormGroup( + { + email: new FormControl('test@test.fr', Validators.required), + password: new FormControl('Testaze123!', [ + Validators.required, + Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/), + ]), + confirmPassword: new FormControl('Testaze123!'), + }, + [MustMatch('password', 'confirmPassword')] + ); beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [CreateAccountFormComponent], @@ -15,10 +27,25 @@ describe('ModalComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(CreateAccountFormComponent); component = fixture.componentInstance; + fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + + it('should emit the form', () => { + spyOn(component.submitForm, 'emit'); + component.onSubmit(accountForm); + expect(component.submitForm.emit).toHaveBeenCalled(); + expect(component.submitForm.emit).toHaveBeenCalledWith(accountForm); + }); + + it('should return control', () => { + component.accountForm = accountForm; + const result = component.getAccountControl('email'); + const control = accountForm.get('email'); + expect(result).toEqual(control); + }); }); -- GitLab From 6e9d3879c56512ac56acec479314a8098708fbf0 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Mon, 11 Jan 2021 11:34:07 +0100 Subject: [PATCH 20/21] fix: change claim from profile to structure --- src/app/form/form.component.ts | 4 ++-- src/app/profile/services/profile.service.ts | 9 +++------ src/app/services/structure.service.ts | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 29871f36b..0a6023941 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -247,14 +247,14 @@ export class FormComponent implements OnInit { } public onSubmitClaim(accountForm: FormGroup): void { if (!this.structureForm.invalid && accountForm.valid) { - this.profileService.claimStructureWithoutAccount(this.structureId, accountForm.value).subscribe((user) => { + this.profileService.createUserandLinkStructure(this.structureId, accountForm.value).subscribe((user) => { this.closeEvent.emit(this.structureForm.value); }); } } public onSubmitClaimWithAccount(): void { - this.profileService + this.structureService .claimStructureWithAccount(this.structureId, this.profile.email) .subscribe((structuresLinked) => { this.profile.structuresLink = structuresLinked; diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index cf7dc2c81..78049a5f1 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -35,12 +35,9 @@ export class ProfileService { this.currentProfile = null; } - public claimStructureWithoutAccount(id: number, body: User): Observable<User> { - return this.http.post<any>(`${this.baseUrl}/claim/` + id, body); - } - - public claimStructureWithAccount(id: number, email: string): Observable<number[]> { - return this.http.post<any>(`${this.baseUrl}/claimWithAccount/` + id, { email }); + public createUserandLinkStructure(id: number, body: User): Observable<User> { + body.structuresLink = [id]; + return this.http.post<any>(`${this.baseUrl}`, body); } public changePassword(newPassword: string, oldPassword: string): Observable<User> { diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index c28d063e5..b4ff54b1c 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -17,27 +17,34 @@ import { User } from '../models/user.model'; providedIn: 'root', }) export class StructureService { + private readonly baseUrl = 'api/structures'; constructor(private http: HttpClient) {} + //TODO: remove ? public createStructure(structure: Structure, profile: User): Observable<Structure> { const idUser = profile.email; - return this.http.post('/api/structures', { structure, idUser }).pipe(map((item: Structure) => new Structure(item))); + return this.http.post(`${this.baseUrl}`, { structure, idUser }).pipe(map((item: Structure) => new Structure(item))); } public postStructure(id: number, structure: Structure): Observable<Structure> { structure.updatedAt = new Date().toString(); - return this.http.post('/api/structures/' + id, structure).pipe(map((item: Structure) => new Structure(item))); + return this.http.post(`${this.baseUrl}/${id}`, structure).pipe(map((item: Structure) => new Structure(item))); } public isClaimed(id: number): Observable<any> { - return this.http.get('/api/structures/isClaimed/' + id); + return this.http.get(`${this.baseUrl}/${id}/isClaimed`); } + + public claimStructureWithAccount(id: number, email: string): Observable<number[]> { + return this.http.post<any>(`${this.baseUrl}/${id}/claim`, { email }); + } + public getStructure(id: number): Observable<Structure> { - return this.http.get('/api/structures/' + id).pipe(map((item: any) => new Structure(item))); + return this.http.get(`${this.baseUrl}/${id}`).pipe(map((item: any) => new Structure(item))); } public getStructures(filters: Filter[]): Observable<Structure[]> { if (filters && filters.length > 0) { - let requestUrl = '/api/structures/search'; + let requestUrl = `${this.baseUrl}/search`; const queryString = _.find(filters, { name: 'query' }); if (queryString) { _.remove(filters, { name: 'query' }); @@ -48,7 +55,7 @@ export class StructureService { .post(requestUrl, { filters: formatedFilters }) .pipe(map((data: any[]) => data.map((item) => new Structure(item)))); } else { - return this.http.get('/api/structures').pipe(map((data: any[]) => data.map((item) => new Structure(item)))); + return this.http.get(`${this.baseUrl}`).pipe(map((data: any[]) => data.map((item) => new Structure(item)))); } } -- GitLab From 7faf3e4645caa2befb4e03e47962314c9de7b19c Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Mon, 11 Jan 2021 12:02:07 +0100 Subject: [PATCH 21/21] fix: function name and clean imports --- src/app/form/form.component.ts | 22 +++++++--------------- src/app/services/structure.service.ts | 5 ++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 0a6023941..f8fd2d78f 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { AbstractControl, Form, FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms'; import { Structure } from '../models/structure.model'; import { Time } from '../models/time.model'; import { Day } from '../models/day.model'; @@ -43,7 +43,6 @@ export class FormComponent implements OnInit { constructor( private structureService: StructureService, private searchService: SearchService, - private formBuilder: FormBuilder, private profileService: ProfileService ) {} @@ -265,21 +264,14 @@ export class FormComponent implements OnInit { public onSubmit(structureForm: FormGroup): void { if (structureForm.valid) { if (this.structureId) { - this.structureService.postStructure(this.structureId, structureForm.value).subscribe( - (structure: Structure) => { - this.closeEvent.emit(structure); - }, - (err) => {} - ); + this.structureService.editStructure(this.structureId, structureForm.value).subscribe((structure: Structure) => { + this.closeEvent.emit(structure); + }); } else { - this.structureService.createStructure(structureForm.value, this.profile).subscribe( - (structure: Structure) => { - this.closeEvent.emit(structure); - }, - (err) => {} - ); + this.structureService.createStructure(structureForm.value, this.profile).subscribe((structure: Structure) => { + this.closeEvent.emit(structure); + }); } - } else { } } } diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index b4ff54b1c..40118194d 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -20,15 +20,14 @@ export class StructureService { private readonly baseUrl = 'api/structures'; constructor(private http: HttpClient) {} - //TODO: remove ? public createStructure(structure: Structure, profile: User): Observable<Structure> { const idUser = profile.email; return this.http.post(`${this.baseUrl}`, { structure, idUser }).pipe(map((item: Structure) => new Structure(item))); } - public postStructure(id: number, structure: Structure): Observable<Structure> { + public editStructure(id: number, structure: Structure): Observable<Structure> { structure.updatedAt = new Date().toString(); - return this.http.post(`${this.baseUrl}/${id}`, structure).pipe(map((item: Structure) => new Structure(item))); + return this.http.put(`${this.baseUrl}/${id}`, structure).pipe(map((item: Structure) => new Structure(item))); } public isClaimed(id: number): Observable<any> { -- GitLab