Skip to content

Commit

Permalink
feat(SharedThematic): deplacement des traitements métier thematic dep…
Browse files Browse the repository at this point in the history
…uis le component vers le service
  • Loading branch information
cboucheIGN committed Dec 17, 2024
1 parent ec5087b commit 4a79908
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 321 deletions.
8 changes: 1 addition & 7 deletions src/app/requete/pages/requete-new/requete-new.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<h1>
Votre forêt
@if (foret) {
@if (foret && foret.name) {
<span> - {{ foret.name }}</span>
}
</h1>
Expand All @@ -22,12 +22,6 @@ <h1>
</div>
</div>

<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-lg-6">
<app-thematic-select *ngIf="step > 1" (select)="updateThematics()"></app-thematic-select>
</div>
</div>

<div class="fr-grid-row fr-grid-row--gutters">

<div class="fr-col-12 fr-col-lg-6" [class.fr-col-lg-12]="step === 1" [class.map-hidden]="step < 1">
Expand Down
3 changes: 2 additions & 1 deletion src/app/requete/pages/requete-new/requete-new.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ export class RequeteNewComponent implements OnInit, AfterViewInit {
}
this.step = 1;
this.nextStep();
this.mapContextService.centerOnDessin();
}


private loadPageComponent() {
const label = this.foret ? `Requête ${this.foret}` : 'Nouvelle requête';
const label = this.foret ? `Requête sur ${this.foret.name}` : 'Nouvelle requête';
this.breadcrumb = this.breadcrumbTransformerService.fromOptions({
label: label, route: ''
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@if(noFeatureAtAll) {
@if(noFeatures) {

<p>
Pour le périmètre saisi, aucun zonage à caractère environnemental ou patrimonial
Expand All @@ -24,22 +24,22 @@ <h3 class="fr-h6">Conseils pour instruire vos travaux</h3>
</li>
</ul>

@for (thematicTab of thematicTabs; track $index; let first = $first) {
@for (thematic of thematics; track $index; let first = $first) {

@if (!first) {
<h3 class="fr-h6">{{thematicTab.label}}</h3>
@if (thematicTab.hasFeature) {
<h3 class="fr-h6">{{thematic.label}}</h3>
@if (checkThematicFeatures(thematic)) {
<p>Le périmètre saisi est concerné par les zones suivantes :</p>
<ul>
@for (layer of thematicTab.layers; track $index) {
@for (layer of thematic.layers; track $index) {
@if (layer.features.length) {
<li>{{layer.title}}</li>
}
}
</ul>
}
@else {
@if (thematicTab.name === 'biodiversite') {
@if (thematic.name === 'biodiversite') {
<p>
Pour le périmètre saisi, aucun zonage à caractère environnemental
n'a été identifié parmi ceux intégrés à l'outil FOREG.
Expand Down
19 changes: 14 additions & 5 deletions src/app/shared-thematic/components/synthese/synthese.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { Thematic } from '../../models/thematic.model';

@Component({
selector: 'app-synthese',
Expand All @@ -7,19 +8,27 @@ import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/cor
})
export class SyntheseComponent implements OnInit, OnChanges {

@Input() features!: any[];
@Input() thematics!: Thematic[];

@Input() thematicTabs!: any[];

noFeatureAtAll: boolean = false;
noFeatures: boolean = false;

constructor() { }

ngOnInit(): void {
}

ngOnChanges(changes: SimpleChanges): void {
this.noFeatureAtAll = this.thematicTabs && !this.thematicTabs[1].hasFeature && !this.thematicTabs[2].hasFeature;
if (this.thematics) {
this.checkFeatures();
}
}

private checkFeatures() {
this.noFeatures = this.thematics.map(t => t.layers).flat().map((l) => l.features).flat().length === 0;
}

checkThematicFeatures(thematic: Thematic) {
return thematic.layers.map((l) => l.features).flat().length > 0;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<app-synthese [thematics]="thematics"></app-synthese>

@for (thematic of thematics; track $index; let first = $first) {
@if (thematic.active) {
<div>
@if (first) {
<app-synthese [features]="responseFeatures"></app-synthese>

} @else {
<app-thematic-view [thematic]="thematic"></app-thematic-view>
<app-thematic-view [thematic]="thematic"></app-thematic-view>
}
</div>
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component } from '@angular/core';

import { ThematicSelectService } from '../../services/thematic-select.service';
import { MapContextService } from '../../../shared-map/services/map-context.service';
import { ThematicFeatureService } from '../../services/fiche-info-feature.service';
import { THEMATIC_LIST } from '../../models/thematic-list.enum';
import { ThematicFeatureService } from '../../services/thematic-feature.service';
import { Thematic } from '../../models/thematic.model';
import { map } from 'rxjs';

@Component({
selector: 'app-thematic-list',
Expand All @@ -12,90 +12,41 @@ import { THEMATIC_LIST } from '../../models/thematic-list.enum';
})
export class ThematicListComponent {

selectedTabIndex: number = 0;

thematics: any[] = [];
thematics: Thematic[] = [];

responseFeatures: any[] = [];

constructor(
private thematicFeatureService: ThematicFeatureService,
private thematicSelectService: ThematicSelectService,
private mapContextService: MapContextService
) { }

ngOnInit() {

this.initFicheList();

this.thematicSelectService.thematicSelection.subscribe((activeThemeList: any[]) => {
activeThemeList.unshift('synthese');
this.updateActiveTabs(activeThemeList);
});
this.thematicFeatureService.listAllFeatures().subscribe((features: any[]) => {
const thematics = this.thematicFeatureService.joinThematicsFeatures(features);
this.thematics = this.displaySituationMapForEachLayer(thematics);

this.thematicFeatureService.listFicheFeatures().subscribe((features: any[]) => {
this.responseFeatures = features;
this.updateActiveThematicLayersFromFeatures(features);
this.mapContextService.updateLayersVisibility('synthese');
this.initFicheList();
this.updateFicheList();
});

}


selectTab(event: any) {
this.setSelectedTabIndex(event);
this.mapContextService.updateLayersVisibility(event);
}


private updateActiveTabs(activeThemeList: any[]) {
this.thematics = THEMATIC_LIST.filter((theme) => activeThemeList.includes(theme.name));
this.selectTab('synthese');
}


private setSelectedTabIndex(tabId: string) {
let indexModifier = 0;
for (let i = 0; i < THEMATIC_LIST.length; i++) {
if (THEMATIC_LIST[i].name === tabId) {
this.selectedTabIndex = i - indexModifier;
} else if (!THEMATIC_LIST[i].active) {
indexModifier++;
}
}
}


private initFicheList() {
this.thematics = THEMATIC_LIST.map((thematic) => {
private displaySituationMapForEachLayer(thematics: Thematic[]): Thematic[] {
return thematics.map((thematic) => {
if (!thematic.layers) {
thematic.layers = [];
}
thematic.layers = thematic.layers.map((layer: any) => {
layer.displaySituationMap = true;
return layer;
});
return thematic;
});
}


private updateFicheList() {
this.thematics = this.thematics.map((thematic) => {
thematic.layers = thematic.layers.map((layer: any) => this.updateFicheLayerList(layer));
return thematic;
});
}


private updateFicheLayerList(layer: any) {
layer.flatview = true;
layer.features = [];
layer.features = this.responseFeatures.filter((feature) => {
return this.parseLayerFromTechnicalName(layer.technicalName) === feature.layer;
});
return layer;
}


private updateActiveThematicLayersFromFeatures(features: any) {
for (let i = 0; i < features.length; i++) {
const layer = features[i].layer;
Expand All @@ -118,11 +69,4 @@ export class ThematicListComponent {
}
}


private parseLayerFromTechnicalName(technicalName: string) {
return technicalName.split(':')[1];
}

}


Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<dsfr-tabs [selectedTabIndex]="selectedTabIndex" (tabSelect)="selectTab($event)">
@if (thematics && thematics.length > 0) {
<dsfr-tabs [selectedTabIndex]="selectedTabIndex">

@for (thematicTab of thematicTabs; track $index; let first = $first) {
@if (thematicTab.active) {
<dsfr-tab [tabId]="thematicTab.name" [label]="thematicTab.label">

@if (first) {
<app-synthese [features]="responseFeatures" [thematicTabs]="thematicTabs"></app-synthese>
} @else {
<app-thematic-view [thematic]="thematicTab"></app-thematic-view>
@for (thematic of thematics; track $index; let first = $first) {
@if (thematic.active) {
<dsfr-tab [tabId]="thematic.name" [label]="thematic.label">

@if (first) {
<app-synthese [thematics]="thematics"></app-synthese>
} @else {
<app-thematic-view [thematic]="thematic"></app-thematic-view>
}

</dsfr-tab>
}

</dsfr-tab>
}
}

</dsfr-tabs>

</dsfr-tabs>
}
Loading

0 comments on commit 4a79908

Please sign in to comment.