| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- define([
- 'angular',
- 'lodash',
- 'kbn'
- ],
- function (angular, _, kbn) {
- 'use strict';
- var module = angular.module('grafana.services');
- module.service('playlistSrv', function($location, $rootScope) {
- var timerInstance;
- var favorites = { dashboards: [] };
- this.init = function() {
- var existingJson = window.localStorage["grafana-favorites"];
- if (existingJson) {
- favorites = angular.fromJson(existingJson);
- }
- };
- this._save = function() {
- window.localStorage["grafana-favorites"] = angular.toJson(favorites);
- };
- this._find = function(title) {
- return _.findWhere(favorites.dashboards, { title: title });
- };
- this._remove = function(existing) {
- if (existing) {
- favorites.dashboards = _.without(favorites.dashboards, existing);
- }
- };
- this.isCurrentFavorite = function(dashboard) {
- return this._find(dashboard.title) ? true : false;
- };
- this.markAsFavorite = function(dashboard) {
- var existing = this._find(dashboard.title);
- this._remove(existing);
- favorites.dashboards.push({
- url: $location.path(),
- title: dashboard.title
- });
- this._save();
- };
- this.removeAsFavorite = function(toRemove) {
- var existing = this._find(toRemove.title);
- this._remove(existing);
- this._save();
- };
- this.getFavorites = function() {
- return favorites;
- };
- this.start = function(dashboards, timespan) {
- var interval = kbn.interval_to_ms(timespan);
- var index = 0;
- $rootScope.playlist_active = true;
- timerInstance = setInterval(function() {
- $rootScope.$apply(function() {
- angular.element(window).unbind('resize');
- $location.path(dashboards[index % dashboards.length].url);
- index++;
- });
- }, interval);
- };
- this.stop = function() {
- clearInterval(timerInstance);
- $rootScope.playlist_active = false;
- };
- this.init();
- });
- });
|