-import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
+import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { CdTableColumn } from '../../../shared/models/cd-table-column';
import { CephShortVersionPipe } from '../../../shared/pipes/ceph-short-version.pipe';
templateUrl: './hosts.component.html',
styleUrls: ['./hosts.component.scss']
})
-export class HostsComponent implements OnInit {
+export class HostsComponent implements OnInit, OnDestroy {
columns: Array<CdTableColumn> = [];
hosts: Array<object> = [];
+ interval: any;
+ isLoadingHosts = false;
@ViewChild('servicesTpl') public servicesTpl: TemplateRef<any>;
pipe: this.cephShortVersionPipe
}
];
+ this.interval = setInterval(() => {
+ this.getHosts();
+ }, 5000);
+ }
+
+ ngOnDestroy() {
+ clearInterval(this.interval);
}
getHosts() {
+ if (this.isLoadingHosts) {
+ return;
+ }
+ this.isLoadingHosts = true;
this.hostService.list().then((resp) => {
resp.map((host) => {
host.services.map((service) => {
return host;
});
this.hosts = resp;
+ this.isLoadingHosts = false;
+ }).catch(() => {
+ this.isLoadingHosts = false;
});
}
}