3064 PO 5) Add confirmation message if not all active participations have been completed.
This commit is contained in:
parent
5f676b2eda
commit
ef301dec4c
view/src
main/java/se/su/dsv/scipro
components
grading
test/java/se/su/dsv/scipro/grading
@ -6,9 +6,13 @@ import org.apache.wicket.model.IModel;
|
||||
/**
|
||||
* Use this class when you want Javascript {@code confirm} behavior but the
|
||||
* component is not a basic {@code a} tag with no other Javascript.
|
||||
*
|
||||
* <p>
|
||||
* If the component is a basic {@link Link} on an {@code a} tag use the
|
||||
* {@link se.su.dsv.scipro.util.JavascriptEventConfirmation} behavior instead.
|
||||
* <p>
|
||||
* If the {@link ConfirmationLink#ConfirmationLink(String, IModel) confirmationMsgModel}
|
||||
* {@link IModel#getObject() getObject()} returns {@code null} no confirmation
|
||||
* prompt is presented.
|
||||
*/
|
||||
public abstract class ConfirmationLink<T> extends Link<T> {
|
||||
protected IModel<String> confirmationMsgModel;
|
||||
@ -25,6 +29,9 @@ public abstract class ConfirmationLink<T> extends Link<T> {
|
||||
|
||||
@Override
|
||||
protected CharSequence getOnClickScript(CharSequence url) {
|
||||
if (confirmationMsgModel.getObject() == null) {
|
||||
return null;
|
||||
}
|
||||
return String.format("event.preventDefault(); if (confirm('%s')) { window.location.href = '%s'; }",
|
||||
confirmationMsgModel.getObject().replace("'", "\\'"),
|
||||
url);
|
||||
|
@ -9,6 +9,7 @@ import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.apache.wicket.model.ResourceModel;
|
||||
import org.apache.wicket.model.StringResourceModel;
|
||||
import se.su.dsv.scipro.components.AutoHidingListView;
|
||||
import se.su.dsv.scipro.components.RedGreenLabel;
|
||||
import se.su.dsv.scipro.components.ScrollSneakBehavior;
|
||||
@ -29,6 +30,7 @@ import javax.inject.Inject;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class IndividualAuthorAssessment extends GenericPanel<User> {
|
||||
@ -138,7 +140,15 @@ public class IndividualAuthorAssessment extends GenericPanel<User> {
|
||||
};
|
||||
add(activeParticipationsCompleted);
|
||||
|
||||
add(new SendToExaminer("send_to_examiner", projectModel, authorModel) {
|
||||
IModel<String> confirmationMessage = completedActiveParticipationsRequirement
|
||||
.flatMap(completed -> {
|
||||
if (Objects.equals(Boolean.TRUE, completed)) {
|
||||
return null;
|
||||
}
|
||||
return new StringResourceModel("active_participations_missing_confirmation_message", this);
|
||||
});
|
||||
|
||||
add(new SendToExaminer("send_to_examiner", projectModel, authorModel, confirmationMessage) {
|
||||
@Override
|
||||
protected void onConfigure() {
|
||||
super.onConfigure();
|
||||
|
@ -21,3 +21,6 @@ active_participations_missing = Not all required active participations have been
|
||||
If the student has performed all mandatory participations anyway, you might still submit the thesis \
|
||||
for examination by choosing "Send to examiner".
|
||||
active_participations_completed = All required active participations performed.
|
||||
active_participations_missing_confirmation_message = \
|
||||
Not all required active participations have been registered in SciPro yet. \
|
||||
Are you sure that you want to send the thesis to the examiner anyway?
|
||||
|
@ -2,10 +2,10 @@ package se.su.dsv.scipro.grading;
|
||||
|
||||
import org.apache.wicket.feedback.FencedFeedbackPanel;
|
||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||
import org.apache.wicket.markup.html.link.Link;
|
||||
import org.apache.wicket.markup.html.panel.GenericPanel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import se.su.dsv.scipro.components.ConfirmationLink;
|
||||
import se.su.dsv.scipro.daisyExternal.http.DaisyAPI;
|
||||
import se.su.dsv.scipro.file.FileDescription;
|
||||
import se.su.dsv.scipro.file.FileService;
|
||||
@ -58,11 +58,12 @@ public class SendToExaminer extends GenericPanel<Project> {
|
||||
|
||||
private IModel<Boolean> needsSending;
|
||||
|
||||
public SendToExaminer(String id, IModel<Project> projectModel, IModel<User> authorModel) {
|
||||
public SendToExaminer(String id, IModel<Project> projectModel, IModel<User> authorModel,
|
||||
IModel<String> confirmationMessage) {
|
||||
super(id, projectModel);
|
||||
|
||||
needsSending = LoadableDetachableModel.of(() -> hasGradedExaminationWithoutSuggestion(authorModel.getObject()));
|
||||
add(new Link<>("send", authorModel) {
|
||||
add(new ConfirmationLink<>("send", authorModel, confirmationMessage) {
|
||||
@Override
|
||||
public void onClick() {
|
||||
sendToExaminer(getModelObject());
|
||||
|
@ -143,7 +143,7 @@ public class SendToExaminerTest extends SciProTest {
|
||||
when(gradingService.sendProtocol(any(), anyLong(), anyLong(), anyInt(), any(), any()))
|
||||
.thenReturn(Either.right(null));
|
||||
|
||||
tester.startComponentInPage(new SendToExaminer("id", () -> project, () -> biden));
|
||||
tester.startComponentInPage(new SendToExaminer("id", () -> project, () -> biden, () -> null));
|
||||
|
||||
tester.clickLink(path("id", "send"));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user