Fixed bug in grafana url setting 51/14551/1
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 19 Jun 2018 23:51:04 +0000 (01:51 +0200)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 19 Jun 2018 23:51:04 +0000 (01:51 +0200)
Change-Id: I1e66c8a35e5b60c559c8e3e3a5e137daed2591f5
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
webapp/src/app/@core-xds/services/config.service.ts
webapp/src/app/pages/supervision/supervision.component.ts

index beeeea8..23a9593 100644 (file)
@@ -57,7 +57,7 @@ export class ConfigService {
       }
       if (tm.name !== this.confStore.theme) {
         this.confStore.theme = tm.name;
-        this.save();
+        this.save(this.confStore);
       }
     });
 
@@ -75,16 +75,13 @@ export class ConfigService {
       this.confSubject.next(Object.assign({}, this.confStore));
     } else {
       // Set default config
-      this.confStore = this.confDefault;
-      this.save();
+      this.save(null);
     }
   }
 
   // Save config into cookie
-  save(cfg?: IConfig) {
-    if (typeof cfg !== 'undefined') {
-      this.confStore = this.confDefault;
-    }
+  save(cfg: IConfig | null) {
+    this.confStore = (cfg !== null) ? cfg : this.confDefault;
 
     // Notify subscribers
     this.confSubject.next(Object.assign({}, this.confStore));
index 53fff22..3fff2b7 100644 (file)
@@ -48,9 +48,11 @@ export interface GrafanaPanel {
 
 export class SupervisionComponent implements OnInit {
 
+  /* TODO bind tm_* and refresh in UI */
   @Input() theme = 'light';
-  @Input() tm_from = 1528988550450;
-  @Input() tm_to = 1528988842496;
+  @Input() tm_from = 'now-60s';
+  @Input() tm_to = 'now';
+  @Input() refresh = '5s';
   @Input() scroll_factor = 10000;
   @Input() zoom_factor = 100000;
 
@@ -111,55 +113,61 @@ export class SupervisionComponent implements OnInit {
   }
 
   timeChange(val: number) {
+    /* TODO: convert tm_from string to number
     this.tm_from += val * this.scroll_factor;
     this.tm_to += val * this.scroll_factor;
     this._initPanels();
+      */
   }
 
   zoomOut() {
+    /* TODO: convert tm_from string to number
     this.tm_from -= this.zoom_factor;
     this.tm_to += this.zoom_factor;
     this._initPanels();
+    */
   }
 
-
   private _initDashboard() {
+    // http://localhost:3000/d/Lbpwc6Iiz/agl-xds-supervisor?from=now-40s&to=now&refresh=5s
     this.dashboards.forEach(dd => {
-      dd.url = this._buildDashboardUrl(dd.shortname, this.tm_from, this.tm_to, this.theme);
+      dd.url = this._buildDashboardUrl(dd.shortname, this.tm_from, this.tm_to, this.refresh, this.theme);
       dd.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(dd.url);
     });
   }
   private _initPanels() {
     this.panels.forEach(gg => {
-      gg.url = this._buildPanelUrl(gg.index, this.tm_from, this.tm_to, this.theme);
+      gg.url = this._buildPanelUrl(gg.index, this.tm_from, this.tm_to, this.refresh, this.theme);
       gg.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(gg.url);
     });
   }
 
-  private _buildDashboardUrl(sname: string, from: number, to: number, theme: string) {
+  private _buildDashboardUrl(sname, from, to, refresh, theme: string) {
     // FIXME get sname from config to support several dashboards
     let url = 'http://localhost:3000/d/Lbpwc6Iiz/' + sname;
     if (this.Config.grafanaDashboardUrl !== '') {
       url = this.Config.grafanaDashboardUrl;
     }
     url += '?orgId=1';
-    url += '&from=' + from;
-    url += '&to=' + to;
-    url += '&theme=' + theme;
+    if (from !== '') { url += '&from=' + from; }
+    if (to !== '') { url += '&to=' + to; }
+    if (theme !== '') { url += '&theme=' + theme; }
+    if (refresh !== '') { url += '&refresh=' + refresh; }
     url += '&sidemenu=close';
     return url;
   }
 
-  private _buildPanelUrl(idx: string, from: number, to: number, theme: string) {
+  private _buildPanelUrl(idx, from, to, refresh, theme: string) {
     let url = 'http://localhost:3000/d-solo/Lbpwc6Iiz/agl-xds-supervisor';
     if (this.Config.grafanaDashboardUrl !== '') {
       url = this.Config.grafanaDashboardUrl;
     }
     url += '?panelId=' + idx;
     url += '&orgId=1';
-    url += '&from=' + from;
-    url += '&to=' + to;
-    url += '&theme=' + theme;
+    if (from !== '') { url += '&from=' + from; }
+    if (to !== '') { url += '&to=' + to; }
+    if (theme !== '') { url += '&theme=' + theme; }
+    if (refresh !== '') { url += '&refresh=' + refresh; }
     url += '&sidemenu=close';
     return url;
   }