From 3949dfe4a72a683e74a7447a3190f96e7f4ca1bc Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Wed, 25 Dec 2019 15:48:05 +0800 Subject: [PATCH] mgr/dashboard: allow refreshing inventory page Fixes: https://tracker.ceph.com/issues/43420 Signed-off-by: Kiefer Chang --- .../inventory-devices.component.ts | 32 ++++++++++++++++--- .../inventory/inventory.component.html | 3 +- .../cluster/inventory/inventory.component.ts | 16 +++------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component.ts index ce5d3c2cfe3..79744611fd7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component.ts @@ -1,11 +1,21 @@ -import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; +import { + Component, + EventEmitter, + Input, + OnDestroy, + OnInit, + Output, + ViewChild +} from '@angular/core'; import { I18n } from '@ngx-translate/i18n-polyfill'; import * as _ from 'lodash'; import { BsModalService } from 'ngx-bootstrap/modal'; +import { Subscription } from 'rxjs'; import { OrchestratorService } from '../../../../shared/api/orchestrator.service'; import { FormModalComponent } from '../../../../shared/components/form-modal/form-modal.component'; +import { TableComponent } from '../../../../shared/datatable/table/table.component'; import { CellTemplate } from '../../../../shared/enum/cell-template.enum'; import { Icons } from '../../../../shared/enum/icons.enum'; import { NotificationType } from '../../../../shared/enum/notification-type.enum'; @@ -24,7 +34,10 @@ import { InventoryDevice } from './inventory-device.model'; templateUrl: './inventory-devices.component.html', styleUrls: ['./inventory-devices.component.scss'] }) -export class InventoryDevicesComponent implements OnInit, OnChanges { +export class InventoryDevicesComponent implements OnInit, OnDestroy { + @ViewChild(TableComponent, { static: true }) + table: TableComponent; + // Devices @Input() devices: InventoryDevice[] = []; @@ -46,11 +59,14 @@ export class InventoryDevicesComponent implements OnInit, OnChanges { @Output() filterChange = new EventEmitter(); + @Output() fetchInventory = new EventEmitter(); + icons = Icons; columns: Array = []; selection: CdTableSelection = new CdTableSelection(); permission: Permission; tableActions: CdTableAction[]; + fetchInventorySub: Subscription; constructor( private authStorageService: AuthStorageService, @@ -141,10 +157,18 @@ export class InventoryDevicesComponent implements OnInit, OnChanges { col.filterable = true; } }); + + if (this.fetchInventory.observers.length > 0) { + this.fetchInventorySub = this.table.fetchData.subscribe(() => { + this.fetchInventory.emit(); + }); + } } - ngOnChanges() { - this.devices = [...this.devices]; + ngOnDestroy() { + if (this.fetchInventorySub) { + this.fetchInventorySub.unsubscribe(); + } } onColumnFiltersChanged(event: CdTableColumnFiltersChange) { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.html index 8f573cf9810..de8a1145bd2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.html @@ -11,7 +11,8 @@
+ selectionType="single" + (fetchInventory)="refresh()">
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.ts index f7481ec417d..a1c6a4eccc1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory.component.ts @@ -22,7 +22,6 @@ export class InventoryComponent implements OnChanges, OnInit { docsUrl: string; devices: Array = []; - isLoadingDevices = false; constructor( private cephReleaseNamePipe: CephReleaseNamePipe, @@ -48,10 +47,6 @@ export class InventoryComponent implements OnChanges, OnInit { this.orchService.status().subscribe((data: { available: boolean }) => { this.orchestratorExist = data.available; this.checkingOrchestrator = false; - - if (this.orchestratorExist) { - this.getInventory(); - } }); } @@ -63,23 +58,20 @@ export class InventoryComponent implements OnChanges, OnInit { } getInventory() { - if (this.isLoadingDevices) { - return; - } - this.isLoadingDevices = true; if (this.hostname === '') { - this.isLoadingDevices = false; return; } this.orchService.inventoryDeviceList(this.hostname).subscribe( (devices: InventoryDevice[]) => { this.devices = devices; - this.isLoadingDevices = false; }, () => { this.devices = []; - this.isLoadingDevices = false; } ); } + + refresh() { + this.getInventory(); + } } -- 2.47.3