From c1d828b9136cf8abdb60071526007a1ad5f83836 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Fri, 9 Sep 2022 14:08:02 +0200
Subject: [PATCH] feat: predams: implement delete icon button in basin list

refs #522
---
 .../basin-fieldset-container.component.ts             |  5 +++++
 src/app/components/pb-schema/pb-schema.component.ts   | 11 +++++++----
 src/app/services/prebarrage.service.ts                |  6 ++++++
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/app/components/basin-fieldset-container/basin-fieldset-container.component.ts b/src/app/components/basin-fieldset-container/basin-fieldset-container.component.ts
index dd8b8f854..63efc5a1f 100644
--- a/src/app/components/basin-fieldset-container/basin-fieldset-container.component.ts
+++ b/src/app/components/basin-fieldset-container/basin-fieldset-container.component.ts
@@ -31,4 +31,9 @@ export class BasinFieldsetContainerComponent extends FieldsetContainerComponent
     protected addSubNub(after: FieldSet, clone?: boolean): void {
         this.predamService.copySelectedBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
     }
+
+    public onRemoveFieldset(fs: FieldSet) {
+        super.onRemoveFieldset(fs);
+        this.predamService.deleteSelected(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
+    }
 }
diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts
index c258b9878..c335b4083 100644
--- a/src/app/components/pb-schema/pb-schema.component.ts
+++ b/src/app/components/pb-schema/pb-schema.component.ts
@@ -459,10 +459,6 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
     /** Removes a basin or wall, and all related items */
     public onRemoveClick() {
         this.predamService.deleteSelected(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
-        this.clearResults();
-        this.unselect();
-        this.refreshWithSelection();
-        this.calculatorComponent.showPBInputData = true;
     }
 
     public get uitextRemove() {
@@ -512,6 +508,13 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
                 this.refreshWithSelection(nub.uid);
                 this.calculatorComponent.showPBInputData = true;
                 break;
+
+            case PrebarrageServiceEvents.BASIN_WALL_REMOVED:
+                this.clearResults();
+                this.unselect();
+                this.refreshWithSelection();
+                this.calculatorComponent.showPBInputData = true;
+                break;
         }
     }
 
diff --git a/src/app/services/prebarrage.service.ts b/src/app/services/prebarrage.service.ts
index da22ff2f9..65e534627 100644
--- a/src/app/services/prebarrage.service.ts
+++ b/src/app/services/prebarrage.service.ts
@@ -4,6 +4,7 @@ import { MermaidUtil, PbBassin, PbBassinParams, PbCloison, PreBarrage } from "ja
 export enum PrebarrageServiceEvents {
     BASIN_WALL_ADDED, // a wall has been added
     BASIN_WALL_COPIED, // a basin or wall has been copied
+    BASIN_WALL_REMOVED, // a basin or a wall has been removed
 }
 /**
  * service relatif au schéma de prébarrage
@@ -67,6 +68,11 @@ export class PrebarrageService {
                 this._model.addChild(new PbCloison(undefined, this._selectedNub.bassinAval, undefined, emptyFields));
             }
         }
+        this._changeEventEmitter.emit(
+            {
+                id: PrebarrageServiceEvents.BASIN_WALL_REMOVED,
+            }
+        );
     }
 
     private copyWall(wall: PbCloison, emptyFields: boolean): PbCloison {
-- 
GitLab