[#88,#67,state,view,app][s]: restore was not in fact working correcty for views as we need to pass the state on initialization (we were setting the state later).
* Also turn off url updating since I think that was messing with things and we were planning to do that. (For later: reintroduce this as it supports well-behaved navigation)
This commit is contained in:
65
src/view.js
65
src/view.js
@@ -185,6 +185,7 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
var self = this;
|
var self = this;
|
||||||
this.el = $(this.el);
|
this.el = $(this.el);
|
||||||
// Hash of 'page' views (i.e. those for whole page) keyed by page name
|
// Hash of 'page' views (i.e. those for whole page) keyed by page name
|
||||||
|
this._setupState(options.state);
|
||||||
if (options.views) {
|
if (options.views) {
|
||||||
this.pageViews = options.views;
|
this.pageViews = options.views;
|
||||||
} else {
|
} else {
|
||||||
@@ -192,26 +193,35 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
id: 'grid',
|
id: 'grid',
|
||||||
label: 'Grid',
|
label: 'Grid',
|
||||||
view: new my.Grid({
|
view: new my.Grid({
|
||||||
model: this.model
|
model: this.model,
|
||||||
})
|
state: this.state.get('view-grid')
|
||||||
|
}),
|
||||||
}, {
|
}, {
|
||||||
id: 'graph',
|
id: 'graph',
|
||||||
label: 'Graph',
|
label: 'Graph',
|
||||||
view: new my.Graph({
|
view: new my.Graph({
|
||||||
model: this.model
|
model: this.model,
|
||||||
})
|
state: this.state.get('view-graph')
|
||||||
|
}),
|
||||||
}, {
|
}, {
|
||||||
id: 'map',
|
id: 'map',
|
||||||
label: 'Map',
|
label: 'Map',
|
||||||
view: new my.Map({
|
view: new my.Map({
|
||||||
model: this.model
|
model: this.model,
|
||||||
})
|
state: this.state.get('view-map')
|
||||||
|
}),
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
// these must be called after pageViews are created
|
// these must be called after pageViews are created
|
||||||
this.render();
|
this.render();
|
||||||
// should come after render as may need to interact with elements in the view
|
this._bindStateChanges();
|
||||||
this._setupState(options.state);
|
// now do updates based on state (need to come after render)
|
||||||
|
if (this.state.get('readOnly')) {
|
||||||
|
this.setReadOnly();
|
||||||
|
}
|
||||||
|
if (this.state.get('currentView')) {
|
||||||
|
this.updateNav(this.state.get('currentView'));
|
||||||
|
}
|
||||||
|
|
||||||
this.router = new Backbone.Router();
|
this.router = new Backbone.Router();
|
||||||
this.setupRouting();
|
this.setupRouting();
|
||||||
@@ -227,7 +237,7 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
var qs = my.parseHashQueryString();
|
var qs = my.parseHashQueryString();
|
||||||
qs.reclineQuery = JSON.stringify(self.model.queryState.toJSON());
|
qs.reclineQuery = JSON.stringify(self.model.queryState.toJSON());
|
||||||
var out = my.getNewHashForQueryString(qs);
|
var out = my.getNewHashForQueryString(qs);
|
||||||
self.router.navigate(out);
|
// self.router.navigate(out);
|
||||||
});
|
});
|
||||||
this.model.bind('query:fail', function(error) {
|
this.model.bind('query:fail', function(error) {
|
||||||
my.clearNotifications();
|
my.clearNotifications();
|
||||||
@@ -290,13 +300,15 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
setupRouting: function() {
|
setupRouting: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
// Default route
|
// Default route
|
||||||
this.router.route(/^(\?.*)?$/, this.pageViews[0].id, function(queryString) {
|
// this.router.route(/^(\?.*)?$/, this.pageViews[0].id, function(queryString) {
|
||||||
self.updateNav(self.pageViews[0].id, queryString);
|
// self.updateNav(self.pageViews[0].id, queryString);
|
||||||
});
|
// });
|
||||||
$.each(this.pageViews, function(idx, view) {
|
// $.each(this.pageViews, function(idx, view) {
|
||||||
self.router.route(/^([^?]+)(\?.*)?/, 'view', function(viewId, queryString) {
|
// self.router.route(/^([^?]+)(\?.*)?/, 'view', function(viewId, queryString) {
|
||||||
self.updateNav(viewId, queryString);
|
// self.updateNav(viewId, queryString);
|
||||||
});
|
// });
|
||||||
|
// });
|
||||||
|
this.router.route(/.*/, 'view', function() {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -356,29 +368,18 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
'view-graph': graphState,
|
'view-graph': graphState,
|
||||||
backend: this.model.backend.__type__,
|
backend: this.model.backend.__type__,
|
||||||
dataset: this.model.toJSON(),
|
dataset: this.model.toJSON(),
|
||||||
currentView: this.pageViews[0].id,
|
currentView: null,
|
||||||
readOnly: false
|
readOnly: false
|
||||||
},
|
},
|
||||||
initialState);
|
initialState);
|
||||||
this.state = new recline.Model.ObjectState(stateData);
|
this.state = new recline.Model.ObjectState(stateData);
|
||||||
|
},
|
||||||
|
|
||||||
// now do updates based on state
|
_bindStateChanges: function() {
|
||||||
if (this.state.get('readOnly')) {
|
var self = this;
|
||||||
this.setReadOnly();
|
|
||||||
}
|
|
||||||
if (this.state.get('currentView')) {
|
|
||||||
this.updateNav(this.state.get('currentView'));
|
|
||||||
}
|
|
||||||
_.each(this.pageViews, function(pageView) {
|
|
||||||
var viewId = 'view-' + pageView.id;
|
|
||||||
if (viewId in self.state.attributes) {
|
|
||||||
pageView.view.state.set(self.state.get(viewId));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// finally ensure we update our state object when state of sub-object changes so that state is always up to date
|
// finally ensure we update our state object when state of sub-object changes so that state is always up to date
|
||||||
this.model.queryState.bind('change', function() {
|
this.model.queryState.bind('change', function() {
|
||||||
self.state.set({queryState: self.model.queryState.toJSON()});
|
self.state.set({query: self.model.queryState.toJSON()});
|
||||||
});
|
});
|
||||||
_.each(this.pageViews, function(pageView) {
|
_.each(this.pageViews, function(pageView) {
|
||||||
if (pageView.view.state && pageView.view.state.bind) {
|
if (pageView.view.state && pageView.view.state.bind) {
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ test('get State', function () {
|
|||||||
var state = explorer.state;
|
var state = explorer.state;
|
||||||
ok(state.get('query'));
|
ok(state.get('query'));
|
||||||
equal(state.get('readOnly'), false);
|
equal(state.get('readOnly'), false);
|
||||||
equal(state.get('currentView'), 'grid');
|
equal(state.get('currentView'), null);
|
||||||
equal(state.get('query').size, 100);
|
equal(state.get('query').size, 100);
|
||||||
deepEqual(state.get('view-grid').hiddenFields, []);
|
deepEqual(state.get('view-grid').hiddenFields, []);
|
||||||
|
deepEqual(state.get('view-graph').group, null);
|
||||||
equal(state.get('backend'), 'memory');
|
equal(state.get('backend'), 'memory');
|
||||||
ok(state.get('dataset').id !== null);
|
ok(state.get('dataset').id !== null);
|
||||||
$el.remove();
|
$el.remove();
|
||||||
|
|||||||
Reference in New Issue
Block a user