Skip to content

Commit

Permalink
#4258 - Reset document button for annotators in dynamic assignment mode
Browse files Browse the repository at this point in the history
- Replace another usage of deprecated ChallengeResponseDialog with modern approach
- Move annotation reset dialog panel code to workload base module so it can be used by the static and matrix modules
- Fix coloring of table headers on dynamic workload page
  • Loading branch information
reckart committed Oct 29, 2023
1 parent ef408ef commit a7e0cf2
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tr.even:hover{
.headers,
.headers a:link,
.headers a:visited{
--bs-table-color: var(--bs-light);
--bs-table-bg: #B90F22 !important;
background-color:#B90F22 !important;
color:white !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ <h1>
class="form-control" />
</div>
</div>
<div class="row form-row">
<label class="col-form-label col-sm-7">
<wicket:message key="workflow" />
<a wicket:id="workflowHelpLink"/>
</label>
<div class="col-sm-5">
<select wicket:id="workflowType" class="form-select"/>
</div>
</div>
<div class="row form-row">
<label class="col-form-label col-sm-7">
<wicket:message key="confirmFinishingDocuments" />
Expand All @@ -204,11 +213,12 @@ <h1>
</div>
<div class="row form-row">
<label class="col-form-label col-sm-7">
<wicket:message key="workflow" />
<a wicket:id="workflowHelpLink"/>
<wicket:message key="documentResetAllowed" />
</label>
<div class="col-sm-5">
<select wicket:id="workflowType" class="form-select"/>
<div class="form-check">
<input class="form-check-input" type="checkbox" wicket:id="documentResetAllowed">
</div>
</div>
</div>
<div class="row form-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
Expand Down Expand Up @@ -81,7 +78,6 @@

import com.googlecode.wicket.jquery.core.JQueryBehavior;
import com.googlecode.wicket.jquery.core.Options;
import com.googlecode.wicket.jquery.ui.widget.menu.IMenuItem;
import com.googlecode.wicket.kendo.ui.KendoDataSource;
import com.googlecode.wicket.kendo.ui.form.multiselect.lazy.MultiSelect;
import com.googlecode.wicket.kendo.ui.renderer.ChoiceRenderer;
Expand Down Expand Up @@ -126,6 +122,7 @@
import de.tudarmstadt.ukp.inception.workload.dynamic.workflow.WorkflowExtensionPoint;
import de.tudarmstadt.ukp.inception.workload.dynamic.workflow.types.WorkflowType;
import de.tudarmstadt.ukp.inception.workload.model.WorkloadManagementService;
import de.tudarmstadt.ukp.inception.workload.ui.ResetAnnotationDocumentConfirmationDialogContentPanel;

/**
* The workload page. It shall give project admins a fast overview on how each annotators progress
Expand Down Expand Up @@ -170,7 +167,7 @@ public class DynamicWorkloadManagementPage
private DataTable<AnnotationQueueItem, AnnotationQueueSortKeys> table;

// Modal dialog
private ModalDialog modalDialog;
private ModalDialog dialog;
private ChallengeResponseDialog resetDocumentDialog;
private ContextMenu contextMenu;

Expand Down Expand Up @@ -243,8 +240,8 @@ public void commonInit()
add(createSettingsForm());
add(new LambdaAjaxLink("refresh", this::actionRefresh));

modalDialog = new BootstrapModalDialog("modalDialog");
add(modalDialog);
dialog = new BootstrapModalDialog("modalDialog");
add(dialog);

add(resetDocumentDialog = new ChallengeResponseDialog("resetDocumentDialog"));
add(contextMenu = new ContextMenu("contextMenu"));
Expand Down Expand Up @@ -356,23 +353,24 @@ protected void onUpdate(AjaxRequestTarget ajaxRequestTarget)
*/
public Form<DynamicWorkloadTraits> createSettingsForm()
{
DynamicWorkloadTraits traits = dynamicWorkloadExtension.readTraits(workloadManagementService
var traits = dynamicWorkloadExtension.readTraits(workloadManagementService
.loadOrCreateWorkloadManagerConfiguration(currentProject.getObject()));

Form<DynamicWorkloadTraits> settingsForm = new Form<>("settingsForm",
new CompoundPropertyModel<>(traits));
var settingsForm = new Form<>("settingsForm", new CompoundPropertyModel<>(traits));
settingsForm.setOutputMarkupId(true);

settingsForm.add(new DocLink("workflowHelpLink", "sect_dynamic_workload"));

settingsForm.add(new CheckBox("documentResetAllowed"));

settingsForm.add(new CheckBox("confirmFinishingDocuments"));

settingsForm.add(new NumberTextField<>("defaultNumberOfAnnotations", Integer.class) //
.setMinimum(1) //
.setConvertEmptyInputStringToNull(false) //
.setRequired(true));

CheckBox abandonationToggle = new CheckBox("abandonationToggle");
var abandonationToggle = new CheckBox("abandonationToggle");
abandonationToggle.setModel(new LambdaModelAdapter<Boolean>(() -> {
Duration d = settingsForm.getModelObject().getAbandonationTimeout();
return !(d.isNegative() || d.isZero());
Expand All @@ -388,7 +386,7 @@ public Form<DynamicWorkloadTraits> createSettingsForm()
_target -> _target.add(settingsForm)));
settingsForm.add(abandonationToggle);

Component abandonationTimeout = new NumberTextField<>("abandonationTimeout", Long.class) //
var abandonationTimeout = new NumberTextField<>("abandonationTimeout", Long.class) //
.setMinimum(0l) //
.setConvertEmptyInputStringToNull(false) //
.setRequired(true)
Expand All @@ -409,8 +407,7 @@ public Form<DynamicWorkloadTraits> createSettingsForm()
_target.add(settingsForm);
}).add(visibleWhen(abandonationToggle.getModel())));

DropDownChoice<AnnotationDocumentState> abandonationState = new DropDownChoice<>(
"abandonationState");
var abandonationState = new DropDownChoice<AnnotationDocumentState>("abandonationState");
abandonationState.setRequired(true);
abandonationState.setNullValid(false);
abandonationState.setChoiceRenderer(new EnumChoiceRenderer<>(abandonationState));
Expand All @@ -419,7 +416,7 @@ public Form<DynamicWorkloadTraits> createSettingsForm()
abandonationState.add(visibleWhen(abandonationToggle.getModel()));
settingsForm.add(abandonationState);

DropDownChoice<String> workflowChoices = new DropDownChoice<>("workflowType");
var workflowChoices = new DropDownChoice<String>("workflowType");
workflowChoices.setChoiceRenderer(
new LambdaChoiceRenderer<>(id -> workflowExtensionPoint.getExtension(id)
.map(WorkflowExtension::getLabel).orElse("<" + id + " not available>")));
Expand Down Expand Up @@ -641,23 +638,23 @@ public void onSourceDocumentFilterStateChanged(SourceDocumentFilterStateChanged

private List<AnnotationQueueItem> getQueue()
{
Project project = currentProject.getObject();
var project = currentProject.getObject();

dynamicWorkloadExtension.freshenStatus(project);

Map<SourceDocument, List<AnnotationDocument>> documentMap = new HashMap<>();
var documentMap = new HashMap<SourceDocument, List<AnnotationDocument>>();

documentService.listSourceDocuments(project)
.forEach(d -> documentMap.put(d, new ArrayList<>()));

documentService.listAnnotationDocuments(project).forEach(ad -> documentMap
.computeIfAbsent(ad.getDocument(), d -> new ArrayList<>()).add(ad));

DynamicWorkloadTraits traits = dynamicWorkloadExtension.readTraits(workloadManagementService
var traits = dynamicWorkloadExtension.readTraits(workloadManagementService
.loadOrCreateWorkloadManagerConfiguration(currentProject.getObject()));

List<AnnotationQueueItem> queue = new ArrayList<>();
for (Entry<SourceDocument, List<AnnotationDocument>> e : documentMap.entrySet()) {
var queue = new ArrayList<AnnotationQueueItem>();
for (var e : documentMap.entrySet()) {
queue.add(new AnnotationQueueItem(e.getKey(), e.getValue(),
traits.getDefaultNumberOfAnnotations(), traits.getAbandonationTimeout()));
}
Expand All @@ -667,10 +664,10 @@ private List<AnnotationQueueItem> getQueue()
@OnEvent
public void onAnnotatorColumnCellClickEvent(AnnotatorColumnCellClickEvent aEvent)
{
AnnotationDocument annotationDocument = documentService
var annotationDocument = documentService
.createOrGetAnnotationDocument(aEvent.getSourceDocument(), aEvent.getUser());

AnnotationDocumentState targetState = oneClickTransition(annotationDocument);
var targetState = oneClickTransition(annotationDocument);

documentService.setAnnotationDocumentState(annotationDocument, targetState);

Expand All @@ -682,9 +679,9 @@ public void onAnnotatorColumnCellClickEvent(AnnotatorColumnCellClickEvent aEvent
@OnEvent
public void onAnnotatorColumnCellClickEvent(AnnotatorColumnCellShowAnnotatorCommentEvent aEvent)
{
AnnotationDocument annDoc = documentService
.getAnnotationDocument(aEvent.getSourceDocument(), aEvent.getUser());
modalDialog.open(new AnnotatorCommentDialogPanel(ModalDialog.CONTENT_ID, Model.of(annDoc)),
var annDoc = documentService.getAnnotationDocument(aEvent.getSourceDocument(),
aEvent.getUser());
dialog.open(new AnnotatorCommentDialogPanel(ModalDialog.CONTENT_ID, Model.of(annDoc)),
aEvent.getTarget());
}

Expand All @@ -697,7 +694,7 @@ public void onAnnotatorStateOpenContextMenuEvent(AnnotatorStateOpenContextMenuEv
return;
}

List<IMenuItem> items = contextMenu.getItemList();
var items = contextMenu.getItemList();
items.clear();

// The AnnotatorColumnCellOpenContextMenuEvent is not serializable, so we need to extract
Expand All @@ -715,11 +712,12 @@ public void onAnnotatorStateOpenContextMenuEvent(AnnotatorStateOpenContextMenuEv
private void actionResetAnnotationDocument(AjaxRequestTarget aTarget, SourceDocument aDocument,
User aUser)
{
resetDocumentDialog.setTitleModel(new ResourceModel("ResetDocumentDialog.title"));
resetDocumentDialog.setMessageModel(new ResourceModel("ResetDocumentDialog.text"));
resetDocumentDialog.setExpectedResponseModel(
var dialogContent = new ResetAnnotationDocumentConfirmationDialogContentPanel(
ModalDialog.CONTENT_ID);

dialogContent.setExpectedResponseModel(
Model.of(aUser.getUiName() + " / " + aDocument.getName()));
resetDocumentDialog.setConfirmAction(_target -> {
dialogContent.setConfirmAction(_target -> {
documentService.resetAnnotationCas(aDocument, aUser);

success(format("The annotations of document [%s] for user [%s] have been set reset.",
Expand All @@ -728,13 +726,14 @@ private void actionResetAnnotationDocument(AjaxRequestTarget aTarget, SourceDocu

updateTable(_target);
});
resetDocumentDialog.show(aTarget);

dialog.open(dialogContent, aTarget);
}

private void actionTouchAnnotationDocument(AjaxRequestTarget aTarget, SourceDocument aDocument,
User aUser)
{
AnnotationDocument ann = documentService.getAnnotationDocument(aDocument, aUser);
var ann = documentService.getAnnotationDocument(aDocument, aUser);
ann.setTimestamp(new Date());
documentService.createAnnotationDocument(ann);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ assignDocument=Assign document(s)
unassignDocument=Delete a document
stateFilter=Document state
confirmFinishingDocuments=Confirm finishing documents
documentResetAllowed=Allow resetting the document to its original state

assignDocument.null=Please select a document
unassignDocument.null=Please select a document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<wicket:panel>
<span wicket:id="item" class="badge rounded-pill">
<span wicket:id="item" class="badge rounded-pill me-1">
<span wicket:id="state">
<wicket:container wicket:id="stateSymbol"/>
<wicket:container wicket:id="annotatorName"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class DynamicWorkloadTraits
private String workflowType;
private int defaultNumberOfAnnotations;
private boolean confirmFinishingDocuments = true;
private boolean documentResetAllowed = true;

private Duration abandonationTimeout;
private AnnotationDocumentState abandonationState = IGNORE;
Expand Down Expand Up @@ -112,4 +113,14 @@ public void setConfirmFinishingDocuments(boolean aConfirmFinishingDocuments)
{
confirmFinishingDocuments = aConfirmFinishingDocuments;
}

public boolean isDocumentResetAllowed()
{
return documentResetAllowed;
}

public void setDocumentResetAllowed(boolean aDocumentResetAllowed)
{
documentResetAllowed = aDocumentResetAllowed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.schema.adapter.AnnotationException;
import de.tudarmstadt.ukp.inception.workload.matrix.MatrixWorkloadExtension;
import de.tudarmstadt.ukp.inception.workload.matrix.management.ResetAnnotationDocumentConfirmationDialogContentPanel;
import de.tudarmstadt.ukp.inception.workload.matrix.trait.MatrixWorkloadTraits;
import de.tudarmstadt.ukp.inception.workload.model.WorkloadManagementService;
import de.tudarmstadt.ukp.inception.workload.ui.ResetAnnotationDocumentConfirmationDialogContentPanel;
import wicket.contrib.input.events.key.KeyType;

public class MatrixWorkflowActionBarItemGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import de.tudarmstadt.ukp.inception.workload.matrix.management.support.UserSelectToolbar;
import de.tudarmstadt.ukp.inception.workload.matrix.trait.MatrixWorkloadTraits;
import de.tudarmstadt.ukp.inception.workload.model.WorkloadManagementService;
import de.tudarmstadt.ukp.inception.workload.ui.ResetAnnotationDocumentConfirmationDialogContentPanel;

@MountPath(NS_PROJECT + "/${" + PAGE_PARAM_PROJECT + "}/monitoring")
public class MatrixWorkloadManagementPage
Expand Down Expand Up @@ -302,7 +303,7 @@ private void actionToggleBulkChange(AjaxRequestTarget aTarget)

private void actionBulkResetDocument(AjaxRequestTarget aTarget)
{
List<AnnotationDocument> selectedDocuments = selectedAnnotationDocuments().stream()
var selectedDocuments = selectedAnnotationDocuments().stream()
.filter(annDoc -> annDoc.getState() == IN_PROGRESS || annDoc.getState() == FINISHED)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.workload.matrix.management;
package de.tudarmstadt.ukp.inception.workload.ui;

import java.util.Collection;
import java.util.Collections;
Expand Down

0 comments on commit a7e0cf2

Please sign in to comment.