diff --git a/src/app/form/form-view/structure-form/structure-type/structure-type.component.html b/src/app/form/form-view/structure-form/structure-type/structure-type.component.html index 540cf100f90132249fba94c8a5789291a2a37bd0..4ede3170418ad681fdfe7b049fd3b51265b0e7df 100644 --- a/src/app/form/form-view/structure-form/structure-type/structure-type.component.html +++ b/src/app/form/form-view/structure-form/structure-type/structure-type.component.html @@ -4,8 +4,45 @@ <h3>De quel type de structure s'agit-il ?</h3> <p>1 seul choix possible</p> </div> - <app-structure-type-picker - [pickedTypeId]="structureForm.get('structureType').valid ? structureForm.get('structureType').value : null" - (selectedType)="setTypeStructure($event)" - /> + <div class="title" style="gap: 12px"> + <h4>{{ structureTypeCategoryEnum.public }}</h4> + <div class="tagList"> + <app-tag-item + *ngFor="let type of publicTypes" + [iconName]="type._id === pickedTypeId ? 'check' : null" + [label]="type.name" + [color]="type._id === pickedTypeId ? 'black' : 'white'" + [clickable]="true" + (action)="pickStructureType(type._id)" + /> + </div> + </div> + + <div class="title" style="gap: 12px"> + <h4>{{ structureTypeCategoryEnum.private }}</h4> + <div class="tagList"> + <app-tag-item + *ngFor="let type of privateTypes" + [iconName]="type._id === pickedTypeId ? 'check' : null" + [label]="type.name" + [color]="type._id === pickedTypeId ? 'black' : 'white'" + [clickable]="true" + (action)="pickStructureType(type._id)" + /> + </div> + </div> + + <div class="title" style="gap: 12px"> + <h4>{{ structureTypeCategoryEnum.privateLucrative }}</h4> + <div class="tagList"> + <app-tag-item + *ngFor="let type of privateLucrativeTypes" + [iconName]="type._id === pickedTypeId ? 'check' : null" + [label]="type.name" + [color]="type._id === pickedTypeId ? 'black' : 'white'" + [clickable]="true" + (action)="pickStructureType(type._id)" + /> + </div> + </div> </form> diff --git a/src/app/form/form-view/structure-form/structure-type/structure-type.component.ts b/src/app/form/form-view/structure-form/structure-type/structure-type.component.ts index 906beaa3ad03006eb020321464b4b6393a60d088..cebf28059be9e8bbe28427c09de0c5655f653040 100644 --- a/src/app/form/form-view/structure-form/structure-type/structure-type.component.ts +++ b/src/app/form/form-view/structure-form/structure-type/structure-type.component.ts @@ -1,5 +1,8 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; +import { StructureType } from '../../../../models/structureType.model'; +import { StructureTypeService } from '../../../../services/structure-type.service'; +import { StructureCategoryEnum } from '../../../../shared/enum/structureCategory.enum'; @Component({ selector: 'app-structure-type', @@ -11,14 +14,41 @@ export class StructureTypeComponent implements OnInit { @Output() typeStructure = new EventEmitter<string>(); @Output() validateForm = new EventEmitter<any>(); + public pickedTypeId = ''; + public publicTypes: StructureType[]; + public privateTypes: StructureType[]; + public privateLucrativeTypes: StructureType[]; + public structureTypeCategoryEnum = StructureCategoryEnum; + + constructor(private structureTypeService: StructureTypeService) {} + ngOnInit(): void { + // Defines which format is valid for the 'structureType' field of the form this.validateForm.emit(); - } - public setTypeStructure(value: string): void { - this.typeStructure.emit(value); + // Get the list of structure types, without the "other" one + this.structureTypeService.getStructureTypes().subscribe((types) => { + types = types.filter((type) => type.selectable); + types = types.sort((a, b) => a.name.localeCompare(b.name)); + this.publicTypes = types.filter((type) => type.category === this.structureTypeCategoryEnum.public); + this.privateTypes = types.filter((type) => type.category === this.structureTypeCategoryEnum.private); + this.privateLucrativeTypes = types.filter( + (type) => type.category === this.structureTypeCategoryEnum.privateLucrative, + ); + }); + + // If any, get the ID of the previously selected structure type + this.pickedTypeId = this.structureForm.get('structureType').valid + ? this.structureForm.get('structureType').value + : null; } + public goBack(): void { history.back(); } + + public pickStructureType(structureTypeId: string): void { + this.pickedTypeId = structureTypeId; + this.typeStructure.emit(structureTypeId); + } } diff --git a/src/app/shared/components/index.ts b/src/app/shared/components/index.ts index f268adefd3f19225df00002fa5d8a074cf68e20b..8accb9542ee9586d72ec4d4b6f7abab10f4adcfc 100644 --- a/src/app/shared/components/index.ts +++ b/src/app/shared/components/index.ts @@ -27,7 +27,6 @@ import { SearchBarComponent } from './search-bar/search-bar.component'; import { StructureDetailPrintComponent } from './structure-detail-print/structure-detail-print.component'; import { StructureHoursListComponent } from './structure-hours/structure-hours-list.component'; import { StructurePmrComponent } from './structure-pmr/structure-pmr.component'; -import { StructureTypePickerComponent } from './structure-type-picker/structure-type-picker.component'; import { SvgIconComponent } from './svg-icon/svg-icon.component'; import { SwitchComponent } from './switch/switch.component'; import { TagItemComponent } from './tag-item/tag-item.component'; @@ -57,7 +56,6 @@ export { StructureHoursListComponent, StructurePmrComponent, StructurePublicTargetComponent, - StructureTypePickerComponent, SvgIconComponent, SwitchComponent, TagItemComponent, @@ -93,7 +91,6 @@ export const SharedComponents = [ StructureDetailPrintComponent, StructurePmrComponent, StructurePublicTargetComponent, - StructureTypePickerComponent, SvgIconComponent, TagItemComponent, TrainingTypePickerComponent, 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 deleted file mode 100644 index 5bf922a4fd477443fd50d05448f06a4b2aca3446..0000000000000000000000000000000000000000 --- a/src/app/shared/components/structure-type-picker/structure-type-picker.component.html +++ /dev/null @@ -1,43 +0,0 @@ -<form> - <div class="title" style="gap: 12px"> - <h4>{{ structureTypeCategoryEnum.public }}</h4> - <div class="tagList"> - <app-tag-item - *ngFor="let type of publicTypes" - [iconName]="type._id === pickedTypeId ? 'check' : null" - [label]="type.name" - [color]="type._id === pickedTypeId ? 'black' : 'white'" - [clickable]="true" - (action)="pickStructureType(type._id)" - /> - </div> - </div> - - <div class="title" style="gap: 12px"> - <h4>{{ structureTypeCategoryEnum.private }}</h4> - <div class="tagList"> - <app-tag-item - *ngFor="let type of privateTypes" - [iconName]="type._id === pickedTypeId ? 'check' : null" - [label]="type.name" - [color]="type._id === pickedTypeId ? 'black' : 'white'" - [clickable]="true" - (action)="pickStructureType(type._id)" - /> - </div> - </div> - - <div class="title" style="gap: 12px"> - <h4>{{ structureTypeCategoryEnum.privateLucrative }}</h4> - <div class="tagList"> - <app-tag-item - *ngFor="let type of privateLucrativeTypes" - [iconName]="type._id === pickedTypeId ? 'check' : null" - [label]="type.name" - [color]="type._id === pickedTypeId ? 'black' : 'white'" - [clickable]="true" - (action)="pickStructureType(type._id)" - /> - </div> - </div> -</form> 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 deleted file mode 100644 index 95b8ae49bde9fdb93f3fba3885c256629024b539..0000000000000000000000000000000000000000 --- a/src/app/shared/components/structure-type-picker/structure-type-picker.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { StructureType } from '../../../models/structureType.model'; -import { StructureTypeService } from '../../../services/structure-type.service'; -import { StructureCategoryEnum } from '../../enum/structureCategory.enum'; - -@Component({ - selector: 'app-structure-type-picker', - templateUrl: './structure-type-picker.component.html', -}) -export class StructureTypePickerComponent implements OnInit { - public publicTypes: StructureType[]; - public privateTypes: StructureType[]; - public privateLucrativeTypes: StructureType[]; - @Input() public pickedTypeId?: string; - @Output() selectedType: EventEmitter<string> = new EventEmitter<string>(); - - public structureTypeCategoryEnum = StructureCategoryEnum; - - constructor(private structureTypeService: StructureTypeService) {} - - ngOnInit(): void { - this.structureTypeService.getStructureTypes().subscribe((types) => { - // Filter "other" structure type - types = types.filter((type) => type.selectable); - types = types.sort((a, b) => a.name.localeCompare(b.name)); - this.publicTypes = types.filter((type) => type.category === this.structureTypeCategoryEnum.public); - this.privateTypes = types.filter((type) => type.category === this.structureTypeCategoryEnum.private); - this.privateLucrativeTypes = types.filter( - (type) => type.category === this.structureTypeCategoryEnum.privateLucrative, - ); - }); - } - - public pickStructureType(structureTypeId: string): void { - this.pickedTypeId = structureTypeId; - this.selectedType.emit(structureTypeId); - } -}