Add dataviews to layergroup metadata

This commit is contained in:
Raul Ochoa 2016-03-18 18:09:17 +01:00
parent f745e915d3
commit ff147ca3bf
2 changed files with 20 additions and 9 deletions

View File

@ -383,6 +383,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());
if (req.method === 'GET') {
var ttl = global.environment.varnish.layergroupTtl || 86400;
res.set('Cache-Control', 'public,max-age='+ttl+',must-revalidate');
@ -401,6 +402,18 @@ MapController.prototype.afterLayergroupCreate = function(req, res, mapconfig, la
);
};
function addDataviewsUrls(username, layergroup, mapConfig) {
layergroup.metadata.dataviews = layergroup.metadata.dataviews || {};
var dataviews = mapConfig.dataviews || {};
Object.keys(dataviews).forEach(function(dataviewName) {
var resource = layergroup.layergroupid + '/dataview/' + dataviewName;
layergroup.metadata.dataviews[dataviewName] = {
url: getUrls(username, resource)
};
});
}
function addWidgetsUrl(username, layergroup) {
if (layergroup.metadata && Array.isArray(layergroup.metadata.layers)) {

View File

@ -138,8 +138,6 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
url += '?' + qs.stringify(extraParams);
}
console.log(url);
var layergroupId;
step(
function createLayergroup() {
@ -165,13 +163,13 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
return next(err);
}
var parsedBody = JSON.parse(res.body);
// var expectedWidgetURLS = {
// http: "/api/v1/map/" + parsedBody.layergroupid + "/dataview/" + dataviewName
// };
// assert.ok(parsedBody.metadata.dataviews[dataviewName]);
// assert.ok(
// parsedBody.metadata.dataviews[dataviewName].url.http.match(expectedWidgetURLS.http)
// );
var expectedDataviewsURLS = {
http: "/api/v1/map/" + parsedBody.layergroupid + "/dataview/" + dataviewName
};
assert.ok(parsedBody.metadata.dataviews[dataviewName]);
assert.ok(
parsedBody.metadata.dataviews[dataviewName].url.http.match(expectedDataviewsURLS.http)
);
return next(null, parsedBody.layergroupid);
}
);