Commit 8722ee8a by Torkel Ödegaard

Worked on playlist update for Grafana 2.0, added dashboard search to playliststart view, #1460

parent 1a440361
...@@ -20,6 +20,7 @@ func AdminGetSettings(c *middleware.Context) { ...@@ -20,6 +20,7 @@ func AdminGetSettings(c *middleware.Context) {
if strings.Contains(keyName, "secret") || strings.Contains(keyName, "password") { if strings.Contains(keyName, "secret") || strings.Contains(keyName, "password") {
value = "************" value = "************"
} }
jsonSec[keyName] = value jsonSec[keyName] = value
} }
} }
......
...@@ -8,29 +8,38 @@ function (angular, _, config) { ...@@ -8,29 +8,38 @@ function (angular, _, config) {
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');
module.controller('PlaylistCtrl', function($scope, playlistSrv) { module.controller('PlaylistCtrl', function($scope, playlistSrv, datasourceSrv) {
$scope.init = function() { $scope.init = function() {
$scope.playlist = [];
$scope.timespan = config.playlist_timespan; $scope.timespan = config.playlist_timespan;
$scope.loadFavorites(); $scope.db = datasourceSrv.getGrafanaDB();
$scope.search();
}; };
$scope.loadFavorites = function() { $scope.search = function() {
$scope.favDashboards = playlistSrv.getFavorites().dashboards; var query = {starred: true, limit: 10};
_.each($scope.favDashboards, function(dashboard) { if ($scope.searchQuery) {
dashboard.include = true; query.query = $scope.searchQuery;
query.starred = false;
}
$scope.db.searchDashboards(query).then(function(results) {
$scope.searchHits = results.dashboards;
}); });
}; };
$scope.removeAsFavorite = function(dashboard) { $scope.addDashboard = function(dashboard) {
playlistSrv.removeAsFavorite(dashboard); $scope.playlist.push(dashboard);
$scope.loadFavorites(); };
$scope.removeDashboard = function(dashboard) {
$scope.playlist = _.without($scope.playlist, dashboard);
}; };
$scope.start = function() { $scope.start = function() {
var included = _.where($scope.favDashboards, { include: true }); playlistSrv.start($scope.playlist, $scope.timespan);
playlistSrv.start(included, $scope.timespan);
}; };
}); });
......
...@@ -61,6 +61,8 @@ function (angular, _, kbn, store) { ...@@ -61,6 +61,8 @@ function (angular, _, kbn, store) {
}; };
this.start = function(dashboards, timespan) { this.start = function(dashboards, timespan) {
this.stop();
var interval = kbn.interval_to_ms(timespan); var interval = kbn.interval_to_ms(timespan);
var index = 0; var index = 0;
...@@ -69,8 +71,10 @@ function (angular, _, kbn, store) { ...@@ -69,8 +71,10 @@ function (angular, _, kbn, store) {
timerInstance = setInterval(function() { timerInstance = setInterval(function() {
$rootScope.$apply(function() { $rootScope.$apply(function() {
angular.element(window).unbind('resize'); angular.element(window).unbind('resize');
$location.search({}); var dash = dashboards[index % dashboards.length];
$location.path(dashboards[index % dashboards.length].url); var relativeUrl = dash.url.substring($location.absUrl().length - $location.url().length);
$location.url(relativeUrl);
index++; index++;
}); });
}, interval); }, interval);
......
...@@ -12,56 +12,88 @@ ...@@ -12,56 +12,88 @@
</div> </div>
<div class="gf-box-body"> <div class="gf-box-body">
<div class="row" style="margin-bottom: 10px;">
<div class="span6">
<div style="display: inline-block">
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item">
Search
</li>
<li>
<input type="text" class="tight-form-input input-xlarge last" ng-model="searchQuery" placeholder="query or empty for starred" ng-change="search()">
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="span6">
<h5>Playlist dashboards</h5>
</div>
</div>
<div class="editor-row"> <div class="row">
<div class="section"> <div class="span6">
<div class="editor-option"> <table class="grafana-options-table">
<table class="table table-striped span4"> <tr ng-repeat="dashboard in searchHits">
<tr>
<th>Dashboard</th>
<th>Include</th>
<th style="white-space: nowrap;">Remove as favorite</th>
</tr>
<tr ng-repeat="dashboard in favDashboards">
<td style="white-space: nowrap;"> <td style="white-space: nowrap;">
{{dashboard.title}} {{dashboard.title}}
</td> </td>
<td style="text-align: center"> <td style="text-align: center">
<input id="dash-{{$index}}" class="cr1" type="checkbox" ng-model="dashboard.include" ng-checked="dashboard.include" /> <button class="btn btn-inverse btn-mini pull-right" ng-click="addDashboard(dashboard)">
<label for="dash-{{$index}}" class="cr1"></label> <i class="fa fa-arrow-right"></i>
</button>
</td>
</tr>
<tr ng-hide="searchHits.length">
<td colspan="3">
<i class="fa fa-warning"></i> No dashboards found
</td>
</tr>
</table>
</div>
<div class="span6">
<table class="grafana-options-table">
<tr ng-repeat="dashboard in playlist">
<td style="white-space: nowrap;">
{{dashboard.title}}
</td> </td>
<td style="text-align: center"> <td style="text-align: center">
<i class="fa fa-remove pointer" ng-click="removeAsFavorite(dashboard)"></i> <button class="btn btn-inverse btn-mini pull-right" ng-click="removeDashboard(dashboard)">
<i class="fa fa-remove"></i>
</button>
</td> </td>
</tr> </tr>
<tr ng-hide="favDashboards.length"> <tr ng-hide="searchHits.length">
<td colspan="3"> <td colspan="3">
<i class="fa fa-warning"></i> No dashboards marked as favorites <i class="fa fa-warning"></i> No dashboards found
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
<div class="editor-option">
<div class="span4">
<span><i class="fa fa-question-circle"></i>
dashboards available in the playlist are only the ones 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 mark as favorite
<br/><br/>
</span>
</div>
</div> </div>
<div class="editor-option">
<label> <br>
Timespan between change <br>
</label> <div class="pull-left">
<input type="text" class="input-small" ng-model="timespan" /> <div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item">
Timespan between dashboard change
</li>
<li>
<input type="text" class="tight-form-input input-small" ng-model="timespan" />
</li>
<li>
<button class="btn btn-success tight-form-btn" ng-click="start();dismiss();"><i class="fa fa-play"></i> Start</button>
</li>
</ul>
<div class="clearfix"></div>
</div> </div>
</div> </div>
</div> <div class="clearfix"></div>
<br>
<button class="btn btn-success pull-right" ng-click="start();dismiss();"><i class="fa fa-play"></i> Start</button>
<br>
</div> </div>
</div> </div>
define([
'angular',
'lodash',
],
function (angular, _) {
'use strict';
var module = angular.module('grafana.services');
module.service('userSrv', function() {
function User() {
if (window.grafanaBootData.user) {
_.extend(this, window.grafanaBootData.user);
}
}
this.getSignedInUser = function() {
return new User();
};
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment