Commit eda3626e authored by Tristan Cavelier's avatar Tristan Cavelier

gidstorage gid parser upgraded to assign several constraints to a metadata

parent 7a11c5e0
......@@ -166,22 +166,38 @@
* constraints
*/
function gidFormat(metadata, constraints) {
var types, i, meta_key, result = {}, tmp;
types = ['default', metadata.type];
var types, i, j, meta_key, result = [], tmp, constraint, actions;
types = (metadata_actions.list(metadata.type) || []).slice();
types.unshift('default');
for (i = 0; i < types.length; i += 1) {
for (meta_key in constraints[types[i]]) {
if (constraints[types[i]].hasOwnProperty(meta_key)) {
constraint = constraints[types[i]];
for (meta_key in constraint) {
if (constraint.hasOwnProperty(meta_key)) {
actions = constraint[meta_key];
if (!Array.isArray(actions)) {
actions = [actions];
}
for (j = 0; j < actions.length; j += 1) {
tmp = metadata_actions[
constraints[types[i]][meta_key]
actions[j]
](metadata[meta_key]);
if (tmp === undefined) {
return;
}
result[meta_key] = tmp;
}
result[result.length] = [meta_key, tmp];
}
}
return JSON.stringify(result);
}
// sort dict keys to make gid universal
result.sort(function (a, b) {
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
});
tmp = {};
for (i = 0; i < result.length; i += 1) {
tmp[result[i][0]] = result[i][1];
}
return JSON.stringify(tmp);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment