Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc/select text detail #1396

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/org/commcare/suite/model/Detail.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class Detail implements Externalizable {
@Nullable
private Text noItemsText;

@Nullable
private Text selectText;

/**
* Optional and only relevant if this detail has child details. In that
* case, form may be 'image' or omitted.
Expand Down Expand Up @@ -123,7 +126,7 @@ public Detail(String id, DisplayUnit title, Text noItemsText, String nodeset, Ve
Vector<Action> actions, Callout callout, String fitAcross,
String uniformUnitsString, String forceLandscape, String focusFunction,
String printPathProvided, String relevancy, Global global, DetailGroup group,
boolean lazyLoading) {
boolean lazyLoading, Text selectText) {

if (detailsVector.size() > 0 && fieldsVector.size() > 0) {
throw new IllegalArgumentException("A detail may contain either sub-details or fields, but not both.");
Expand All @@ -132,6 +135,7 @@ public Detail(String id, DisplayUnit title, Text noItemsText, String nodeset, Ve
this.id = id;
this.title = title;
this.noItemsText = noItemsText;
this.selectText = selectText;
if (nodeset != null) {
this.nodeset = XPathReference.getPathExpr(nodeset).getReference();
}
Expand Down Expand Up @@ -201,6 +205,11 @@ public Text getNoItemsText() {
return noItemsText;
}

@Nullable
public Text getSelectText() {
return selectText;
}

/**
* @return A reference to a set of sub-elements of this detail. If provided,
* the detail will display fields for each element of this nodeset.
Expand Down Expand Up @@ -284,6 +293,7 @@ public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOExcep
global = (Global)ExtUtil.read(in, new ExtWrapNullable(new ExtWrapTagged()), pf);
group = (DetailGroup) ExtUtil.read(in, new ExtWrapNullable(DetailGroup.class), pf);
lazyLoading = ExtUtil.readBool(in);
selectText = (Text) ExtUtil.read(in, new ExtWrapNullable(Text.class), pf);
}

@Override
Expand All @@ -307,6 +317,7 @@ public void writeExternal(DataOutputStream out) throws IOException {
ExtUtil.write(out, new ExtWrapNullable(global == null ? null : new ExtWrapTagged(global)));
ExtUtil.write(out, new ExtWrapNullable(group));
ExtUtil.writeBool(out, lazyLoading);
ExtUtil.write(out, new ExtWrapNullable(selectText));
}

public OrderedHashtable<String, XPathExpression> getVariableDeclarations() {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/commcare/xml/DetailParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public Detail parse() throws InvalidStructureException, IOException, XmlPullPars

//Now get the headers and templates.
Text noItemsText = null;
Text selectText = null;
Vector<Detail> subdetails = new Vector<>();
Vector<DetailField> fields = new Vector<>();
OrderedHashtable<String, String> variables = new OrderedHashtable<>();
Expand All @@ -85,6 +86,14 @@ public Detail parse() throws InvalidStructureException, IOException, XmlPullPars
}
continue;
}
if ("select_text".equals(parser.getName().toLowerCase())) {
checkNode("select_text");
getNextTagInBlock("select_text");
if ("text".equals(parser.getName().toLowerCase())) {
selectText = new TextParser(parser).parse();
}
continue;
}
if ("variables".equals(parser.getName().toLowerCase())) {
while (nextTagInBlock("variables")) {
String function = parser.getAttributeValue(null, "function");
Expand Down Expand Up @@ -132,7 +141,7 @@ public Detail parse() throws InvalidStructureException, IOException, XmlPullPars

return new Detail(id, title, noItemsText, nodeset, subdetails, fields, variables, actions, callout,
fitAcross, useUniformUnits, forceLandscapeView, focusFunction, printTemplatePath,
relevancy, global, detailGroup, isLazyLoading);
relevancy, global, detailGroup, isLazyLoading, selectText);
}

protected DetailParser getDetailParser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public void testDetailNoItemsText() {
Assert.assertEquals("Empty List", noItemsText.evaluate());
}

@Test
public void testDetailSelectText() {
Text selectText = mApp.getSession().getPlatform().getDetail("m0_case_short").getSelectText();
Assert.assertEquals("Continue With Case", selectText.evaluate());
}

@Test
public void testDemoUserRestoreParsing() throws Exception {
// Test parsing an app with a properly-formed demo user restore file
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/app_structure/app_strings.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
m0_no_items_text=Empty List
m0_no_items_text=Empty List
m0_select_text=Continue With Case
5 changes: 5 additions & 0 deletions src/test/resources/app_structure/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<locale id="m0_no_items_text"/>
</text>
</no_items_text>
<select_text>
<text>
<locale id="m0_select_text"/>
</text>
</select_text>
<global>
<geo-overlay>
<coordinates>
Expand Down