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

Xml Model Change: Adds action in detail field #1337

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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