From 6fa99a0cf0a2b68b95f72678b0ef3c5bfd5acaae Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Wed, 12 Sep 2012 11:40:41 +0200 Subject: [PATCH 1/6] compile of dist/recline --- dist/recline.js | 89 ++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/dist/recline.js b/dist/recline.js index 238ab5a4..11910563 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -2501,18 +2501,18 @@ my.Map = Backbone.View.extend({ // Listen to changes in the fields this.model.fields.bind('change', function() { - self._setupGeometryField() - self.render() + self._setupGeometryField(); + self.render(); }); // Listen to changes in the records - this.model.records.bind('add', function(doc){self.redraw('add',doc)}); + this.model.records.bind('add', function(doc){self.redraw('add',doc);}); this.model.records.bind('change', function(doc){ self.redraw('remove',doc); self.redraw('add',doc); }); - this.model.records.bind('remove', function(doc){self.redraw('remove',doc)}); - this.model.records.bind('reset', function(){self.redraw('reset')}); + this.model.records.bind('remove', function(doc){self.redraw('remove',doc);}); + this.model.records.bind('reset', function(){self.redraw('reset');}); this.menu = new my.MapMenu({ model: this.model, @@ -2612,7 +2612,7 @@ my.Map = Backbone.View.extend({ var count = 0; var wrongSoFar = 0; - _.every(docs,function(doc){ + _.every(docs, function(doc){ count += 1; var feature = self._getGeometryFromRecord(doc); if (typeof feature === 'undefined' || feature === null){ @@ -2621,7 +2621,7 @@ my.Map = Backbone.View.extend({ } else if (feature instanceof Object){ // Build popup contents // TODO: mustache? - html = '' + html = ''; for (key in doc.attributes){ if (!(self.state.get('geomField') && key == self.state.get('geomField'))){ html += '
' + key + ': '+ doc.attributes[key] + '
'; @@ -2634,7 +2634,11 @@ my.Map = Backbone.View.extend({ feature.properties.cid = doc.cid; try { - self.features.addGeoJSON(feature); + self.features.addData(feature); + + if (feature.properties && feature.properties.popupContent) { + self.features.bindPopup(feature.properties.popupContent); + } } catch (except) { wrongSoFar += 1; var msg = 'Wrong geometry value'; @@ -2644,7 +2648,7 @@ my.Map = Backbone.View.extend({ } } } else { - wrongSoFar += 1 + wrongSoFar += 1; if (wrongSoFar <= 10) { self.trigger('recline:flash', {message: 'Wrong geometry value', category:'error'}); } @@ -2663,7 +2667,7 @@ my.Map = Backbone.View.extend({ _.each(docs,function(doc){ for (key in self.features._layers){ - if (self.features._layers[key].cid == doc.cid){ + if (self.features._layers[key].feature.properties.cid == doc.cid){ self.features.removeLayer(self.features._layers[key]); } } @@ -2762,10 +2766,10 @@ my.Map = Backbone.View.extend({ // _zoomToFeatures: function(){ var bounds = this.features.getBounds(); - if (bounds){ + if (bounds.getNorthEast()){ this.map.fitBounds(bounds); } else { - this.map.setView(new L.LatLng(0, 0), 2); + this.map.setView([0, 0], 2); } }, @@ -2779,39 +2783,13 @@ my.Map = Backbone.View.extend({ var mapUrl = "http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png"; var osmAttribution = 'Map data © 2011 OpenStreetMap contributors, Tiles Courtesy of MapQuest '; - var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution, subdomains: '1234'}); + var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution ,subdomains: '1234'}); this.map.addLayer(bg); this.features = new L.GeoJSON(); - this.features.on('featureparse', function (e) { - if (e.properties && e.properties.popupContent){ - e.layer.bindPopup(e.properties.popupContent); - } - if (e.properties && e.properties.cid){ - e.layer.cid = e.properties.cid; - } - }); - - // This will be available in the next Leaflet stable release. - // In the meantime we add it manually to our layer. - this.features.getBounds = function(){ - var bounds = new L.LatLngBounds(); - this._iterateLayers(function (layer) { - if (layer instanceof L.Marker){ - bounds.extend(layer.getLatLng()); - } else { - if (layer.getBounds){ - bounds.extend(layer.getBounds().getNorthEast()); - bounds.extend(layer.getBounds().getSouthWest()); - } - } - }, this); - return (typeof bounds.getNorthEast() !== 'undefined') ? bounds : null; - } - this.map.addLayer(this.features); - this.map.setView(new L.LatLng(0, 0), 2); + this.map.setView([0, 0], 2); this.mapReady = true; }, @@ -3111,8 +3089,9 @@ my.MultiView = Backbone.View.extend({ \ \
\ @@ -3142,28 +3121,28 @@ my.MultiView = Backbone.View.extend({ view: new my.SlickGrid({ model: this.model, state: this.state.get('view-grid') - }), + }) }, { id: 'graph', label: 'Graph', view: new my.Graph({ model: this.model, state: this.state.get('view-graph') - }), + }) }, { id: 'map', label: 'Map', view: new my.Map({ model: this.model, state: this.state.get('view-map') - }), + }) }, { id: 'timeline', label: 'Timeline', view: new my.Timeline({ model: this.model, state: this.state.get('view-timeline') - }), + }) }, { id: 'transform', label: 'Transform', @@ -3246,6 +3225,7 @@ my.MultiView = Backbone.View.extend({ render: function() { var tmplData = this.model.toTemplateJSON(); tmplData.views = this.pageViews; + tmplData.sidebarViews = this.sidebarViews; var template = Mustache.render(this.template, tmplData); $(this.el).html(template); @@ -3265,7 +3245,7 @@ my.MultiView = Backbone.View.extend({ _.each(this.sidebarViews, function(view) { this['$'+view.id] = view.view.el; $dataSidebar.append(view.view.el); - }); + }, this); var pager = new recline.View.Pager({ model: this.model.queryState @@ -3308,13 +3288,7 @@ my.MultiView = Backbone.View.extend({ _onMenuClick: function(e) { e.preventDefault(); var action = $(e.target).attr('data-action'); - if (action === 'filters') { - this.$filterEditor.toggle(); - } else if (action === 'fields') { - this.$fieldsView.toggle(); - } else if (action === 'transform') { - this.transformView.el.toggle(); - } + this['$'+action].toggle(); }, _onSwitchView: function(e) { @@ -3379,7 +3353,7 @@ my.MultiView = Backbone.View.extend({ var self = this; _.each(this.pageViews, function(pageView) { pageView.view.bind('recline:flash', function(flash) { - self.notify(flash); + self.notify(flash); }); }); }, @@ -3401,14 +3375,15 @@ my.MultiView = Backbone.View.extend({ }, flash ); + var _template; if (tmplData.loader) { - var _template = ' \ + _template = ' \
\ {{message}} \   \
'; } else { - var _template = ' \ + _template = ' \
× \ {{message}} \
'; From 881fee5fe7cffa683e8a39ff716f896e3e56e459 Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Wed, 12 Sep 2012 12:48:59 +0200 Subject: [PATCH 2/6] Fixes #230 - updated the feature popup code The feature popup code was broken since commit 9b1bedc97c6febd236023e1ec40114ed288eecd4 --- dist/recline.js | 9 +++++---- src/view.map.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dist/recline.js b/dist/recline.js index f3d4605a..7c8f896a 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -2696,9 +2696,6 @@ my.Map = Backbone.View.extend({ try { self.features.addData(feature); - if (feature.properties && feature.properties.popupContent) { - self.features.bindPopup(feature.properties.popupContent); - } } catch (except) { wrongSoFar += 1; var msg = 'Wrong geometry value'; @@ -2846,7 +2843,11 @@ my.Map = Backbone.View.extend({ var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution ,subdomains: '1234'}); this.map.addLayer(bg); - this.features = new L.GeoJSON(); + this.features = new L.GeoJSON(null, + {onEachFeature: function(feature,layer) { + layer.bindPopup(feature.properties.popupContent); + } + }); this.map.addLayer(this.features); this.map.setView([0, 0], 2); diff --git a/src/view.map.js b/src/view.map.js index cd69bf34..c74b2cf0 100644 --- a/src/view.map.js +++ b/src/view.map.js @@ -217,9 +217,6 @@ my.Map = Backbone.View.extend({ try { self.features.addData(feature); - if (feature.properties && feature.properties.popupContent) { - self.features.bindPopup(feature.properties.popupContent); - } } catch (except) { wrongSoFar += 1; var msg = 'Wrong geometry value'; @@ -367,7 +364,11 @@ my.Map = Backbone.View.extend({ var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution ,subdomains: '1234'}); this.map.addLayer(bg); - this.features = new L.GeoJSON(); + this.features = new L.GeoJSON(null, + {onEachFeature: function(feature,layer) { + layer.bindPopup(feature.properties.popupContent); + } + }); this.map.addLayer(this.features); this.map.setView([0, 0], 2); From fbea51030bcca5eef99ea24f225a4a5b25607ebc Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Thu, 13 Sep 2012 14:50:25 +0200 Subject: [PATCH 3/6] fixes #222 It's quite simple obviously fields can not only be null but also undefined.... --- dist/recline.dataset.js | 2 +- dist/recline.js | 2 +- src/backend.memory.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index 4c4b3e38..99fd7876 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -733,7 +733,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; - if (value !== null) { + if ((value !== null) && (value !== undefined)) { value = value.toString(); } else { // value can be null (apparently in some cases) diff --git a/dist/recline.js b/dist/recline.js index 7c8f896a..e1b5f239 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -1038,7 +1038,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; - if (value !== null) { + if ((value !== null) && (value !== undefined)) { value = value.toString(); } else { // value can be null (apparently in some cases) diff --git a/src/backend.memory.js b/src/backend.memory.js index fd7f6119..c75f6f6f 100644 --- a/src/backend.memory.js +++ b/src/backend.memory.js @@ -148,7 +148,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; - if (value !== null) { + if ((value !== null) && (value !== undefined)) { value = value.toString(); } else { // value can be null (apparently in some cases) From 4954e442a386585d13d26e3d28a27a3d30793f77 Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Thu, 13 Sep 2012 16:32:36 +0200 Subject: [PATCH 4/6] added regex support for query Added a the regex support for queries - this will also match substrings! (change from previous behavior). Also fixed the test vor Custom popups, since this was b0rken. --- src/backend.memory.js | 7 +++++-- test/view.map.test.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend.memory.js b/src/backend.memory.js index c75f6f6f..ece95bd2 100644 --- a/src/backend.memory.js +++ b/src/backend.memory.js @@ -142,9 +142,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; this._applyFreeTextQuery = function(results, queryObj) { if (queryObj.q) { var terms = queryObj.q.split(' '); + var patterns=_.map(terms, function(term) { + return new RegExp(term.toLowerCase());; + }); results = _.filter(results, function(rawdoc) { var matches = true; - _.each(terms, function(term) { + _.each(patterns, function(pattern) { var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; @@ -155,7 +158,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; value = ''; } // TODO regexes? - foundmatch = foundmatch || (value.toLowerCase() === term.toLowerCase()); + foundmatch = foundmatch || (pattern.test(value.toLowerCase())); // TODO: early out (once we are true should break to spare unnecessary testing) // if (foundmatch) return true; }); diff --git a/test/view.map.test.js b/test/view.map.test.js index 1efd3d83..698c22e6 100644 --- a/test/view.map.test.js +++ b/test/view.map.test.js @@ -177,7 +177,7 @@ test('Popup - Custom', function () { assertPresent(popup); var text = popup.html(); - ok((text.indexOf('

3

y: 6') != -1)) + ok((text.indexOf('

1

y: 2') != -1)) view.remove(); }); From 73c414be30a6127a0791a510ef64e9b56490482b Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Thu, 13 Sep 2012 16:35:43 +0200 Subject: [PATCH 5/6] changed memory test to reflect changed behavior --- test/backend.memory.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/backend.memory.test.js b/test/backend.memory.test.js index 23bea1d9..3c858206 100644 --- a/test/backend.memory.test.js +++ b/test/backend.memory.test.js @@ -74,7 +74,7 @@ test('query string', function () { }); data.query({q: 'UK 6'}).then(function(out) { - equal(out.total, 1); + equal(out.total, 2); // the new regex support will find 2 hits deepEqual(out.hits[0].id, 1); }); }); @@ -234,7 +234,7 @@ test('query string', function () { }); dataset.query({q: 'UK 6'}).then(function() { - equal(dataset.records.length, 1); + equal(dataset.records.length, 2); deepEqual(dataset.records.models[0].id, 1); }); }); From d5e36944d76e5786715fd45e5cc07323bbf960cf Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Thu, 13 Sep 2012 16:37:08 +0200 Subject: [PATCH 6/6] query now supports regexes actually compile stuff :/ --- dist/recline.dataset.js | 7 +++++-- dist/recline.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index 99fd7876..83cb1a2b 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -727,9 +727,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; this._applyFreeTextQuery = function(results, queryObj) { if (queryObj.q) { var terms = queryObj.q.split(' '); + var patterns=_.map(terms, function(term) { + return new RegExp(term.toLowerCase());; + }); results = _.filter(results, function(rawdoc) { var matches = true; - _.each(terms, function(term) { + _.each(patterns, function(pattern) { var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; @@ -740,7 +743,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; value = ''; } // TODO regexes? - foundmatch = foundmatch || (value.toLowerCase() === term.toLowerCase()); + foundmatch = foundmatch || (pattern.test(value.toLowerCase())); // TODO: early out (once we are true should break to spare unnecessary testing) // if (foundmatch) return true; }); diff --git a/dist/recline.js b/dist/recline.js index e1b5f239..2a1c5071 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -1032,9 +1032,12 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; this._applyFreeTextQuery = function(results, queryObj) { if (queryObj.q) { var terms = queryObj.q.split(' '); + var patterns=_.map(terms, function(term) { + return new RegExp(term.toLowerCase());; + }); results = _.filter(results, function(rawdoc) { var matches = true; - _.each(terms, function(term) { + _.each(patterns, function(pattern) { var foundmatch = false; _.each(self.fields, function(field) { var value = rawdoc[field.id]; @@ -1045,7 +1048,7 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; value = ''; } // TODO regexes? - foundmatch = foundmatch || (value.toLowerCase() === term.toLowerCase()); + foundmatch = foundmatch || (pattern.test(value.toLowerCase())); // TODO: early out (once we are true should break to spare unnecessary testing) // if (foundmatch) return true; });