3391 Fix warning

This commit is contained in:
Andreas Svanberg 2024-05-22 10:45:29 +02:00
parent e8e8bf8a68
commit 325b93ce3d
3 changed files with 57 additions and 7 deletions
view/src
main/java/se/su/dsv/scipro
test/java/se/su/dsv/scipro/grading

@ -100,9 +100,7 @@ public class SendToExaminer extends GenericPanel<Project> {
add(form);
WebMarkupContainer sendButton = new WebMarkupContainer("send");
if (confirmationMessage.getObject() != null) {
sendButton.add(new JavascriptEventConfirmation("click", confirmationMessage));
}
sendButton.add(new JavascriptEventConfirmation("click", confirmationMessage));
form.add(sendButton);
TextField<LocalDate> examinationDateField = new TextField<>("examinationDate", examinationDate, LocalDate.class);

@ -37,18 +37,20 @@ public class JavascriptEventConfirmation extends Behavior {
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
final String confirmationMsg = getConfirmationMsg(component);
if (confirmationMsg == null) return;
String confirmScript = "var conf = confirm('" + confirmationMsg.replaceAll("'", "\\\\'") + "'); " +
"if (!conf) event.preventDefault();";
response.render(OnEventHeaderItem.forComponent(component, event, confirmScript));
}
private String getConfirmationMsg(Component component) {
IModel<?> model = msgModel;
if (model instanceof IComponentAssignedModel)
IModel<String> model = msgModel;
if (model instanceof IComponentAssignedModel<String> icam)
{
model = ((IComponentAssignedModel<?>)model).wrapOnAssignment(component);
model = icam.wrapOnAssignment(component);
}
return String.valueOf(model.getObject());
return model.getObject();
}
@Override

@ -18,6 +18,7 @@ import se.su.dsv.scipro.system.DegreeType;
import se.su.dsv.scipro.system.ProjectType;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.util.Either;
import se.su.dsv.scipro.util.JavascriptEventConfirmation;
import java.math.BigDecimal;
import java.time.LocalDate;
@ -152,6 +153,55 @@ public class SendToExaminerTest extends SciProTest {
verify(gradingService).reportGrade(TOKEN, project.getIdentifier(), biden.getIdentifier(), gw.id(), grade.name(), finalThesis.getUploadDate());
}
@Test
public void author_without_active_participations_done_should_generate_confirmation_on_sending_to_examiner() {
ProjectType bachelor = new ProjectType(DegreeType.BACHELOR, "Bachelor", "Bachelor");
User obama = User.builder()
.firstName("Barack")
.lastName("Obama")
.emailAddress("obama@example.com")
.identifier(44)
.build();
User biden = User.builder()
.firstName("Joe")
.lastName("Biden")
.emailAddress("joe@example.com")
.identifier(46)
.build();
biden.setId(46L);
Project project = Project.builder()
.title("My project")
.projectType(bachelor)
.startDate(LocalDate.of(2023, Month.JANUARY, 6))
.headSupervisor(obama)
.projectParticipants(Set.of(biden))
.identifier(1888)
.build();
project.setId(8L);
Examination gw = new Examination(
2,
new Name("Examensarbete", "Graduation work"),
"KX1E",
BigDecimal.valueOf(9),
List.of(
new Grade(Grade.Type.PASSING, "A"),
new Grade(Grade.Type.PASSING, "B"),
new Grade(Grade.Type.PASSING, "C"),
new Grade(Grade.Type.PASSING, "D"),
new Grade(Grade.Type.PASSING, "E"),
new Grade(Grade.Type.FAILING, "F")));
when(gradingService.getExaminations(any(), anyLong(), anyLong()))
.thenReturn(List.of(gw));
when(gradingService.getResult(any(), anyLong(), anyLong(), anyLong()))
.thenReturn(Either.right(Optional.empty()));
tester.startComponentInPage(new SendToExaminer("id", () -> project, () -> biden, () -> "please check active participations"));
tester.assertBehavior(path("id", "form", "send"), JavascriptEventConfirmation.class);
}
private static Thesis daisyThesis() {
Unit unit = new Unit();
unit.setId(1);