2013-09-13 13:52:13 -07:00
|
|
|
define([
|
|
|
|
|
'angular',
|
2013-12-30 09:44:19 +01:00
|
|
|
'underscore',
|
|
|
|
|
'moment'
|
2013-09-13 13:52:13 -07:00
|
|
|
],
|
2013-12-30 09:44:19 +01:00
|
|
|
function (angular, _, moment) {
|
2013-09-13 13:52:13 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var module = angular.module('kibana.controllers');
|
|
|
|
|
|
2014-05-19 15:31:30 +02:00
|
|
|
module.controller('dashLoader', function($scope, $rootScope, $http, dashboard, alertSrv, $location, playlistSrv) {
|
2013-09-13 13:52:13 -07:00
|
|
|
$scope.loader = dashboard.current.loader;
|
|
|
|
|
|
|
|
|
|
$scope.init = function() {
|
|
|
|
|
$scope.gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
|
|
|
|
|
$scope.gist = $scope.gist || {};
|
|
|
|
|
$scope.elasticsearch = $scope.elasticsearch || {};
|
2013-12-29 11:46:36 +01:00
|
|
|
|
|
|
|
|
$rootScope.$on('save-dashboard', function() {
|
|
|
|
|
$scope.elasticsearch_save('dashboard', false);
|
|
|
|
|
});
|
2013-12-29 13:17:04 +01:00
|
|
|
|
|
|
|
|
$rootScope.$on('zoom-out', function() {
|
|
|
|
|
$scope.zoom(2);
|
|
|
|
|
});
|
2013-09-13 13:52:13 -07:00
|
|
|
};
|
|
|
|
|
|
2014-02-13 12:41:38 +01:00
|
|
|
$scope.exitFullscreen = function() {
|
|
|
|
|
$rootScope.$emit('panel-fullscreen-exit');
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-13 13:52:13 -07:00
|
|
|
$scope.showDropdown = function(type) {
|
2013-10-08 18:38:08 +02:00
|
|
|
if(_.isUndefined(dashboard.current.loader)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _l = dashboard.current.loader;
|
2013-09-13 13:52:13 -07:00
|
|
|
if(type === 'load') {
|
|
|
|
|
return (_l.load_elasticsearch || _l.load_gist || _l.load_local);
|
|
|
|
|
}
|
|
|
|
|
if(type === 'save') {
|
2013-10-07 08:04:37 +02:00
|
|
|
return (_l.save_elasticsearch || _l.save_gist || _l.save_local || _l.save_default);
|
2013-09-13 13:52:13 -07:00
|
|
|
}
|
|
|
|
|
if(type === 'share') {
|
|
|
|
|
return (_l.save_temp);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.set_default = function() {
|
2013-12-06 14:29:21 -07:00
|
|
|
if(dashboard.set_default($location.path())) {
|
2014-04-07 11:13:18 -07:00
|
|
|
alertSrv.set('Home Set','This page has been set as your default dashboard','success',5000);
|
2013-09-13 13:52:13 -07:00
|
|
|
} else {
|
|
|
|
|
alertSrv.set('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.purge_default = function() {
|
|
|
|
|
if(dashboard.purge_default()) {
|
2014-04-07 11:13:18 -07:00
|
|
|
alertSrv.set('Local Default Clear','Your default dashboard has been reset to the default',
|
2013-12-06 14:29:21 -07:00
|
|
|
'success',5000);
|
2013-09-13 13:52:13 -07:00
|
|
|
} else {
|
|
|
|
|
alertSrv.set('Incompatible Browser','Sorry, your browser is too old for this feature','error',5000);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.elasticsearch_save = function(type,ttl) {
|
2014-04-27 12:22:38 +02:00
|
|
|
dashboard.elasticsearch_save(type, dashboard.current.title, ttl)
|
|
|
|
|
.then(function(result) {
|
|
|
|
|
if(_.isUndefined(result._id)) {
|
|
|
|
|
alertSrv.set('Save failed','Dashboard could not be saved to Elasticsearch','error',5000);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-01 10:51:35 +01:00
|
|
|
|
2014-04-27 12:22:38 +02:00
|
|
|
alertSrv.set('Dashboard Saved', 'Dashboard has been saved to Elasticsearch as "' + result._id + '"','success', 5000);
|
|
|
|
|
if(type === 'temp') {
|
|
|
|
|
$scope.share = dashboard.share_link(dashboard.current.title,'temp',result._id);
|
|
|
|
|
}
|
2014-02-01 10:51:35 +01:00
|
|
|
|
2014-05-27 17:17:12 +02:00
|
|
|
$rootScope.$emit('dashboard-saved', dashboard.current);
|
2014-04-27 12:22:38 +02:00
|
|
|
});
|
2013-09-13 13:52:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.elasticsearch_delete = function(id) {
|
2013-12-28 23:54:07 +01:00
|
|
|
if (!confirm('Are you sure you want to delete dashboard?')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-13 13:52:13 -07:00
|
|
|
dashboard.elasticsearch_delete(id).then(
|
|
|
|
|
function(result) {
|
|
|
|
|
if(!_.isUndefined(result)) {
|
|
|
|
|
if(result.found) {
|
|
|
|
|
alertSrv.set('Dashboard Deleted',id+' has been deleted','success',5000);
|
|
|
|
|
// Find the deleted dashboard in the cached list and remove it
|
|
|
|
|
var toDelete = _.where($scope.elasticsearch.dashboards,{_id:id})[0];
|
|
|
|
|
$scope.elasticsearch.dashboards = _.without($scope.elasticsearch.dashboards,toDelete);
|
|
|
|
|
} else {
|
|
|
|
|
alertSrv.set('Dashboard Not Found','Could not find '+id+' in Elasticsearch','warning',5000);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
alertSrv.set('Dashboard Not Deleted','An error occurred deleting the dashboard','error',5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.save_gist = function() {
|
2014-06-07 06:38:33 +02:00
|
|
|
dashboard.save_gist($scope.gist.title).then(function(link) {
|
|
|
|
|
if (!_.isUndefined(link)) {
|
2013-09-13 13:52:13 -07:00
|
|
|
$scope.gist.last = link;
|
|
|
|
|
alertSrv.set('Gist saved','You will be able to access your exported dashboard file at '+
|
2014-06-07 06:38:33 +02:00
|
|
|
'<a href="'+link+'">'+link+'</a> in a moment','success');
|
2013-09-13 13:52:13 -07:00
|
|
|
} else {
|
|
|
|
|
alertSrv.set('Save failed','Gist could not be saved','error',5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.gist_dblist = function(id) {
|
2014-06-07 06:38:33 +02:00
|
|
|
dashboard.gist_list(id).then(function(files) {
|
|
|
|
|
if (files && files.length > 0) {
|
2013-09-13 13:52:13 -07:00
|
|
|
$scope.gist.files = files;
|
|
|
|
|
} else {
|
|
|
|
|
alertSrv.set('Gist Failed','Could not retrieve dashboard list from gist','error',5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-29 13:17:04 +01:00
|
|
|
// function $scope.zoom
|
|
|
|
|
// factor :: Zoom factor, so 0.5 = cuts timespan in half, 2 doubles timespan
|
|
|
|
|
$scope.zoom = function(factor) {
|
2014-05-19 15:31:30 +02:00
|
|
|
var _range = this.filter.timeRange();
|
2013-12-29 13:17:04 +01:00
|
|
|
var _timespan = (_range.to.valueOf() - _range.from.valueOf());
|
|
|
|
|
var _center = _range.to.valueOf() - _timespan/2;
|
|
|
|
|
|
|
|
|
|
var _to = (_center + (_timespan*factor)/2);
|
|
|
|
|
var _from = (_center - (_timespan*factor)/2);
|
|
|
|
|
|
|
|
|
|
// If we're not already looking into the future, don't.
|
|
|
|
|
if(_to > Date.now() && _range.to < Date.now()) {
|
|
|
|
|
var _offset = _to - Date.now();
|
|
|
|
|
_from = _from - _offset;
|
|
|
|
|
_to = Date.now();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 15:31:30 +02:00
|
|
|
this.filter.setTime({
|
2013-12-29 13:17:04 +01:00
|
|
|
from:moment.utc(_from).toDate(),
|
|
|
|
|
to:moment.utc(_to).toDate(),
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-08 16:27:01 +01:00
|
|
|
$scope.openSaveDropdown = function() {
|
|
|
|
|
$scope.isFavorite = playlistSrv.isCurrentFavorite();
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-07 19:24:45 +01:00
|
|
|
$scope.markAsFavorite = function() {
|
|
|
|
|
playlistSrv.markAsFavorite();
|
2014-03-08 16:27:01 +01:00
|
|
|
$scope.isFavorite = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.removeAsFavorite = function() {
|
|
|
|
|
playlistSrv.removeAsFavorite(dashboard.current);
|
|
|
|
|
$scope.isFavorite = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.stopPlaylist = function() {
|
|
|
|
|
playlistSrv.stop(1);
|
2014-03-07 19:24:45 +01:00
|
|
|
};
|
|
|
|
|
|
2013-09-13 13:52:13 -07:00
|
|
|
});
|
|
|
|
|
|
2013-10-07 08:04:37 +02:00
|
|
|
});
|