Commit 51008341 by Torkel Ödegaard

worked on favorites feature and dashboard playlist, #36

parent a387d48b
...@@ -154,8 +154,22 @@ function (angular, _, moment) { ...@@ -154,8 +154,22 @@ function (angular, _, moment) {
}); });
}; };
$scope.openSaveDropdown = function() {
$scope.isFavorite = playlistSrv.isCurrentFavorite();
};
$scope.markAsFavorite = function() { $scope.markAsFavorite = function() {
playlistSrv.markAsFavorite(); playlistSrv.markAsFavorite();
$scope.isFavorite = true;
};
$scope.removeAsFavorite = function() {
playlistSrv.removeAsFavorite(dashboard.current);
$scope.isFavorite = false;
};
$scope.stopPlaylist = function() {
playlistSrv.stop(1);
}; };
}); });
......
define([ define([
'angular' 'angular',
'underscore'
], ],
function (angular) { function (angular, _) {
'use strict'; 'use strict';
var module = angular.module('kibana.controllers'); var module = angular.module('kibana.controllers');
...@@ -16,10 +17,20 @@ function (angular) { ...@@ -16,10 +17,20 @@ function (angular) {
$scope.loadFavorites = function() { $scope.loadFavorites = function() {
$scope.favDashboards = playlistSrv.getFavorites().dashboards; $scope.favDashboards = playlistSrv.getFavorites().dashboards;
_.each($scope.favDashboards, function(dashboard) {
dashboard.include = true;
});
};
$scope.removeAsFavorite = function(dashboard) {
playlistSrv.removeAsFavorite(dashboard);
$scope.loadFavorites();
}; };
$scope.start = function() { $scope.start = function() {
playlistSrv.start($scope.favDashboards, $scope.timespan); var included = _.where($scope.favDashboards, { include: true });
playlistSrv.start(included, $scope.timespan);
}; };
}); });
......
...@@ -18,6 +18,7 @@ function (angular, _, $) { ...@@ -18,6 +18,7 @@ function (angular, _, $) {
elem.bind('click',function() { elem.bind('click',function() {
if ($(id).length) { if ($(id).length) {
elem.attr('data-target', id).attr('data-toggle', 'modal'); elem.attr('data-target', id).attr('data-toggle', 'modal');
scope.$apply(function() { scope.$broadcast('modal-opened'); });
return; return;
} }
...@@ -32,8 +33,6 @@ function (angular, _, $) { ...@@ -32,8 +33,6 @@ function (angular, _, $) {
$q.when(panelModal).then(function(modalEl) { $q.when(panelModal).then(function(modalEl) {
elem.attr('data-target', id).attr('data-toggle', 'modal'); elem.attr('data-target', id).attr('data-toggle', 'modal');
scope.$emit('modal-opened');
$timeout(function () { $timeout(function () {
if (!modalEl.data('modal').isShown) { if (!modalEl.data('modal').isShown) {
modalEl.modal('show'); modalEl.modal('show');
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<li ng-repeat="pulldown in dashboard.current.nav" ng-controller="PulldownCtrl" ng-show="pulldown.enable"><kibana-simple-panel type="pulldown.type" ng-cloak></kibana-simple-panel></li> <li ng-repeat="pulldown in dashboard.current.nav" ng-controller="PulldownCtrl" ng-show="pulldown.enable"><kibana-simple-panel type="pulldown.type" ng-cloak></kibana-simple-panel></li>
<li class="dropdown grafana-menu-save" ng-show="showDropdown('save')"> <li class="dropdown grafana-menu-save" ng-show="showDropdown('save')">
<a href="#" bs-tooltip="'Save'" data-placement="bottom" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" bs-tooltip="'Save'" data-placement="bottom" class="dropdown-toggle" data-toggle="dropdown" ng-click="openSaveDropdown()">
<i class='icon-save'></i> <i class='icon-save'></i>
</a> </a>
...@@ -38,9 +38,12 @@ ...@@ -38,9 +38,12 @@
<li ng-show="dashboard.current.loader.save_default"> <li ng-show="dashboard.current.loader.save_default">
<a class="link" ng-click="purge_default()">Reset Home</a> <a class="link" ng-click="purge_default()">Reset Home</a>
</li> </li>
<li> <li ng-show="!isFavorite">
<a class="link" ng-click="markAsFavorite()">Mark as favorite</a> <a class="link" ng-click="markAsFavorite()">Mark as favorite</a>
</li> </li>
<li ng-show="isFavorite">
<a class="link" ng-click="removeAsFavorite()">Remove as favorite</a>
</li>
<li ng-show="dashboard.current.loader.save_local"> <li ng-show="dashboard.current.loader.save_local">
<a class="link" ng-click="dashboard.to_file()">Export schema</a> <a class="link" ng-click="dashboard.to_file()">Export schema</a>
</li> </li>
...@@ -67,3 +70,8 @@ ...@@ -67,3 +70,8 @@
<li class="grafana-menu-edit" ng-show="dashboard.current.editable" bs-tooltip="'Configure dashboard'" data-placement="bottom"><a class="link" config-modal="app/partials/dasheditor.html"><i class='icon-cog pointer'></i></a></li> <li class="grafana-menu-edit" ng-show="dashboard.current.editable" bs-tooltip="'Configure dashboard'" data-placement="bottom"><a class="link" config-modal="app/partials/dasheditor.html"><i class='icon-cog pointer'></i></a></li>
<li class="grafana-menu-stop-playlist hide">
<a class='small' ng-click='stopPlaylist(2)'>
Stop playlist
</a>
</li>
\ No newline at end of file
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
</div> </div>
</div> </div>
<div class="row-fluid" ng-show='dashboard.current.editable && dashboard.current.panel_hints' class="add-row-panel-hint"> <div ng-show='dashboard.current.editable && dashboard.current.panel_hints' class="row-fluid add-row-panel-hint">
<div class="span12" style="text-align:right;"> <div class="span12" style="text-align:right;">
<span style="margin-left: 0px;" class="pointer btn btn-mini" config-modal="app/partials/dasheditor.html"> <span style="margin-left: 0px;" class="pointer btn btn-mini" config-modal="app/partials/dasheditor.html">
<span ng-click="editor.index = 1"><i class="icon-plus-sign"></i> ADD A ROW</span> <span ng-click="editor.index = 1"><i class="icon-plus-sign"></i> ADD A ROW</span>
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
<div ng-controller="PlaylistCtrl" ng-init="init()"> <div ng-controller="PlaylistCtrl" ng-init="init()">
<div class="modal-header"> <div class="modal-header">
<h3>Start playlist</h3> <h3>Start dashboard playlist</h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="editor-row"> <div class="editor-row">
<div class="section span4"> <div class="section">
<div class="editor-option"> <div class="editor-option">
<label class="small">Dashboards</label> <table class="table table-striped span4">
<tr>
<table class="table table-striped" style="width: 300px"> <th>Dashboard</th>
<tr ng-repeat="dashboard in favDashboards"> <th>Include</th>
<td> <th style="white-space: nowrap;">Remove as favorite</th>
{{dashboard.title}} </tr>
</td> <tr ng-repeat="dashboard in favDashboards">
</tr> <td style="white-space: nowrap;">
</table> {{dashboard.title}}
</div> </td>
</div> <td style="text-align: center">
<div class="section span4"> <input type="checkbox" ng-model="dashboard.include" ng-checked="dashboard.include" />
<label> </td>
Timespan between change <td style="text-align: center">
</label> <i class="icon-remove pointer" ng-click="removeAsFavorite(dashboard)"></i>
<input type="text" class="input-small" ng-model="timespan" /> </td>
</div> </tr>
<div class="section"> <tr ng-hide="favDashboards.length">
<span> <td colspan="3">
Dashboards available in the playlist are only the once marked as favorites (stored in local browser storage). <i class="icon-warning"></i> No dashboards marked as favorites
To mark a dashboard as favorite, use save icon in the menu and in the dropdown select Favorites > Mark as favorite </td>
</span> </tr>
</div> </table>
</div> </div>
</div> <div class="editor-option">
<div class="modal-footer"> <div class="span4">
<button class="btn btn-success" ng-click="start();dismiss();"><i class="icon-play"></i> Start</button> <span><i class="icon-question-sign"></i>
<button type="button" class="btn btn-primary" ng-click="dismiss();"><i class="icon-ban-circle"></i> Cancel</button> Dashboards available in the playlist are only the once marked as favorites (stored in local browser storage).
</div> 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 class="editor-option">
<label>
Timespan between change
</label>
<input type="text" class="input-small" ng-model="timespan" />
</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> </div>
\ No newline at end of file
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
</a> </a>
</td> </td>
<td style="width:100%;padding-left: 10px;font-weight: bold;"> <td style="width:100%;padding-left: 10px;font-weight: bold;">
</td> </td>
</tr> </tr>
</table> </table>
......
...@@ -9,29 +9,53 @@ function (angular, _, kbn) { ...@@ -9,29 +9,53 @@ function (angular, _, kbn) {
var module = angular.module('kibana.services'); var module = angular.module('kibana.services');
module.service('playlistSrv', function(dashboard, $location, $rootScope) { module.service('playlistSrv', function(dashboard, $location, $rootScope) {
var timerInstance;
var favorites = { dashboards: [] };
this.markAsFavorite = function() { this.init = function() {
var favorites = this.getFavorites(); var existingJson = window.localStorage["grafana-favorites"];
if (existingJson) {
favorites = angular.fromJson(existingJson);
}
};
this._save = function() {
window.localStorage["grafana-favorites"] = angular.toJson(favorites);
};
var existing = _.findWhere(favorites.dashboards, { title: dashboard.current.title }); this._find = function(title) {
return _.findWhere(favorites.dashboards, { title: title });
};
this._remove = function(existing) {
if (existing) { if (existing) {
favorites.dashboard = _.without(favorites.dashboards, existing); favorites.dashboards = _.without(favorites.dashboards, existing);
} }
};
favorites.dashboards.push({ url: $location.path(), title: dashboard.current.title }); this.isCurrentFavorite = function() {
return this._find(dashboard.current.title) ? true : false;
window.localStorage["grafana-favorites"] = angular.toJson(favorites);
}; };
this.getFavorites = function() { this.markAsFavorite = function() {
var existing = this._find(dashboard.current.title);
this._remove(existing);
var favorites = { dashboards: [] }; favorites.dashboards.push({
var existingJson = window.localStorage["grafana-favorites"]; url: $location.path(),
if (existingJson) { title: dashboard.current.title
favorites = angular.fromJson(existingJson); });
}
this._save();
};
this.removeAsFavorite = function(toRemove) {
var existing = this._find(toRemove.title);
this._remove(existing);
this._save();
};
this.getFavorites = function() {
return favorites; return favorites;
}; };
...@@ -40,9 +64,8 @@ function (angular, _, kbn) { ...@@ -40,9 +64,8 @@ function (angular, _, kbn) {
var index = 0; var index = 0;
$rootScope.playlist_active = true; $rootScope.playlist_active = true;
$rootScope.playlist_interval = interval;
setInterval(function() { timerInstance = setInterval(function() {
$rootScope.$apply(function() { $rootScope.$apply(function() {
$location.path(dashboards[index % dashboards.length].url); $location.path(dashboards[index % dashboards.length].url);
index++; index++;
...@@ -50,6 +73,13 @@ function (angular, _, kbn) { ...@@ -50,6 +73,13 @@ function (angular, _, kbn) {
}, interval); }, interval);
}; };
this.stop = function() {
clearInterval(timerInstance);
$rootScope.playlist_active = false;
};
this.init();
}); });
}); });
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -18,11 +18,16 @@ ...@@ -18,11 +18,16 @@
.grafana-menu-zoom-out, .grafana-menu-zoom-out,
.grafana-menu-save, .grafana-menu-save,
.grafana-menu-load, .grafana-menu-load,
.add-row-panel-hint,
.grafana-menu-home, .grafana-menu-home,
.grafana-menu-refresh, .grafana-menu-refresh,
.grafana-menu-edit { .grafana-menu-edit {
display: none; display: none;
} }
.grafana-menu-stop-playlist {
display: list-item;
}
} }
// Search // Search
...@@ -61,7 +66,7 @@ ...@@ -61,7 +66,7 @@
.search-tagview-switch { .search-tagview-switch {
position: absolute; position: absolute;
top: 15px; top: 15px;
right: 180px; right: 263px;
color: darken(@linkColor, 30%); color: darken(@linkColor, 30%);
&.active { &.active {
color: @linkColor; color: @linkColor;
......
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