Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 207f823

Browse files
BarnaBarthabarnabartha
andauthored
SORMAS-Foundation#3290 - show all diagramId's in dashboard grid not only ones already associated to a campaign (SORMAS-Foundation#3335)
Co-authored-by: barnabartha <[email protected]>
1 parent 5fe87ad commit 207f823

3 files changed

Lines changed: 107 additions & 74 deletions

File tree

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,83 @@
11
package de.symeda.sormas.api.campaign.diagram;
22

33
import java.io.Serializable;
4+
import java.util.Objects;
45

56
public class CampaignDashboardElement implements Serializable {
67

7-
private String diagramId;
8-
private String tabId;
9-
private Integer order;
10-
private Integer width;
11-
private Integer height;
12-
13-
public CampaignDashboardElement() {
14-
}
15-
16-
public CampaignDashboardElement(String diagramId, String tabId, Integer order, Integer width, Integer height) {
17-
this.diagramId = diagramId;
18-
this.tabId = tabId;
19-
this.order = order;
20-
this.width = width;
21-
this.height = height;
22-
}
23-
24-
public String getDiagramId() {
25-
return diagramId;
26-
}
27-
28-
public void setDiagramId(String diagramId) {
29-
this.diagramId = diagramId;
30-
}
31-
32-
public String getTabId() {
33-
return tabId;
34-
}
35-
36-
public void setTabId(String tabId) {
37-
this.tabId = tabId;
38-
}
39-
40-
public Integer getOrder() {
41-
return order;
42-
}
43-
44-
public void setOrder(Integer order) {
45-
this.order = order;
46-
}
47-
48-
public Integer getWidth() {
49-
return width;
50-
}
51-
52-
public void setWidth(Integer width) {
53-
this.width = width;
54-
}
55-
56-
public Integer getHeight() {
57-
return height;
58-
}
59-
60-
public void setHeight(Integer height) {
61-
this.height = height;
62-
}
8+
private String diagramId;
9+
private String tabId;
10+
private Integer order;
11+
private Integer width;
12+
private Integer height;
13+
14+
public CampaignDashboardElement() {
15+
}
16+
17+
public CampaignDashboardElement(String diagramId, String tabId, Integer order, Integer width, Integer height) {
18+
this.diagramId = diagramId;
19+
this.tabId = tabId;
20+
this.order = order;
21+
this.width = width;
22+
this.height = height;
23+
}
24+
25+
public String getDiagramId() {
26+
return diagramId;
27+
}
28+
29+
public void setDiagramId(String diagramId) {
30+
this.diagramId = diagramId;
31+
}
32+
33+
public String getTabId() {
34+
return tabId;
35+
}
36+
37+
public void setTabId(String tabId) {
38+
this.tabId = tabId;
39+
}
40+
41+
public Integer getOrder() {
42+
return order;
43+
}
44+
45+
public void setOrder(Integer order) {
46+
this.order = order;
47+
}
48+
49+
public Integer getWidth() {
50+
return width;
51+
}
52+
53+
public void setWidth(Integer width) {
54+
this.width = width;
55+
}
56+
57+
public Integer getHeight() {
58+
return height;
59+
}
60+
61+
public void setHeight(Integer height) {
62+
this.height = height;
63+
}
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
if (this == o)
68+
return true;
69+
if (o == null || getClass() != o.getClass())
70+
return false;
71+
CampaignDashboardElement that = (CampaignDashboardElement) o;
72+
return Objects.equals(diagramId, that.diagramId)
73+
&& Objects.equals(tabId, that.tabId)
74+
&& Objects.equals(order, that.order)
75+
&& Objects.equals(width, that.width)
76+
&& Objects.equals(height, that.height);
77+
}
78+
79+
@Override
80+
public int hashCode() {
81+
return Objects.hash(diagramId, tabId, order, width, height);
82+
}
6383
}

