Skip to content

Commit

Permalink
Merge pull request #1337 from dimagi/fieldAction
Browse files Browse the repository at this point in the history
Xml Model Change: Adds action in detail field
  • Loading branch information
shubham1g5 authored Sep 26, 2023
2 parents 2e00d50 + 9627329 commit 540cb67
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/commcare/suite/model/DetailField.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class DetailField implements Externalizable {
private String verticalAlign;
private String fontSize;
private String cssID;
private Action action;

public DetailField() {
}
Expand Down Expand Up @@ -201,6 +202,7 @@ public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOExcep
horizontalAlign = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
verticalAlign = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
cssID = ExtUtil.nullIfEmpty(ExtUtil.readString(in));
action = (Action)ExtUtil.read(in, new ExtWrapNullable(new ExtWrapTagged()), pf);
}

@Override
Expand Down Expand Up @@ -230,6 +232,7 @@ public void writeExternal(DataOutputStream out) throws IOException {
ExtUtil.writeString(out, ExtUtil.emptyIfNull(horizontalAlign));
ExtUtil.writeString(out, ExtUtil.emptyIfNull(verticalAlign));
ExtUtil.writeString(out, ExtUtil.emptyIfNull(cssID));
ExtUtil.write(out, new ExtWrapNullable(action == null ? null : new ExtWrapTagged(action)));
}

public int getGridX() {
Expand Down Expand Up @@ -264,6 +267,10 @@ public String getCssId() {
return cssID;
}

public Action getAction() {
return action;
}

public static class Builder {
final DetailField field;

Expand Down Expand Up @@ -382,5 +389,9 @@ public void setFontSize(String fontSize) {
public void setCssID(String id) {
field.cssID = id;
}

public void setAction(Action action) {
field.action = action;
}
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/commcare/xml/DetailFieldParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public DetailField parse() throws InvalidStructureException, IOException, XmlPul
} else {
throw new InvalidStructureException("detail <field> with no <template>!", parser);
}
if (nextTagInBlock("field")) {
while(nextTagInBlock("field")) {
//sort details
checkNode(new String[]{"sort", "background"});
checkNode(new String[]{"sort", "background", "action"});

String name = parser.getName().toLowerCase();

Expand All @@ -84,6 +84,9 @@ public DetailField parse() throws InvalidStructureException, IOException, XmlPul
} else if (name.equals("background")) {
// background tag in fields is deprecated
skipBlock("background");
} else if (name.equals(ActionParser.NAME_ACTION)) {
checkNode(ActionParser.NAME_ACTION);
builder.setAction(new ActionParser(parser).parse());
}
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.commcare.backend.suite.model.test;

import org.commcare.resources.model.UnresolvedResourceException;
import org.commcare.suite.model.Action;
import org.commcare.suite.model.AssertionSet;
import org.commcare.suite.model.Callout;
import org.commcare.suite.model.Detail;
import org.commcare.suite.model.DetailField;
import org.commcare.suite.model.GeoOverlay;
import org.commcare.suite.model.Global;
Expand All @@ -20,6 +22,7 @@
import io.reactivex.observers.TestObserver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

/**
Expand Down Expand Up @@ -90,6 +93,13 @@ public void testDetailWithFocusFunction() {
Assert.assertTrue(focusFunction != null);
}

@Test
public void testDetailWithFieldAction() {
Detail detail = mApp.getSession().getPlatform().getDetail("m0_case_short");
DetailField field = detail.getFields()[0];
assertNotNull(field.getAction());
}

@Test
public void testDetailWithoutFocusFunction() {
XPathExpression focusFunction =
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/app_structure/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
<xpath function="case_name"/>
</text>
</sort>
<action>
<display>
<text>Action Form</text>
</display>
<stack>
<push>
<command value="'m0-f0'"/>
<datum id="case_id_new_case_0" value="uuid()"/>
</push>
</stack>
</action>
</field>
</detail>
<detail id="m0_case_long">
Expand Down

0 comments on commit 540cb67

Please sign in to comment.