From 5e9b0fb8846bdb7b2ab8caaabc3403ac6ff83315 Mon Sep 17 00:00:00 2001 From: Melanie Retter Date: Thu, 19 Jul 2018 08:37:06 +0200 Subject: [PATCH] The Rollout groups legend shows max 7 groups (#705) * Fix Rollouts Groups legend * Fix totalTargetAmount display when editing a rollout * Fix code glitches * Fix PR review findings Signed-off-by: Melanie Retter --- .../rollout/AddUpdateRolloutWindowLayout.java | 10 +-- .../rollout/rollout/GroupsLegendLayout.java | 66 ++++++++++++++----- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index 56552348d..19588cb11 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -656,7 +656,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { UIComponentIdProvider.ROLLOUT_APPROVAL_REMARK_FIELD_ID, Rollout.APPROVAL_REMARK_MAX_SIZE); approvalRemarkField.setWidth(100.0F, Unit.PERCENTAGE); - HorizontalLayout layout = new HorizontalLayout(approveButtonsGroup, approvalRemarkField); + final HorizontalLayout layout = new HorizontalLayout(approveButtonsGroup, approvalRemarkField); layout.setWidth(100.0F, Unit.PERCENTAGE); layout.setExpandRatio(approvalRemarkField, 1.0F); return layout; @@ -1013,6 +1013,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { groupsDefinitionTabs.setSelectedTab(1); window.clearOriginalValues(); + totalTargetsCount = targetManagement.countByRsql(rollout.getTargetFilterQuery()); + groupsLegendLayout.populateTotalTargets(totalTargetsCount); } else { editRolloutEnabled = true; if (rollout.getStatus() != Rollout.RolloutStatus.READY) { @@ -1043,10 +1045,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { updateGroupsChart(rolloutGroupManagement .findByRollout(new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout()), rollout.getId()) .getContent(), rollout.getTotalTargets()); - } - totalTargetsCount = targetManagement.countByRsql(rollout.getTargetFilterQuery()); - groupsLegendLayout.populateTotalTargets(totalTargetsCount); + totalTargetsCount = rollout.getTotalTargets(); + groupsLegendLayout.populateTotalTargets(totalTargetsCount); + } } private void disableRequiredFieldsOnEdit() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/GroupsLegendLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/GroupsLegendLayout.java index f8dd10c6d..a748403ee 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/GroupsLegendLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/GroupsLegendLayout.java @@ -28,7 +28,9 @@ import com.vaadin.ui.VerticalLayout; */ public class GroupsLegendLayout extends VerticalLayout { - private static final long serialVersionUID = 5483206203739308677L; + private static final long serialVersionUID = 1L; + + private static final int MAX_GROUPS_TO_BE_DISPLAYED = 7; private final VaadinMessageSource i18n; @@ -63,9 +65,10 @@ public class GroupsLegendLayout extends VerticalLayout { addComponent(loadingLabel); addComponent(unassignedTargetsLabel); addComponent(groupsLegend); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < MAX_GROUPS_TO_BE_DISPLAYED; i++) { groupsLegend.addComponent(createGroupTargetsLabel()); } + groupsLegend.addComponent(createToBeContinuedLabel()); } @@ -75,6 +78,9 @@ public class GroupsLegendLayout extends VerticalLayout { public void reset() { totalTargetsLabel.setVisible(false); populateGroupsLegendByTargetCounts(Collections.emptyList()); + if (groupsLegend.getComponentCount() > MAX_GROUPS_TO_BE_DISPLAYED) { + groupsLegend.getComponent(MAX_GROUPS_TO_BE_DISPLAYED).setVisible(false); + } } private static Label createTotalTargetsLabel() { @@ -108,6 +114,10 @@ public class GroupsLegendLayout extends VerticalLayout { return label; } + private static Label createToBeContinuedLabel() { + return new LabelBuilder().caption("...").visible(false).buildLabel(); + } + private String getTotalTargetMessage(final long totalTargetsCount) { return i18n.getMessage("label.target.filter.count") + totalTargetsCount; } @@ -128,7 +138,7 @@ public class GroupsLegendLayout extends VerticalLayout { * null to hide the label or a count to be displayed as total * targets message */ - public void populateTotalTargets(Long totalTargets) { + public void populateTotalTargets(final Long totalTargets) { if (totalTargets == null) { totalTargetsLabel.setVisible(false); } else { @@ -141,19 +151,19 @@ public class GroupsLegendLayout extends VerticalLayout { * Populates the legend based on a list of anonymous groups. They can't have * unassigned targets. * - * @param targetsPerGroup + * @param listOfTargetCountPerGroup * list of target counts */ - public void populateGroupsLegendByTargetCounts(final List targetsPerGroup) { + public void populateGroupsLegendByTargetCounts(final List listOfTargetCountPerGroup) { loadingLabel.setVisible(false); - for (int i = 0; i < groupsLegend.getComponentCount(); i++) { + for (int i = 0; i < getGroupsWithoutToBeContinuedLabel(listOfTargetCountPerGroup.size()); i++) { final Component component = groupsLegend.getComponent(i); final Label label = (Label) component; - if (targetsPerGroup.size() > i) { - final Long targetCount = targetsPerGroup.get(i); - label.setValue( - getTargetsInGroupMessage(targetCount, i18n.getMessage("textfield.rollout.group.default.name", i + 1))); + if (listOfTargetCountPerGroup.size() > i) { + final Long targetCount = listOfTargetCountPerGroup.get(i); + label.setValue(getTargetsInGroupMessage(targetCount, + i18n.getMessage("textfield.rollout.group.default.name", i + 1))); label.setVisible(true); } else { label.setValue(""); @@ -161,9 +171,33 @@ public class GroupsLegendLayout extends VerticalLayout { } } + showOrHideToBeContinueLabel(listOfTargetCountPerGroup); + unassignedTargetsLabel.setValue(""); unassignedTargetsLabel.setVisible(false); + } + private void showOrHideToBeContinueLabel(final List listOfTargetCountPerGroup) { + if (hasMoreGroupsToShowAsLimit(listOfTargetCountPerGroup)) { + groupsLegend.getComponent(MAX_GROUPS_TO_BE_DISPLAYED).setVisible(true); + } else if (hasLessGroupsToShowAsLimit(listOfTargetCountPerGroup)) { + groupsLegend.getComponent(groupsLegend.getComponentCount() - 1).setVisible(false); + } + } + + private boolean hasLessGroupsToShowAsLimit(final List listOfTargetCountPerGroup) { + return groupsLegend.getComponentCount() > listOfTargetCountPerGroup.size(); + } + + private static boolean hasMoreGroupsToShowAsLimit(final List listOfTargetCountPerGroup) { + return listOfTargetCountPerGroup.size() > MAX_GROUPS_TO_BE_DISPLAYED; + } + + private int getGroupsWithoutToBeContinuedLabel(final int amountOfRolloutGroups) { + if (amountOfRolloutGroups < groupsLegend.getComponentCount()) { + return groupsLegend.getComponentCount(); + } + return groupsLegend.getComponentCount() - 1; } /** @@ -185,11 +219,11 @@ public class GroupsLegendLayout extends VerticalLayout { if (validation == null) { return; } - List targetsPerGroup = validation.getTargetsPerGroup(); + final List targetsPerGroup = validation.getTargetsPerGroup(); final long unassigned = validation.getTotalTargets() - validation.getTargetsInGroups(); - final int labelsToUpdate = (unassigned > 0) ? (groupsLegend.getComponentCount() - 1) + final int labelsToUpdate = (unassigned > 0) ? (getGroupsWithoutToBeContinuedLabel(groups.size()) - 1) : groupsLegend.getComponentCount(); - for (int i = 0; i < groupsLegend.getComponentCount(); i++) { + for (int i = 0; i < getGroupsWithoutToBeContinuedLabel(groups.size()); i++) { final Component component = groupsLegend.getComponent(i); final Label label = (Label) component; if (targetsPerGroup.size() > i && groups.size() > i && labelsToUpdate > i) { @@ -204,6 +238,8 @@ public class GroupsLegendLayout extends VerticalLayout { } } + showOrHideToBeContinueLabel(groups); + if (unassigned > 0) { unassignedTargetsLabel.setValue(getTargetsInGroupMessage(unassigned, "Unassigned")); unassignedTargetsLabel.setVisible(true); @@ -211,7 +247,6 @@ public class GroupsLegendLayout extends VerticalLayout { unassignedTargetsLabel.setValue(""); unassignedTargetsLabel.setVisible(false); } - } /** @@ -223,7 +258,7 @@ public class GroupsLegendLayout extends VerticalLayout { public void populateGroupsLegendByGroups(final List groups) { loadingLabel.setVisible(false); - for (int i = 0; i < groupsLegend.getComponentCount(); i++) { + for (int i = 0; i < getGroupsWithoutToBeContinuedLabel(groups.size()); i++) { final Component component = groupsLegend.getComponent(i); final Label label = (Label) component; if (groups.size() > i) { @@ -238,6 +273,7 @@ public class GroupsLegendLayout extends VerticalLayout { } } + showOrHideToBeContinueLabel(groups); } private String getTargetsInGroupMessage(final Long targets, final String groupName) {