Bläddra i källkod

Merge branch 'playlist_reload' of https://github.com/bergquist/grafana into bergquist-playlist_reload

Torkel Ödegaard 10 år sedan
förälder
incheckning
4ff7b0f49b

+ 0 - 56
public/app/features/playlist/playlistSrv.js

@@ -1,56 +0,0 @@
-define([
-  'angular',
-  'lodash',
-  'app/core/utils/kbn',
-],
-function (angular, _, kbn) {
-  'use strict';
-
-  var module = angular.module('grafana.services');
-
-  module.service('playlistSrv', function($location, $rootScope, $timeout) {
-    var self = this;
-
-    this.next = function() {
-      $timeout.cancel(self.cancelPromise);
-
-      angular.element(window).unbind('resize');
-      var dash = self.dashboards[self.index % self.dashboards.length];
-
-      $location.url('dashboard/' + dash.uri);
-
-      self.index++;
-      self.cancelPromise = $timeout(self.next, self.interval);
-    };
-
-    this.prev = function() {
-      self.index = Math.max(self.index - 2, 0);
-      self.next();
-    };
-
-    this.start = function(dashboards, interval) {
-      self.stop();
-
-      self.index = 0;
-      self.interval = kbn.interval_to_ms(interval);
-
-      self.dashboards = dashboards;
-      $rootScope.playlistSrv = this;
-
-      self.cancelPromise = $timeout(self.next, self.interval);
-      self.next();
-    };
-
-    this.stop = function() {
-      self.index = 0;
-
-      if (self.cancelPromise) {
-        $timeout.cancel(self.cancelPromise);
-      }
-
-      $rootScope.playlistSrv = null;
-    };
-
-  });
-
-});

+ 72 - 0
public/app/features/playlist/playlistSrv.ts

@@ -0,0 +1,72 @@
+///<reference path="../../headers/common.d.ts" />
+
+import angular from 'angular';
+import coreModule from '../../core/core_module';
+import kbn from 'app/core/utils/kbn';
+
+class PlaylistSrv {
+  private cancelPromise: any;
+  private dashboards: any;
+  private index: number;
+  private interval: any;
+  private playlistId: number;
+
+  /** @ngInject */
+  constructor(private $rootScope: any, private $location: any, private $timeout: any, private backendSrv: any) { }
+
+  next() {
+    this.$timeout.cancel(this.cancelPromise);
+
+    angular.element(window).unbind('resize');
+
+    if (this.index > this.dashboards.length -1) {
+      this.start(this.playlistId);
+    } else {
+      var dash = this.dashboards[this.index];
+
+      this.$location.url('dashboard/' + dash.uri);
+
+      this.index++;
+      this.cancelPromise = this.$timeout(() => { this.next(); }, this.interval);
+    }
+  }
+
+  prevfunction() {
+    this.index = Math.max(this.index - 2, 0);
+    this.next();
+  }
+
+  start(playlistId) {
+    this.stop();
+
+    this.index = 0;
+    this.playlistId = playlistId;
+
+    this.$rootScope.playlistSrv = this;
+
+    this.backendSrv.get('/api/playlists/' + playlistId)
+      .then((playlist) => {
+        this.backendSrv.get('/api/playlists/' + playlistId + '/dashboards')
+          .then((dashboards) => {
+            this.dashboards = dashboards;
+            this.interval = kbn.interval_to_ms(playlist.interval);
+            this.cancelPromise = this.$timeout(() => { this.next(); }, this.interval);
+
+            this.next();
+          });
+      });
+  }
+
+  stop() {
+    this.index = 0;
+    this.playlistId = 0;
+
+    if (this.cancelPromise) {
+        this.$timeout.cancel(this.cancelPromise);
+    }
+
+    this.$rootScope.playlistSrv = null;
+  }
+}
+
+coreModule.service('playlistSrv', PlaylistSrv);

+ 2 - 8
public/app/features/playlist/playlist_routes.js

@@ -26,16 +26,10 @@ function (angular) {
         templateUrl: 'app/partials/dashboard.html',
         controller : 'LoadDashboardCtrl',
         resolve: {
-          init: function(backendSrv, playlistSrv, $route) {
+          init: function(playlistSrv, $route) {
             var playlistId = $route.current.params.id;
 
-            return backendSrv.get('/api/playlists/' + playlistId)
-              .then(function(playlist) {
-                return backendSrv.get('/api/playlists/' + playlistId + '/dashboards')
-                  .then(function(dashboards) {
-                    playlistSrv.start(dashboards, playlist.interval);
-                  });
-              });
+            playlistSrv.start(playlistId);
           }
         }
       });