Remove step and assert dependencies

This commit is contained in:
Daniel García Aubert 2017-12-30 18:02:48 +01:00
parent 543d257a20
commit 80e4306fbc

View File

@ -1,5 +1,3 @@
var step = require('step');
var assert = require('assert');
var _ = require('underscore'); var _ = require('underscore');
var NamedMapsCacheEntry = require('../cache/model/named_maps_entry'); var NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
@ -151,8 +149,6 @@ function numMapper(n) {
NamedMapsController.prototype.getStaticImageOptions = function () { NamedMapsController.prototype.getStaticImageOptions = function () {
return function getStaticImageOptionsMiddleware(req, res, next) { return function getStaticImageOptionsMiddleware(req, res, next) {
var self = this;
const { user, namedMapProvider, zoom, lon, lat, bbox } = res.locals; const { user, namedMapProvider, zoom, lon, lat, bbox } = res.locals;
if ([zoom, lon, lat].map(numMapper).every(Number.isFinite)) { if ([zoom, lon, lat].map(numMapper).every(Number.isFinite)) {
@ -183,12 +179,10 @@ NamedMapsController.prototype.getStaticImageOptions = function () {
} }
} }
step( namedMapProvider.getTemplate((err, template) => {
function getTemplate() { if (err) {
namedMapProvider.getTemplate(this); return next(err);
}, }
function handleTemplateView(err, template) {
assert.ifError(err);
if (template.view) { if (template.view) {
var zoomCenter = templateZoomCenter(template.view); var zoomCenter = templateZoomCenter(template.view);
@ -196,45 +190,40 @@ NamedMapsController.prototype.getStaticImageOptions = function () {
if (Number.isFinite(+zoom)) { if (Number.isFinite(+zoom)) {
zoomCenter.zoom = +zoom; zoomCenter.zoom = +zoom;
} }
return zoomCenter; res.locals.imageOpts = zoomCenter;
return next();
} }
var bounds = templateBounds(template.view); var bounds = templateBounds(template.view);
if (bounds) { if (bounds) {
return bounds; res.locals.imageOpts = bounds;
return next();
} }
} }
return false; res.locals.imageOpts = DEFAULT_ZOOM_CENTER;
},
function estimateBoundsIfNoImageOpts(err, imageOpts) {
if (imageOpts) {
return imageOpts;
}
var _next = this; namedMapProvider.getAffectedTablesAndLastUpdatedTime((err, affectedTablesAndLastUpdate) => {
namedMapProvider.getAffectedTablesAndLastUpdatedTime(function(err, affectedTablesAndLastUpdate) {
if (err) { if (err) {
return _next(null); return next();
} }
var affectedTables = affectedTablesAndLastUpdate.tables || []; var affectedTables = affectedTablesAndLastUpdate.tables || [];
if (affectedTables.length === 0) { if (affectedTables.length === 0) {
return _next(null);
}
self.tablesExtentApi.getBounds(user, affectedTables, function (err, result) {
return _next(null, result);
});
});
},
function returnCallback(err, imageOpts) {
res.locals.imageOpts = imageOpts || DEFAULT_ZOOM_CENTER;
return next(); return next();
} }
);
this.tablesExtentApi.getBounds(user, affectedTables, (err, bounds) => {
if (err) {
return next();
}
res.locals.imageOpts = bounds;
return next();
});
});
});
}.bind(this); }.bind(this);
}; };