]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard_v2: Auto refresh hosts
authorRicardo Marques <rimarques@suse.com>
Tue, 20 Feb 2018 10:37:52 +0000 (10:37 +0000)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:12 +0000 (13:07 +0000)
Signed-off-by: Ricardo Marques <rimarques@suse.com>
src/pybind/mgr/dashboard_v2/frontend/src/app/ceph/cluster/hosts/hosts.component.ts

index dfc7b62e050a989fe293a744a4aa40eda6daca91..f92f6de881b03a28ba937b581f3b262206fdc0ad 100644 (file)
@@ -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<CdTableColumn> = [];
   hosts: Array<object> = [];
+  interval: any;
+  isLoadingHosts = false;
 
   @ViewChild('servicesTpl') public servicesTpl: TemplateRef<any>;
 
@@ -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;
     });
   }
 }