Просмотр исходного кода

feat(playlist): playlistsrv is now started by id

bergquist 10 лет назад
Родитель
Сommit
dca503bcbd
2 измененных файлов с 20 добавлено и 6 удалено
  1. 17 6
      public/app/features/playlist/playlistSrv.ts
  2. 3 0
      public/app/features/playlist/playlist_routes.js

+ 17 - 6
public/app/features/playlist/playlistSrv.ts

@@ -11,7 +11,11 @@ class PlaylistSrv {
   private interval: any
   private interval: any
 
 
   /** @ngInject */
   /** @ngInject */
-  constructor(private $rootScope:any, private $location:any, private $timeout:any) {
+  constructor(
+    private $rootScope:any,
+    private $location:any,
+    private $timeout:any,
+    private backendSrv:any) {
   }
   }
 
 
   next() {
   next() {
@@ -31,17 +35,24 @@ class PlaylistSrv {
     this.next();
     this.next();
   }
   }
 
 
-  start(dashboards, interval) {
+  start(playlistId) {
     this.stop();
     this.stop();
 
 
     this.index = 0;
     this.index = 0;
-    this.interval = kbn.interval_to_ms(interval);
 
 
-    this.dashboards = dashboards;
     this.$rootScope.playlistSrv = this;
     this.$rootScope.playlistSrv = this;
 
 
-    this.cancelPromise = this.$timeout(() => { this.next(); }, this.interval);
-    this.next();
+    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() {
   stop() {

+ 3 - 0
public/app/features/playlist/playlist_routes.js

@@ -29,6 +29,8 @@ function (angular) {
           init: function(backendSrv, playlistSrv, $route) {
           init: function(backendSrv, playlistSrv, $route) {
             var playlistId = $route.current.params.id;
             var playlistId = $route.current.params.id;
 
 
+            playlistSrv.start(playlistId)
+            /*
             return backendSrv.get('/api/playlists/' + playlistId)
             return backendSrv.get('/api/playlists/' + playlistId)
               .then(function(playlist) {
               .then(function(playlist) {
                 return backendSrv.get('/api/playlists/' + playlistId + '/dashboards')
                 return backendSrv.get('/api/playlists/' + playlistId + '/dashboards')
@@ -36,6 +38,7 @@ function (angular) {
                     playlistSrv.start(dashboards, playlist.interval);
                     playlistSrv.start(dashboards, playlist.interval);
                   });
                   });
               });
               });
+            */
           }
           }
         }
         }
       });
       });