-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';
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[] = [];
@Output() filterChange = new EventEmitter<CdTableColumnFiltersChange>();
+ @Output() fetchInventory = new EventEmitter();
+
icons = Icons;
columns: Array<CdTableColumn> = [];
selection: CdTableSelection = new CdTableSelection();
permission: Permission;
tableActions: CdTableAction[];
+ fetchInventorySub: Subscription;
constructor(
private authStorageService: AuthStorageService,
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) {
docsUrl: string;
devices: Array<InventoryDevice> = [];
- isLoadingDevices = false;
constructor(
private cephReleaseNamePipe: CephReleaseNamePipe,
this.orchService.status().subscribe((data: { available: boolean }) => {
this.orchestratorExist = data.available;
this.checkingOrchestrator = false;
-
- if (this.orchestratorExist) {
- this.getInventory();
- }
});
}
}
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();
+ }
}