]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard v2: Introduce CdTableSelection model 20746/head
authorVolker Theile <vtheile@suse.com>
Tue, 6 Mar 2018 12:14:27 +0000 (13:14 +0100)
committerVolker Theile <vtheile@suse.com>
Tue, 6 Mar 2018 16:01:03 +0000 (17:01 +0100)
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.ts
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/datatable/table/table.component.html
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/datatable/table/table.component.ts
src/pybind/mgr/dashboard_v2/frontend/src/app/shared/models/cd-table-selection.ts [new file with mode: 0644]

index f4be3192364708e9c979eea61b2192db930410ee..a9b41942bcdf884bcc3f10bea241eed775670126 100644 (file)
@@ -1,6 +1,7 @@
 import { Component } from '@angular/core';
 
 import { CdTableColumn } from '../../../shared/models/cd-table-column';
+import { CdTableSelection } from '../../../shared/models/cd-table-selection';
 import { CephShortVersionPipe } from '../../../shared/pipes/ceph-short-version.pipe';
 import { RgwDaemonService } from '../services/rgw-daemon.service';
 
@@ -45,7 +46,7 @@ export class RgwDaemonListComponent {
       });
   }
 
-  beforeShowDetails(selected: Array<object>) {
-    return selected.length === 1;
+  beforeShowDetails(selection: CdTableSelection) {
+    return selection.hasSingleSelection;
   }
 }
index 87feb73b7007ee1306253fdbafccf9bc59e2bf60..7ae84f98ca844db7ae1272c13eacb21a0e62b172 100644 (file)
@@ -51,8 +51,8 @@
                  class="bootstrap oadatatable"
                  [cssClasses]="paginationClasses"
                  [selectionType]="selectionType"
-                 [selected]="selected"
-                 (select)="toggleExpandRow()"
+                 [selected]="selection.selected"
+                 (select)="onSelect()"
                  [sorts]="sorts"
                  [columns]="columns"
                  [columnMode]="columnMode"
index 0df9d419f41cd1bfc00930a642f26eefef13b5bc..17998fb0b765cb7de0b7558fcfc170a8041e03a6 100644 (file)
@@ -20,6 +20,7 @@ import 'rxjs/add/observable/timer';
 import { Observable } from 'rxjs/Observable';
 
 import { CdTableColumn } from '../../models/cd-table-column';
+import { CdTableSelection } from '../../models/cd-table-selection';
 import { TableDetailsDirective } from '../table-details.directive';
 
 @Component({
@@ -79,13 +80,17 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
    */
   @Output() fetchData = new EventEmitter();
 
+  /**
+   * Use this variable to access the selected row(s).
+   */
+  selection = new CdTableSelection();
+
   cellTemplates: {
     [key: string]: TemplateRef<any>
   } = {};
   selectionType: string = undefined;
   search = '';
   rows = [];
-  selected = [];
   loadingIndicator = true;
   paginationClasses = {
     pagerLeftArrow: 'i fa fa-angle-double-left',
@@ -201,9 +206,14 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
     this.updating = false;
   }
 
+  onSelect() {
+    this.selection.update();
+    this.toggleExpandRow();
+  }
+
   toggleExpandRow() {
-    if (this.selected.length > 0) {
-      this.table.rowDetail.toggleExpandRow(this.selected[0]);
+    if (this.selection.hasSelection) {
+      this.table.rowDetail.toggleExpandRow(this.selection.first());
     } else {
       this.detailTemplate.viewContainerRef.clear();
     }
@@ -214,7 +224,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
       return;
     }
     if (_.isFunction(this.beforeShowDetails)) {
-      if (!this.beforeShowDetails(this.selected)) {
+      if (!this.beforeShowDetails(this.selection)) {
         return;
       }
     }
@@ -224,7 +234,7 @@ export class TableComponent implements AfterContentChecked, OnInit, OnChanges, O
     const cmpRef = this.detailTemplate.viewContainerRef.createComponent(
       this.componentFactoryResolver.resolveComponentFactory(factoryClass)
     );
-    cmpRef.instance.selected = this.selected;
+    cmpRef.instance.selected = this.selection.selected;
   }
 
   updateFilter(event?) {
diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/models/cd-table-selection.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/shared/models/cd-table-selection.ts
new file mode 100644 (file)
index 0000000..f6ec8b4
--- /dev/null
@@ -0,0 +1,24 @@
+export class CdTableSelection {
+  selected: any[] = [];
+  hasMultiSelection: boolean;
+  hasSingleSelection: boolean;
+  hasSelection: boolean;
+
+  constructor() {
+    this.update();
+  }
+
+  /**
+   * Recalculate the variables based on the current number
+   * of selected rows.
+   */
+  update() {
+    this.hasSelection = this.selected.length > 0;
+    this.hasSingleSelection = this.selected.length === 1;
+    this.hasMultiSelection = this.selected.length > 1;
+  }
+
+  first() {
+    return this.hasSelection ? this.selected[0] : null;
+  }
+}