Skip to content
Snippets Groups Projects
Commit 8d7aa8e2 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat: move structureType to back

parent 5d0bd5b2
3 merge requests!68Recette,!67Dev,!66Fix/form design create structure
export class StructureType {
values: string[];
name: string;
constructor(obj?: any) {
Object.assign(this, obj);
}
}
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');
}
}
<div class="container" fxLayout="column"> <div class="container" fxLayout="column">
<div fxLayout="row" fxLayoutAlign="center center" fxLayoutGap="30px"> <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)"> <button (click)="pickType(type.name)">
<div class="containerBtn"> <div class="containerBtn">
<div class="btn"> <div class="btn">
<svg aria-hidden="true"> <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> </svg>
</div> </div>
</div> </div>
......
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; 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({ @Component({
selector: 'app-structure-type-picker', selector: 'app-structure-type-picker',
...@@ -7,70 +15,56 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; ...@@ -7,70 +15,56 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
}) })
export class StructureTypePickerComponent implements OnInit { export class StructureTypePickerComponent implements OnInit {
public pickedType: string; public pickedType: string;
public structureTypes: StructureType[];
@Input() public pickedChoice?: string; @Input() public pickedChoice?: string;
@Output() selectedType: EventEmitter<string> = new EventEmitter<string>(); @Output() selectedType: EventEmitter<string> = new EventEmitter<string>();
public type_data = [ constructor(private structureTypeService: StructureTypeService) {}
{
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() {}
ngOnInit() { ngOnInit() {
if (this.pickedChoice) { if (this.pickedChoice) {
this.pickedType = this.getType(this.pickedChoice); this.pickedType = this.getType(this.pickedChoice);
} }
this.structureTypeService.getStructureTypes().subscribe((types) => {
this.structureTypes = types;
});
} }
getType(nameChoice: string): string { public getType(nameChoice: string): string {
return this.type_data.filter((type) => { return this.structureTypes.filter((type) => {
if (type.choices.includes(nameChoice)) { if (type.values.includes(nameChoice)) {
return type.name; return type.name;
} }
})[0].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) { 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; this.pickedType = type;
} }
pickChoice(choice: string): void {
public pickChoice(choice: string): void {
this.pickedChoice = choice; this.pickedChoice = choice;
this.selectedType.emit(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');
}
}
} }
...@@ -86,14 +86,15 @@ ...@@ -86,14 +86,15 @@
<a *ngIf="!isClaimed && userIsLoggedIn()" (click)="toggleClaimModal()" class="primary" tabindex="0" <a *ngIf="!isClaimed && userIsLoggedIn()" (click)="toggleClaimModal()" class="primary" tabindex="0"
>Revendiquer cette structure</a >Revendiquer cette structure</a
> >
<a <!-- temporary remove edit -->
<!-- <a
*ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()" *ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()"
(click)="editStructure()" (click)="editStructure()"
class="primary" class="primary"
tabindex="0" tabindex="0"
> >
Modifier cette structure Modifier cette structure
</a> </a> -->
<a *ngIf="profileService.isAdmin()" (click)="toggleDeleteModal()" class="primary" tabindex="0"> <a *ngIf="profileService.isAdmin()" (click)="toggleDeleteModal()" class="primary" tabindex="0">
Supprimer cette structure Supprimer cette structure
</a> </a>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment