Skip to content

Commit 58e9c09

Browse files
committed
🐛 👕 fix nested geo fields, eslint cleanup
1 parent ee13bb1 commit 58e9c09

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"ampersand-sync-localforage": "^0.1.1",
9393
"ampersand-view": "^9.0.0",
9494
"ampersand-view-switcher": "^2.0.0",
95+
"async": "^1.5.0",
9596
"backoff": "^2.4.1",
9697
"bootstrap": "https://github.com/twbs/bootstrap/archive/v3.3.5.tar.gz",
9798
"browserify": "^12.0.1",

src/field-list/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ FieldListView = View.extend({
147147
},
148148
makeFieldVisible: function() {
149149
var views = this.fieldCollectionView.views;
150-
_.each(views, function(field_view) {
150+
_.each(views, function(fieldView) {
151151
raf(function() {
152-
field_view.visible = true;
152+
fieldView.visible = true;
153153
});
154154
});
155155
},

src/minicharts/d3fns/geo.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ var minicharts_d3fns_geo = function() {
195195
var el = d3.select(this);
196196

197197
if (!singleton.google) {
198-
parallel({ timeoutMS: 3000 }, [ // 10 second timeout
198+
parallel({ timeoutMS: 5000 }, [ // 5 second timeout
199199
// tasks
200200
function(done) {
201201
GoogleMapsLoader.KEY = 'AIzaSyDrhE1qbcnNIh4sK3t7GEcbLRdCNKWjlt0';
@@ -321,10 +321,28 @@ var minicharts_d3fns_geo = function() {
321321
});
322322
}
323323

324-
_.defer(function() {
325-
google.maps.event.trigger(googleMap, 'resize');
326-
googleMap.fitBounds(bounds);
327-
}, 100);
324+
// need to fit the map bounds after view became visible
325+
var fieldView = options.view.parent.parent;
326+
if (fieldView.parent.parent.modelType === 'FieldView') {
327+
debug('we are in a nested field, wait until it expands...');
328+
// we're inside a nested list, wait until expanded
329+
var parentFieldView = fieldView.parent.parent;
330+
parentFieldView.on('change:expanded', function(view, value) {
331+
if (value) {
332+
debug('field %s expanded. fitting map.', view.model.name);
333+
_.defer(function() {
334+
google.maps.event.trigger(googleMap, 'resize');
335+
googleMap.fitBounds(bounds);
336+
});
337+
}
338+
});
339+
} else {
340+
debug('toplevel location field. fitting map.');
341+
_.defer(function() {
342+
google.maps.event.trigger(googleMap, 'resize');
343+
googleMap.fitBounds(bounds);
344+
});
345+
}
328346
}); // end selection.each()
329347
}
330348

src/minicharts/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ var DocumentRootMinichartView = require('./document-root');
88
var ArrayRootMinichartView = require('./array-root');
99
var vizFns = require('./d3fns');
1010
var QueryBuilderMixin = require('./querybuilder');
11-
var debug = require('debug')('scout:minicharts:index');
1211
var Collection = require('ampersand-collection');
1312

13+
// var debug = require('debug')('scout:minicharts:index');
14+
1415
var ArrayCollection = Collection.extend({
1516
model: Array
1617
});
@@ -57,7 +58,11 @@ module.exports = AmpersandView.extend(QueryBuilderMixin, {
5758
}
5859
return false;
5960
},
61+
/* eslint complexity: 0 */
6062
render: function() {
63+
var isGeo = false;
64+
var coords;
65+
6166
this.renderWithTemplate(this);
6267

6368
if (['String', 'Number'].indexOf(this.model.name) !== -1
@@ -70,7 +75,6 @@ module.exports = AmpersandView.extend(QueryBuilderMixin, {
7075
} else if (this.model.name === 'Document') {
7176
// are these coordinates? Do a basic check for now, until we support semantic schema types
7277
// here we check for GeoJSON form: { loc: {type: "Point", "coordinates": [47.80, 9.63] } }
73-
var isGeo = false;
7478
if (app.isFeatureEnabled('Geo Minicharts')) {
7579
if (this.model.fields.length === 2
7680
&& this.model.fields.get('type')
@@ -81,7 +85,7 @@ module.exports = AmpersandView.extend(QueryBuilderMixin, {
8185
=== this.model.fields.get('coordinates').count
8286
&& this.model.fields.get('coordinates').types.get('Array').average_length === 2
8387
) {
84-
var coords =this._mangleGeoCoordinates(
88+
coords = this._mangleGeoCoordinates(
8589
this.model.fields.get('coordinates').types.get('Array')
8690
.types.get('Number').values.serialize());
8791
if (coords) {
@@ -103,13 +107,13 @@ module.exports = AmpersandView.extend(QueryBuilderMixin, {
103107
this.subview = new DocumentRootMinichartView(this.viewOptions);
104108
}
105109
} else if (this.model.name === 'Array') {
106-
var isGeo = false;
110+
isGeo = false;
107111
if (app.isFeatureEnabled('Geo Minicharts')) {
108112
// are these coordinates? Do a basic check for now, until we support semantic schema types
109113
// here we check for legacy coordinates in array form: { loc: [47.80, 9.63] }
110114
var lengths = this.model.lengths;
111115
if (_.min(lengths) === 2 && _.max(lengths) === 2) {
112-
var coords = this._mangleGeoCoordinates(
116+
coords = this._mangleGeoCoordinates(
113117
this.model.types.get('Number').values.serialize());
114118
if (coords) {
115119
this.model.values = coords;

src/minicharts/querybuilder.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var LeafClause = require('mongodb-language-model').LeafClause;
88
var ListOperator = require('mongodb-language-model').ListOperator;
99
var GeoOperator = require('mongodb-language-model').GeoOperator;
1010
var Range = require('mongodb-language-model').helpers.Range;
11-
var debug = require('debug')('scout:minicharts:querybuilder');
11+
12+
// var debug = require('debug')('scout:minicharts:querybuilder');
1213

1314
var MODIFIERKEY = 'shiftKey';
1415
var checkBounds = {
@@ -48,6 +49,7 @@ module.exports = {
4849
* }
4950
*
5051
*/
52+
/* eslint complexity: 0 */
5153
handleQueryBuilderEvent: function(data) {
5254
var queryType;
5355

0 commit comments

Comments
 (0)