Add metadata information about analyses
This commit is contained in:
parent
077c4ab907
commit
0981ccd0c4
@ -130,6 +130,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
var self = this;
|
||||
|
||||
var mapConfig;
|
||||
var analysesResults = [];
|
||||
|
||||
step(
|
||||
function setupParams(){
|
||||
@ -164,9 +165,10 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
}
|
||||
self.analysisMapConfigAdapter.getLayers(analysisConfiguration, requestMapConfig, filters, this);
|
||||
},
|
||||
function beforeLayergroupCreate(err, requestMapConfig) {
|
||||
function beforeLayergroupCreate(err, requestMapConfig, _analysesResults) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
analysesResults = _analysesResults;
|
||||
self.namedLayersAdapter.getLayers(req.context.user, requestMapConfig.layers, self.pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
if (err) {
|
||||
@ -222,7 +224,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
},
|
||||
function afterLayergroupCreate(err, layergroup) {
|
||||
assert.ifError(err);
|
||||
self.afterLayergroupCreate(req, res, mapConfig, layergroup, this);
|
||||
self.afterLayergroupCreate(req, res, mapConfig, analysesResults, layergroup, this);
|
||||
},
|
||||
function finish(err, layergroup) {
|
||||
if (err) {
|
||||
@ -282,7 +284,7 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn
|
||||
},
|
||||
function afterLayergroupCreate(err, layergroup) {
|
||||
assert.ifError(err);
|
||||
self.afterLayergroupCreate(req, res, mapConfig, layergroup, this);
|
||||
self.afterLayergroupCreate(req, res, mapConfig, [],layergroup, this);
|
||||
},
|
||||
function finishTemplateInstantiation(err, layergroup) {
|
||||
if (err) {
|
||||
@ -303,7 +305,7 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn
|
||||
};
|
||||
|
||||
|
||||
MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, layergroup, callback) {
|
||||
MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, analysesResults, layergroup, callback) {
|
||||
var self = this;
|
||||
|
||||
var username = req.context.user;
|
||||
@ -369,6 +371,7 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la
|
||||
// TODO this should take into account several URL patterns
|
||||
addWidgetsUrl(username, layergroup);
|
||||
addDataviewsUrls(username, layergroup, mapconfig.obj());
|
||||
addAnalysesMetadata(username, layergroup, analysesResults);
|
||||
if (req.method === 'GET') {
|
||||
var ttl = global.environment.varnish.layergroupTtl || 86400;
|
||||
res.set('Cache-Control', 'public,max-age='+ttl+',must-revalidate');
|
||||
@ -387,6 +390,30 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la
|
||||
);
|
||||
};
|
||||
|
||||
function addAnalysesMetadata(username, layergroup, analysesResults) {
|
||||
analysesResults = analysesResults || [];
|
||||
layergroup.metadata.analyses = layergroup.metadata.analyses || [];
|
||||
|
||||
analysesResults.forEach(function(analysis, index) {
|
||||
var resource = layergroup.layergroupid + '/analysis/' + index;
|
||||
var nodes = [analysis.getRoot()].concat(analysis.getSortedNodes());
|
||||
layergroup.metadata.analyses.push({
|
||||
url: getUrls(username, resource),
|
||||
nodes: nodes.reduce(function(nodesIdMap, node) {
|
||||
if (node.params.id) {
|
||||
var nodeResource = layergroup.layergroupid + '/analysis/' + index + '/node/' + node.params.id;
|
||||
nodesIdMap[node.params.id] = {
|
||||
query: node.getQuery(),
|
||||
url: getUrls(username, nodeResource)
|
||||
};
|
||||
}
|
||||
|
||||
return nodesIdMap;
|
||||
}, {})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function addDataviewsUrls(username, layergroup, mapConfig) {
|
||||
layergroup.metadata.dataviews = layergroup.metadata.dataviews || {};
|
||||
var dataviews = mapConfig.dataviews || {};
|
||||
|
@ -138,6 +138,6 @@ AnalysisMapConfigAdapter.prototype.getLayers = function(analysisConfiguration, r
|
||||
|
||||
debug('mapconfig output', JSON.stringify(requestMapConfig, null, 4));
|
||||
|
||||
return callback(null, requestMapConfig);
|
||||
return callback(null, requestMapConfig, analysesResults);
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user