From 793fde461753bdaf5af660a46be1976b6662a7a3 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Sat, 21 Apr 2012 23:47:52 +0100 Subject: [PATCH] [bugfix,view-map][s]: 30m to track down and fix a bug whereby map view was ignoring config passed to it. * setupGeometryFields was running (and overwriting) even if fields set in state passed in (which I don't think we want). --- src/view-map.js | 14 +++++++++----- src/view.js | 2 +- test/view.test.js | 11 ++++++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/view-map.js b/src/view-map.js index 9ceb07b1..a6361d75 100644 --- a/src/view-map.js +++ b/src/view-map.js @@ -335,12 +335,16 @@ my.Map = Backbone.View.extend({ // If not found, the user can define them via the UI form. _setupGeometryField: function(){ var geomField, latField, lonField; - this.state.set({ - geomField: this._checkField(this.geometryFieldNames), - latField: this._checkField(this.latitudeFieldNames), - lonField: this._checkField(this.longitudeFieldNames) - }); this.geomReady = (this.state.get('geomField') || (this.state.get('latField') && this.state.get('lonField'))); + // should not overwrite if we have already set this (e.g. explicitly via state) + if (!this.geomReady) { + this.state.set({ + geomField: this._checkField(this.geometryFieldNames), + latField: this._checkField(this.latitudeFieldNames), + lonField: this._checkField(this.longitudeFieldNames) + }); + this.geomReady = (this.state.get('geomField') || (this.state.get('latField') && this.state.get('lonField'))); + } }, // Private: Check if a field in the current model exists in the provided diff --git a/src/view.js b/src/view.js index 358b2aa3..44881967 100644 --- a/src/view.js +++ b/src/view.js @@ -184,8 +184,8 @@ my.DataExplorer = Backbone.View.extend({ initialize: function(options) { var self = this; this.el = $(this.el); - // Hash of 'page' views (i.e. those for whole page) keyed by page name this._setupState(options.state); + // Hash of 'page' views (i.e. those for whole page) keyed by page name if (options.views) { this.pageViews = options.views; } else { diff --git a/test/view.test.js b/test/view.test.js index 19fcc177..4dec5d89 100644 --- a/test/view.test.js +++ b/test/view.test.js @@ -47,17 +47,26 @@ test('initialize state', function () { currentView: 'graph', 'view-grid': { hiddenFields: ['x'] + }, + 'view-map': { + latField: 'lat1', + lonField: 'lon1' } } }); ok(explorer.state.get('readOnly')); ok(explorer.state.get('currentView'), 'graph'); + // check the correct view is visible var css = explorer.el.find('.navigation a[data-view="graph"]').attr('class').split(' '); ok(_.contains(css, 'disabled'), css); - var css = explorer.el.find('.navigation a[data-view="grid"]').attr('class').split(' '); ok(!(_.contains(css, 'disabled')), css); + + // check pass through of view config + deepEqual(explorer.state.get('view-grid')['hiddenFields'], ['x']); + equal(explorer.state.get('view-map')['lonField'], 'lon1'); + $el.remove(); });