summaryrefslogtreecommitdiff
path: root/app/node_modules/okview/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/node_modules/okview/index.js')
-rw-r--r--app/node_modules/okview/index.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/app/node_modules/okview/index.js b/app/node_modules/okview/index.js
index fba1c18..5f99d59 100644
--- a/app/node_modules/okview/index.js
+++ b/app/node_modules/okview/index.js
@@ -135,25 +135,28 @@ function fetchTemplateData(meta, queries, id) {
if (!result) {
return cache;
}
- var resource = queries[i].resource;
- var type = queries[i].as || queries[i].type;
+ var query = queries[i]
+ var resource = query.resource;
+ var type = query.as || query.type;
var manyResult = isarray(result);
- // Inform template of ID in generic field
- if (manyResult) {
- result = result.map(function(data) {
- return assign({}, data, {id: resource.getID(data)})
- });
- } else {
- result = assign({}, result, {id: resource.getID(result)});
- }
+ var groupBy = query.groupBy
// If we have a lot of results for a certain type,
// we pluralize the key and yield an array of results
- if (cache[type] || manyResult) {
+ if (cache[type] || manyResult || groupBy) {
var plural = pluralize(type);
delete cache[type];
cache[plural] = [];
+ // Pluralize grouped field
+ if (query.groupBy) {
+ result = Object.keys(result).reduce(function(acc, key) {
+ acc[pluralize(key)] = result[key]
+ return acc
+ }, {})
+ }
if (manyResult) {
cache[plural] = cache[plural].concat(result);
+ } else if (groupBy) {
+ cache[plural] = result
} else {
cache[plural].push(result);
}
@@ -162,7 +165,6 @@ function fetchTemplateData(meta, queries, id) {
}
return cache;
}, {meta: meta});
-
resolve(normalized);
}
}).fail(reject);