[#34,view][s]: query state in url (store into and read from).
* Also change so that query values are not automatically JSON.stringify-ied (bad idea since it leads to repeated jsonification of same value ...)
This commit is contained in:
@@ -41,7 +41,7 @@ my.Dataset = Backbone.Model.extend({
|
|||||||
query: function(queryObj) {
|
query: function(queryObj) {
|
||||||
this.trigger('query:start');
|
this.trigger('query:start');
|
||||||
var self = this;
|
var self = this;
|
||||||
this.queryState.set(queryObj, {silent: true});
|
this.queryState.set(queryObj);
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
this.backend.query(this, this.queryState.toJSON()).done(function(rows) {
|
this.backend.query(this, this.queryState.toJSON()).done(function(rows) {
|
||||||
var docs = _.map(rows, function(row) {
|
var docs = _.map(rows, function(row) {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ my.FlotGraph = Backbone.View.extend({
|
|||||||
this._getEditorData();
|
this._getEditorData();
|
||||||
// update navigation
|
// update navigation
|
||||||
var qs = my.parseHashQueryString();
|
var qs = my.parseHashQueryString();
|
||||||
qs['graph'] = this.chartConfig;
|
qs['graph'] = JSON.stringify(this.chartConfig);
|
||||||
my.setHashQueryString(qs);
|
my.setHashQueryString(qs);
|
||||||
this.redraw();
|
this.redraw();
|
||||||
},
|
},
|
||||||
|
|||||||
13
src/view.js
13
src/view.js
@@ -111,6 +111,10 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
my.clearNotifications();
|
my.clearNotifications();
|
||||||
self.el.find('.doc-count').text(self.model.docCount || 'Unknown');
|
self.el.find('.doc-count').text(self.model.docCount || 'Unknown');
|
||||||
my.notify('Data loaded', {category: 'success'});
|
my.notify('Data loaded', {category: 'success'});
|
||||||
|
// update navigation
|
||||||
|
var qs = my.parseHashQueryString();
|
||||||
|
qs['reclineQuery'] = JSON.stringify(self.model.queryState.toJSON());
|
||||||
|
my.setHashQueryString(qs);
|
||||||
});
|
});
|
||||||
this.model.bind('query:fail', function(error) {
|
this.model.bind('query:fail', function(error) {
|
||||||
my.clearNotifications();
|
my.clearNotifications();
|
||||||
@@ -134,8 +138,11 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
// note this.model and dataset returned are the same
|
// note this.model and dataset returned are the same
|
||||||
this.model.fetch()
|
this.model.fetch()
|
||||||
.done(function(dataset) {
|
.done(function(dataset) {
|
||||||
self.el.find('.doc-count').text(self.model.docCount || 'Unknown');
|
var queryState = my.parseHashQueryString().reclineQuery;
|
||||||
self.model.query();
|
if (queryState) {
|
||||||
|
queryState = JSON.parse(queryState);
|
||||||
|
}
|
||||||
|
self.model.query(queryState);
|
||||||
})
|
})
|
||||||
.fail(function(error) {
|
.fail(function(error) {
|
||||||
my.notify(error.message, {category: 'error', persist: true});
|
my.notify(error.message, {category: 'error', persist: true});
|
||||||
@@ -296,7 +303,7 @@ my.composeQueryString = function(queryParams) {
|
|||||||
var queryString = '?';
|
var queryString = '?';
|
||||||
var items = [];
|
var items = [];
|
||||||
$.each(queryParams, function(key, value) {
|
$.each(queryParams, function(key, value) {
|
||||||
items.push(key + '=' + JSON.stringify(value));
|
items.push(key + '=' + value);
|
||||||
});
|
});
|
||||||
queryString += items.join('&');
|
queryString += items.join('&');
|
||||||
return queryString;
|
return queryString;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ test('composeQueryString', function () {
|
|||||||
a: 'b'
|
a: 'b'
|
||||||
};
|
};
|
||||||
var out = recline.View.composeQueryString(params);
|
var out = recline.View.composeQueryString(params);
|
||||||
equal(out, '?x="y"&a="b"');
|
equal(out, '?x=y&a=b');
|
||||||
});
|
});
|
||||||
|
|
||||||
})(this.jQuery);
|
})(this.jQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user