diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js
index ce2b3ebcfc3..a4a4f8af401 100644
--- a/src/app/controllers/dash.js
+++ b/src/app/controllers/dash.js
@@ -45,7 +45,6 @@ function (angular, $, config, _) {
$scope.setupDashboard = function(event, dashboardData) {
timer.cancel_all();
- alertSrv.clearAll();
$rootScope.fullscreen = false;
diff --git a/src/app/controllers/dashLoader.js b/src/app/controllers/dashLoader.js
index 55cb8fc6cfa..ec91b3e6e9e 100644
--- a/src/app/controllers/dashLoader.js
+++ b/src/app/controllers/dashLoader.js
@@ -64,17 +64,23 @@ function (angular, _, moment) {
}
};
- $scope.elasticsearch_save = function(type, ttl) {
+ $scope.saveForSharing = function() {
+ elastic.saveForSharing($scope.dashboard)
+ .then(function(result) {
+
+ $scope.share = { url: result.url, title: result.title };
+
+ }, function(err) {
+ alertSrv.set('Save for sharing failed', err, 'error',5000);
+ });
+ };
+
+ $scope.saveDashboard = function() {
elastic.saveDashboard($scope.dashboard, $scope.dashboard.title)
.then(function(result) {
alertSrv.set('Dashboard Saved', 'Dashboard has been saved to Elasticsearch as "' + result.title + '"','success', 5000);
- if(type === 'temp') {
- $scope.share = $scope.dashboard.share_link($scope.dashboard.title, 'temp', result.title);
- }
- else {
- $location.path(result.url);
- }
+ $location.path(result.url);
$rootScope.$emit('dashboard-saved', $scope.dashboard);
diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js
index 70b082ccb3a..3c2fe8af79f 100644
--- a/src/app/controllers/search.js
+++ b/src/app/controllers/search.js
@@ -48,6 +48,15 @@ function (angular, _, config, $) {
}
};
+ $scope.shareDashboard = function(title, id) {
+ var baseUrl = window.location.href.replace(window.location.hash,'');
+
+ $scope.share = {
+ title: title,
+ url: baseUrl + '#dashboard/elasticsearch/' + encodeURIComponent(id)
+ };
+ };
+
$scope.searchDasboards = function(queryString) {
var tagsOnly = queryString.indexOf('tags!:') === 0;
if (tagsOnly) {
@@ -71,7 +80,7 @@ function (angular, _, config, $) {
sort: ["_uid"]
};
- return elastic.post('dashboard/_search', query)
+ return elastic.post('/dashboard/_search', query)
.then(function(results) {
if(_.isUndefined(results.hits)) {
$scope.results.dashboards = [];
diff --git a/src/app/partials/dashLoader.html b/src/app/partials/dashLoader.html
index 228a94a88e6..2d9b37975e0 100644
--- a/src/app/partials/dashLoader.html
+++ b/src/app/partials/dashLoader.html
@@ -28,7 +28,7 @@
@@ -47,7 +47,7 @@
Export dashboard
- Share temp copy
+ Share temp copy
Gist
diff --git a/src/app/partials/dashLoaderShare.html b/src/app/partials/dashLoaderShare.html
index 77697735983..979a0771f59 100644
--- a/src/app/partials/dashLoaderShare.html
+++ b/src/app/partials/dashLoaderShare.html
@@ -4,7 +4,7 @@
-
+
diff --git a/src/app/routes/dashboard-from-es.js b/src/app/routes/dashboard-from-es.js
index 74e2ff651ed..511bb6ac6cf 100644
--- a/src/app/routes/dashboard-from-es.js
+++ b/src/app/routes/dashboard-from-es.js
@@ -13,36 +13,31 @@ function (angular, $, config) {
.when('/dashboard/elasticsearch/:id', {
templateUrl: 'app/partials/dashboard.html',
controller : 'DashFromElasticProvider',
+ })
+ .when('/dashboard/temp/:id', {
+ templateUrl: 'app/partials/dashboard.html',
+ controller : 'DashFromElasticProvider',
});
});
- module.controller('DashFromElasticProvider', function($scope, $rootScope, $http, $routeParams, alertSrv) {
+ module.controller('DashFromElasticProvider', function($scope, $rootScope, elastic, $routeParams, alertSrv) {
var elasticsearch_load = function(id) {
- var url = config.elasticsearch + "/" + config.grafana_index + "/dashboard/" + id;
+ var url = '/dashboard/' + id;
- var options = {
- url: url +'?' + new Date().getTime(),
- method: "GET",
- transformResponse: function(response) {
- var esResponse = angular.fromJson(response);
- if (esResponse._source && esResponse._source.dashboard) {
- return angular.fromJson(esResponse._source.dashboard);
+ // hack to check if it is a temp dashboard
+ if (window.location.href.indexOf('dashboard/temp') > 0) {
+ url = '/temp/' + id;
+ }
+
+ return elastic.get(url)
+ .then(function(result) {
+ if (result._source && result._source.dashboard) {
+ return angular.fromJson(result._source.dashboard);
} else {
return false;
}
- }
- };
-
- if (config.elasticsearchBasicAuth) {
- options.withCredentials = true;
- options.headers = {
- "Authorization": "Basic " + config.elasticsearchBasicAuth
- };
- }
-
- return $http(options)
- .error(function(data, status) {
+ }, function(data, status) {
if(status === 0) {
alertSrv.set('Error',"Could not contact Elasticsearch at " +
config.elasticsearch + ". Please ensure that Elasticsearch is reachable from your browser.",'error');
@@ -53,8 +48,8 @@ function (angular, $, config) {
});
};
- elasticsearch_load($routeParams.id).then(function(result) {
- $scope.emitAppEvent('setup-dashboard', result.data);
+ elasticsearch_load($routeParams.id).then(function(dashboard) {
+ $scope.emitAppEvent('setup-dashboard', dashboard);
});
});
diff --git a/src/app/services/elasticsearch/es-client.js b/src/app/services/elasticsearch/es-client.js
index 6b13345e44a..a4fe051fce6 100644
--- a/src/app/services/elasticsearch/es-client.js
+++ b/src/app/services/elasticsearch/es-client.js
@@ -11,7 +11,7 @@ function(angular, config) {
this._request = function(method, url, data) {
var options = {
- url: config.elasticsearch + "/" + config.grafana_index + "/" + url,
+ url: config.elasticsearch + "/" + config.grafana_index + url,
method: method,
data: data
};
@@ -25,16 +25,45 @@ function(angular, config) {
return $http(options);
};
+ this.get = function(url) {
+ return this._request('GET', url)
+ .then(function(results) {
+ return results.data;
+ });
+ };
+
this.post = function(url, data) {
return this._request('POST', url, data)
.then(function(results) {
return results.data;
- }, function(err) {
- return err.data;
});
};
- this.saveDashboard = function(dashboard, title, ttl) {
+ this.saveForSharing = function(dashboard) {
+ var data = {
+ user: 'guest',
+ group: 'guest',
+ title: dashboard.title,
+ tags: dashboard.tags,
+ dashboard: angular.toJson(dashboard)
+ };
+
+ var ttl = dashboard.loader.save_temp_ttl;
+
+ return this._request('POST', '/temp/?ttl=' + ttl, data)
+ .then(function(result) {
+
+ var baseUrl = window.location.href.replace(window.location.hash,'');
+ var url = baseUrl + "#dashboard/temp/" + result.data._id;
+
+ return { title: dashboard.title, url: url };
+
+ }, function(err) {
+ throw "Failed to save to temp dashboard to elasticsearch " + err.data;
+ });
+ };
+
+ this.saveDashboard = function(dashboard, title) {
var dashboardClone = angular.copy(dashboard);
title = dashboardClone.title = title ? title : dashboard.title;
diff --git a/src/app/services/elasticsearch/es-client2.js b/src/app/services/elasticsearch/es-client2.js
deleted file mode 100644
index 1a19fa06e1d..00000000000
--- a/src/app/services/elasticsearch/es-client2.js
+++ /dev/null
@@ -1,46 +0,0 @@
-define([
- 'angular',
- 'config'
-],
-function(angular, config) {
- "use strict";
-
- var module = angular.module('kibana.services');
-
- module.service('elastic', function($http) {
-
- this.put = function(url, data) {
- url = config.elasticsearch + '/' + config.grafana_index + url;
-
- var options = {
- url: url,
- method: 'PUT',
- data: data
- };
-
- return $http(options);
- };
-
- this.saveDashboard = function(dashboard, title, ttl) {
- var dashboardClone = angular.copy(dashboard);
- title = dashboardClone.title = title ? title : dashboard.title;
-
- var data = {
- user: 'guest',
- group: 'guest',
- title: title,
- tags: dashboardClone.tags,
- dashboard: angular.toJson(dashboardClone)
- };
-
- return this.put('/dashboard/' + encodeURIComponent(title), data)
- .then(function() {
- return { title: title, url: '/dashboard/elasticsearch/' + title };
- }, function(err) {
- throw 'Failed to save to elasticsearch ' + err.data;
- });
- };
-
- });
-
-});