diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 3ccaf52ed887eb8aaa801474e74e87ac96c07e69..1a1d0edd2fdb7f09584a8439906e513aa042fe47 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/form/form.component.html b/src/app/form/form.component.html index e662a3d76d6a81059aec8aeb5d30337f1ec6ad8a..7804991513a421522737bf4bd7d55fa91dc6c0a5 100644 --- a/src/app/form/form.component.html +++ b/src/app/form/form.component.html @@ -1,245 +1,271 @@ -<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> - <app-validator-form [control]="getStructureControl('description')"></app-validator-form> - <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>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> + <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 && !profile" + (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 14dbd367db5fec418a7b3dd8ae56477b85c5108d..8db71778cd2627ee8691f6325efd44662bf13364 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.spec.ts b/src/app/form/form.component.spec.ts index 54eeeb118a7b21a4d86c990c93811398ef5cbf5c..83f6d5e3d547b07fadcd128c30934f1fff0e885c 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/form/form.component.ts b/src/app/form/form.component.ts index dedb2ae2baa74350d9c3283dfbfdb5d4f757ce80..f8fd2d78f9d45dbdfcf5cf7dd8699c3fa3ea90fd 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -11,6 +11,7 @@ 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 { ProfileService } from '../profile/services/profile.service'; import { User } from '../models/user.model'; @Component({ @@ -20,9 +21,13 @@ import { User } from '../models/user.model'; }) export class FormComponent implements OnInit { @Input() public idStructure?: number; + @Input() public isEditMode: boolean; @Input() public profile?: User; @Output() closeEvent = new EventEmitter<Structure>(); public structureForm: FormGroup; + + public userAlreadyExist = false; + public equipmentAccess = EquipmentAccess; public weekDay = WeekDayEnum; public typeStructure = typeStructureEnum; @@ -35,7 +40,11 @@ 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 profileService: ProfileService + ) {} ngOnInit(): void { if (this.idStructure) { @@ -75,6 +84,7 @@ export class FormComponent implements OnInit { } }); }); + this.searchService.getCategoriesTraining().subscribe((t) => { this.categoryTraining = t; }); @@ -143,6 +153,13 @@ export class FormComponent implements OnInit { equipmentsDetails: new FormControl(structure.equipmentsDetails), equipmentsAccessType: this.loadArrayForCheckbox(structure.equipmentsAccessType, false), }); + + // Disable form when it's to claim. + if (!this.isEditMode && this.idStructure) { + Object.keys(this.structureForm.controls).forEach((controlName) => { + this.structureForm.controls[controlName].disable(); + }); + } } private loadArrayForCheckbox(array: string[], isRequired: boolean): FormArray { @@ -151,7 +168,6 @@ export class FormComponent implements OnInit { isRequired ? Validators.required : Validators.nullValidator ); } - public getStructureControl(nameControl: string): AbstractControl { return this.structureForm.get(nameControl); } @@ -186,8 +202,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), }); } @@ -228,24 +244,34 @@ export class FormComponent implements OnInit { } return false; } + public onSubmitClaim(accountForm: FormGroup): void { + if (!this.structureForm.invalid && accountForm.valid) { + this.profileService.createUserandLinkStructure(this.structureId, accountForm.value).subscribe((user) => { + this.closeEvent.emit(this.structureForm.value); + }); + } + } + + public onSubmitClaimWithAccount(): void { + this.structureService + .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 { 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/header/header.component.spec.ts b/src/app/header/header.component.spec.ts index 6e760707ff97617a977cfc619c02c079cfd5c644..bd80c9e4de57072b73fc13e4540e882568cfe8fa 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/map/services/map.service.spec.ts b/src/app/map/services/map.service.spec.ts index ca4b202d0b46c786fe7e90b1b554daa0b793689e..e4d405c3fb227f95433c198c2d822075acffa53b 100644 --- a/src/app/map/services/map.service.spec.ts +++ b/src/app/map/services/map.service.spec.ts @@ -22,22 +22,22 @@ 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', () => { - const marker = service.createMarker(45.764043, 4.835659, 1, '<p>Hello <br/>World !</p>'); + 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, '<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, '<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/profile/profile.component.html b/src/app/profile/profile.component.html index 7e26fd2292017a79dfa4a9c57e9f7e8878a43b21..0216130a4cb92db883e763248ed71fa004b0525c 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)="toogleAddStructure()">Ajouter une structure</button> <button (click)="toogleChangeEmail()">Changer d'email</button> <form diff --git a/src/app/profile/profile.component.spec.ts b/src/app/profile/profile.component.spec.ts index e88012e7aeab34312f88c177994686deb064e20b..855f40fa17cece8f47801728546a56d8e32c7721 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/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index 78e6a3c1edd892c3edb2cc3d65599f9dfa87ae61..78049a5f10c0a161562a6918fed5426385aebcf9 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,27 +9,37 @@ 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 removeProfile(): void { + this.currentProfile = null; + } + + 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> { return this.http.post<any>(`${this.baseUrl}/change-password`, { newPassword, oldPassword }); } diff --git a/src/app/reset-email/reset-email.component.spec.ts b/src/app/reset-email/reset-email.component.spec.ts index 126ebbac503a4ec775ad1dea0c0e06f4171c7344..0f79540ddf3e3668b06c5c573be1736897edefe4 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/reset-password/reset-password.component.spec.ts b/src/app/reset-password/reset-password.component.spec.ts index 92e44ad4534e2126ee299a3dcfce553d9a95ea0f..921329cb4bae7a946eab9234cc72e5bd490ca390 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/services/auth.service.spec.ts b/src/app/services/auth.service.spec.ts index f1251cacf9dda3b3bd9dc5222583fafa110ffe8f..85272789d299a72ab01fcb1066b4f6d063f05247 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/services/structure.service.ts b/src/app/services/structure.service.ts index 0c8192ceaabdb7b91c7138e4dcb275b136595be0..40118194df608cb916f0ab6b25eea29db1bf1298 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -17,24 +17,33 @@ import { User } from '../models/user.model'; providedIn: 'root', }) export class StructureService { + private readonly baseUrl = 'api/structures'; constructor(private http: HttpClient) {} 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> { + public editStructure(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.put(`${this.baseUrl}/${id}`, structure).pipe(map((item: Structure) => new Structure(item))); + } + + public isClaimed(id: number): Observable<any> { + 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' }); @@ -45,7 +54,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)))); } } 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 0000000000000000000000000000000000000000..e8a4bd04558a327bbc8fd9c4850e6b57e357a015 --- /dev/null +++ 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">Valider</button> + </div> +</form> 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..259b99060fe3314017597122b7ce9e1e2eaac102 --- /dev/null +++ b/src/app/shared/components/create-account-form/create-account-form.component.spec.ts @@ -0,0 +1,51 @@ +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('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], + }).compileComponents(); + }); + + 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); + }); +}); 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 0000000000000000000000000000000000000000..2ae7b4136730d0497ed5a5a49c30a5e054bf0be5 --- /dev/null +++ b/src/app/shared/components/create-account-form/create-account-form.component.ts @@ -0,0 +1,40 @@ +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', + templateUrl: './create-account-form.component.html', + styleUrls: ['./create-account-form.component.scss'], +}) +export class CreateAccountFormComponent implements OnInit { + constructor() {} + public accountForm: FormGroup; + public submitted: boolean = false; + @Output() public submitForm = new EventEmitter<FormGroup>(); + + 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/index.ts b/src/app/shared/components/index.ts index 7eb5744bb6cefd8c4740e69c8534260bfb563ef5..89b310d7237b90231eb9b548fc868546dfd8290f 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, ]; 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 32b67d9f0b8743494662bef0f94db4be72968eb7..6ee59acffee05435dca12ab5df407bc56201dac0 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('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); }); }); 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 4d0b4c3de3b555027d9551d422bd871fd372abda..d8d32764aff38dc22474a6c36b8ab0cc1b452541 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 (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.spec.ts b/src/app/shared/components/signin-modal/signin-modal.component.spec.ts index d7bcc9ccbd538ed5f68655312242b1093cdac0ae..45e193fe145fed7b8e79258bd132a2d3736ad372 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/signin-modal/signin-modal.component.ts b/src/app/shared/components/signin-modal/signin-modal.component.ts index 253ec9136e9f410ff1a85d862d04430024d42ae8..d76097a7ba18bcd8003f6bc638a862be22095a4e 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/signup-modal/signup-modal.component.spec.ts b/src/app/shared/components/signup-modal/signup-modal.component.spec.ts index dfc6badbb2d213984c67aab883c17f7f85c44a5e..af1e490623d88dbb00612d7fc497b03198a9dce6 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/shared/components/validator-form/validator-form.component.html b/src/app/shared/components/validator-form/validator-form.component.html index a1494a2dfb91c000c20e94498600e958b07a8b9d..55e0bf9894b00431aad79ac6275121f31cd5b1c4 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 && 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/shared/components/validator-form/validator-form.component.spec.ts b/src/app/shared/components/validator-form/validator-form.component.spec.ts index 7e5ecc4cb7aa019ebbac7e6de0a7281b09879651..85f448156bdecd7672eb2e403aaac73c659fcd35 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', () => { +describe('validatorForm', () => { let component: ValidatorFormComponent; let fixture: ComponentFixture<ValidatorFormComponent>; 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 f226ca915a93341d4a919bbba57013a73c2f491c..cc10fe185e67d0392ba2f46850eeeea1fc490c61 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'; + } + } } 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 37156feec2e79471944a97882e17adfbeceaec3f..6550c1cfb85cb915def03259a1b9f85f74ce4c14 100644 --- a/src/app/structure-list/components/card/card.component.spec.ts +++ b/src/app/structure-list/components/card/card.component.spec.ts @@ -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 ade585e5d8d4753dfb28d46ac6c6b0e15bcddb59..e9778837277fa60e9a2ad27a4ff598d13c29fb7c 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 (let i = 0; i < typeStructure.length; i++) { if (label) { label += ', '; } - label += typeStructureEnum[type]; - }); + label += typeStructureEnum[typeStructure[i]]; + } return label; } public cardHover(): void { 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 d81c0bea51f58226b6a965e1961d508d2e6c0f93..08583519907633fe953eb0ef7551c451e787c89d 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); }); @@ -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); 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 5412f1e53091817c7436e1d935df5dfe00b48e80..95e09eeb66082056737556816b5401158382b053 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,15 +1,22 @@ <app-structureForm *ngIf="showForm" [idStructure]="structure.id" + [isEditMode]="isEditMode" + [profile]="currentProfile" (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="end center"> - <button *ngIf="profileService.isLinkedToStructure(structure.id)" (click)="displayForm()"> - Modifier la structure + <div fxLayout="row" fxLayoutAlign="center center" *ngIf="!isClaimed"> + <button (click)="claimStructure()">Revendiquer</button> + </div> + <div fxLayout="row" fxLayoutAlign="center center"> + <button *ngIf="profileService.isLinkedToStructure(structure.id)" (click)="editStructure()"> + Modifier ma structure </button> + </div> + <div fxLayout="row" fxLayoutAlign="end center"> <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.spec.ts b/src/app/structure-list/components/structure-details/structure-details.component.spec.ts index 6254b606ee48ec0d66260bf7ff820e3020cae453..d1e70665c38558bbc6f00435bab37ff7d5237aef 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,5 +1,6 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +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'; @@ -13,17 +14,17 @@ describe('StructureDetailsComponent', () => { 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', () => { 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 cf521ac418ad11c8d836ebbcacdf232c6dc7d4e4..ef9efeb2ddac4d9310e1ee81fd27dd5fb7f66c80 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,10 +9,12 @@ 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'; import { TclService } from '../../../services/tcl.service'; import { TclStopPoint } from '../../../models/tclStopPoint.model'; 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', @@ -32,14 +34,19 @@ export class StructureDetailsComponent implements OnInit { public printMode = false; public isOtherSection = false; public showForm = false; + public isClaimed: boolean = null; + public isLoading: boolean = false; + public isEditMode: boolean = false; public currentProfile: User; constructor( route: ActivatedRoute, private printService: PrintService, + private searchService: SearchService, + private structureService: StructureService, private tclService: TclService, private profileService: ProfileService, - private searchService: SearchService + private authService: AuthService ) { route.url.subscribe((url) => { if (url[0].path === 'structure') { @@ -50,31 +57,34 @@ export class StructureDetailsComponent implements OnInit { } ngOnInit(): void { - this.profileService.getProfile().then((p: User) => { - this.currentProfile = p; - }); - this.setReferentiels(); - const index = this.structure.proceduresAccompaniment.indexOf('autres'); - if (index > -1) { - this.structure.proceduresAccompaniment.splice(index, 1); - this.isOtherSection = true; + this.isLoading = true; + if (this.authService.isLoggedIn()) { + this.profileService.getProfile().then((p: User) => { + this.currentProfile = p; + }); } // GetTclStopPoints this.getTclStopPoints(); - } - - private setReferentiels(): void { - this.searchService.getCategoriesTraining().subscribe((referentiels) => { - referentiels.forEach((referentiel) => { - if (referentiel.isBaseSkills()) { - this.baseSkillssReferentiel = referentiel; - } else if (referentiel.isRigthtsAccess()) { - this.accessRightsReferentiel = referentiel; + 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; } }); } @@ -131,7 +141,16 @@ 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; } @@ -139,8 +158,8 @@ export class StructureDetailsComponent implements OnInit { public updateStructure(s: Structure): void { this.structure = new Structure({ ...this.structure, ...s }); this.updatedStructure.emit(this.structure); - this.setReferentiels(); this.displayForm(); + this.ngOnInit(); } public getAccessIcon(accessModality: AccessModality): string { switch (accessModality) { diff --git a/src/app/structure-list/structure-list.component.spec.ts b/src/app/structure-list/structure-list.component.spec.ts index 45ed7ac0e857548b415c9c2c16f90842b6ac47dc..793f39969e1010251686b75b678a9078b9f60352 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]); }); diff --git a/src/app/user-verification/user-verification.component.spec.ts b/src/app/user-verification/user-verification.component.spec.ts index 241a7b6ad2873d8422d1b0d5563d9e0d77a0a3ec..48c1ec0b0bd22a386651a80588023d0f0d844415 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(() => {