Skip to content
Snippets Groups Projects
Commit 726187ae authored by Etienne LOUPIAS's avatar Etienne LOUPIAS
Browse files

feat(orientation): disable items if not offered for rdv

parent 9ae9f143
Branches
Tags
2 merge requests!608V2.4.2,!599Resolve "[Orientation depuis la fiche annuaire et carto] - choix des démarches"
......@@ -6,6 +6,7 @@
<app-button
[ngClass]="{ selectedChoice: true }"
[extraClass]="isSelectedModule(module.id) ? 'selected' : ''"
[disabled]="module.disabled"
[style]="buttonTypeEnum.CheckButton"
[text]="module.name"
(action)="handleClick(module)"
......
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { OrientationService } from '../../../../services/orientation.service';
import { PersonalOfferService } from '../../../../services/personal-offer.service';
import { CategoryEnum } from '../../../../shared/enum/category.enum';
import { Category } from '../../../../structure-list/models/category.model';
import { Module } from '../../../../structure-list/models/module.model';
import { SearchService } from '../../../../structure-list/services/search.service';
import { OrientationUtils } from '../../../../utils/orientationUtils';
import { SelectComponent } from '../../global-components/select/select.component';
import { FiltersForm } from '../../interfaces/filtersForm.interface';
......@@ -13,17 +16,31 @@ import { FiltersForm } from '../../interfaces/filtersForm.interface';
})
export class BaseSkillsChoiceComponent extends SelectComponent implements OnInit {
@Input() form: FormGroup<FiltersForm>;
public orientationUtils = new OrientationUtils();
public baseSkills: Module[] = [];
constructor(private searchService: SearchService) {
constructor(
private searchService: SearchService,
public orientationService: OrientationService,
public personalOfferService: PersonalOfferService
) {
super();
}
ngOnInit(): void {
this.selectedModules = this.form.get('filters').value;
this.searchService.getCategories().subscribe((categories: Category[]) => {
this.searchService.getCategories().subscribe(async (categories: Category[]) => {
this.baseSkills = categories.find((el) => el.id === CategoryEnum.baseSkills).modules;
// For rdv from structure or annuaire, disable items which are not offered
await this.orientationUtils.rdvDisableItemsNotOffered(
this.baseSkills,
this.orientationService,
this.personalOfferService,
'baseSkills'
);
});
this.checkValidation.emit();
}
}
......@@ -5,6 +5,7 @@
*ngIf="module.id !== 'autres'"
[ngClass]="{ selectedChoice: true }"
[extraClass]="isSelectedModule(module.id) ? 'selected' : ''"
[disabled]="module.disabled"
[style]="buttonTypeEnum.CheckButton"
[text]="module.name"
(action)="handleClick(module)"
......
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { CategoryEnum } from 'src/app/shared/enum/category.enum';
import { OrientationService } from '../../../../services/orientation.service';
import { PersonalOfferService } from '../../../../services/personal-offer.service';
import { StructureService } from '../../../../services/structure.service';
import { ButtonType } from '../../../../shared/components/button/buttonType.enum';
import { Category } from '../../../../structure-list/models/category.model';
import { Module } from '../../../../structure-list/models/module.model';
import { SearchService } from '../../../../structure-list/services/search.service';
import { OrientationUtils } from '../../../../utils/orientationUtils';
@Component({
selector: 'app-online-demarch',
......@@ -13,7 +17,14 @@ import { SearchService } from '../../../../structure-list/services/search.servic
export class OnlineDemarchComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Output() checkValidation = new EventEmitter<any>();
constructor(private searchService: SearchService) {}
constructor(
private searchService: SearchService,
public structureService: StructureService,
public orientationService: OrientationService,
public personalOfferService: PersonalOfferService
) {}
public orientationUtils = new OrientationUtils();
public accompanimentType: Module[];
public buttonTypeEnum = ButtonType;
public selectedModules: Module[] = [];
......@@ -22,9 +33,18 @@ export class OnlineDemarchComponent implements OnInit {
ngOnInit(): void {
this.selectedModules = this.form.get('onlineDemarcheType').value;
// TODO move this in form init categories
this.searchService.getCategories().subscribe((categories: Category[]) => {
this.searchService.getCategories().subscribe(async (categories: Category[]) => {
this.accompanimentType = categories.find((el) => el.id === CategoryEnum.onlineProcedures).modules;
// For rdv from structure or annuaire, disable items which are not offered
await this.orientationUtils.rdvDisableItemsNotOffered(
this.accompanimentType,
this.orientationService,
this.personalOfferService,
'onlineProcedures'
);
});
this.checkValidation.emit();
}
......
......@@ -2,6 +2,7 @@ export class Module {
id: string;
name: string;
displayText?: string;
disabled?: boolean = false;
constructor(id: string, name: string, displayText?: string) {
this.id = id;
......
import { FormControl, FormGroup, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import _ from 'lodash';
import { Observable, forkJoin, lastValueFrom, tap } from 'rxjs';
import { structureFormStep } from '../form/form-view/structure-form/structureFormStep.enum';
import { AppointmentSteps } from '../form/orientation-form-view/enums/AppointmentSteps.enum';
import { FiltersSteps } from '../form/orientation-form-view/enums/filtersSteps.enum';
......@@ -12,6 +14,9 @@ import { FiltersForm } from '../form/orientation-form-view/interfaces/filtersFor
import { OnlineDemarchesForm } from '../form/orientation-form-view/interfaces/onlineDemarchesForm.interface';
import { StructureOrientationForm } from '../form/orientation-form-view/interfaces/structureOrientationForm.interface';
import { StructureOrientator } from '../form/orientation-form-view/interfaces/structureOrientator.interface';
import { PersonalOffer } from '../models/personalOffer.model';
import { OrientationService } from '../services/orientation.service';
import { PersonalOfferService } from '../services/personal-offer.service';
import { Filter } from '../structure-list/models/filter.model';
import { Module } from '../structure-list/models/module.model';
import { CustomRegExp } from './CustomRegExp';
......@@ -256,4 +261,49 @@ export class OrientationUtils {
}
}
}
public async rdvDisableItemsNotOffered(
modules: Module[],
orientationService: OrientationService,
personalOfferService: PersonalOfferService,
category: string
) {
// If rdv from structure, enable only personalOffers of the structure
if (orientationService.rdvStructure) {
// Get offers to enable
let offersEnabled = [];
orientationService.rdvStructure.personalOffers.forEach((personalOffer) => {
// use lodash _.union fonction to concat array without duplicates
offersEnabled = _.union(offersEnabled, personalOffer.categories[category]);
});
// Disable items not offered by the structure
modules.forEach((m) => (m.disabled = !offersEnabled.includes(m.id)));
}
// If rdv from annuaire, enable only offers of the social worker
if (orientationService.rdvUser) {
// Get its personalOffers
const personalOffers$: Observable<any>[] = [];
const rdvUserPersonalOffersPopulated: PersonalOffer[] = [];
orientationService.rdvUser.personalOffers.forEach((personalOffer) => {
personalOffers$.push(
personalOfferService.getPersonalOffer(personalOffer).pipe(
tap((personalOffer) => {
rdvUserPersonalOffersPopulated.push(new PersonalOffer(personalOffer));
})
)
);
});
await lastValueFrom(forkJoin(personalOffers$));
// Get offers to enable
let offersEnabled = [];
rdvUserPersonalOffersPopulated.forEach((personalOffer) => {
// use lodash _.union fonction to concat array without duplicates
offersEnabled = _.union(offersEnabled, personalOffer.categories[category]);
});
// Disable items not offered by the social worker
modules.forEach((m) => (m.disabled = !offersEnabled.includes(m.id)));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment