diff --git a/src/app/models/structure-type.model.ts b/src/app/models/structure-type.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..91d50c378a4e839bda563e98a9b76742ca8d2e6c --- /dev/null +++ b/src/app/models/structure-type.model.ts @@ -0,0 +1,8 @@ +export class StructureType { + values: string[]; + name: string; + + constructor(obj?: any) { + Object.assign(this, obj); + } +} diff --git a/src/app/services/structure-type.service.ts b/src/app/services/structure-type.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..0f18c3bcaf20b994e6949c763c8d4aa829440904 --- /dev/null +++ b/src/app/services/structure-type.service.ts @@ -0,0 +1,18 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { StructureType } from '../models/structure-type.model'; + +@Injectable({ + providedIn: 'root', +}) +export class StructureTypeService { + constructor(private http: HttpClient) {} + + /** + * Retrive all tcl stop point around given coord + */ + public getStructureTypes(): Observable<any> { + return this.http.get<StructureType[]>('/api/structure-type'); + } +} diff --git a/src/app/shared/components/structure-type-picker/structure-type-picker.component.html b/src/app/shared/components/structure-type-picker/structure-type-picker.component.html index cdeca18aa0ede33413f3f73a9a8b841e7768b223..3c6fa1bb62feabd9dc263db1b43c65c507766189 100644 --- a/src/app/shared/components/structure-type-picker/structure-type-picker.component.html +++ b/src/app/shared/components/structure-type-picker/structure-type-picker.component.html @@ -1,11 +1,15 @@ <div class="container" fxLayout="column"> <div fxLayout="row" fxLayoutAlign="center center" fxLayoutGap="30px"> - <div class="boutonSection" [ngClass]="{ selectedType: type.name == pickedType }" *ngFor="let type of type_data"> + <div + class="boutonSection" + [ngClass]="{ selectedType: type.name == pickedType }" + *ngFor="let type of structureTypes" + > <button (click)="pickType(type.name)"> <div class="containerBtn"> <div class="btn"> <svg aria-hidden="true"> - <use [attr.xlink:href]="'assets/form/sprite.svg#' + type.logo"></use> + <use [attr.xlink:href]="'assets/form/sprite.svg#' + getStructureTypeIcon(type.name)"></use> </svg> </div> </div> diff --git a/src/app/shared/components/structure-type-picker/structure-type-picker.component.ts b/src/app/shared/components/structure-type-picker/structure-type-picker.component.ts index cea43c01f6c90353343ccd351718dc6b20ec6365..7de31248696706fbd40a1b25dde2dcbf4746542a 100644 --- a/src/app/shared/components/structure-type-picker/structure-type-picker.component.ts +++ b/src/app/shared/components/structure-type-picker/structure-type-picker.component.ts @@ -1,4 +1,12 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { StructureType } from '../../../models/structure-type.model'; +import { StructureTypeService } from '../../../services/structure-type.service'; + +export enum structureTypes { + public = 'Publique', + private = 'Privée à but non lucratif', + privateLucratif = 'Privée à but lucratif', +} @Component({ selector: 'app-structure-type-picker', @@ -7,70 +15,56 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; }) export class StructureTypePickerComponent implements OnInit { public pickedType: string; + public structureTypes: StructureType[]; @Input() public pickedChoice?: string; @Output() selectedType: EventEmitter<string> = new EventEmitter<string>(); - public type_data = [ - { - name: 'Publique', - logo: 'typeStructure_public', - choices: [ - 'Mairie', - 'CAF', - 'CCAS', - 'Maison de la métropole', - 'CARSAT', - 'Médiathèque/Bibliothèque', - 'Pôle Emploi', - 'Préfecture', - 'BIJ/PIJ', - ], - }, - { - name: 'Privée à but non lucratif', - logo: 'typeStructure_private', - choices: [ - 'Association', - 'Centre socio-culturel', - 'MJC / Cyberbase', - 'PIMMS', - 'Structure information jeunesse (SIJ)', - 'Missions locales ', - ], - }, - { - name: 'Privée à but lucratif', - logo: 'typeStructure_privateLucratif', - choices: ['Structure de formation', "Structure d'insertion"], - }, - ]; - constructor() {} + constructor(private structureTypeService: StructureTypeService) {} ngOnInit() { if (this.pickedChoice) { this.pickedType = this.getType(this.pickedChoice); } + this.structureTypeService.getStructureTypes().subscribe((types) => { + this.structureTypes = types; + }); } - getType(nameChoice: string): string { - return this.type_data.filter((type) => { - if (type.choices.includes(nameChoice)) { + public getType(nameChoice: string): string { + return this.structureTypes.filter((type) => { + if (type.values.includes(nameChoice)) { return type.name; } })[0].name; } - getChoices(nameType: string): string[] { - return this.type_data.filter((type) => { + + public getChoices(nameType: string): string[] { + return this.structureTypes.filter((type) => { if (type.name == nameType) { - return type.choices; + return type.values; } - })[0].choices; + })[0].values; } - pickType(type: string): void { + + public pickType(type: string): void { this.pickedType = type; } - pickChoice(choice: string): void { + + public pickChoice(choice: string): void { this.pickedChoice = choice; this.selectedType.emit(choice); } + + public getStructureTypeIcon(type: string): string { + switch (type) { + case structureTypes.public: + return 'typeStructure_public'; + case structureTypes.private: + return 'typeStructure_private'; + case structureTypes.privateLucratif: + return 'typeStructure_privateLucratif'; + default: + throw new Error('Structure type not handle'); + } + } } 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 305838f568c23997cc9a6e1d2af23b6baeb79dd1..3e8aae19d4ae9606da566d7c21e8c4259a394793 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 @@ -86,14 +86,15 @@ <a *ngIf="!isClaimed && userIsLoggedIn()" (click)="toggleClaimModal()" class="primary" tabindex="0" >Revendiquer cette structure</a > - <a + <!-- temporary remove edit --> + <!-- <a *ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()" (click)="editStructure()" class="primary" tabindex="0" > Modifier cette structure - </a> + </a> --> <a *ngIf="profileService.isAdmin()" (click)="toggleDeleteModal()" class="primary" tabindex="0"> Supprimer cette structure </a>