Skip to content

Commit

Permalink
modified to use hash
Browse files Browse the repository at this point in the history
Fixes #5497
  • Loading branch information
BigFunger authored and Jim Unger committed Dec 18, 2015
1 parent 4831453 commit efa6210
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 161 deletions.
16 changes: 1 addition & 15 deletions src/plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ define(function (require) {
'kibana/courier',
'kibana/config',
'kibana/notify',
'kibana/typeahead',
'kibana/share'
'kibana/typeahead'
]);

require('ui/routes')
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -157,15 +155,13 @@ 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);
}

// update root source when filters update
$scope.$listen(queryFilter, 'update', function () {
//console.log('queryFilter update');
updateQueryOnRootSource();
$state.save();
});
Expand Down Expand Up @@ -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: '<iframe src="' + $location.absUrl().replace('?', '?embed&') +
// '" height="600" width="800"></iframe>'
// };
// }
};

init();
Expand Down
21 changes: 0 additions & 21 deletions src/plugins/kibana/public/dashboard/partials/share.html
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
<share object-type="dashboard"></share>
<!-- <form role="form" class="vis-share">
<p>
<div class="input-group">
<label>
Embed this dashboard
<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<div class="form-control" disabled>{{opts.shareData().embed}}</div>
</div>
</p>
<p>
<div class="input-group">
<label>
Share a link
</label>
<div class="form-control" disabled>{{opts.shareData().link}}</div>
</div>
</p>
</form> -->
1 change: 1 addition & 0 deletions src/plugins/kibana/public/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 0 additions & 21 deletions src/plugins/kibana/public/discover/partials/share_search.html
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
<share object-type="search"></share>
<!-- <form role="form" class="vis-share">
<p>
<div class="input-group">
<label>
Embed this dashboard
<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<div class="form-control" disabled>{{opts.shareData().embed}}</div>
</div>
</p>
<p>
<div class="input-group">
<label>
Share a link
</label>
<div class="form-control" disabled>{{opts.shareData().link}}</div>
</div>
</p>
</form> -->
22 changes: 0 additions & 22 deletions src/plugins/kibana/public/goto/index.js

This file was deleted.

10 changes: 1 addition & 9 deletions src/plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(function (require) {

require('ui/visualize');
require('ui/collapsible_sidebar');
require('ui/share');

require('ui/routes')
.when('/visualize/create', {
Expand Down Expand Up @@ -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: '<iframe src="' + $location.absUrl().replace('?', '?embed&') +
// '" height="600" width="800"></iframe>'
// };
// };

$scope.unlink = function () {
if (!$state.linked) return;

Expand Down
22 changes: 0 additions & 22 deletions src/plugins/kibana/public/visualize/editor/panels/share.html
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
<share object-type="visualization"></share>
<!-- <form role="form" class="vis-share">
<p>
<div class="form-group">
<label>
Embed this visualization.
<small>Add to your html source. Note all clients must still be able to access kibana</small>
</label>
<div class="form-control" disabled>{{conf.shareData().embed}}</div>
</div>
</p>
<p>
<div class="form-group">
<label>
Share a link
</label>
<div class="form-control" disabled>{{conf.shareData().link}}</div>
</div>
</p>
</form> -->
1 change: 0 additions & 1 deletion src/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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({
Expand Down
112 changes: 67 additions & 45 deletions src/server/http/urlLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '/';
}
}
};
};
2 changes: 0 additions & 2 deletions src/ui/public/directives/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/share/index.js
Original file line number Diff line number Diff line change
@@ -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'));
Expand Down
3 changes: 1 addition & 2 deletions src/ui/public/share/url_shortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit efa6210

Please sign in to comment.