From d68414947ae2775c3bf4c2a9514aaecbb5bd4252 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg <andreass@dsv.su.se> Date: Tue, 4 Mar 2025 10:48:22 +0100 Subject: [PATCH] Include projects in group in available list If a project was inactive or completed it was not included in the "relevant projects" list so that they could never be removed from the group. Now all current projects in the group are always included. If such a project is removed it can however not be added back. --- .../java/se/su/dsv/scipro/group/EditGroupPanel.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/view/src/main/java/se/su/dsv/scipro/group/EditGroupPanel.java b/view/src/main/java/se/su/dsv/scipro/group/EditGroupPanel.java index be0d59af6b..f5e00ef0e6 100644 --- a/view/src/main/java/se/su/dsv/scipro/group/EditGroupPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/group/EditGroupPanel.java @@ -42,8 +42,17 @@ public class EditGroupPanel extends Panel { feedbackPanel.setOutputMarkupId(true); add(feedbackPanel); + IModel<List<Project>> availableProjects = LoadableDetachableModel.of(() -> { + Set<Project> projects = new HashSet<>(); + projects.addAll(getAllRelevantProjects()); + // Have to add the projects that are already in the group to the list of available projects + // since they may not be included in the relevant projects if they're inactive or completed. + // To allow them to be removed from the group, it will not be possible to add them again. + projects.addAll(model.getObject().getProjects()); + return projects.stream().toList(); + }); add( - new ListView<>("available_projects", LoadableDetachableModel.of(this::getAllRelevantProjects)) { + new ListView<>("available_projects", availableProjects) { @Override protected void populateItem(ListItem<Project> item) { CheckBox checkbox = new CheckBox("selected", new SelectProjectModel(model, item.getModel()));