Skip to content

Commit

Permalink
[contact-summary] allow structured card.fields
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jun 11, 2018
1 parent 2e8c12b commit 65e03c5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.16.14
* [contact-summary] allow structured card.fields
* Fix __include_inline__() input trimming

## v1.16.13
* Update ordering and content of README
* Remove items from README which have been done
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-conf",
"version": "1.16.13",
"version": "1.16.14",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
61 changes: 47 additions & 14 deletions src/lib/compile-contact-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,64 @@ var result = {
};
function addCard(card, r) {
if(!card.appliesIf(r)) return;
function addValue(src, dst, prop) {
switch(typeof src[prop]) {
case 'undefined': return;
case 'function': dst[prop] = src[prop](r); break;
default: dst[prop] = src[prop];
}
}
var fields = typeof card.fields === 'function' ?
card.fields(r) :
card.fields
.filter(function(f) {
switch(typeof f.appliesIf) {
case 'undefined': return true;
case 'function': return f.appliesIf(r);
default: return f.appliesIf;
}
})
.map(function(f) {
var ret = {};
addValue(f, ret, 'label');
addValue(f, ret, 'value');
addValue(f, ret, 'translate');
addValue(f, ret, 'filter');
addValue(f, ret, 'width');
addValue(f, ret, 'icon');
if(f.context) {
ret.context = {};
addValue(f.context, ret.context, 'count');
addValue(f.context, ret.context, 'total');
}
return ret;
});
result.cards.push({
label: card.label,
fields: fields,
});
if(card.modifyContext) card.modifyContext(context, r);
}
cards.forEach(function(card) {
var idx1, r;
switch(card.appliesToType) {
case 'report':
for(idx1=0; idx1<reports.length; ++idx1) {
r = reports[idx1];
if(!isReportValid(r)) continue;
if(card.appliesIf(r)) {
result.cards.push({
label: card.label,
fields: card.fields(r),
});
if(card.modifyContext) card.modifyContext(context);
}
addCard(card, r);
}
break;
default:
if(contact.type !== card.appliesToType) return;
if(card.appliesIf()) {
result.cards.push({
label: card.label,
fields: card.fields(),
});
if(card.modifyContext) card.modifyContext(context);
}
addCard(card);
}
});
Expand Down

0 comments on commit 65e03c5

Please sign in to comment.