From a61789da167f799c86ac987cbe8ef27a0c78791f Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Mon, 9 Sep 2019 18:04:17 +0200
Subject: [PATCH] only show selected regions if lengh > 0 update bookmark
 confirm icon

---
 src/components/dialog/dialog.component.ts            |  5 ++++-
 src/components/dialog/dialog.template.html           |  2 +-
 src/plugin_examples/plugin_api.md                    |  1 +
 src/services/dialogService.service.ts                | 12 ++++++++++--
 .../viewerStateController/viewerState.component.ts   |  6 ++++--
 .../viewerStateController/viewerState.template.html  |  2 +-
 6 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/components/dialog/dialog.component.ts b/src/components/dialog/dialog.component.ts
index 7001bbf09..1e5b2ce32 100644
--- a/src/components/dialog/dialog.component.ts
+++ b/src/components/dialog/dialog.component.ts
@@ -15,6 +15,8 @@ import { filter, share } from "rxjs/operators";
 export class DialogComponent implements OnInit, OnDestroy {
 
   private subscrptions: Subscription[] = []
+
+  @Input() iconClass: string = `fas fa-save`
   
   @Input() title: string = 'Message'
   @Input() placeholder: string = "Type your response here"
@@ -29,11 +31,12 @@ export class DialogComponent implements OnInit, OnDestroy {
     @Inject(MAT_DIALOG_DATA) public data:any,
     private dialogRef: MatDialogRef<DialogComponent>
   ){
-    const { title, placeholder, defaultValue, message } = this.data
+    const { title, placeholder, defaultValue, message, iconClass = null } = this.data
     if (title) this.title = title
     if (placeholder) this.placeholder = placeholder
     if (defaultValue) this.value = defaultValue
     if (message) this.message = message
+    if (typeof iconClass !== 'undefined') this.iconClass = iconClass
   }
 
   ngOnInit(){
diff --git a/src/components/dialog/dialog.template.html b/src/components/dialog/dialog.template.html
index 311b6f30f..067ecb0ff 100644
--- a/src/components/dialog/dialog.template.html
+++ b/src/components/dialog/dialog.template.html
@@ -32,7 +32,7 @@
     class="ml-1"
     mat-raised-button
     color="primary">
-    <i class="fas fa-save mr-1"></i>
+    <i *ngIf="iconClass" [ngClass]="iconClass" class="mr-1"></i>
     Confirm
   </button>
 </div>
\ No newline at end of file
diff --git a/src/plugin_examples/plugin_api.md b/src/plugin_examples/plugin_api.md
index f997fd378..9ae6069b3 100644
--- a/src/plugin_examples/plugin_api.md
+++ b/src/plugin_examples/plugin_api.md
@@ -155,6 +155,7 @@ window.interactiveViewer
     "message":"Message to be seen by the user.", // default: ""
     "placeholder": "Start typing here", // default: "Type your response here"
     "defaultValue": "42" // default: ""
+    "iconClass":"fas fa-save" // default fas fa-save, set to falsy value to disable
   }
   ```
   - *getUserConfirmation(config)* returns a Promise, resolves when user confirms, rejects when user cancels. expects config object object with the following structure:
diff --git a/src/services/dialogService.service.ts b/src/services/dialogService.service.ts
index 110edf666..02fd6b387 100644
--- a/src/services/dialogService.service.ts
+++ b/src/services/dialogService.service.ts
@@ -31,13 +31,20 @@ export class DialogService{
   }
 
   public getUserInput(config: Partial<DialogConfig> = {}):Promise<string>{
-    const { defaultValue = '', placeholder = 'Type your response here', title = 'Message', message = '' } = config
+    const {
+      defaultValue = '',
+      placeholder = 'Type your response here',
+      title = 'Message',
+      message = '',
+      iconClass
+    } = config
     this.dialogRef = this.dialog.open(DialogComponent, {
       data: {
         title,
         placeholder,
         defaultValue,
-        message
+        message,
+        iconClass
       }
     })
     return new Promise((resolve, reject) => {
@@ -59,4 +66,5 @@ export interface DialogConfig{
   placeholder: string
   defaultValue: string
   message: string
+  iconClass: string
 }
\ No newline at end of file
diff --git a/src/ui/viewerStateController/viewerState.component.ts b/src/ui/viewerStateController/viewerState.component.ts
index c344d3315..a0c33fd2b 100644
--- a/src/ui/viewerStateController/viewerState.component.ts
+++ b/src/ui/viewerStateController/viewerState.component.ts
@@ -132,7 +132,8 @@ export class ViewerStateController implements OnInit{
     this.dialogService.getUserInput({
       defaultValue: savedRegionsSelection.name,
       placeholder: `Enter new name`,
-      title: 'Edit name'
+      title: 'Edit name',
+      iconClass: null
     }).then(name => {
       if (!name) throw new Error('user cancelled')
       this.store$.dispatch({
@@ -186,7 +187,8 @@ export class ViewerStateController implements OnInit{
     this.dialogService.getUserInput({
       defaultValue: `Saved Region`,
       placeholder: `Name the selection`,
-      title: 'Save region selection'
+      title: 'Save region selection',
+      iconClass: 'far fa-bookmark'
     })
       .then(name => {
         if (!name) throw new Error('User cancelled')
diff --git a/src/ui/viewerStateController/viewerState.template.html b/src/ui/viewerStateController/viewerState.template.html
index 0f814b3e5..5223f311c 100644
--- a/src/ui/viewerStateController/viewerState.template.html
+++ b/src/ui/viewerStateController/viewerState.template.html
@@ -135,7 +135,7 @@
 
   <!-- selected regions -->
   <mat-card-content>
-    <mat-chip-list>
+    <mat-chip-list *ngIf="(regionsSelected$ | async)?.length > 0 ">
       <cdk-virtual-scroll-viewport
         class="w-100 h-10em overflow-x-hidden"
         [itemSize]="32">
-- 
GitLab