Allow supervisors to write a note associated with their projects #8

Merged
ansv7779 merged 10 commits from 3399-supervisor-project-note into develop 2024-07-10 13:43:27 +02:00
8 changed files with 61 additions and 14 deletions
Showing only changes of commit ec6eb86f91 - Show all commits

View File

@ -0,0 +1,5 @@
package se.su.dsv.scipro.settings.dataobjects;
public enum SupervisorProjectNoteDisplay {
COMPACT, FULL
}

View File

@ -58,6 +58,11 @@ public class UserProfile extends DomainObject {
@Enumerated(EnumType.STRING)
private Roles selectedRole;
@Basic
@Enumerated(EnumType.STRING)
@Column(name = "supervisor_project_note_display")
private SupervisorProjectNoteDisplay supervisorProjectNoteDisplay = SupervisorProjectNoteDisplay.COMPACT;
@Override
public Long getId() {
return this.id;
@ -147,6 +152,14 @@ public class UserProfile extends DomainObject {
this.selectedRole = selectedRole;
}
public SupervisorProjectNoteDisplay getSupervisorProjectNoteDisplay() {
return supervisorProjectNoteDisplay;
}
public void setSupervisorProjectNoteDisplay(SupervisorProjectNoteDisplay supervisorProjectNoteDisplay) {
this.supervisorProjectNoteDisplay = supervisorProjectNoteDisplay;
}
@Override
public String toString() {
return "UserProfile(id=" + this.getId() + ", user=" + this.getUser() + ", skypeId=" + this.getSkypeId() + ", phoneNumber=" + this.getPhoneNumber() + ", otherInfo=" + this.getOtherInfo() + ", mailCompilation=" + this.isMailCompilation() + ", defaultProjectStatusFilter=" + this.getDefaultProjectStatusFilter() + ", defaultProjectTeamMemberRolesFilter=" + this.getDefaultProjectTeamMemberRolesFilter() + ", defaultSupervisorFilter=" + this.isDefaultSupervisorFilter() + ", defaultProjectTypeFilter=" + this.getDefaultProjectTypeFilter() + ", selectedRole=" + this.getSelectedRole() + ")";

View File

@ -6,3 +6,6 @@ CREATE TABLE IF NOT EXISTS `project_user_note` (
CONSTRAINT `FK_project_user_note_project` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_project_user_note_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
ALTER TABLE `user_profile`
ADD COLUMN `supervisor_project_note_display` VARCHAR(15) NOT NULL DEFAULT 'COMPACT';

View File

@ -2,23 +2,16 @@ package se.su.dsv.scipro.components;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;
import java.util.Locale;
public class MaxLengthLabel extends Label {
private static final int DEFAULT_MAX_LENGTH = 50;
private final IModel<Integer> maxLengthModel;
private final int maxLength;
public MaxLengthLabel(String id, IModel<String> dataModel) {
this(id, dataModel, DEFAULT_MAX_LENGTH);
}
public MaxLengthLabel(String id, IModel<String> dataModel, int maxLength) {
public MaxLengthLabel(String id, IModel<String> dataModel, IModel<Integer> maxLength) {
super(id, dataModel);
this.maxLength = maxLength;
this.maxLengthModel = maxLength;
}
@Override
@ -34,6 +27,7 @@ public class MaxLengthLabel extends Label {
@Override
public String convertToString(String o, Locale locale) {
Integer maxLength = maxLengthModel.getObject();
if (o.length() > maxLength) {
return o.substring(0, maxLength) + "...";
}

View File

@ -10,7 +10,6 @@ import org.apache.wicket.feedback.FencedFeedbackPanel;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
@ -21,6 +20,7 @@ import se.su.dsv.scipro.components.MaxLengthLabel;
import se.su.dsv.scipro.components.ModalWindowPlus;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.project.ProjectNoteService;
import se.su.dsv.scipro.settings.dataobjects.SupervisorProjectNoteDisplay;
import se.su.dsv.scipro.system.User;
import java.time.LocalTime;
@ -31,10 +31,13 @@ public class ProjectNoteColumn extends AbstractExportableColumn<Project, String>
private ProjectNoteService projectNoteService;
private final IModel<User> user;
private final IModel<SupervisorProjectNoteDisplay> supervisorProjectNoteDisplayModel;
public ProjectNoteColumn(IModel<String> displayModel, IModel<User> user) {
public ProjectNoteColumn(IModel<String> displayModel, IModel<User> user,
IModel<SupervisorProjectNoteDisplay> supervisorProjectNoteDisplayModel) {
super(displayModel);
Injector.get().inject(this);
this.supervisorProjectNoteDisplayModel = supervisorProjectNoteDisplayModel;
this.user = user;
}
@ -66,7 +69,11 @@ public class ProjectNoteColumn extends AbstractExportableColumn<Project, String>
setOutputMarkupId(true);
modal.onClose(target -> target.add(this));
add(new MaxLengthLabel("shortened_note", getDataModel(model)));
IModel<Integer> maxLength = supervisorProjectNoteDisplayModel.map(display -> switch (display) {
case FULL -> Integer.MAX_VALUE;
case COMPACT -> 100;
});
add(new MaxLengthLabel("shortened_note", getDataModel(model), maxLength));
AjaxLink<Object> noteLink = new AjaxLink<>("view_note") {
@Override

View File

@ -31,6 +31,10 @@
</strong>
<div wicket:id="projectTypes"></div>
</div>
<fieldset class="col-6 col-md-3 col-lg-2">
<legend>Note</legend>
<div wicket:id="note_display"></div>
</fieldset>
</div>
</form>
</div>

View File

@ -1,6 +1,7 @@
package se.su.dsv.scipro.supervisor.panels;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
@ -25,6 +26,7 @@ import se.su.dsv.scipro.project.ProjectService;
import se.su.dsv.scipro.project.ProjectStatus;
import se.su.dsv.scipro.project.ProjectTeamMemberRoles;
import se.su.dsv.scipro.session.SciProSession;
import se.su.dsv.scipro.settings.dataobjects.SupervisorProjectNoteDisplay;
import se.su.dsv.scipro.settings.dataobjects.UserProfile;
import se.su.dsv.scipro.springdata.services.UserProfileService;
import se.su.dsv.scipro.system.ProjectType;
@ -55,6 +57,7 @@ public class SupervisorMyProjectsPanel extends Panel {
private ExportableDataPanel dataPanel;
private ProjectService.Filter filter = new ProjectService.Filter();
private IModel<SupervisorProjectNoteDisplay> supervisorProjectNoteDisplayModel = new Model<>();
public SupervisorMyProjectsPanel(String id) {
super(id);
@ -82,7 +85,7 @@ public class SupervisorMyProjectsPanel extends Panel {
return new ListAdapterModel<>(rowModel.map(Project::getProjectParticipants));
}
});
columns.add(new ProjectNoteColumn(Model.of("Note"), LoadableDetachableModel.of(this::currentUser)));
columns.add(new ProjectNoteColumn(Model.of("Note"), LoadableDetachableModel.of(this::currentUser), supervisorProjectNoteDisplayModel));
columns.add(new UserColumn<>(Model.of("Head supervisor"), "headSupervisor.fullName", Project::getHeadSupervisor));
return columns;
}
@ -105,6 +108,7 @@ public class SupervisorMyProjectsPanel extends Panel {
filter.setRoles(userProfile.getDefaultProjectTeamMemberRolesFilter());
filter.setFilterSupervisor(userProfile.isDefaultSupervisorFilter());
filter.setProjectTypes(userProfile.getDefaultProjectTypeFilter());
supervisorProjectNoteDisplayModel.setObject(userProfile.getSupervisorProjectNoteDisplay());
}
private User currentUser() {
@ -148,6 +152,19 @@ public class SupervisorMyProjectsPanel extends Panel {
updateProfileWithCurrentFilter();
}
});
BootstrapRadioChoice<SupervisorProjectNoteDisplay> noteDisplay = new BootstrapRadioChoice<>(
"note_display",
supervisorProjectNoteDisplayModel,
List.of(SupervisorProjectNoteDisplay.values()),
new EnumChoiceRenderer<>(this));
noteDisplay.add(new AjaxFormChoiceComponentUpdatingBehavior() {
@Override
public void onUpdate(AjaxRequestTarget target) {
target.add(dataPanel);
updateProfileWithCurrentFilter();
}
});
add(noteDisplay);
}
private void updateProfileWithCurrentFilter() {
@ -156,6 +173,7 @@ public class SupervisorMyProjectsPanel extends Panel {
userProfile.setDefaultProjectTeamMemberRolesFilter(filter.getRoles());
userProfile.setDefaultSupervisorFilter(filter.isFilterSupervisor());
userProfile.setDefaultProjectTypeFilter(filter.getProjectTypes());
userProfile.setSupervisorProjectNoteDisplay(supervisorProjectNoteDisplayModel.getObject());
profileService.save(userProfile);
}
}

View File

@ -9,3 +9,6 @@ ProjectTeamMemberRoles.CO_SUPERVISOR= Co-Supervisor
ProjectStatus.ACTIVE= Active
ProjectStatus.INACTIVE= Inactive
ProjectStatus.COMPLETED= Completed
SupervisorProjectNoteDisplay.COMPACT=Compact
SupervisorProjectNoteDisplay.FULL=Full