You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by GitBox <gi...@apache.org> on 2018/11/16 09:36:49 UTC

[GitHub] tobias-istvan closed pull request #23: [AMBARI-24891] [Log Serach UI] The Log Index Filter panel does not work

tobias-istvan closed pull request #23: [AMBARI-24891] [Log Serach UI] The Log Index Filter panel does not work
URL: https://github.com/apache/ambari-logsearch/pull/23
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ambari-logsearch-web/src/app/components/action-menu/action-menu.component.ts b/ambari-logsearch-web/src/app/components/action-menu/action-menu.component.ts
index 721ae93d74..a5d9ae2f32 100644
--- a/ambari-logsearch-web/src/app/components/action-menu/action-menu.component.ts
+++ b/ambari-logsearch-web/src/app/components/action-menu/action-menu.component.ts
@@ -75,6 +75,9 @@ export class ActionMenuComponent  implements OnInit, OnDestroy {
     this.selectedClusterName$.takeUntil(this.destroyed$).subscribe(
       (clusterName: string) => this.setModalSubmitDisabled(!clusterName)
     );
+    this.clustersListItems$.filter((items: ListItem[]) => items.some((item: ListItem) => item.isChecked)).first()
+      .map((items: ListItem[]) => items.find((item: ListItem) => item.isChecked))
+      .subscribe((item) => this.selectedClusterName$.next(item.value));
   }
 
   ngOnDestroy() {
diff --git a/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.ts b/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.ts
index d6f24e5291..21cc1510f2 100644
--- a/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.ts
+++ b/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.ts
@@ -51,7 +51,7 @@ export class FilterButtonComponent extends MenuButtonComponent implements Contro
   }
 
   writeValue(items: ListItem[]) {
-    this.selection = items;
+    this.selection = items ? (Array.isArray(items) ? items : [items] ) : [];
   }
 
   registerOnChange(callback: any): void {
diff --git a/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.html b/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.html
index 7061defaa7..28cde2be3f 100644
--- a/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.html
+++ b/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.html
@@ -15,7 +15,7 @@
   limitations under the License.
 -->
 
-<div #dropdown [ngClass]="{'dropdown': hasSubItems, 'text-center': true, 'open': dropdownIsOpen, 'disabled': isDisabled}">
+<div #dropdown [ngClass]="{'dropdown': hasSubItems, 'text-center': true, 'open': dropdownIsOpen, 'disabled': isDisabled, 'has-selection': hasSelection}">
   <a class="dropdown-toggle" [ngClass]="(labelClass || '') + (hasCaret ? ' has-caret' : '')"
     (click)="onMouseClick($event)"
     (mousedown)="onMouseDown($event)">
diff --git a/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.ts b/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.ts
index faf2165c7a..317499146f 100644
--- a/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.ts
+++ b/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.ts
@@ -127,6 +127,14 @@ export class MenuButtonComponent {
     return this.subItems && this.subItems.filter((option: ListItem): boolean => option.isChecked);
   }
 
+  get hasSelection(): boolean {
+    return this.subItems && this.subItems.filter((option: ListItem): boolean => option.isChecked).length > 0;
+  }
+
+  get totalSelection(): number {
+    return this.subItems ? this.subItems.filter((option: ListItem): boolean => option.isChecked).length : 0;
+  }
+
   constructor(private utils: UtilsService) {}
 
   findItemIndexInList(item: ListItem, itemList: ListItem[] = this.subItems): number {
diff --git a/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.html b/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.html
index 714002854a..f4fdf4f1b6 100644
--- a/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.html
+++ b/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.html
@@ -15,17 +15,19 @@
   limitations under the License.
 -->
 
-<div [ngClass]="{'dropup': isDropup}">
+<div [ngClass]="{'dropup': isDropup, 'has-selection': hasSelection}">
   <button [ngClass]="['btn', 'dropdown-toggle', buttonClass]" data-toggle="dropdown">
     <span class="filter-label">
       <span *ngIf="iconClass || label" [class.plain]="!isMultipleChoice && !hideCaret && showSelectedValue">
         <span *ngIf="iconClass" [ngClass]="iconClass"></span>
-        <span *ngIf="label && (!selection.length || isMultipleChoice || showCommonLabelWithSelection)"
+        <span *ngIf="label && (!hasSelection || isMultipleChoice || showCommonLabelWithSelection)"
               [class.label-before-selection]="isSelectionDisplayable">
           {{label}}
         </span>
       </span>
-      <span *ngIf="isSelectionDisplayable">{{selection[0].label | translate}}</span>
+      <span *ngIf="isSelectionDisplayable">
+        <span class="selected-item-label" *ngFor="let item of selectedItems">{{ item.label | translate }}</span>
+      </span>
       <span *ngIf="!hideCaret" class="caret"></span>
     </span>
   </button>
diff --git a/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.ts b/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.ts
index 74341aeff4..2d04f210e5 100644
--- a/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.ts
+++ b/ambari-logsearch-web/src/app/modules/shared/components/dropdown-button/dropdown-button.component.ts
@@ -67,14 +67,31 @@ export class DropdownButtonComponent {
   @Input()
   useClearToDefaultSelection = false;
 
-  protected selectedItems?: ListItem[] = [];
+  protected selectedItems: ListItem[] = [];
 
   get selection(): ListItem[] {
     return this.selectedItems;
   }
 
   set selection(items: ListItem[]) {
-    this.selectedItems = items;
+    this.selectedItems = <ListItem[]>(Array.isArray(items) ? items : (items || []));
+    if (this.selectedItems.length > 1 && !this.isMultipleChoice) {
+      this.selectedItems = this.selectedItems.slice(0, 1);
+    }
+    if (this.isMultipleChoice && this.options) {
+      this.options.forEach((option: ListItem): void => {
+        const selectionItem = this.selectedItems.find((item: ListItem): boolean => this.utils.isEqual(item.value, option.value));
+        option.isChecked = !!selectionItem;
+      });
+    }
+  }
+
+  get hasSelection(): boolean {
+    return this.selectedItems.length > 0;
+  }
+
+  get totalSelection(): number {
+    return this.selectedItems.length;
   }
 
   // TODO handle case of selections with multiple items
@@ -84,7 +101,7 @@ export class DropdownButtonComponent {
    * @returns {boolean}
    */
   get isSelectionDisplayable(): boolean {
-    return this.showSelectedValue && !this.isMultipleChoice && this.selection.length > 0;
+    return this.showSelectedValue && !this.isMultipleChoice && this.hasSelection;
   }
 
   constructor(
diff --git a/ambari-logsearch-web/src/app/modules/shared/components/dropdown-list/dropdown-list.component.ts b/ambari-logsearch-web/src/app/modules/shared/components/dropdown-list/dropdown-list.component.ts
index 9967c80468..14537b6248 100644
--- a/ambari-logsearch-web/src/app/modules/shared/components/dropdown-list/dropdown-list.component.ts
+++ b/ambari-logsearch-web/src/app/modules/shared/components/dropdown-list/dropdown-list.component.ts
@@ -20,9 +20,8 @@ import {
   Component, OnChanges, AfterViewChecked, OnDestroy, SimpleChanges, Input, Output, EventEmitter,
   ViewChildren, ViewContainerRef, QueryList, ChangeDetectorRef, ElementRef, ViewChild, OnInit
 } from '@angular/core';
-import {Subscription} from 'rxjs/Subscription';
-import {ListItem} from '@app/classes/list-item';
-import {ComponentGeneratorService} from '@app/services/component-generator.service';
+import { ListItem } from '@app/classes/list-item';
+import { ComponentGeneratorService } from '@app/services/component-generator.service';
 import { Subject } from 'rxjs/Subject';
 
 @Component({
diff --git a/ambari-logsearch-web/src/app/modules/shared/components/filter-dropdown/filter-dropdown.component.ts b/ambari-logsearch-web/src/app/modules/shared/components/filter-dropdown/filter-dropdown.component.ts
index 669fcc9d3d..b0c766e933 100644
--- a/ambari-logsearch-web/src/app/modules/shared/components/filter-dropdown/filter-dropdown.component.ts
+++ b/ambari-logsearch-web/src/app/modules/shared/components/filter-dropdown/filter-dropdown.component.ts
@@ -36,20 +36,6 @@ export class FilterDropdownComponent extends DropdownButtonComponent implements
 
   private onChange;
 
-  get selection(): ListItem[] {
-    return this.selectedItems;
-  }
-
-  set selection(items: ListItem[]) {
-    this.selectedItems = items;
-    if (this.isMultipleChoice && this.options) {
-      this.options.forEach((option: ListItem): void => {
-        const selectionItem = items.find((item: ListItem): boolean => this.utils.isEqual(item.value, option.value));
-        option.isChecked = Boolean(selectionItem);
-      });
-    }
-  }
-
   private _onChange(value) {
     if (this.onChange) {
       this.onChange(value);
@@ -65,7 +51,7 @@ export class FilterDropdownComponent extends DropdownButtonComponent implements
   }
 
   writeValue(items: ListItem[]) {
-    this.selection = items || [];
+    this.selection = items ? (Array.isArray(items) ? items : [items] ) : [];
   }
 
   registerOnChange(callback: any): void {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services