Keep and validate project type selection when creating/editing application periods #47
@ -16,10 +16,7 @@
|
||||
|
||||
<fieldset class="mb-3">
|
||||
<legend><wicket:message key="projectTypes"/></legend>
|
||||
<div class="form-check" wicket:id="projectTypes">
|
||||
<input type="checkbox" wicket:id="checkbox" class="form-check-input"/>
|
||||
<label class="form-check-label" wicket:for="checkbox"><span wicket:id="name"></span></label>
|
||||
</div>
|
||||
<div wicket:id="projectTypes"></div>
|
||||
</fieldset>
|
||||
|
||||
<div class="form-row">
|
||||
|
@ -4,17 +4,14 @@ import jakarta.inject.Inject;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
import org.apache.wicket.extensions.model.AbstractCheckBoxModel;
|
||||
import org.apache.wicket.feedback.FencedFeedbackPanel;
|
||||
import org.apache.wicket.markup.html.basic.Label;
|
||||
import org.apache.wicket.markup.html.form.*;
|
||||
import org.apache.wicket.markup.html.list.ListItem;
|
||||
import org.apache.wicket.markup.html.list.ListView;
|
||||
import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel;
|
||||
import org.apache.wicket.model.IModel;
|
||||
import org.apache.wicket.model.LambdaModel;
|
||||
import org.apache.wicket.model.LoadableDetachableModel;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
import se.su.dsv.scipro.components.BootstrapCheckBoxMultipleChoice;
|
||||
import se.su.dsv.scipro.components.BootstrapDatePicker;
|
||||
import se.su.dsv.scipro.components.BootstrapTimePicker;
|
||||
import se.su.dsv.scipro.components.DatesValidator;
|
||||
@ -39,7 +36,6 @@ public class AdminEditApplicationPeriodPage
|
||||
public static final String TITLE = "title";
|
||||
public static final String FEEDBACK = "Feedback";
|
||||
public static final String TITLE_FEEDBACK = "titleFeedback";
|
||||
public static final String CHECKBOX = "checkbox";
|
||||
|
||||
@Inject
|
||||
private ProjectTypeService projectTypeService;
|
||||
@ -63,18 +59,13 @@ public class AdminEditApplicationPeriodPage
|
||||
add(new ComponentFeedbackPanel(TITLE_FEEDBACK, title));
|
||||
add(title);
|
||||
add(
|
||||
new ListView<>(PROJECT_TYPES, availableProjectTypes()) {
|
||||
@Override
|
||||
protected void populateItem(ListItem<ProjectType> item) {
|
||||
item.add(
|
||||
new CheckBox(CHECKBOX, new ProjectTypeSelectionModel(item.getModel())).setOutputMarkupId(
|
||||
true
|
||||
new BootstrapCheckBoxMultipleChoice<>(
|
||||
PROJECT_TYPES,
|
||||
LambdaModel.of(getModel(), ApplicationPeriod::getProjectTypes, ApplicationPeriod::setProjectTypes),
|
||||
availableProjectTypes(),
|
||||
new LambdaChoiceRenderer<>(ProjectType::getName, ProjectType::getId)
|
||||
)
|
||||
);
|
||||
item.add(new Label("name", item.getModel().map(ProjectType::getName)));
|
||||
}
|
||||
}
|
||||
);
|
||||
final FormComponent<LocalDate> startDate = addDateField(
|
||||
START_DATE,
|
||||
LambdaModel.of(getModel(), ApplicationPeriod::getStartDate, ApplicationPeriod::setStartDate)
|
||||
@ -139,30 +130,6 @@ public class AdminEditApplicationPeriodPage
|
||||
getRootForm().error(getString("overlapping"));
|
||||
}
|
||||
}
|
||||
|
||||
private class ProjectTypeSelectionModel extends AbstractCheckBoxModel {
|
||||
|
||||
private final IModel<ProjectType> model;
|
||||
|
||||
public ProjectTypeSelectionModel(IModel<ProjectType> model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected() {
|
||||
return getModelObject().getProjectTypes().contains(model.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select() {
|
||||
getModelObject().addProjectType(model.getObject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unselect() {
|
||||
getModelObject().removeProjectType(model.getObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LoadableDetachableModel<ApplicationPeriod> getLoaded(final PageParameters pp) {
|
||||
|
@ -7,8 +7,10 @@ import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.Page;
|
||||
import org.apache.wicket.feedback.FeedbackMessage;
|
||||
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
|
||||
import org.apache.wicket.markup.html.form.RequiredTextField;
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
import org.apache.wicket.util.tester.FormTester;
|
||||
@ -36,6 +38,7 @@ public class AdminEditApplicationPeriodPageTest extends SciProTest {
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
bachelor = new ProjectType(DegreeType.BACHELOR, "Bachelor", "Bachelor");
|
||||
bachelor.setId(8L);
|
||||
bachelor.addModule(ProjectModule.MATCH);
|
||||
when(projectTypeService.findWithModule(ProjectModule.MATCH)).thenReturn(Collections.singletonList(bachelor));
|
||||
startPage();
|
||||
@ -47,8 +50,12 @@ public class AdminEditApplicationPeriodPageTest extends SciProTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void contains_project_type_selection() {
|
||||
tester.assertModelValue(path(FORM, PROJECT_TYPES), projectTypeService.findWithModule(ProjectModule.MATCH));
|
||||
tester.assertComponent(path(FORM, PROJECT_TYPES), CheckBoxMultipleChoice.class);
|
||||
Component component = tester.getComponentFromLastRenderedPage(path(FORM, PROJECT_TYPES));
|
||||
CheckBoxMultipleChoice<ProjectType> choice = (CheckBoxMultipleChoice<ProjectType>) component;
|
||||
Assertions.assertEquals(projectTypeService.findWithModule(ProjectModule.MATCH), choice.getChoices());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -105,7 +112,7 @@ public class AdminEditApplicationPeriodPageTest extends SciProTest {
|
||||
);
|
||||
FormTester formTester = tester.newFormTester(FORM);
|
||||
fillInForm("Title", 0, 1, 2, formTester);
|
||||
formTester.setValue(path(PROJECT_TYPES, 0, CHECKBOX), true);
|
||||
formTester.setValue(path(PROJECT_TYPES), String.valueOf(bachelor.getId()));
|
||||
formTester.submit();
|
||||
|
||||
ArgumentCaptor<ApplicationPeriod> captor = ArgumentCaptor.forClass(ApplicationPeriod.class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user