Skip to content

Commit

Permalink
Merge pull request #1098 from dimagi/sk/learn-display-condition
Browse files Browse the repository at this point in the history
add 'display condition' for Learn Module question type
  • Loading branch information
snopoke authored Sep 28, 2023
2 parents 51a317d + 88c4bcb commit 9f53905
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
71 changes: 34 additions & 37 deletions src/commcareConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ define([
// allows the parser to know which mug to associate with this node
"vellum:role": mug.__className,
}),
getBindList: mug => {
// return list of bind elements to add to the form
let mugConfig = mugConfigs[mug.__className];
let binds = [{
nodeset: mug.hashtagPath,
relevant: mug.p.relevantAttr,
}];
return binds.concat(mugConfig.childNodes.filter(child => !child.writeToData).map(child => {
return {
nodeset: `${mug.absolutePath}/${mugConfig.rootName}/${child.id}`,
calculate: mug.p[child.id],
};
}));
},
parseDataNode: (mug, node) => {
let children = node.children(),
mugConfig = mugConfigs[mug.__className];
Expand Down Expand Up @@ -122,7 +136,6 @@ define([
mug.p.description = "";
mug.p.time_estimate = "";
},
getBindList: () => [],
spec: util.extend(baseSpec, {
nodeID: {
lstring: gettext('Module ID'),
Expand All @@ -149,17 +162,29 @@ define([
return val && val.match(/^\d+$/) ? "pass" : gettext("Must be an integer");
},
help: gettext('Estimated time to complete the module in hours.'),
},
relevantAttr: {
visibility: 'visible',
presence: 'optional',
widget: widgets.xPath,
xpathType: "bool",
serialize: mugs.serializeXPath,
deserialize: mugs.deserializeXPath,
lstring: gettext('Display Condition'),
}
})
}),
sections: [_.extend({}, baseSection, {
properties: [
"nodeID",
"name",
"description",
"time_estimate",
],
})],
sections: [
_.extend({}, baseSection, {
properties: [
"nodeID",
"name",
"description",
"time_estimate",
],
}),
_.clone(logicSection),
],
},
ConnectAssessment: {
rootName: "assessment",
Expand All @@ -172,20 +197,6 @@ define([
init: mug => {
mug.p.user_score = "";
},
getBindList: mug => {
// return list of bind elements to add to the form
let mugConfig = mugConfigs[mug.__className];
let binds = [{
nodeset: mug.hashtagPath,
relevant: mug.p.relevantAttr,
}];
return binds.concat(mugConfig.childNodes.map(child => {
return {
nodeset: `${mug.absolutePath}/${mugConfig.rootName}/${child.id}`,
calculate: mug.p[child.id],
};
}));
},
spec: util.extend(baseSpec, {
nodeID: {
lstring: gettext('Assessment ID'),
Expand Down Expand Up @@ -235,20 +246,6 @@ define([
mug.p.entity_id = "";
mug.p.entity_name = "";
},
getBindList: mug => {
// return list of bind elements to add to the form
let mugConfig = mugConfigs[mug.__className];
let binds = [{
nodeset: mug.hashtagPath,
relevant: mug.p.relevantAttr,
}];
return binds.concat(mugConfig.childNodes.filter(child => !child.writeToData).map(child => {
return {
nodeset: `${mug.absolutePath}/${mugConfig.rootName}/${child.id}`,
calculate: mug.p[child.id],
};
}));
},
spec: util.extend(baseSpec, {
nodeID: {
lstring: gettext('Delivery Unit ID'),
Expand Down
1 change: 1 addition & 0 deletions tests/commcareConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define([
assert.equal(module.p.name, "module 1");
assert.equal(module.p.description, "Module 1 is fun\nLearning is fun");
assert.equal(module.p.time_estimate, "2");
assert.equal(module.p.relevantAttr, "x = 2");
util.assertXmlEqual(call("createXML"), LEARN_MODULE_XML);
});

Expand Down
1 change: 1 addition & 0 deletions tests/static/commcareConnect/learn_module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</data>
</instance>
<bind vellum:nodeset="#form/name" nodeset="/data/name" type="xsd:string" />
<bind vellum:nodeset="#form/module_1" nodeset="/data/module_1" relevant="x = 2" />
<itext>
<translation lang="en" default="">
<text id="name-label">
Expand Down

0 comments on commit 9f53905

Please sign in to comment.