Skip to content

Commit

Permalink
Merge pull request #3796 from inception-project/bugfix/3795-Document-…
Browse files Browse the repository at this point in the history
…state-toggle-tooltip-does-not-change-depending-on-document-state

#3795 - Document state toggle tooltip does not change depending on document state
  • Loading branch information
reckart authored Feb 5, 2023
2 parents 03a932b + 8a1849e commit 4c365a3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static java.util.Collections.unmodifiableList;

import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -31,13 +32,16 @@

import org.apache.commons.collections4.ListValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;

public class VDocument
implements Serializable
{
private static final long serialVersionUID = 683698003864323322L;
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private final Map<VID, VArc> arcs = new LinkedHashMap<>();
private final Map<VID, VSpan> spans = new LinkedHashMap<>();
Expand Down Expand Up @@ -120,6 +124,11 @@ public void add(VSpan aSpan)

public void add(VComment aComment)
{
if (get(aComment.getVid()) == null) {
LOG.warn("VID {} referenced by comment does not exist: {}", aComment.getVid(),
aComment);
}

comments.put(aComment.getVid(), aComment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token;
Expand All @@ -46,6 +50,8 @@
public class CompactSerializerV2Impl
implements CompactSerializerV2
{
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String ID = "compact_v2";

private final AnnotationEditorProperties properties;
Expand Down Expand Up @@ -175,6 +181,12 @@ private void renderComments(VDocument aVDoc, HashMap<VID, CompactAnnotation> vid
{
for (var comment : aVDoc.comments()) {
var cann = vidToAnnotation.get(comment.getVid());
if (cann == null) {
LOG.warn("VID {} referenced by comment does not exist: {}", comment.getVid(),
comment);
continue;
}

String code;
switch (comment.getCommentType()) {
case ERROR:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ public void render(VDocument aVdoc, RenderRequest aRequest)

object.setVid(curationVid);
object.setColorHint(COLOR);
aVdoc.add(object);

aVdoc.add(new VComment(object.getVid(), VCommentType.INFO,
"Users with this annotation:\n" + cfg.getCasGroupIds().stream()
.collect(Collectors.joining(", "))));
Expand All @@ -233,8 +235,6 @@ public void render(VDocument aVdoc, RenderRequest aRequest)
else {
log.trace("Rendering curation vid: {}", object.getVid());
}

aVdoc.add(object);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

import java.io.IOException;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalDialog;
import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LambdaModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;
Expand Down Expand Up @@ -117,8 +118,13 @@ private LambdaAjaxLink createToggleDocumentStateLink(String aId)
}
link.setOutputMarkupId(true);
link.add(enabledWhen(() -> page.isEditable() || isReopenableByUser()));
link.add(new Label("state")
.add(new CssClassNameModifier(LambdaModel.of(this::getStateClass))));
var stateLabel = new Label("state");
stateLabel.add(new CssClassNameModifier(LoadableDetachableModel.of(this::getStateClass)));
stateLabel.add(AttributeModifier.replace("title", LoadableDetachableModel.of(() -> {
var tooltip = this.getStateTooltip();
return tooltip.wrapOnAssignment(stateLabel).getObject();
})));
link.add(stateLabel);
return link;
}

Expand All @@ -142,6 +148,28 @@ protected AnnotationPageBase getAnnotationPage()
return page;
}

public ResourceModel getStateTooltip()
{
AnnotatorState state = page.getModelObject();

// Curation sidebar: when writing to the curation document, we need to update the document
if (state.getUser().getUsername().equals(CURATION_USER)) {
if (state.getDocument().getState() == SourceDocumentState.CURATION_FINISHED) {
return new ResourceModel("stateToggle.curationFinished");
}
else {
return new ResourceModel("stateToggle.curationInProgress");
}
}

if (documentService.isAnnotationFinished(state.getDocument(), state.getUser())) {
return new ResourceModel("stateToggle.annotationFinished");
}
else {
return new ResourceModel("stateToggle.annotationInProgress");
}
}

public String getStateClass()
{
AnnotatorState state = page.getModelObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
finishDocumentDescription=This action will mark the document as <b>Finished</b>. <br/> You can no longer make changes to the document after this step. <br/> Only a project manager or curator can put the document back into editing mode. <br/> If you indicate that the document had a problem, it will be removed from your list of documents and you can no longer access it.

stateToggle.curationFinished=Curation finished. Click return to curation-in-progress.
stateToggle.curationInProgress=Curation in progress. Click to finish curation.
stateToggle.annotationFinished=Annotation finished.
stateToggle.annotationInProgress=Annotation in progress. Click to finish annotation.

0 comments on commit 4c365a3

Please sign in to comment.