Fix rendering of QuestionnaireResponses - render items in answers properly

This commit is contained in:
Grahame Grieve 2021-12-22 22:36:51 +11:00
parent 4ce07531ef
commit bb78aeea8e
1 changed files with 35 additions and 17 deletions

View File

@ -62,7 +62,7 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer {
public boolean render(XhtmlNode x, ResourceWrapper qr) throws UnsupportedEncodingException, IOException { public boolean render(XhtmlNode x, ResourceWrapper qr) throws UnsupportedEncodingException, IOException {
switch (context.getQuestionnaireMode()) { switch (context.getQuestionnaireMode()) {
case FORM: return renderForm(x, qr); case FORM: return renderTree(x, qr);
case LINKS: return renderLinks(x, qr); case LINKS: return renderLinks(x, qr);
// case LOGIC: return renderLogic(x, q); // case LOGIC: return renderLogic(x, q);
// case DEFNS: return renderDefns(x, q); // case DEFNS: return renderDefns(x, q);
@ -74,7 +74,7 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer {
public boolean renderTree(XhtmlNode x, ResourceWrapper qr) throws UnsupportedEncodingException, IOException { public boolean renderTree(XhtmlNode x, ResourceWrapper qr) throws UnsupportedEncodingException, IOException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true); HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true);
TableModel model = gen.new TableModel("qtree="+qr.getId(), true); TableModel model = gen.new TableModel("qtree="+qr.getId(), false);
model.setAlternating(true); model.setAlternating(true);
model.setDocoImg(context.getSpecificationLink() +"help16.png"); model.setDocoImg(context.getSpecificationLink() +"help16.png");
model.setDocoRef(context.getSpecificationLink()+"formats.html#table"); model.setDocoRef(context.getSpecificationLink()+"formats.html#table");
@ -175,6 +175,25 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer {
} }
} else if (answers.size() == 1) { } else if (answers.size() == 1) {
BaseWrapper ans = answers.get(0); BaseWrapper ans = answers.get(0);
renderAnswer(gen, q, r, ans);
} else {
r.getCells().add(gen.new Cell(null, null, null, null, null));
for (BaseWrapper ans : answers) {
Row ar = gen.new Row();
ar.setIcon("icon-q-string.png", "Item");
ar.getSubRows().add(ar);
ar.getCells().add(gen.new Cell(null, null, null, null, null));
ar.getCells().add(gen.new Cell(null, null, text, null, null));
ar.getCells().add(gen.new Cell(null, null, null, null, null));
renderAnswer(gen, q, ar, ans);
}
}
return hasExt;
}
public void renderAnswer(HierarchicalTableGenerator gen, ResourceWrapper q, Row r, BaseWrapper ans) throws UnsupportedEncodingException, IOException {
List<BaseWrapper> items;
Base b = ans.get("value[x]"); Base b = ans.get("value[x]");
if (b == null) { if (b == null) {
r.getCells().add(gen.new Cell(null, null, "null!", null, null)); r.getCells().add(gen.new Cell(null, null, "null!", null, null));
@ -189,11 +208,10 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer {
render(x, (DataType) b); render(x, (DataType) b);
r.getCells().add(cell); r.getCells().add(cell);
} }
} else { items = ans.children("item");
r.getCells().add(gen.new Cell(null, null, "{todo #2}", null, null)); for (BaseWrapper si : items) {
renderTreeItem(gen, r.getSubRows(), q, si);
} }
return hasExt;
} }
private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, QuestionnaireResponse q, QuestionnaireResponseItemComponent i) throws IOException { private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, QuestionnaireResponse q, QuestionnaireResponseItemComponent i) throws IOException {