sormas-ui/src/main/java/de/symeda/sormas/ui/campaign/campaigns/CampaignDashboardElementsGridComponent.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,35 @@ public CampaignDashboardElementsGridComponent(List<CampaignDashboardElement> sav
3131
protected Binder<CampaignDashboardElement> addColumnsBinder(List<CampaignDashboardElement> allElements) {
3232
Binder<CampaignDashboardElement> binder = new Binder<>();
3333

34-
ComboBox<String> diagramIdCombo = new ComboBox<>(
35-
Captions.campaignDashboardChart,
36-
allElements.stream()
37-
.map(campaignDiagramDefinitionDto -> campaignDiagramDefinitionDto.getDiagramId())
38-
.distinct()
39-
.collect(Collectors.toList()));
34+
final List<String> existingDiagramIds = allElements.stream()
35+
.map(campaignDiagramDefinitionDto -> campaignDiagramDefinitionDto.getDiagramId())
36+
.distinct()
37+
.collect(Collectors.toList());
38+
final ComboBox<String> diagramIdCombo = new ComboBox<>(Captions.campaignDashboardChart, existingDiagramIds);
4039
diagramIdCombo.setEmptySelectionAllowed(false);
41-
Binder.Binding<CampaignDashboardElement, String> diagramIdBind =
40+
final Binder.Binding<CampaignDashboardElement, String> diagramIdBind =
4241
binder.bind(diagramIdCombo, CampaignDashboardElement::getDiagramId, CampaignDashboardElement::setDiagramId);
43-
Grid.Column<CampaignDashboardElement, String> diagramIdColumn =
42+
final Grid.Column<CampaignDashboardElement, String> diagramIdColumn =
4443
grid.addColumn(campaignDashboardElement -> campaignDashboardElement.getDiagramId())
4544
.setCaption(I18nProperties.getCaption(Captions.campaignDashboardChart));
4645
diagramIdColumn.setEditorBinding(diagramIdBind);
4746

48-
ComboBox<String> tabIdCombo = new ComboBox<>(
49-
Captions.campaignDashboardTabName,
50-
allElements.stream()
51-
.map(campaignDiagramDefinitionDto -> campaignDiagramDefinitionDto.getTabId())
52-
.distinct()
53-
.collect(Collectors.toList()));
47+
final List<String> existingTabIds = allElements.stream()
48+
.map(campaignDiagramDefinitionDto -> campaignDiagramDefinitionDto.getTabId())
49+
.filter(s -> StringUtils.isNotEmpty(s))
50+
.distinct()
51+
.collect(Collectors.toList());
52+
final ComboBox<String> tabIdCombo = new ComboBox<>(Captions.campaignDashboardTabName, existingTabIds);
5453

5554
tabIdCombo.setEmptySelectionAllowed(false);
5655
tabIdCombo.setTextInputAllowed(true);
5756
tabIdCombo.setNewItemProvider((ComboBox.NewItemProvider<String>) s -> Optional.of(s));
5857

59-
Binder.Binding<CampaignDashboardElement, String> tabIdBind =
58+
final Binder.Binding<CampaignDashboardElement, String> tabIdBind =
6059
binder.bind(tabIdCombo, CampaignDashboardElement::getTabId, CampaignDashboardElement::setTabId);
61-
Grid.Column<CampaignDashboardElement, String> tabIdColumn = grid.addColumn(campaignDashboardElement -> campaignDashboardElement.getTabId())
62-
.setCaption(I18nProperties.getCaption(Captions.campaignDashboardTabName));
60+
final Grid.Column<CampaignDashboardElement, String> tabIdColumn =
61+
grid.addColumn(campaignDashboardElement -> campaignDashboardElement.getTabId())
62+
.setCaption(I18nProperties.getCaption(Captions.campaignDashboardTabName));
6363
tabIdColumn.setEditorBinding(tabIdBind);
6464

6565
TextField width = new TextField(Captions.campaignDashboardChartWidth);

sormas-ui/src/main/java/de/symeda/sormas/ui/campaign/campaigns/CampaignEditForm.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Collections;
2424
import java.util.Comparator;
2525
import java.util.HashSet;
26+
import java.util.List;
27+
import java.util.Optional;
2628
import java.util.stream.Collectors;
2729

2830
import org.apache.commons.collections.CollectionUtils;
@@ -150,11 +152,22 @@ protected void addFields() {
150152
FacadeProvider.getCampaignFormMetaFacade().getAllCampaignFormMetasAsReferences());
151153
getContent().addComponent(campaignFormsGridComponent, CAMPAIGN_DATA_LOC);
152154

155+
final List<CampaignDashboardElement> campaignDashboardElements = FacadeProvider.getCampaignFacade().getCampaignDashboardElements(null);
156+
FacadeProvider.getCampaignDiagramDefinitionFacade().getAll().forEach(campaignDiagramDefinitionDto -> {
157+
final String diagramId = campaignDiagramDefinitionDto.getDiagramId();
158+
final Optional<CampaignDashboardElement> diagramAlreadyUsed =
159+
campaignDashboardElements.stream().filter(cde -> cde.getDiagramId().equals(diagramId)).findAny();
160+
if (!diagramAlreadyUsed.isPresent()) {
161+
final CampaignDashboardElement campaignDashboardElement = new CampaignDashboardElement();
162+
campaignDashboardElement.setDiagramId(diagramId);
163+
campaignDashboardElements.add(campaignDashboardElement);
164+
}
165+
});
153166
campaignDashboardGridComponent = new CampaignDashboardElementsGridComponent(
154167
this.campaignDto == null
155168
? Collections.EMPTY_LIST
156169
: FacadeProvider.getCampaignFacade().getCampaignDashboardElements(campaignDto.getUuid()),
157-
FacadeProvider.getCampaignFacade().getCampaignDashboardElements(null));
170+
campaignDashboardElements);
158171
getContent().addComponent(campaignDashboardGridComponent, CAMPAIGN_DASHBOARD_LOC);
159172

160173
final Label spacer = new Label();

0 commit comments

Comments
 (0)