[#67,app][s]: first pass at sharable link support in app (though seems rather buggy).

This commit is contained in:
Rufus Pollock
2012-04-16 15:17:19 +01:00
parent a42840cdf3
commit 0f0fa633a1
3 changed files with 57 additions and 19 deletions

View File

@@ -81,6 +81,12 @@
</li> </li>
</ul> </ul>
</li> </li>
<li>
<a href=".js-share-and-embed-dialog" data-toggle="modal">
Share and Embed
<i class="icon-share icon-white"></i>
</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -148,6 +154,17 @@
</div> </div>
</div> </div>
<div class="modal fade in js-share-and-embed-dialog" style="display: none;">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Share and Embed</h3>
</div>
<div class="modal-body">
<h4>Sharable Link to current View</h4>
<textarea class="view-link" style="width: 100%; height: 100px;"></textarea>
</div>
</div>
<div class="container-fluid"> <div class="container-fluid">
<div class="content"> <div class="content">
<div class="data-explorer-here"></div> <div class="data-explorer-here"></div>

View File

@@ -1,20 +1,5 @@
jQuery(function($) { jQuery(function($) {
var qs = recline.View.parseQueryString(window.location.search);
var dataest = null;
if (qs.url) {
dataset = new recline.Model.Dataset({
id: 'my-dataset',
url: qs.url,
webstore_url: qs.url
},
qs.backend || 'elasticsearch'
);
} else {
dataset = localDataset();
}
var app = new ExplorerApp({ var app = new ExplorerApp({
model: dataset,
el: $('.recline-app') el: $('.recline-app')
}) })
Backbone.history.start(); Backbone.history.start();
@@ -27,14 +12,32 @@ var ExplorerApp = Backbone.View.extend({
}, },
initialize: function() { initialize: function() {
this.el = $(this.el);
this.explorer = null; this.explorer = null;
this.explorerDiv = $('.data-explorer-here'); this.explorerDiv = $('.data-explorer-here');
this.createExplorer(this.model);
var state = recline.View.parseQueryString(window.location.search);
if (state) {
_.each(state, function(value, key) {
try {
value = JSON.parse(value);
} catch(e) {}
state[key] = value;
});
}
var dataset = null;
if (state.dataset || state.url) {
dataset = recline.Model.Dataset.restore(state);
} else {
dataset = localDataset();
}
this.createExplorer(dataset, state);
}, },
// make Explorer creation / initialization in a function so we can call it // make Explorer creation / initialization in a function so we can call it
// again and again // again and again
createExplorer: function(dataset) { createExplorer: function(dataset, state) {
var self = this;
// remove existing data explorer view // remove existing data explorer view
var reload = false; var reload = false;
if (this.dataExplorer) { if (this.dataExplorer) {
@@ -45,9 +48,12 @@ var ExplorerApp = Backbone.View.extend({
var $el = $('<div />'); var $el = $('<div />');
$el.appendTo(this.explorerDiv); $el.appendTo(this.explorerDiv);
this.dataExplorer = new recline.View.DataExplorer({ this.dataExplorer = new recline.View.DataExplorer({
el: $el model: dataset,
, model: dataset el: $el,
state: state
}); });
this._setupPermaLink(this.dataExplorer);
// HACK (a bit). Issue is that Backbone will not trigger the route // HACK (a bit). Issue is that Backbone will not trigger the route
// if you are already at that location so we have to make sure we genuinely switch // if you are already at that location so we have to make sure we genuinely switch
if (reload) { if (reload) {
@@ -56,6 +62,18 @@ var ExplorerApp = Backbone.View.extend({
} }
}, },
_setupPermaLink: function(explorer) {
var $viewLink = this.el.find('.js-share-and-embed-dialog .view-link');
function makePermaLink(state) {
var qs = recline.View.composeQueryString(state.toJSON());
return window.location.origin + window.location.pathname + qs;
}
explorer.state.bind('change', function() {
$viewLink.val(makePermaLink(explorer.state));
});
$viewLink.val(makePermaLink(explorer.state));
},
// setup the loader menu in top bar // setup the loader menu in top bar
setupLoader: function(callback) { setupLoader: function(callback) {
// pre-populate webstore load form with an example url // pre-populate webstore load form with an example url

View File

@@ -682,6 +682,9 @@ my.composeQueryString = function(queryParams) {
var queryString = '?'; var queryString = '?';
var items = []; var items = [];
$.each(queryParams, function(key, value) { $.each(queryParams, function(key, value) {
if (typeof(value) === 'object') {
value = JSON.stringify(value);
}
items.push(key + '=' + value); items.push(key + '=' + value);
}); });
queryString += items.join('&'); queryString += items.join('&');