diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js
index f55e8b96371cc..d3464adca65be 100644
--- a/src/plugins/kibana/public/dashboard/index.js
+++ b/src/plugins/kibana/public/dashboard/index.js
@@ -26,8 +26,7 @@ define(function (require) {
'kibana/courier',
'kibana/config',
'kibana/notify',
- 'kibana/typeahead',
- 'kibana/share'
+ 'kibana/typeahead'
]);
require('ui/routes')
@@ -92,7 +91,6 @@ define(function (require) {
var $uiState = $scope.uiState = $state.makeStateful('uiState');
$scope.$watchCollection('state.options', function (newVal, oldVal) {
- //console.log('watch state.options');
if (!angular.equals(newVal, oldVal)) $state.save();
});
$scope.$watch('state.options.darkTheme', setDarkTheme);
@@ -157,7 +155,6 @@ define(function (require) {
}
function setDarkTheme(enabled) {
- //console.log('setDarkTheme');
var theme = Boolean(enabled) ? 'theme-dark' : 'theme-light';
chrome.removeApplicationClass(['theme-dark', 'theme-light']);
chrome.addApplicationClass(theme);
@@ -165,7 +162,6 @@ define(function (require) {
// update root source when filters update
$scope.$listen(queryFilter, 'update', function () {
- //console.log('queryFilter update');
updateQueryOnRootSource();
$state.save();
});
@@ -239,16 +235,6 @@ define(function (require) {
save: $scope.save,
addVis: $scope.addVis,
addSearch: $scope.addSearch
- // ,
- // shareData: function () {
- // //console.log('this is being called.');
- // return {
- // link: $location.absUrl(),
- // // This sucks, but seems like the cleanest way. Uhg.
- // embed: ''
- // };
- // }
};
init();
diff --git a/src/plugins/kibana/public/dashboard/partials/share.html b/src/plugins/kibana/public/dashboard/partials/share.html
index 79046da5db0b1..cf9fc6898b4f2 100644
--- a/src/plugins/kibana/public/dashboard/partials/share.html
+++ b/src/plugins/kibana/public/dashboard/partials/share.html
@@ -1,22 +1 @@
-
diff --git a/src/plugins/kibana/public/discover/controllers/discover.js b/src/plugins/kibana/public/discover/controllers/discover.js
index e69f9065736e2..a457131965d30 100644
--- a/src/plugins/kibana/public/discover/controllers/discover.js
+++ b/src/plugins/kibana/public/discover/controllers/discover.js
@@ -20,6 +20,7 @@ define(function (require) {
require('ui/state_management/app_state');
require('ui/timefilter');
require('ui/highlight/highlight_tags');
+ require('ui/share');
var app = require('ui/modules').get('apps/discover', [
'kibana/notify',
diff --git a/src/plugins/kibana/public/discover/partials/share_search.html b/src/plugins/kibana/public/discover/partials/share_search.html
index 6b878b6c8c7f4..3870634f84832 100644
--- a/src/plugins/kibana/public/discover/partials/share_search.html
+++ b/src/plugins/kibana/public/discover/partials/share_search.html
@@ -1,22 +1 @@
-
diff --git a/src/plugins/kibana/public/goto/index.js b/src/plugins/kibana/public/goto/index.js
deleted file mode 100644
index 9c1aea43172de..0000000000000
--- a/src/plugins/kibana/public/goto/index.js
+++ /dev/null
@@ -1,22 +0,0 @@
-define(function (require) {
- var angular = require('angular');
-
- require('ui/routes')
- .when('/goto/:id', {
- template: require('plugins/kibana/dashboard/index.html'),
- resolve: {
- dash: function (savedDashboards, Notifier, $route, $location, courier) {
- return savedDashboards.get($route.current.params.id)
- .catch(courier.redirectWhenMissing({
- 'dashboard' : '/dashboard'
- }));
- }
- }
- });
-
- require('ui/routes')
- .when('/visualize', {
- redirectTo: '/visualize/step/1'
- });
-
-});
diff --git a/src/plugins/kibana/public/visualize/editor/editor.js b/src/plugins/kibana/public/visualize/editor/editor.js
index 92f4e2f2ea88b..9f7c628493c0e 100644
--- a/src/plugins/kibana/public/visualize/editor/editor.js
+++ b/src/plugins/kibana/public/visualize/editor/editor.js
@@ -6,6 +6,7 @@ define(function (require) {
require('ui/visualize');
require('ui/collapsible_sidebar');
+ require('ui/share');
require('ui/routes')
.when('/visualize/create', {
@@ -234,15 +235,6 @@ define(function (require) {
}, notify.fatal);
};
- // $scope.shareData = function () {
- // return {
- // link: $location.absUrl(),
- // // This sucks, but seems like the cleanest way. Uhg.
- // embed: ''
- // };
- // };
-
$scope.unlink = function () {
if (!$state.linked) return;
diff --git a/src/plugins/kibana/public/visualize/editor/panels/share.html b/src/plugins/kibana/public/visualize/editor/panels/share.html
index 2292d1eb311c0..0a3cda5e13b24 100644
--- a/src/plugins/kibana/public/visualize/editor/panels/share.html
+++ b/src/plugins/kibana/public/visualize/editor/panels/share.html
@@ -1,23 +1 @@
-
diff --git a/src/server/http/index.js b/src/server/http/index.js
index 9c7fcfab30f34..52a79d1450584 100644
--- a/src/server/http/index.js
+++ b/src/server/http/index.js
@@ -31,7 +31,6 @@ module.exports = function (kbnServer, server, config) {
server.connection(connectionOptions);
-
// provide a simple way to expose static directories
server.decorate('server', 'exposeStaticDir', function (routePath, dirPath) {
this.route({
diff --git a/src/server/http/urlLookup.js b/src/server/http/urlLookup.js
index e7c8f03931f6c..18e094a08462a 100644
--- a/src/server/http/urlLookup.js
+++ b/src/server/http/urlLookup.js
@@ -17,61 +17,83 @@ export default function (server) {
}
});
} catch (err) {
- console.log(err);
- //swallow errors. We don't care if there is no update.
+ console.log('Error updating url metadata', err);
+ //swallow errors. It isn't critical if there is no update.
}
}
- return {
- async generateUrlId(url) {
- const urlId = await new Promise((resolve, reject) => {
- const client = server.plugins.elasticsearch.client;
+ async function getUrlDoc(urlId) {
+ const urlDoc = await new Promise((resolve, reject) => {
+ const client = server.plugins.elasticsearch.client;
- // const urlId = crypto.createHash('md5')
- // .update(url)
- // .digest('hex');
+ client.get({
+ index: '.kibana',
+ type: 'url',
+ id: urlId
+ })
+ .then(response => {
+ resolve(response);
+ })
+ .catch(err => {
+ resolve();
+ });
+ });
- client.index({
- index: '.kibana',
- type: 'url',
- body: {
- url,
- 'access-count': 0,
- 'create-date': new Date(),
- 'access-date': new Date()
- }
- })
- .then(response => {
- const urlId = response._id;
- resolve(urlId);
- })
- .catch(err => {
- reject(err);
- });
+ return urlDoc;
+ }
+
+ async function createUrlDoc(url, urlId) {
+ const newUrlId = await new Promise((resolve, reject) => {
+ const client = server.plugins.elasticsearch.client;
+
+ client.index({
+ index: '.kibana',
+ type: 'url',
+ id: urlId,
+ body: {
+ url,
+ 'access-count': 0,
+ 'create-date': new Date(),
+ 'access-date': new Date()
+ }
+ })
+ .then(response => {
+ resolve(response._id);
+ })
+ .catch(err => {
+ reject(err);
});
+ });
+
+ return newUrlId;
+ }
+
+ function createUrlId(url) {
+ const urlId = crypto.createHash('md5')
+ .update(url)
+ .digest('hex');
+
+ return urlId;
+ }
- return urlId;
+ return {
+ async generateUrlId(url) {
+ const urlId = createUrlId(url);
+
+ const urlDoc = await getUrlDoc(urlId);
+ if (urlDoc) return urlId;
+
+ return createUrlDoc(url, urlId);
},
async getUrl(urlId) {
- const url = await new Promise((resolve, reject) => {
- const client = server.plugins.elasticsearch.client;
-
- client.get({
- index: '.kibana',
- type: 'url',
- id: urlId
- })
- .then(response => {
- const url = response._source.url;
- updateMetadata(urlId, response);
- resolve(url);
- })
- .catch(err => {
- resolve('/');
- });
- });
+ try {
+ const urlDoc = await getUrlDoc(urlId);
+ updateMetadata(urlId, urlDoc);
- return url;
+ return urlDoc._source.url;
+ } catch (err) {
+ return '/';
+ }
}
};
};
diff --git a/src/ui/public/directives/config.js b/src/ui/public/directives/config.js
index d02e99d7d0746..a8f69b28ca5e7 100644
--- a/src/ui/public/directives/config.js
+++ b/src/ui/public/directives/config.js
@@ -29,7 +29,6 @@ define(function (require) {
var tmpScope = $scope.$new();
$scope.$watch('configObject', function (newVal) {
- console.log('config watch');
$scope[attr.configObject] = $scope.configObject;
});
@@ -45,7 +44,6 @@ define(function (require) {
'configSubmit',
'configTemplate.current || configTemplate'
], function () {
- console.log('config watchMulti');
var tmpl = $scope.configTemplate;
if (tmpl instanceof ConfigTemplate) {
tmpl = tmpl.toString();
diff --git a/src/ui/public/share/index.js b/src/ui/public/share/index.js
index a815bf6ee29b8..1e587a0fd7452 100644
--- a/src/ui/public/share/index.js
+++ b/src/ui/public/share/index.js
@@ -1,5 +1,5 @@
define(function (require) {
- const app = require('ui/modules').get('kibana/share');
+ const app = require('ui/modules').get('kibana');
app.directive('share', function (Private) {
const urlShortener = Private(require('./url_shortener'));
diff --git a/src/ui/public/share/url_shortener.js b/src/ui/public/share/url_shortener.js
index 304e30b3456d0..98411fd2bcd6c 100644
--- a/src/ui/public/share/url_shortener.js
+++ b/src/ui/public/share/url_shortener.js
@@ -7,8 +7,7 @@ define(function (require) {
async function shortenUrl(url) {
const relativeUrl = url.replace(baseUrl, '');
-
- var formData = { url: relativeUrl };
+ const formData = { url: relativeUrl };
try {
const result = await $http.post('/shorten', formData);