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