Skip to content

Commit

Permalink
add selectText to Detail and parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Costello committed Jan 15, 2024
1 parent 451ee3c commit 3dc8dee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit 3dc8dee

Please sign in to comment.