From bc21862661c25e025ee9b5cfc1399e8d82f16120 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 18 Jan 2016 13:21:48 +0100 Subject: [PATCH] tech(playlist): refactor playlistSrv to typescript --- public/app/features/playlist/playlistSrv.js | 56 -------------------- public/app/features/playlist/playlistSrv.ts | 58 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 56 deletions(-) delete mode 100644 public/app/features/playlist/playlistSrv.js create mode 100644 public/app/features/playlist/playlistSrv.ts diff --git a/public/app/features/playlist/playlistSrv.js b/public/app/features/playlist/playlistSrv.js deleted file mode 100644 index f7ea59b6c98..00000000000 --- a/public/app/features/playlist/playlistSrv.js +++ /dev/null @@ -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; - }; - - }); - -}); diff --git a/public/app/features/playlist/playlistSrv.ts b/public/app/features/playlist/playlistSrv.ts new file mode 100644 index 00000000000..2377aae8db2 --- /dev/null +++ b/public/app/features/playlist/playlistSrv.ts @@ -0,0 +1,58 @@ +/// + +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 + + /** @ngInject */ + constructor(private $rootScope:any, private $location:any, private $timeout:any) { + } + + next() { + this.$timeout.cancel(this.cancelPromise); + + angular.element(window).unbind('resize'); + var dash = this.dashboards[this.index % this.dashboards.length]; + + 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(dashboards, interval) { + this.stop(); + + this.index = 0; + this.interval = kbn.interval_to_ms(interval); + + this.dashboards = dashboards; + this.$rootScope.playlistSrv = this; + + this.cancelPromise = this.$timeout(() => { this.next(); }, this.interval); + this.next(); + } + + stop() { + this.index = 0; + + if (this.cancelPromise) { + this.$timeout.cancel(this.cancelPromise); + } + + this.$rootScope.playlistSrv = null; + } +} + +coreModule.service('playlistSrv', PlaylistSrv)