From f60e2cd08b4dd804ad76848d05fdee2c106a3e9f Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Tue, 20 Feb 2018 10:37:52 +0000 Subject: [PATCH] mgr/dashboard_v2: Auto refresh hosts Signed-off-by: Ricardo Marques --- .../app/ceph/cluster/hosts/hosts.component.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/hosts/hosts.component.ts b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/hosts/hosts.component.ts index dfc7b62e050..f92f6de881b 100644 --- a/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/hosts/hosts.component.ts +++ b/src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/hosts/hosts.component.ts @@ -1,4 +1,4 @@ -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'; @@ -9,10 +9,12 @@ import { HostService } from '../../../shared/services/host.service'; templateUrl: './hosts.component.html', styleUrls: ['./hosts.component.scss'] }) -export class HostsComponent implements OnInit { +export class HostsComponent implements OnInit, OnDestroy { columns: Array = []; hosts: Array = []; + interval: any; + isLoadingHosts = false; @ViewChild('servicesTpl') public servicesTpl: TemplateRef; @@ -39,9 +41,20 @@ export class HostsComponent implements OnInit { 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) => { @@ -51,6 +64,9 @@ export class HostsComponent implements OnInit { return host; }); this.hosts = resp; + this.isLoadingHosts = false; + }).catch(() => { + this.isLoadingHosts = false; }); } } -- 2.39.5