playlistSrv.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'app/core/utils/kbn',
  5. ],
  6. function (angular, _, kbn) {
  7. 'use strict';
  8. var module = angular.module('grafana.services');
  9. module.service('playlistSrv', function($location, $rootScope, $timeout) {
  10. var self = this;
  11. this.next = function() {
  12. $timeout.cancel(self.cancelPromise);
  13. angular.element(window).unbind('resize');
  14. var dash = self.dashboards[self.index % self.dashboards.length];
  15. $location.url('dashboard/' + dash.uri);
  16. self.index++;
  17. self.cancelPromise = $timeout(self.next, self.interval);
  18. };
  19. this.prev = function() {
  20. self.index = Math.max(self.index - 2, 0);
  21. self.next();
  22. };
  23. this.start = function(dashboards, timespan) {
  24. self.stop();
  25. self.index = 0;
  26. self.interval = kbn.interval_to_ms(timespan);
  27. self.dashboards = dashboards;
  28. $rootScope.playlistSrv = this;
  29. self.cancelPromise = $timeout(self.next, self.interval);
  30. self.next();
  31. };
  32. this.stop = function() {
  33. self.index = 0;
  34. if (self.cancelPromise) {
  35. $timeout.cancel(self.cancelPromise);
  36. }
  37. $rootScope.playlistSrv = null;
  38. };
  39. });
  40. });