From e502a52fc39e86a70f2b4c96687c4b24145f030d Mon Sep 17 00:00:00 2001 From: cbourget Date: Wed, 17 Jul 2019 13:59:32 -0400 Subject: [PATCH] feat(catalog): optionnally force a user to expand a group of layers before adding it to the map --- .../catalog-browser-group.component.html | 7 ++-- .../catalog-browser-group.component.ts | 34 +++++++++++++++++++ .../catalog-browser.component.html | 1 + .../catalog-browser.component.ts | 5 +++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.html b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.html index 5e32477cb0..16c3876af0 100644 --- a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.html +++ b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.html @@ -1,11 +1,12 @@ + [collapsed]="collapsed" + (toggle)="onToggleCollapsed($event)">

{{title}}

@@ -17,6 +18,7 @@

{{title}}

matTooltipShowDelay="500" [matTooltip]="'igo.geo.catalog.group.removeFromMap' | translate" color="warn" + [disabled]="disabled$ | async" (click)="onToggleClick()"> @@ -28,6 +30,7 @@

{{title}}

tooltip-position="below" matTooltipShowDelay="500" [matTooltip]="'igo.geo.catalog.group.addToMap' | translate" + [disabled]="disabled$ | async" (click)="onToggleClick()"> diff --git a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.ts b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.ts index 8e61b494a9..c0ba9304e5 100644 --- a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.ts +++ b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser-group.component.ts @@ -30,6 +30,7 @@ import { changeDetection: ChangeDetectionStrategy.OnPush }) export class CatalogBrowserGroupComponent implements OnInit, OnDestroy { + /** * Group's items store * @internal @@ -42,6 +43,12 @@ export class CatalogBrowserGroupComponent implements OnInit, OnDestroy { */ added$: BehaviorSubject = new BehaviorSubject(false); + /** + * Whether the toggle button is disabled + * @internal + */ + disabled$: BehaviorSubject = new BehaviorSubject(false); + /** * Catalog */ @@ -52,6 +59,16 @@ export class CatalogBrowserGroupComponent implements OnInit, OnDestroy { */ @Input() group: CatalogItemGroup; + /** + * Whether the group is collapsed + */ + @Input() collapsed: boolean = true; + + /** + * Whether the group can be toggled when it's collapsed + */ + @Input() toggleCollapsed: boolean = true; + /** * Parent catalog's items store state. Groups share a unique * EntityState that tracks the group and it's layers state (whether they are added or not). @@ -90,6 +107,7 @@ export class CatalogBrowserGroupComponent implements OnInit, OnDestroy { ngOnInit() { this.store.load(this.group.items); this.evaluateAdded(); + this.evaluateDisabled(this.collapsed); if (this.catalog && this.catalog.sortDirection !== undefined) { this.store.view.sort({ direction: this.catalog.sortDirection, @@ -124,6 +142,14 @@ export class CatalogBrowserGroupComponent implements OnInit, OnDestroy { this.added$.value ? this.remove() : this.add(); } + /** + * On toggle button click, emit the added change event + * @internal + */ + onToggleCollapsed(collapsed: boolean) { + this.evaluateDisabled(collapsed); + } + /** * When a layer is added or removed, evaluate if all the layers of the group * are now added or removed. If so, consider that the group itself is added @@ -184,4 +210,12 @@ export class CatalogBrowserGroupComponent implements OnInit, OnDestroy { }); this.added$.next(added); } + + private evaluateDisabled(collapsed: boolean) { + let disabled = false; + if (this.toggleCollapsed === false) { + disabled = collapsed; + } + this.disabled$.next(disabled); + } } diff --git a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.html b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.html index 0cdc51dd12..bd1243d19c 100644 --- a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.html +++ b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.html @@ -5,6 +5,7 @@ [catalog]="catalog" [group]="item" [state]="store.state" + [toggleCollapsed]="toggleCollapsedGroup" (addedChange)="onGroupAddedChange($event)" (layerAddedChange)="onLayerAddedChange($event)"> diff --git a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts index f89998cc39..b5e12f4f1c 100644 --- a/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts +++ b/packages/geo/src/lib/catalog/catalog-browser/catalog-browser.component.ts @@ -52,6 +52,11 @@ export class CatalogBrowserComponent implements OnInit, OnDestroy { */ @Input() map: IgoMap; + /** + * Whether a group can be toggled when it's collapsed + */ + @Input() toggleCollapsedGroup: boolean = true; + constructor( private layerService: LayerService, private cdRef: ChangeDetectorRef