2014-03-07 12:24:45 -06:00
|
|
|
define([
|
2014-03-08 09:27:01 -06:00
|
|
|
'angular',
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash',
|
2014-05-26 07:12:26 -05:00
|
|
|
'config'
|
2014-03-07 12:24:45 -06:00
|
|
|
],
|
2014-05-26 07:12:26 -05:00
|
|
|
function (angular, _, config) {
|
2014-03-07 12:24:45 -06:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.controllers');
|
2014-03-07 12:24:45 -06:00
|
|
|
|
2015-02-28 03:04:19 -06:00
|
|
|
module.controller('PlaylistCtrl', function($scope, playlistSrv, backendSrv) {
|
2014-03-07 12:24:45 -06:00
|
|
|
|
|
|
|
$scope.init = function() {
|
2015-02-13 01:47:44 -06:00
|
|
|
$scope.playlist = [];
|
2014-05-29 23:05:49 -05:00
|
|
|
$scope.timespan = config.playlist_timespan;
|
2015-02-13 01:47:44 -06:00
|
|
|
$scope.search();
|
2014-03-07 12:24:45 -06:00
|
|
|
};
|
|
|
|
|
2015-02-13 01:47:44 -06:00
|
|
|
$scope.search = function() {
|
|
|
|
var query = {starred: true, limit: 10};
|
2014-03-08 09:27:01 -06:00
|
|
|
|
2015-02-13 01:47:44 -06:00
|
|
|
if ($scope.searchQuery) {
|
|
|
|
query.query = $scope.searchQuery;
|
|
|
|
query.starred = false;
|
|
|
|
}
|
|
|
|
|
2015-02-28 03:04:19 -06:00
|
|
|
backendSrv.search(query).then(function(results) {
|
2015-06-26 12:11:52 -05:00
|
|
|
$scope.searchHits = results;
|
2015-02-13 07:36:16 -06:00
|
|
|
$scope.filterHits();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.filterHits = function() {
|
|
|
|
$scope.filteredHits = _.reject($scope.searchHits, function(dash) {
|
2015-06-26 12:11:52 -05:00
|
|
|
return _.findWhere($scope.playlist, {uri: dash.uri});
|
2014-03-08 09:27:01 -06:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-02-13 01:47:44 -06:00
|
|
|
$scope.addDashboard = function(dashboard) {
|
|
|
|
$scope.playlist.push(dashboard);
|
2015-02-13 07:36:16 -06:00
|
|
|
$scope.filterHits();
|
2015-02-13 01:47:44 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeDashboard = function(dashboard) {
|
|
|
|
$scope.playlist = _.without($scope.playlist, dashboard);
|
2015-02-13 07:36:16 -06:00
|
|
|
$scope.filterHits();
|
2014-03-07 12:24:45 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.start = function() {
|
2015-02-13 01:47:44 -06:00
|
|
|
playlistSrv.start($scope.playlist, $scope.timespan);
|
2014-03-07 12:24:45 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-26 07:12:26 -05:00
|
|
|
});
|