mirror of https://github.com/grafana/grafana
began work on dashboard playlist feature, #36
parent
adfa341d6e
commit
a387d48b48
@ -0,0 +1,27 @@ |
||||
define([ |
||||
'angular' |
||||
], |
||||
function (angular) { |
||||
'use strict'; |
||||
|
||||
var module = angular.module('kibana.controllers'); |
||||
|
||||
module.controller('PlaylistCtrl', function($scope, playlistSrv) { |
||||
|
||||
$scope.init = function() { |
||||
$scope.timespan = "15s"; |
||||
$scope.loadFavorites(); |
||||
$scope.$on('modal-opened', $scope.loadFavorites); |
||||
}; |
||||
|
||||
$scope.loadFavorites = function() { |
||||
$scope.favDashboards = playlistSrv.getFavorites().dashboards; |
||||
}; |
||||
|
||||
$scope.start = function() { |
||||
playlistSrv.start($scope.favDashboards, $scope.timespan); |
||||
}; |
||||
|
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,38 @@ |
||||
<div ng-controller="PlaylistCtrl" ng-init="init()"> |
||||
<div class="modal-header"> |
||||
<h3>Start playlist</h3> |
||||
</div> |
||||
<div class="modal-body"> |
||||
<div class="editor-row"> |
||||
<div class="section span4"> |
||||
<div class="editor-option"> |
||||
<label class="small">Dashboards</label> |
||||
|
||||
<table class="table table-striped" style="width: 300px"> |
||||
<tr ng-repeat="dashboard in favDashboards"> |
||||
<td> |
||||
{{dashboard.title}} |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
<div class="section span4"> |
||||
<label> |
||||
Timespan between change |
||||
</label> |
||||
<input type="text" class="input-small" ng-model="timespan" /> |
||||
</div> |
||||
<div class="section"> |
||||
<span> |
||||
Dashboards available in the playlist are only the once marked as favorites (stored in local browser storage). |
||||
To mark a dashboard as favorite, use save icon in the menu and in the dropdown select Favorites > Mark as favorite |
||||
</span> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="modal-footer"> |
||||
<button class="btn btn-success" ng-click="start();dismiss();"><i class="icon-play"></i> Start</button> |
||||
<button type="button" class="btn btn-primary" ng-click="dismiss();"><i class="icon-ban-circle"></i> Cancel</button> |
||||
</div> |
||||
</div> |
@ -0,0 +1,55 @@ |
||||
define([ |
||||
'angular', |
||||
'underscore', |
||||
'kbn' |
||||
], |
||||
function (angular, _, kbn) { |
||||
'use strict'; |
||||
|
||||
var module = angular.module('kibana.services'); |
||||
|
||||
module.service('playlistSrv', function(dashboard, $location, $rootScope) { |
||||
|
||||
this.markAsFavorite = function() { |
||||
var favorites = this.getFavorites(); |
||||
|
||||
var existing = _.findWhere(favorites.dashboards, { title: dashboard.current.title }); |
||||
|
||||
if (existing) { |
||||
favorites.dashboard = _.without(favorites.dashboards, existing); |
||||
} |
||||
|
||||
favorites.dashboards.push({ url: $location.path(), title: dashboard.current.title }); |
||||
|
||||
window.localStorage["grafana-favorites"] = angular.toJson(favorites); |
||||
}; |
||||
|
||||
this.getFavorites = function() { |
||||
|
||||
var favorites = { dashboards: [] }; |
||||
var existingJson = window.localStorage["grafana-favorites"]; |
||||
if (existingJson) { |
||||
favorites = angular.fromJson(existingJson); |
||||
} |
||||
|
||||
return favorites; |
||||
}; |
||||
|
||||
this.start = function(dashboards, timespan) { |
||||
var interval = kbn.interval_to_ms(timespan); |
||||
var index = 0; |
||||
|
||||
$rootScope.playlist_active = true; |
||||
$rootScope.playlist_interval = interval; |
||||
|
||||
setInterval(function() { |
||||
$rootScope.$apply(function() { |
||||
$location.path(dashboards[index % dashboards.length].url); |
||||
index++; |
||||
}); |
||||
}, interval); |
||||
}; |
||||
|
||||
}); |
||||
|
||||
}); |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue