use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestComponentRenderer method renderAssessmentSectionRubrickBlock.
private void renderAssessmentSectionRubrickBlock(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode sectionNode, URLBuilder ubu, Translator translator) {
AssessmentSection selectedSection = component.getAssessmentSection(sectionNode.getIdentifier());
if (selectedSection != null && selectedSection.getRubricBlocks().size() > 0) {
for (RubricBlock rubricBlock : selectedSection.getRubricBlocks()) {
// @view (candidate)
sb.append("<div class='rubric'>");
rubricBlock.getBlocks().forEach((block) -> renderBlock(renderer, sb, component, null, null, block, ubu, translator));
sb.append("</div>");
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestComponentRenderer method renderSectionRubrics.
private void renderSectionRubrics(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode itemRefNode, URLBuilder ubu, Translator translator) {
boolean writeRubrics = false;
boolean writeTitles = false;
List<AssessmentSection> sectionParentLine = new ArrayList<>();
for (TestPlanNode parentNode = itemRefNode.getParent(); parentNode.getParent() != null; parentNode = parentNode.getParent()) {
AssessmentSection selectedSection = component.getAssessmentSection(parentNode.getIdentifier());
if (selectedSection != null && selectedSection.getVisible()) {
sectionParentLine.add(selectedSection);
if (selectedSection.getRubricBlocks().size() > 0) {
for (RubricBlock rubric : selectedSection.getRubricBlocks()) {
if (rubric.getBlocks().size() > 0) {
writeRubrics = true;
}
}
}
if (StringHelper.containsNonWhitespace(selectedSection.getTitle())) {
writeTitles = true;
}
}
}
if (writeRubrics) {
boolean show = true;
for (int i = sectionParentLine.size(); i-- > 0; ) {
AssessmentSection selectedSection = sectionParentLine.get(i);
if (component.getCandidateSessionContext().isRubricHidden(selectedSection.getIdentifier())) {
show = false;
}
}
String key = sectionParentLine.get(0).getIdentifier().toString();
Form form = component.getQtiItem().getRootForm();
String dispatchId = component.getQtiItem().getFormDispatchId();
sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRNFFnCallFor(form, dispatchId, 1, new NameValuePair("cid", Event.rubric.name()), new NameValuePair("section", key))).append("; return false;\" class='o_toogle_rubrics translated'><i class='o_icon o_icon-fw ");
if (show) {
sb.append("o_icon_close_togglebox'> </i> <span>").append(translator.translate("hide.rubric"));
} else {
sb.append("o_icon_open_togglebox'> </i> <span>").append(translator.translate("show.rubric"));
}
sb.append("</span></a>");
sb.append("<div class='o_info o_assessmentsection_rubrics clearfix");
if (show) {
sb.append(" o_show");
} else {
sb.append(" o_hide");
}
sb.append("'>");
// write the titles first
if (writeTitles) {
sb.append("<h4>");
for (int i = 0; i < sectionParentLine.size(); i++) {
if (i == 1) {
sb.append("<small>");
} else if (i > 1) {
sb.append(" / ");
}
sb.append(sectionParentLine.get(i).getTitle());
}
if (sectionParentLine.size() > 1) {
sb.append("</small>");
}
sb.append("</h4>");
}
for (int i = sectionParentLine.size(); i-- > 0; ) {
AssessmentSection selectedSection = sectionParentLine.get(i);
for (RubricBlock rubricBlock : selectedSection.getRubricBlocks()) {
// @view (candidate)
sb.append("<div class='rubric'>");
rubricBlock.getBlocks().forEach(block -> renderBlock(renderer, sb, component, null, null, block, ubu, translator));
sb.append("</div>");
}
}
sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRNFFnCallFor(form, dispatchId, 1, new NameValuePair("cid", Event.rubric.name()), new NameValuePair("section", key))).append("; return false;\" class='o_toogle_rubrics o_hide'><span>").append(translator.translate("hide.rubric.short")).append("</span></a>");
// script to show/hide the rubrics with the translated linked
sb.append("<script type=\"text/javascript\">\n").append("/* <![CDATA[ */ \n").append("jQuery(function() {\n").append(" jQuery('.o_toogle_rubrics').on('click', function() {\n").append(" jQuery('.o_assessmentsection_rubrics').each(function(index, el) {\n").append(" var current = jQuery(el).attr('class');\n").append(" if(current.indexOf('o_hide') >= 0) {\n").append(" jQuery(el).removeClass('o_hide').addClass('o_show');\n").append(" jQuery('a.o_toogle_rubrics.translated i').removeClass('o_icon_open_togglebox').addClass('o_icon_close_togglebox');\n").append(" jQuery('a.o_toogle_rubrics.translated span').html('").append(translator.translate("hide.rubric")).append("');").append(" } else {\n").append(" jQuery(el).removeClass('o_show').addClass('o_hide');\n").append(" jQuery('a.o_toogle_rubrics.translated i').removeClass('o_icon_close_togglebox').addClass('o_icon_open_togglebox');\n").append(" jQuery('a.o_toogle_rubrics.translated span').html('").append(translator.translate("show.rubric")).append("');").append(" }\n").append(" });").append(" });").append("});\n /* ]]> */").append("</script>").append("</div>");
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestComposerController method doNewAssessmentItem.
/**
* The method create a simple single choice, save the assessment item
* and append it to the test, update the manifest file.
*
* @param ureq
* @param selectedNode
*/
private void doNewAssessmentItem(UserRequest ureq, TreeNode selectedNode, AssessmentItemBuilder itemBuilder) {
try {
TreeNode sectionNode = getNearestSection(selectedNode);
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
AssessmentItemRef itemRef = new AssessmentItemRef(section);
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
itemRef.setIdentifier(Identifier.parseString(itemId));
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
itemRef.setHref(new URI(itemFile.getName()));
section.getSectionParts().add(itemRef);
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
qtiService.persistAssessmentObject(itemFile, assessmentItem);
Map<AssessmentItemRef, AssessmentItem> flyingObjects = Collections.singletonMap(itemRef, assessmentItem);
doSaveAssessmentTest(ureq, flyingObjects);
manifestBuilder.appendAssessmentItem(itemFile.getName());
doSaveManifest();
updateTreeModel(false);
TreeNode newItemNode = menuTree.getTreeModel().getNodeById(itemId);
menuTree.setSelectedNode(newItemNode);
menuTree.open(newItemNode);
partEditorFactory(ureq, newItemNode);
} catch (URISyntaxException e) {
logError("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestComposerController method doDeleteTestPart.
private void doDeleteTestPart(UserRequest ureq, TestPart testPart) {
List<AssessmentSection> sections = new ArrayList<>(testPart.getAssessmentSections());
for (AssessmentSection section : sections) {
doDeleteAssessmentSection(ureq, section);
}
testPart.getParent().getTestParts().remove(testPart);
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestComposerController method doNewSection.
private void doNewSection(UserRequest ureq, TreeNode selectedNode) {
AbstractPart parentPart;
TreeNode sectionNode = getNearestSection(selectedNode);
if (sectionNode != null) {
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
parentPart = section.getParent();
} else if (selectedNode.getUserObject() instanceof TestPart) {
parentPart = (TestPart) selectedNode.getUserObject();
} else {
TreeNode rootNode = menuTree.getTreeModel().getRootNode();
AssessmentTest assessmentTest = (AssessmentTest) rootNode.getUserObject();
List<TestPart> parts = assessmentTest.getTestParts();
if (parts != null && parts.size() > 0) {
parentPart = parts.get(0);
} else {
showWarning("error.cannot.create.section");
return;
}
}
AssessmentSection newSection;
if (parentPart instanceof TestPart) {
newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (TestPart) parentPart);
} else if (parentPart instanceof AssessmentSection) {
newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (AssessmentSection) parentPart);
} else {
showWarning("error.cannot.create.section");
return;
}
// save the test
URI testUri = resolvedAssessmentTest.getTestLookup().getSystemId();
File testFile = new File(testUri);
qtiService.updateAssesmentObject(testFile, resolvedAssessmentTest);
assessmentChanged(ureq);
// reload the test
updateTreeModel(false);
TreeNode newSectionNode = menuTree.getTreeModel().getNodeById(newSection.getIdentifier().toString());
menuTree.setSelectedNode(newSectionNode);
menuTree.open(newSectionNode);
partEditorFactory(ureq, newSectionNode);
}
Aggregations