Skip to content

Commit

Permalink
Remove dummy contacts for collaborators for admins during project cre…
Browse files Browse the repository at this point in the history
…ation (#961)

Removes the dummy contact selection for collaborators within the project creation dialog for admins.
  • Loading branch information
Steffengreiner authored Jan 7, 2025
1 parent 492d375 commit 01692c7
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 127 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
import static java.util.Objects.isNull;

import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.customfield.CustomField;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.data.validator.EmailValidator;
import java.util.ArrayList;
import java.util.List;
import life.qbic.datamanager.views.general.HasBinderValidation;
import life.qbic.datamanager.views.general.utils.Utility;

Expand All @@ -29,8 +24,6 @@
public class AutocompleteContactField extends CustomField<Contact> implements
HasBinderValidation<Contact> {


private final ComboBox<Contact> contactSelection;
private final Checkbox selfSelect;
private final TextField nameField;
private final TextField emailField;
Expand All @@ -42,15 +35,6 @@ public AutocompleteContactField(String label, String shortName) {
binder = new Binder<>();
binder.addStatusChangeListener(event -> updateValidationProperty());

contactSelection = new ComboBox<>();
contactSelection.addClassName("contact-selection");
contactSelection.setPlaceholder("(Optional) select from existing contacts");
contactSelection.setAllowCustomValue(false);
contactSelection.setClearButtonVisible(true);
contactSelection.setRenderer(new ComponentRenderer<>(AutocompleteContactField::renderContact));
contactSelection.setItemLabelGenerator(
contact -> "%s - %s".formatted(contact.getFullName(), contact.getEmail()));

selfSelect = new Checkbox("Choose myself as %s for this project".formatted(shortName));
selfSelect.addClassName("contact-self-select");
selfSelect.addValueChangeListener(this::onSelfSelected);
Expand All @@ -65,8 +49,6 @@ public AutocompleteContactField(String label, String shortName) {
emailField.addClassName("email-field");
emailField.setPlaceholder("Please enter an email address");

contactSelection.addValueChangeListener(this::onContactSelectionChanged); //write only

binder.forField(nameField)
.withValidator(it -> !isRequired()
|| !(isNull(it) || it.isBlank()), "Please provide a name")
Expand All @@ -86,28 +68,16 @@ public AutocompleteContactField(String label, String shortName) {
.bind(Contact::getEmail,
Contact::setEmail);

Div preselectLayout = new Div(selfSelect, contactSelection);
Div preselectLayout = new Div(selfSelect);
preselectLayout.addClassName("prefill-input-fields");

Div layout = new Div(nameField, emailField);
layout.addClassName("input-fields");

add(preselectLayout, layout);
setItems(new ArrayList<>());
clear();
}

private static Div renderContact(Contact contact) {
var contactName = new Span(contact.getFullName());
contactName.addClassName("contact-name");
var contactEmail = new Span(contact.getEmail());
contactEmail.addClassName("contact-email");
var container = new Div();
container.addClassName("contact-item");
container.add(contactName, contactEmail);
return container;
}

private void onSelfSelected(
ComponentValueChangeEvent<Checkbox, Boolean> checkboxvalueChangeEvent) {
if (Boolean.TRUE.equals(checkboxvalueChangeEvent.getValue())) {
Expand All @@ -120,31 +90,12 @@ private void updateValidationProperty() {
this.getElement().setProperty("invalid", !binder.isValid());
}

private void onContactSelectionChanged(
ComponentValueChangeEvent<ComboBox<Contact>, Contact> valueChanged) {
//ignore clearing the combobox or empty selection
if (valueChanged.getValue() == null) {
return;
}
if (valueChanged.getValue().isEmpty()) {
return;
}
// update the contact to the selected value
setContact(valueChanged.getValue());
// clear selection box
valueChanged.getHasValue().clear();
}

public void setContact(Contact contact) {
binder.setBean(contact);
updateValidationProperty();
setValue(contact);
}

public void setItems(List<Contact> contacts) {
contactSelection.setItems(contacts);
}

@Override
protected Contact generateModelValue() {
return new Contact(nameField.getValue(), emailField.getValue());
Expand Down Expand Up @@ -191,7 +142,4 @@ public Binder<Contact> getBinder() {
return binder;
}

public void hideContactBox() {
contactSelection.setVisible(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@
import com.vaadin.flow.spring.annotation.UIScope;
import java.io.Serial;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import life.qbic.datamanager.views.general.HasBinderValidation;
import life.qbic.datamanager.views.general.QbicDialog;
import life.qbic.datamanager.views.general.Stepper;
import life.qbic.datamanager.views.general.Stepper.StepIndicator;
import life.qbic.datamanager.views.general.contact.Contact;
import life.qbic.datamanager.views.general.funding.FundingEntry;
import life.qbic.datamanager.views.notifications.CancelConfirmationDialogFactory;
import life.qbic.datamanager.views.notifications.NotificationDialog;
import life.qbic.datamanager.views.projects.create.CollaboratorsLayout.ProjectCollaborators;
import life.qbic.datamanager.views.projects.create.ExperimentalInformationLayout.ExperimentalInformation;
import life.qbic.datamanager.views.projects.create.ProjectDesignLayout.ProjectDesign;
import life.qbic.finances.api.FinanceService;
import life.qbic.projectmanagement.application.ContactRepository;
import life.qbic.projectmanagement.application.ProjectInformationService;
import life.qbic.projectmanagement.application.ontology.SpeciesLookupService;
import life.qbic.projectmanagement.application.ontology.TerminologyService;
Expand Down Expand Up @@ -73,8 +70,7 @@ private StepIndicator addStep(Stepper stepper, String label, Component layout) {

public AddProjectDialog(ProjectInformationService projectInformationService,
FinanceService financeService,
SpeciesLookupService speciesLookupService,
ContactRepository contactRepository, TerminologyService terminologyService,
SpeciesLookupService speciesLookupService, TerminologyService terminologyService,
CancelConfirmationDialogFactory cancelConfirmationDialogFactory) {
super();

Expand All @@ -91,14 +87,6 @@ public AddProjectDialog(ProjectInformationService projectInformationService,
this.experimentalInformationLayout = new ExperimentalInformationLayout(
speciesLookupService, terminologyService);

List<Contact> knownContacts = contactRepository.findAll().stream().map(contact ->
new Contact(contact.fullName(), contact.emailAddress())).toList();
if(knownContacts.isEmpty()) {
collaboratorsLayout.hideContactBox();
} else {
collaboratorsLayout.setKnownContacts(knownContacts);
}

stepContent = new HashMap<>();

setHeaderTitle("Create Project");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jakarta.validation.constraints.NotEmpty;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import life.qbic.application.commons.ApplicationException;
Expand Down Expand Up @@ -87,17 +86,6 @@ public boolean isInvalid() {
return HasBinderValidation.super.isInvalid();
}

public void setProjectManagers(List<Contact> projectManagers) {
projectManagerField.setItems(projectManagers);
}

public void setResponsiblePersons(List<Contact> contactPersons) {
responsiblePersonField.setItems(contactPersons);
}
public void setPrincipalInvestigators(List<Contact> principalInvestigators) {
principalInvestigatorField.setItems(principalInvestigators);
}

@Override
public Binder<ProjectCollaborators> getBinder() {
return collaboratorsBinder;
Expand All @@ -119,18 +107,6 @@ public ProjectCollaborators getProjectCollaborators() {
return projectCollaborators;
}

public void setKnownContacts(List<Contact> knownContacts) {
principalInvestigatorField.setItems(knownContacts);
responsiblePersonField.setItems(knownContacts);
projectManagerField.setItems(knownContacts);
}

public void hideContactBox() {
principalInvestigatorField.hideContactBox();
responsiblePersonField.hideContactBox();
projectManagerField.hideContactBox();
}

public static final class ProjectCollaborators implements Serializable {

@Serial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import life.qbic.logging.api.Logger;
import life.qbic.projectmanagement.application.AddExperimentToProjectService;
import life.qbic.projectmanagement.application.AuthenticationToUserIdTranslationService;
import life.qbic.projectmanagement.application.ContactRepository;
import life.qbic.projectmanagement.application.ProjectCreationService;
import life.qbic.projectmanagement.application.ProjectInformationService;
import life.qbic.projectmanagement.application.ontology.SpeciesLookupService;
Expand Down Expand Up @@ -61,7 +60,6 @@ public class ProjectOverviewMain extends Main {
private final transient FinanceService financeService;
private final transient SpeciesLookupService ontologyTermInformationService;
private final transient AddExperimentToProjectService addExperimentToProjectService;
private final transient ContactRepository contactRepository;
private final transient UserInformationService userInformationService;
private final transient AuthenticationToUserIdTranslationService userIdTranslator;

Expand All @@ -71,7 +69,6 @@ public ProjectOverviewMain(@Autowired ProjectCollectionComponent projectCollecti
SpeciesLookupService ontologyTermInformationService,
AddExperimentToProjectService addExperimentToProjectService,
UserInformationService userInformationService,
ContactRepository contactRepository,
AuthenticationToUserIdTranslationService userIdTranslator,
TerminologyService terminologyService,
CancelConfirmationDialogFactory cancelConfirmationDialogFactory) {
Expand All @@ -86,8 +83,6 @@ public ProjectOverviewMain(@Autowired ProjectCollectionComponent projectCollecti
"ontology term information service can not be null");
this.addExperimentToProjectService = requireNonNull(addExperimentToProjectService,
"add experiment to project service cannot be null");
this.contactRepository = requireNonNull(contactRepository,
"contact repository can not be null");
this.userInformationService = requireNonNull(userInformationService,
"user information service can not be null");
this.userIdTranslator = requireNonNull(userIdTranslator, "userIdTranslator must not be null");
Expand All @@ -100,7 +95,7 @@ public ProjectOverviewMain(@Autowired ProjectCollectionComponent projectCollecti
this.projectCollectionComponent.addCreateClickedListener(projectCreationClickedEvent -> {
AddProjectDialog addProjectDialog = new AddProjectDialog(this.projectInformationService,
this.financeService,
this.ontologyTermInformationService, this.contactRepository, terminologyService,
this.ontologyTermInformationService, terminologyService,
cancelConfirmationDialogFactory);
if (isOfferSearchAllowed()) {
addProjectDialog.enableOfferSearch();
Expand Down

0 comments on commit 01692c7

Please sign in to comment.