Skip to content
Snippets Groups Projects
Commit 46146431 authored by srosse's avatar srosse
Browse files

OO-5107: more informations for user disadvantage in user management

parent 95398fcc
No related branches found
No related tags found
No related merge requests found
Showing
with 116 additions and 16 deletions
......@@ -74,12 +74,21 @@ public class DisadvantageCompensationDAO {
return dbInstance.getCurrentEntityManager().merge(compensation);
}
/**
* Fetch all repository informations.
*
* @param identity
* @return
*/
public List<DisadvantageCompensation> getDisadvantageCompensations(IdentityRef identity) {
QueryBuilder sb = new QueryBuilder();
sb.append("select compensation from dcompensation as compensation")
.append(" inner join fetch compensation.creator as creator")
.append(" inner join fetch creator.user as userCreator")
.append(" inner join fetch compensation.entry as v")
.append(" inner join fetch v.olatResource as res")
.append(" inner join fetch v.statistics as statistics")
.append(" left join fetch v.lifecycle as lifecycle")
.append(" where compensation.identity.key=:identityKey");
return dbInstance.getCurrentEntityManager()
......
......@@ -61,6 +61,9 @@ public class DisadvantageCompensationServiceImpl implements DisadvantageCompensa
return disadvantageCompensationDao.updateDisadvantageCompensation(compensation);
}
/**
* Fetch all repository informations (resource, statistics...)
*/
@Override
public List<DisadvantageCompensation> getDisadvantageCompensations(IdentityRef identity) {
return disadvantageCompensationDao.getDisadvantageCompensations(identity);
......
......@@ -117,8 +117,7 @@ public class UserDisadvantageCompensationEditController extends FormBasicControl
selectRepositoryEntryLayout.setMandatory(true);
formLayout.add(selectRepositoryEntryLayout);
if(compensation != null && compensation.getEntry() != null) {
String displayName = StringHelper.escapeHtml(compensation.getEntry().getDisplayname());
selectRepositoryEntryLayout.contextPut("entryName", displayName);
updateEntryName(compensation.getEntry());
}
selectEntryButton = uifactory.addFormLink("select.entry", selectRepositoryEntryLayout, Link.BUTTON);
selectEntryButton.getComponent().setSuppressDirtyFormWarning(true);
......@@ -127,7 +126,7 @@ public class UserDisadvantageCompensationEditController extends FormBasicControl
elementEl = uifactory.addDropdownSingleselect("select.entry.element", formLayout, new String[0], new String[0]);
elementEl.setHelpTextKey("select.entry.element.hint", null);
if(compensation != null && compensation.getEntry() != null) {
updateElementSelection(compensation.getEntry());
updateElementSelection(compensation.getEntry(), compensation.getSubIdent());
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
......@@ -269,17 +268,36 @@ public class UserDisadvantageCompensationEditController extends FormBasicControl
private void doSelectForm(RepositoryEntry selectedEntry) {
this.entry = selectedEntry;
selectRepositoryEntryLayout.contextPut("entryName", selectedEntry.getDisplayname());
updateElementSelection(selectedEntry);
updateEntryName(selectedEntry);
String currentSelected = null;
if(elementEl != null && elementEl.isOneSelected()) {
currentSelected = elementEl.getSelectedKey();
}
updateElementSelection(selectedEntry, currentSelected);
}
private void updateEntryName(RepositoryEntry selectedEntry) {
if(selectedEntry == null) {
selectRepositoryEntryLayout.contextRemove("entryName");
} else {
StringBuilder sb = new StringBuilder(64);
sb.append(StringHelper.escapeHtml(selectedEntry.getDisplayname()));
if(StringHelper.containsNonWhitespace(entry.getExternalRef())) {
sb.append(" (").append(StringHelper.escapeHtml(selectedEntry.getExternalRef())).append(")");
}
selectRepositoryEntryLayout.contextPut("entryName", sb.toString());
}
}
private void updateElementSelection(RepositoryEntry selectedEntry) {
private void updateElementSelection(RepositoryEntry selectedEntry, String currentSelectedIdent) {
final KeyValues values = new KeyValues();
Visitor visitor = node -> {
if(node instanceof IQTESTCourseNode) {
IQTESTCourseNode testNode = (IQTESTCourseNode)node;
if(testNode.hasQTI21TimeLimit(testNode.getCachedReferencedRepositoryEntry())) {
values.add(KeyValues.entry(testNode.getIdent(), testNode.getShortTitle()));
RepositoryEntry testEntry = testNode.getCachedReferencedRepositoryEntry();
if(testNode.hasQTI21TimeLimit(testEntry)) {
String value = makeElementValue(testNode, testEntry);
values.add(KeyValues.entry(testNode.getIdent(), value));
}
}
};
......@@ -289,5 +307,18 @@ public class UserDisadvantageCompensationEditController extends FormBasicControl
new TreeVisitor(visitor, rootNode, false)
.visitAll();
elementEl.setKeysAndValues(values.keys(), values.values(), null);
if(currentSelectedIdent != null && values.containsKey(currentSelectedIdent)) {
elementEl.select(currentSelectedIdent, true);
}
}
private String makeElementValue(IQTESTCourseNode testNode, RepositoryEntry testEntry) {
StringBuilder sb = new StringBuilder();
sb.append(StringHelper.escapeHtml(testNode.getShortTitle()))
.append(" - ").append(StringHelper.escapeHtml(testEntry.getDisplayname()));
if(StringHelper.containsNonWhitespace(testEntry.getExternalRef())) {
sb.append(" (").append(StringHelper.escapeHtml(testEntry.getExternalRef())).append(")");
}
return sb.toString();
}
}
......@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.olat.NewControllerFactory;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.form.flexible.FormItem;
......@@ -39,6 +40,7 @@ import org.olat.core.gui.components.form.flexible.impl.elements.table.DateFlexiC
import org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel;
import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel;
import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModelFactory;
import org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent;
import org.olat.core.gui.components.link.Link;
import org.olat.core.gui.components.link.LinkFactory;
import org.olat.core.gui.components.velocity.VelocityContainer;
......@@ -51,11 +53,16 @@ import org.olat.core.gui.control.generic.closablewrapper.CloseableModalControlle
import org.olat.core.id.Identity;
import org.olat.core.util.Formatter;
import org.olat.core.util.StringHelper;
import org.olat.course.CourseFactory;
import org.olat.course.ICourse;
import org.olat.course.nodes.CourseNode;
import org.olat.course.nodes.IQTESTCourseNode;
import org.olat.modules.dcompensation.DisadvantageCompensation;
import org.olat.modules.dcompensation.DisadvantageCompensationAuditLog;
import org.olat.modules.dcompensation.DisadvantageCompensationService;
import org.olat.modules.dcompensation.DisadvantageCompensationStatusEnum;
import org.olat.modules.dcompensation.ui.UserDisadvantageCompensationTableModel.CompensationCols;
import org.olat.repository.RepositoryEntry;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -112,9 +119,10 @@ public class UserDisadvantageCompensationListController extends FormBasicControl
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, CompensationCols.creationDate));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, CompensationCols.creator));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, CompensationCols.entryKey));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.entry));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.externalRef));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.courseElement));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.entry, "select_course"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.externalRef, "select_course"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.courseElement, "select_test"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.testEntryExternalRef, "select_test"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.extraTime,
new ExtraTimeCellRenderer(getTranslator())));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(CompensationCols.approvedBy));
......@@ -144,7 +152,7 @@ public class UserDisadvantageCompensationListController extends FormBasicControl
filters.add(new FlexiTableFilter(translate("show.all"), "all", true));
tableEl.setFilters("status", filters, false);
tableEl.setSelectedFilterKey(DisadvantageCompensationStatusEnum.active.name());
tableEl.setAndLoadPersistedPreferences(ureq, "user-disadvantage-compensations-list");
tableEl.setAndLoadPersistedPreferences(ureq, "user-disadvantage-compensations-list-v2");
}
@Override
......@@ -159,8 +167,9 @@ public class UserDisadvantageCompensationListController extends FormBasicControl
String creatorFullName = userManager.getUserDisplayName(compensation.getCreator());
FormLink toolsLink = uifactory.addFormLink("tools_" + (++counter), "tools", "", null, null, Link.NONTRANSLATED);
toolsLink.setIconLeftCSS("o_icon o_icon_actions o_icon-lg");
UserDisadvantageCompensationRow row = new UserDisadvantageCompensationRow(compensation, creatorFullName, toolsLink);
RepositoryEntry testEntry = getTestEntry(compensation);
UserDisadvantageCompensationRow row = new UserDisadvantageCompensationRow(compensation, testEntry, creatorFullName, toolsLink);
rows.add(row);
toolsLink.setUserObject(row);
}
......@@ -168,6 +177,16 @@ public class UserDisadvantageCompensationListController extends FormBasicControl
tableEl.reset(true, true, true);
}
private RepositoryEntry getTestEntry(DisadvantageCompensation compensation) {
ICourse course = CourseFactory.loadCourse(compensation.getEntry());
CourseNode courseNode = course.getRunStructure().getNode(compensation.getSubIdent());
if(courseNode instanceof IQTESTCourseNode) {
IQTESTCourseNode node = (IQTESTCourseNode)courseNode;
return node.getCachedReferencedRepositoryEntry();
}
return null;
}
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if(editCtrl == source || confirmDeleteCtrl == source) {
......@@ -200,6 +219,15 @@ public class UserDisadvantageCompensationListController extends FormBasicControl
doAddCompensation(ureq);
} else if(batchDeleteButton == source) {
doConfirmDelete(ureq);
} else if(tableEl == source) {
if(event instanceof SelectionEvent) {
SelectionEvent se = (SelectionEvent)event;
if("select_course".equals(se.getCommand())) {
doOpenCourse(ureq, tableModel.getObject(se.getIndex()));
} else if("select_test".equals(se.getCommand())) {
doOpenTest(ureq, tableModel.getObject(se.getIndex()));
}
}
} else if(source instanceof FormLink) {
FormLink link = (FormLink)source;
if("tools".equals(link.getCmd()) && link.getUserObject() instanceof UserDisadvantageCompensationRow) {
......@@ -210,6 +238,19 @@ public class UserDisadvantageCompensationListController extends FormBasicControl
super.formInnerEvent(ureq, source, event);
}
private void doOpenCourse(UserRequest ureq, UserDisadvantageCompensationRow row) {
String businessPath = "[RepositoryEntry:" + row.getEntry().getKey() + "][CourseNode:" + row.getCourseElementId() + "]";
NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
}
private void doOpenTest(UserRequest ureq, UserDisadvantageCompensationRow row) {
RepositoryEntry testEntry = row.getTestEntry();
if(testEntry != null) {
String businessPath = "[RepositoryEntry:" + testEntry.getKey() + "]";
NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
}
}
private void doAddCompensation(UserRequest ureq) {
if(guardModalController(editCtrl)) return;
......
......@@ -24,6 +24,7 @@ import java.util.Date;
import org.olat.core.gui.components.form.flexible.elements.FormLink;
import org.olat.modules.dcompensation.DisadvantageCompensation;
import org.olat.modules.dcompensation.DisadvantageCompensationStatusEnum;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryRef;
/**
......@@ -35,14 +36,17 @@ import org.olat.repository.RepositoryEntryRef;
public class UserDisadvantageCompensationRow {
private final String creatorFullName;
private final RepositoryEntry testEntry;
private final DisadvantageCompensation compensation;
private final FormLink toolsLink;
public UserDisadvantageCompensationRow(DisadvantageCompensation compensation, String creatorFullName, FormLink toolsLink) {
public UserDisadvantageCompensationRow(DisadvantageCompensation compensation, RepositoryEntry testEntry,
String creatorFullName, FormLink toolsLink) {
this.compensation = compensation;
this.creatorFullName = creatorFullName;
this.toolsLink = toolsLink;
this.testEntry = testEntry;
}
public Long getKey() {
......@@ -81,6 +85,14 @@ public class UserDisadvantageCompensationRow {
return compensation.getSubIdentName();
}
public RepositoryEntry getTestEntry() {
return testEntry;
}
public String getTestExternalRef() {
return testEntry == null ? null : testEntry.getExternalRef();
}
public Integer getExtraTime() {
return compensation.getExtraTime();
}
......
......@@ -86,6 +86,7 @@ implements SortableFlexiTableDataModel<UserDisadvantageCompensationRow>, Filtera
case entryKey: return row.getEntryKey();
case externalRef: return row.getEntryExternalRef();
case courseElement: return row.getCourseElement();
case testEntryExternalRef: return row.getTestExternalRef();
case extraTime: return row.getExtraTime();
case approvedBy: return row.getApprovedBy();
case approvalDate: return row.getApprovalDate();
......@@ -114,6 +115,7 @@ implements SortableFlexiTableDataModel<UserDisadvantageCompensationRow>, Filtera
entry("table.header.entry.displayname"),
externalRef("table.header.entry.external.ref"),
courseElement("table.header.course.element"),
testEntryExternalRef("table.header.course.element.entry.ref"),
extraTime("table.header.extra.time"),
approvedBy("table.header.approved.by"),
approvalDate("table.header.approval.date"),
......
#if($r.isNotNull($entryName)) <i class="o_icon o_icon-lg o_CourseModule_icon"> </i> $r.escapeHtml($entryName) #end
#if($r.isNotNull($entryName)) <p class='form-control-static'><i class="o_icon o_icon-lg o_CourseModule_icon"> </i> $r.escapeHtml($entryName)</p> #end
#if($r.visible("select.entry"))
$r.render("select.entry")
#end
\ No newline at end of file
......@@ -21,6 +21,7 @@ table.header.approved.by=Bewilligt von
table.header.approval.date=Bewilligungsdatum
table.header.before=Vor \u00C4nderung
table.header.course.element=Test
table.header.course.element.entry.ref= Test Ext. Ref.
table.header.creationdate=Erstellt am
table.header.creator=Erstellt von
table.header.doer=Actor
......
......@@ -21,6 +21,7 @@ table.header.approved.by=Approved by
table.header.approval.date=Approval date
table.header.before=Before changes
table.header.course.element=Test
table.header.course.element.entry.ref= Test ext. ref.
table.header.creationdate=Created at
table.header.creator=Created by
table.header.doer=Aktor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment