Skip to content

Commit

Permalink
use card collection to make variables look similar to groups (#356)
Browse files Browse the repository at this point in the history
* use card collection to make variables look similar to groups

* create card-collection that is independent of card type, rework css, remove unecessary classes

* simplify listeners and events

* rename variable level formatter and use it

* rename methods to add listeners

---------

Co-authored-by: Tobias Koch <[email protected]>
  • Loading branch information
wow-such-code and KochTobi authored Sep 5, 2023
1 parent e9d1ed2 commit 4a9ddda
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 383 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import life.qbic.projectmanagement.domain.project.experiment.ExperimentalValue;

public class ExperimentValueFormatter {
public class VariableValueFormatter {

private VariableValueFormatter() {}

/**
* Formats the {@link ExperimentalValue} to show the defined value with the unit if a unit is
Expand Down
83 changes: 16 additions & 67 deletions vaadinfrontend/frontend/themes/datamanager/components/card.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,36 @@
max-width: 300px;
}

.experimental-group-card-collection {
.card-collection {
display: flex;
align-content: space-evenly;
flex-flow: column;
gap: 1rem;
margin-left: 1.5rem;
margin-top: 1.5rem;
}

.experimental-group-card-collection .groups-header {
.card-collection .collection-title {
font-weight: bold;
color: var(--lumo-secondary-text-color);
font-size: var(--lumo-font-size-m);
margin-bottom: 0.5rem;
}

.card-collection .collection-header {
justify-content: space-between;
display: flex;
}

.experimental-group-card-collection .groups-content {
.card-collection .collection-content {
display: flex;
align-content: space-evenly;
flex-flow: row wrap;
gap: 1rem;
flex-direction: row;
}

.experimental-group-card-collection .groups-controls {
.card-collection .collection-controls {
display: flex;
align-content: space-evenly;
flex-flow: row wrap;
Expand All @@ -91,12 +100,12 @@
margin-bottom: var(--lumo-space-m);
}

.experimental-group .title {
color: var(--lumo-header-text-color);
.experimental-group .card-title {
color: var(--lumo-secondary-text-color);
font-size: var(--lumo-font-size-m);
font-weight: bold;
white-space: nowrap;
margin-bottom: 1em;
margin-bottom: 0.5rem;
}

.experimental-group .content {
Expand Down Expand Up @@ -151,66 +160,6 @@
font-weight: bold;
}

.card.experimental-variables {
flex: auto;
font-size: var(--lumo-font-size-s);
padding: var(--lumo-space-l);
}

.card.experimental-variables .variables-content {
display: flex;
align-content: space-evenly;
flex-flow: row wrap;
gap: 1rem;
}

.card.experimental-variables .controls {
display: flex;
gap: var(--lumo-space-s);
}

.card.experimental-variables .variables-header {
color: var(--lumo-header-text-color);
font-size: var(--lumo-font-size-m);
font-weight: bold;
display: flex;
justify-content: space-between;
align-items: baseline;
}

.experimental-variables-fact-sheet {
display: flex;
flex-direction: column;
flex-basis: 20%;
font-size: var(--lumo-font-size-s);
border: 1px solid lightgray;
border-radius: var(--lumo-border-radius-m);
}

.experimental-variables-fact-sheet .variable-header {
background-color: var(--lumo-primary-color-10pct);
color: var(--lumo-primary-text-color);
font-weight: bold;
font-size: var(--lumo-font-size-s);
padding: 0.25rem 0.5rem 0.1rem 0.25rem;
}


.experimental-variables-fact-sheet .variable-name {
font-weight: bold;
font-size: var(--lumo-font-size-s);
}

.experimental-variables-fact-sheet .variable-values {
font-size: var(--lumo-font-size-s);
padding: 0.25rem 0.5rem 0.1rem 0.25rem;
}

.experimental-variables-fact-sheet ul {
list-style-type: none;
display: contents;
}

/* Support section formatting and components */

.experiment-item-collection {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
import com.vaadin.flow.theme.lumo.LumoIcon;
import com.vaadin.flow.theme.lumo.LumoUtility.Display;
import java.io.Serial;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -36,13 +35,12 @@
import life.qbic.datamanager.views.general.PageArea;
import life.qbic.datamanager.views.general.ToggleDisplayEditComponent;
import life.qbic.datamanager.views.projects.project.experiments.ExperimentInformationMain;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.CardCollection;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExistingGroupsPreventVariableEdit;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExistingSamplesPreventVariableEdit;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExperimentalGroupCardCollection;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExperimentalGroupsDialog;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExperimentalGroupsDialog.ExperimentalGroupContent;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExperimentalVariableContent;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExperimentalVariablesComponent;
import life.qbic.datamanager.views.projects.project.experiments.experiment.components.ExperimentalVariablesDialog;
import life.qbic.datamanager.views.projects.project.experiments.experiment.create.ExperimentInformationContent;
import life.qbic.projectmanagement.application.DeletionService;
Expand Down Expand Up @@ -84,11 +82,10 @@ public class ExperimentDetailsComponent extends PageArea {

private final Span sampleSourceComponent = new Span();
private final TabSheet experimentSheet = new TabSheet();
private final ExperimentalVariablesComponent experimentalVariablesComponent = ExperimentalVariablesComponent.create(
new ArrayList<>());
private final Div experimentalGroups = new Div();
private final Div experimentalVariables = new Div();
private final ExperimentalGroupCardCollection experimentalGroupsCollection = new ExperimentalGroupCardCollection();
private final CardCollection experimentalGroupsCollection = new CardCollection("GROUPS");
private final CardCollection experimentalVariableCollection = new CardCollection("VARIABLES");
private final Disclaimer noExperimentalVariablesDefined;
private final Disclaimer noExperimentalGroupsDefined;
private final Disclaimer addExperimentalVariablesNote;
Expand Down Expand Up @@ -235,9 +232,8 @@ private void fireExperimentNameChangedEvent(String oldExperimentName, String new
}

private void listenForExperimentalVariablesComponentEvents() {
experimentalVariablesComponent.addAddListener(addEvent -> openExperimentalVariablesAddDialog());
experimentalVariablesComponent.addEditListener(
editEvent -> openExperimentalVariablesEditDialog());
experimentalVariableCollection.addAddListener(addEvent -> openExperimentalVariablesAddDialog());
experimentalVariableCollection.addEditListener(editEvent -> openExperimentalVariablesEditDialog());
}

private void deleteExistingExperimentalVariables() {
Expand Down Expand Up @@ -397,17 +393,15 @@ private void loadSampleSources(Experiment experiment) {

private void layoutTabSheet() {
experimentSheet.add("Experimental Variables", experimentalVariables);
experimentalVariables.addClassName(Display.FLEX);
experimentalVariables.addClassName("experimental-variables-container");
experimentalVariables.addClassName("experimental-groups-container");
experimentSheet.add("Experimental Groups", experimentalGroups);
experimentalGroups.addClassName("experimental-groups-container");
content.add(experimentSheet);
}

private void listenForExperimentCollectionComponentEvents() {
experimentalGroupsCollection.addAddEventListener(listener -> openExperimentalGroupAddDialog());
experimentalGroupsCollection.addEditEventListener(
editEvent -> openExperimentalGroupEditDialog());
experimentalGroupsCollection.addAddListener(listener -> openExperimentalGroupAddDialog());
experimentalGroupsCollection.addEditListener(editEvent -> openExperimentalGroupEditDialog());
}

/**
Expand Down Expand Up @@ -441,7 +435,6 @@ private void onExperimentalGroupAddConfirmed(
dialog.close();
}


private void openExperimentalGroupEditDialog() {
if (editGroupsNotAllowed()) {
return;
Expand Down Expand Up @@ -575,11 +568,16 @@ private void loadTagInformation(Experiment experiment) {

private void loadExperimentalVariables(Experiment experiment) {
this.experimentalVariables.removeAll();
this.experimentalVariablesComponent.setExperimentalVariables(experiment.variables());
if (experiment.variables().isEmpty()) {
// We load the experimental variables of the experiment and render them as cards
List<ExperimentalVariable> variables = experiment.variables();
List<ExperimentalVariableCard> experimentalVariableCards = variables.stream()
.map(ExperimentalVariableCard::new).toList();
experimentalVariableCollection.setContent(experimentalVariableCards);

if (variables.isEmpty()) {
this.experimentalVariables.add(addExperimentalVariablesNote);
} else {
this.experimentalVariables.add(experimentalVariablesComponent);
this.experimentalVariables.add(experimentalVariableCollection);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void layoutComponent() {
private Span title(String value) {
Span cardTitle = new Span();
cardTitle.setText(value);
cardTitle.addClassName("title");
cardTitle.addClassName("card-title");
return cardTitle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.stream.Collectors;
import life.qbic.datamanager.views.general.Container;
import life.qbic.datamanager.views.projects.project.experiments.experiment.ExperimentalGroupInput.ExperimentalGroupBean;
import life.qbic.projectmanagement.application.ExperimentValueFormatter;
import life.qbic.projectmanagement.application.VariableValueFormatter;
import life.qbic.projectmanagement.domain.project.experiment.BiologicalReplicate;
import life.qbic.projectmanagement.domain.project.experiment.Condition;
import life.qbic.projectmanagement.domain.project.experiment.Experiment;
Expand All @@ -44,7 +44,7 @@ public class ExperimentalGroupInput extends CustomField<ExperimentalGroupBean> {
.thenComparing(level -> level.experimentalValue().value());
private static final ItemLabelGenerator<VariableLevel> VARIABLE_LEVEL_ITEM_LABEL_GENERATOR = it -> String.format(
"%s: %s", it.variableName().value(),
ExperimentValueFormatter.format(it.experimentalValue()));
VariableValueFormatter.format(it.experimentalValue()));

private final List<ComponentEventListener<RemoveEvent>> removeEventListeners;
private final MultiSelectComboBox<VariableLevel> variableLevelSelect;
Expand Down Expand Up @@ -201,7 +201,7 @@ private void filterShownLevels() {
}

private boolean filterLevel(VariableLevel level, String filterString) {
boolean levelValueContainsFilterString = ExperimentValueFormatter.format(
boolean levelValueContainsFilterString = VariableValueFormatter.format(
level.experimentalValue()).toLowerCase()
.contains(filterString.toLowerCase());
boolean variableNameContainsFilterString = level.variableName().value().toLowerCase()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package life.qbic.datamanager.views.projects.project.experiments.experiment;


import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import java.io.Serial;
import java.util.Comparator;
import java.util.List;
import life.qbic.datamanager.views.general.Card;
import life.qbic.projectmanagement.application.VariableValueFormatter;
import life.qbic.projectmanagement.domain.project.experiment.ExperimentalVariable;

/**
* <b>Experimental Variable Card</b>
* <p>
* An experimental variable card can be used to display content of {@link ExperimentalVariable} and
* provide interaction, such as edit and deletion.
*
* @since 1.0.0
*/
public class ExperimentalVariableCard extends Card {

@Serial
private static final long serialVersionUID = -3801182379812377200L;
private final transient ExperimentalVariable experimentalVariable;

public ExperimentalVariableCard(ExperimentalVariable experimentalVariable) {
super();
this.experimentalVariable = experimentalVariable;
layoutComponent();
}

private void layoutComponent() {
addClassName("experimental-group");

Div cardHeader = new Div();
cardHeader.addClassName("header");

cardHeader.add(title(experimentalVariable.name().value()));
this.add(cardHeader);

Div cardContent = new Div();
cardContent.add(levels());
cardContent.addClassName("content");
this.add(cardContent);
}


private Span title(String value) {
Span cardTitle = new Span();
cardTitle.setText(value);
cardTitle.addClassName("card-title");
return cardTitle;
}

private Div levels() {
var variableLevels = experimentalVariable.levels();
Div tagLayout = new Div();
tagLayout.addClassName("tag-collection");
List<Tag> tags = variableLevels.stream()
.sorted(Comparator.comparing(variable -> variable.variableName().value()))
.map(variableLevel -> new Tag(VariableValueFormatter.format(variableLevel.experimentalValue()))).toList();
tags.forEach(tagLayout::add);
return tagLayout;
}

public String variableName() {
return this.experimentalVariable.name().value();
}

public ExperimentalVariable experimentalVariable() {
return this.experimentalVariable;
}

}
Loading

0 comments on commit 4a9ddda

Please sign in to comment.