From 24f83870fdabbeb3cae80465781b3c7d88799092 Mon Sep 17 00:00:00 2001 From: Filip Leitner Date: Thu, 7 Mar 2024 14:18:09 +0100 Subject: [PATCH] feat(add-data): Remove catalogue layers via panel-header buttons --- .../add-data/add-data.component.html | 40 ++++++++---- .../components/add-data/add-data.component.ts | 61 +++++++++++++++++-- .../add-data/catalogue/catalogue.component.ts | 15 ++++- .../layer-manager/layer-manager.component.ts | 1 + .../add-data/catalogue/catalogue.service.ts | 4 +- projects/hslayers/shared/draw/draw.service.ts | 7 ++- projects/hslayers/src/assets/locales/cs.json | 11 ++-- projects/hslayers/src/assets/locales/en.json | 9 ++- projects/hslayers/src/assets/locales/lv.json | 5 +- projects/hslayers/src/assets/locales/sk.json | 9 ++- .../hslayers-app/hslayers-app.component.ts | 2 +- tsconfig.json | 10 +-- 12 files changed, 133 insertions(+), 41 deletions(-) diff --git a/projects/hslayers/components/add-data/add-data.component.html b/projects/hslayers/components/add-data/add-data.component.html index c3b9518a73..b9a08875fc 100644 --- a/projects/hslayers/components/add-data/add-data.component.html +++ b/projects/hslayers/components/add-data/add-data.component.html @@ -1,14 +1,30 @@
- -
- - - - - - -
-
+ + + @if(dataset.selected === 'catalogue' && hsAddDataCatalogueService.data.onlyMine){ + + + +  {{'DRAW.removeMultipleLayers' | translateHs }} + + +  {{'LAYERMANAGER.removeAllLayers' | translateHs }} + + + + + } + +
+ + + + + + +
+
+ + \ No newline at end of file diff --git a/projects/hslayers/components/add-data/add-data.component.ts b/projects/hslayers/components/add-data/add-data.component.ts index 8a5bbf614d..ef5e8eee79 100644 --- a/projects/hslayers/components/add-data/add-data.component.ts +++ b/projects/hslayers/components/add-data/add-data.component.ts @@ -1,17 +1,21 @@ import {Component, OnDestroy, OnInit} from '@angular/core'; -import {Subject, takeUntil} from 'rxjs'; +import {Observable, Subject, of, switchMap, takeUntil} from 'rxjs'; import {AddDataUrlType} from 'hslayers-ng/types'; import {DatasetType} from 'hslayers-ng/types'; -import {HsAddDataService} from 'hslayers-ng/shared/add-data'; +import { + HsAddDataCatalogueService, + HsAddDataService, +} from 'hslayers-ng/shared/add-data'; import {HsAddDataUrlService} from 'hslayers-ng/shared/add-data'; +import {HsConfirmDialogComponent} from 'hslayers-ng/common/confirm'; import {HsDialogContainerService} from 'hslayers-ng/common/dialogs'; -import {HsEventBusService} from 'hslayers-ng/shared/event-bus'; import {HsGetCapabilitiesErrorComponent} from './common/capabilities-error-dialog/capabilities-error-dialog.component'; +import {HsLaymanService} from 'hslayers-ng/shared/save-map'; import {HsLayoutService} from 'hslayers-ng/shared/layout'; import {HsPanelBaseComponent} from 'hslayers-ng/common/panels'; +import {HsRemoveLayerDialogService} from 'hslayers-ng/common/remove-multiple'; import {HsShareUrlService} from 'hslayers-ng/components/share'; -import {HsSidebarService} from 'hslayers-ng/shared/sidebar'; import {servicesSupportedByUrl} from 'hslayers-ng/types'; @Component({ @@ -23,16 +27,24 @@ export class HsAddDataComponent implements OnInit, OnDestroy { private end = new Subject(); + layersAvailable: Observable; constructor( public hsAddDataService: HsAddDataService, public hsShareUrlService: HsShareUrlService, public hsLayoutService: HsLayoutService, - public hsEventBusService: HsEventBusService, public hsAddDataUrlService: HsAddDataUrlService, - private hsSidebarService: HsSidebarService, private hsDialogContainerService: HsDialogContainerService, + public hsAddDataCatalogueService: HsAddDataCatalogueService, + private hsRemoveLayerDialogService: HsRemoveLayerDialogService, + private hsLaymanService: HsLaymanService, ) { super(hsLayoutService); + this.layersAvailable = + this.hsAddDataCatalogueService.addDataCatalogueReloaded.pipe( + switchMap(() => { + return of(this.hsAddDataCatalogueService.catalogEntries.length > 0); + }), + ); } name = 'addData'; @@ -78,4 +90,41 @@ export class HsAddDataComponent this.hsAddDataUrlService.typeSelected = type; } } + + /** + * Create remove-layer dialog which allows for single/multiple layer removal + */ + async removeMultipleLayers() { + const confirmed = + await this.hsRemoveLayerDialogService.removeMultipleLayers( + this.hsAddDataCatalogueService.catalogEntries + .filter((layer) => layer.editable) + .map((l) => { + return l.name; + }), + ['catalogue'], + ); + if (confirmed) { + this.hsAddDataCatalogueService.reloadData(); + } + } + + /** + * Remove all user's layers from Layman catalogue + */ + async removeAllLayers() { + const dialog = this.hsDialogContainerService.create( + HsConfirmDialogComponent, + { + message: 'LAYERMANAGER.dialogRemoveAll.dialogMessage', + note: 'DRAW.deleteNotePlural', + title: 'LAYERMANAGER.dialogRemoveAll.removeAllCatalogueLayers', + }, + ); + const confirmed = await dialog.waitResult(); + if (confirmed === 'yes') { + await this.hsLaymanService.removeLayer(); + this.hsAddDataCatalogueService.reloadData(); + } + } } diff --git a/projects/hslayers/components/add-data/catalogue/catalogue.component.ts b/projects/hslayers/components/add-data/catalogue/catalogue.component.ts index aabffa1179..6a221b5481 100644 --- a/projects/hslayers/components/add-data/catalogue/catalogue.component.ts +++ b/projects/hslayers/components/add-data/catalogue/catalogue.component.ts @@ -1,6 +1,9 @@ import {Component, OnInit} from '@angular/core'; -import {HsAddDataCatalogueMapService} from 'hslayers-ng/shared/add-data'; +import { + HsAddDataCatalogueMapService, + HsAddDataService, +} from 'hslayers-ng/shared/add-data'; import {HsAddDataCatalogueService} from 'hslayers-ng/shared/add-data'; import {HsAddDataLayerDescriptor} from 'hslayers-ng/types'; import {HsCommonLaymanService} from 'hslayers-ng/common/layman'; @@ -36,6 +39,7 @@ export class HsAddDataCatalogueComponent implements OnInit { public hsUtilsService: HsUtilsService, public hsLaymanService: HsLaymanService, public hsCommonLaymanService: HsCommonLaymanService, + private hsAddDataService: HsAddDataService, ) { this.advancedSearch = false; } @@ -68,7 +72,14 @@ export class HsAddDataCatalogueComponent implements OnInit { } queryByFilter(): void { - this.hsAddDataCatalogueService.reloadData(); + /** + * A bit tricky way how to force add-data hs-panel-header to refresh its template + * in order to show/hide buttons. Previously done by reloadData call. + * This achieves the same via datasetTypeSelected subscription in catalgoue service + */ + this.hsAddDataService.datasetSelected.next( + this.hsAddDataService.datasetSelected.getValue(), + ); } selectType(type: string): void { diff --git a/projects/hslayers/components/layer-manager/layer-manager.component.ts b/projects/hslayers/components/layer-manager/layer-manager.component.ts index 7094bd386c..cfa839ca3e 100644 --- a/projects/hslayers/components/layer-manager/layer-manager.component.ts +++ b/projects/hslayers/components/layer-manager/layer-manager.component.ts @@ -261,6 +261,7 @@ export class HsLayerManagerComponent .map((l) => { return l.layer; }), + ['map', 'mapcatalogue'], ); } diff --git a/projects/hslayers/shared/add-data/catalogue/catalogue.service.ts b/projects/hslayers/shared/add-data/catalogue/catalogue.service.ts index f5254e36c8..3e84d50da7 100644 --- a/projects/hslayers/shared/add-data/catalogue/catalogue.service.ts +++ b/projects/hslayers/shared/add-data/catalogue/catalogue.service.ts @@ -2,7 +2,7 @@ import {Injectable, NgZone} from '@angular/core'; import {Feature} from 'ol'; import {Geometry} from 'ol/geom'; -import {Observable, forkJoin} from 'rxjs'; +import {Observable, Subject, forkJoin} from 'rxjs'; import {DatasetType} from 'hslayers-ng/types'; import {HsAddDataCatalogueMapService} from './catalogue-map.service'; @@ -49,6 +49,7 @@ class HsAddDataCatalogueParams { matchedRecords: number; extentChangeSuppressed = false; + addDataCatalogueReloaded: Subject = new Subject(); constructor() {} } @@ -142,6 +143,7 @@ export class HsAddDataCatalogueService extends HsAddDataCatalogueParams { this.queryCatalogs(); // this.hsMickaFilterService.fillCodesets(); this.calcExtentLayerVisibility(); + this.addDataCatalogueReloaded.next(); } /** diff --git a/projects/hslayers/shared/draw/draw.service.ts b/projects/hslayers/shared/draw/draw.service.ts index 33d3918eab..f1a004776a 100644 --- a/projects/hslayers/shared/draw/draw.service.ts +++ b/projects/hslayers/shared/draw/draw.service.ts @@ -536,9 +536,10 @@ export class HsDrawService extends HsDrawServiceParams { ); } } - this.drawableLayersAvailable = this.drawableLayers.length > 0 || this.drawableLaymanLayers.length > 0; - this.hasSomeDrawables = this.drawableLayers.length > 0 ; - this.moreThenOneDrawable = this.drawableLaymanLayers?.length > 1; + this.drawableLayersAvailable = + this.drawableLayers.length > 0 || this.drawableLaymanLayers.length > 0; + this.hasSomeDrawables = this.drawableLayers.length > 0; + this.moreThenOneDrawable = this.drawableLayers?.length > 1; } private selectedLayerNotAvailable(drawables) { diff --git a/projects/hslayers/src/assets/locales/cs.json b/projects/hslayers/src/assets/locales/cs.json index 23e904f3bd..964c40d69f 100644 --- a/projects/hslayers/src/assets/locales/cs.json +++ b/projects/hslayers/src/assets/locales/cs.json @@ -580,7 +580,8 @@ "dialogRemoveAll": { "dialogMessage": "Opravdu chcete odstranit všechny vámi přidané vrstvy?", "reloadComposition": "Obnovit kompozici", - "removeAllAdded": "Odstranit všechny přidané vrstvy" + "removeAllAdded": "Odstranit všechny přidané vrstvy", + "removeAllCatalogueLayers": "Odstranit všechny vaše vrstvy z katalogu" }, "dialogRemoveLayer": { "dialogMessage": "Opravdu chcete odstranit vybranou vrstvu?" @@ -667,8 +668,10 @@ "newLayer": "Nová vrstva", "removeLayer": { "map": "Mapy", - "catalogue": "Mapy a Katalogu", - "deleteFrom": "Smazat z" + "catalogue": "Katalogu", + "deleteFrom": "Smazat z", + "mapcatalogue": "Mapy a Katalogu", + "noLayersToDelete": "Žádné vrstvy k odstranění" } }, "LAYMAN": { @@ -1036,4 +1039,4 @@ "waypointLayer": "Vrstva s body trasy", "waypoints": "Body trasy" } -} +} \ No newline at end of file diff --git a/projects/hslayers/src/assets/locales/en.json b/projects/hslayers/src/assets/locales/en.json index c0b6f52cfe..9983f6347a 100644 --- a/projects/hslayers/src/assets/locales/en.json +++ b/projects/hslayers/src/assets/locales/en.json @@ -580,7 +580,8 @@ "dialogRemoveAll": { "dialogMessage": "Do you really want to remove all your layers?", "reloadComposition": "Reload composition", - "removeAllAdded": "Remove all added layers" + "removeAllAdded": "Remove all added layers", + "removeAllCatalogueLayers": "Remove all your catalogue layers" }, "dialogRemoveLayer": { "dialogMessage": "Do You really want to remove the selected layer?" @@ -667,8 +668,10 @@ "newLayer": "New layer", "removeLayer": { "map": "Map", - "catalogue": "Map & Catalogue", - "deleteFrom": "Delete from" + "catalogue": "Catalogue", + "deleteFrom": "Delete from", + "mapcatalogue": "Map & Catalogue", + "noLayersToDelete": "No layers to delete" } }, "LAYMAN": { diff --git a/projects/hslayers/src/assets/locales/lv.json b/projects/hslayers/src/assets/locales/lv.json index 18f5d94794..d0363fdcce 100644 --- a/projects/hslayers/src/assets/locales/lv.json +++ b/projects/hslayers/src/assets/locales/lv.json @@ -634,7 +634,10 @@ "LAYERS": { "existingLayer": "Eksistējošs slānis", "newLayer": "Jauns slānis", - "featuresLoadError": "Grafisko objektu ielāde neizdevās" + "featuresLoadError": "Grafisko objektu ielāde neizdevās", + "removeLayer": { + "mapcatalogue": "Map & Catalogue" + } }, "LAYMAN": { "allLayersSuccessfullyRemoved": "Visi slāņi veiksmīgi noņemti", diff --git a/projects/hslayers/src/assets/locales/sk.json b/projects/hslayers/src/assets/locales/sk.json index d82814d1c0..beb96978d2 100644 --- a/projects/hslayers/src/assets/locales/sk.json +++ b/projects/hslayers/src/assets/locales/sk.json @@ -580,7 +580,8 @@ "dialogRemoveAll": { "dialogMessage": "Naozaj chcete odstrániť všetky vami pridané vrstvy?", "reloadComposition": "Obnoviť kompozíciu", - "removeAllAdded": "Odstrániť všetky pridané vrstvy" + "removeAllAdded": "Odstrániť všetky pridané vrstvy", + "removeAllCatalogueLayers": "Odstrániť všetky vaše vrstvy z katalógu" }, "dialogRemoveLayer": { "dialogMessage": "Naozaj chcete odstrániť vybratú vrstvu?" @@ -667,8 +668,10 @@ "featuresLoadError": "Načítanie prvkov zlyhalo", "removeLayer": { "map": "Mapy", - "catalogue": "Mapy a Katalógu", - "deleteFrom": "Odstrániť z" + "catalogue": "Katalógu", + "deleteFrom": "Odstrániť z", + "mapcatalogue": "Mapy a Katalógu", + "noLayersToDelete": "Žiadne vrstvy na odstránenie" } }, "LAYMAN": { diff --git a/projects/test-app/src/hslayers-app/hslayers-app.component.ts b/projects/test-app/src/hslayers-app/hslayers-app.component.ts index cdce02dd5e..e2761c0ef2 100644 --- a/projects/test-app/src/hslayers-app/hslayers-app.component.ts +++ b/projects/test-app/src/hslayers-app/hslayers-app.component.ts @@ -341,7 +341,7 @@ export class HslayersAppComponent { }); this.hsConfig.update({ panelsEnabled: { - draw: false, + draw: true, mapSwipe: true, language: true, }, diff --git a/tsconfig.json b/tsconfig.json index 992f4700c6..ad77ce2581 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,15 +25,15 @@ "hslayers-cesium": ["dist/hslayers-cesium"], "hslayers-cesium/*": [ "projects/hslayers-cesium/*", - "projects/hslayers-cesium" + "projects/hslayers-cesium", ], - "cesium/*": ["node_modules/cesium/*"] + "cesium/*": ["node_modules/cesium/*"], }, - "useDefineForClassFields": false + "useDefineForClassFields": false, }, "angularCompilerOptions": { "enableResourceInlining": true, "fullTemplateTypeCheck": true, - "strictInjectionParameters": true - } + "strictInjectionParameters": true, + }, }