diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index 0bd083e36..be55a24f3 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -78,6 +78,25 @@ true + + org.apache.maven.plugins + maven-jar-plugin + + + true + + true + true + + + + CustomRenderers + 1 + org.eclipse.hawkbit.ui.customrenderers.CustomRendererWidgetSet + + + + @@ -173,8 +192,11 @@ com.vaadin vaadin-server - - + + com.vaadin + vaadin-client + + com.vaadin vaadin-push diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml index 020ce7a77..31a67cacb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/AppWidgetSet.gwt.xml @@ -1,14 +1,8 @@ - + - + + + + + + + + + + + + + + + + + + - - - - - - - diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/CustomRendererWidgetSet.gwt.xml b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/CustomRendererWidgetSet.gwt.xml new file mode 100644 index 000000000..0697836a7 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/CustomRendererWidgetSet.gwt.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlButtonRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlButtonRendererConnector.java new file mode 100644 index 000000000..c02939a9c --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlButtonRendererConnector.java @@ -0,0 +1,14 @@ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import com.vaadin.client.connectors.ButtonRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer.class) +public class HtmlButtonRendererConnector extends ButtonRendererConnector { + private static final long serialVersionUID = 7987417436367399331L; + + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlButtonRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlButtonRenderer) super.getRenderer(); + } +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlLabelRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlLabelRendererConnector.java new file mode 100644 index 000000000..b36712e8f --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/HtmlLabelRendererConnector.java @@ -0,0 +1,16 @@ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import com.vaadin.client.connectors.AbstractRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer.class) +public class HtmlLabelRendererConnector extends AbstractRendererConnector { + + private static final long serialVersionUID = 7697966991925490786L; + + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlLabelRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.HtmlLabelRenderer) super.getRenderer(); + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java new file mode 100644 index 000000000..dcd308d8d --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/LinkRendererConnector.java @@ -0,0 +1,14 @@ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import com.vaadin.client.connectors.ButtonRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer.class) +public class LinkRendererConnector extends ButtonRendererConnector { + private static final long serialVersionUID = 7987417436367399331L; + + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer getRenderer() { + return (org.eclipse.hawkbit.ui.customrenderers.client.renderers.LinkRenderer) super.getRenderer(); + } +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/StringDistributionBarRendererConnector.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/StringDistributionBarRendererConnector.java new file mode 100644 index 000000000..bd1485312 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/StringDistributionBarRendererConnector.java @@ -0,0 +1,18 @@ +package org.eclipse.hawkbit.ui.customrenderers.client; + +import com.vaadin.client.connectors.AbstractRendererConnector; +import com.vaadin.shared.ui.Connect; + +@Connect(org.eclipse.hawkbit.ui.customrenderers.renderers.StringDistributionBarRenderer.class) +public class StringDistributionBarRendererConnector extends AbstractRendererConnector { + + private static final long serialVersionUID = 7697966991925490786L; + + @Override + public org.eclipse.hawkbit.ui.customrenderers.client.renderers.StringDistributionBarRenderer getRenderer() { + org.eclipse.hawkbit.ui.customrenderers.client.renderers.StringDistributionBarRenderer renderer = (org.eclipse.hawkbit.ui.customrenderers.client.renderers.StringDistributionBarRenderer) super.getRenderer(); + renderer.setUiWidgetClassName(StringDistributionBarRendererConnector.this.getConnection().getUIConnector().getWidget().getParent().getStyleName()); + return renderer; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlButtonRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlButtonRenderer.java new file mode 100644 index 000000000..b0019086b --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlButtonRenderer.java @@ -0,0 +1,26 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import com.google.gwt.user.client.ui.Button; +import com.vaadin.client.renderers.ButtonRenderer; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class HtmlButtonRenderer extends ButtonRenderer { + @Override + public void render(RendererCellReference cell, String text, Button button) { + if (text != null) { + button.setHTML(text); + } + applystyles(button); + // this is to allow the button to disappear, if the text is null + button.setVisible(text != null); + button.getElement().setId("rollout.action.button.id"); + } + + private void applystyles(Button button) { + button.setStylePrimaryName("v-button"); + button.setStyleName("tiny v-button-tiny"); + button.addStyleName("borderless v-button-borderless"); + button.addStyleName("icon-only v-button-icon-only"); + button.addStyleName("button-no-border v-button-button-no-border"); + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlLabelRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlLabelRenderer.java new file mode 100644 index 000000000..5ff1b1814 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/HtmlLabelRenderer.java @@ -0,0 +1,54 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import java.util.HashMap; +import java.util.Map; + +import com.google.gwt.core.client.GWT; +import com.vaadin.client.renderers.WidgetRenderer; +import com.vaadin.client.ui.VLabel; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class HtmlLabelRenderer extends WidgetRenderer { + + @Override + public VLabel createWidget() { + return GWT.create(VLabel.class); + } + + @Override + public void render(RendererCellReference cell, String input, VLabel label) { + Map map = formatInput(input); + String value = map.containsKey("value") ? map.get("value") : null; + String style = map.containsKey("style") ? map.get("style") : null; + String id = map.containsKey("id") ? map.get("id") : null; + + if (value != null) { + label.setHTML("&#x" + Integer.toHexString(Integer.parseInt(value)) + ";"); + } + else{ + label.setHTML(""); + } + applyStyle(label, style); + label.getElement().setId(id); + } + + private void applyStyle(VLabel label, String style) { + label.setStylePrimaryName("v-label"); + label.setStyleName("small v-label-small"); + label.addStyleName("font-icon v-label-font-icon"); + if (style != null) { + label.addStyleName(style + " v-label-" + style); + } + } + + private Map formatInput(String input) { + Map details = new HashMap<>(); + String[] tempData = input.split(","); + for (String statusWithCount : tempData) { + String[] statusWithCountList = statusWithCount.split(":"); + details.put(statusWithCountList[0], statusWithCountList[1]); + } + return details; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java new file mode 100644 index 000000000..016fbf8b5 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/LinkRenderer.java @@ -0,0 +1,24 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import com.google.gwt.user.client.ui.Button; +import com.vaadin.client.renderers.ButtonRenderer; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class LinkRenderer extends ButtonRenderer { + @Override + public void render(RendererCellReference cell, String text, Button button) { + button.setText(text); + applystyle(button); + // this is to allow the button to disappear, if the text is null + button.setVisible(text != null); + button.getElement().setId(new StringBuilder("link").append(".").append(text).toString()); + } + + private void applystyle(Button button) { + button.setStylePrimaryName("v-button"); + button.setStyleName("borderless v-button-borderless"); + button.addStyleName("small v-button-small"); + button.addStyleName("on-focus-no-border v-button-on-focus-no-border"); + button.addStyleName("link v-button-link"); + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/StringDistributionBarRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/StringDistributionBarRenderer.java new file mode 100644 index 000000000..1fa2f4efe --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/client/renderers/StringDistributionBarRenderer.java @@ -0,0 +1,114 @@ +package org.eclipse.hawkbit.ui.customrenderers.client.renderers; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.vaadin.alump.distributionbar.gwt.client.GwtDistributionBar; +import org.vaadin.alump.distributionbar.gwt.client.dom.ToolTipPresenter.TooltipClassNameProvider; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.Unit; +import com.vaadin.client.renderers.WidgetRenderer; +import com.vaadin.client.widget.grid.RendererCellReference; + +public class StringDistributionBarRenderer extends WidgetRenderer { + + private static final String STATUS_BAR_PART = "status-bar-part-"; + private static final String FINISHED = "FINISHED"; + private static final String SCHEDULED = "SCHEDULED"; + private static final String ROLLOUT_STATUS_PROGRESS_BAR_ID = "rollout.status.progress.bar.id"; + private String uiWidgetClassName; + + @Override + public GwtDistributionBar createWidget() { + GwtDistributionBar gwt = GWT.create(GwtDistributionBar.class); + gwt.setTooltipClassNameProvider(new TooltipClassNameProvider() { + @Override + public String getClassNames() { + return getUiWidgetClassName(); + } + }); + return gwt; + } + + + @Override + public void render(RendererCellReference cell, String input, GwtDistributionBar widget) { + if (null != input) { + widget.setNumberOfParts(2); + Map map = formatData(input); + if (!map.isEmpty()) { + if (isNoTargets(map.values())) { + setBarPartSize(widget, SCHEDULED.toLowerCase(), 0, 0); + setBarPartSize(widget, FINISHED.toLowerCase(), 0, 1); + + } else { + setThePartDetails(widget, map); + } + } + widget.getElement().setId(ROLLOUT_STATUS_PROGRESS_BAR_ID); + widget.getElement().getStyle().setWidth(100, Unit.PCT); + widget.getElement().getStyle().setHeight(100, Unit.PCT); + } + widget.updateParts(); + } + + private void setThePartDetails(GwtDistributionBar widget, Map map) { + widget.setNumberOfParts(getNumberOfParts(map.values())); + int index = 0; + for (Entry entryVal : map.entrySet()) { + Long count = entryVal.getValue(); + if (count > 0) { + setBarPartSize(widget, entryVal.getKey().toLowerCase(), count.intValue(), index); + index++; + } + } + } + + private Map formatData(String input) { + Map details = new HashMap<>(); + String[] tempData = input.split(","); + for (String statusWithCount : tempData) { + String[] statusWithCountList = statusWithCount.split(":"); + details.put(statusWithCountList[0], new Long(statusWithCountList[1])); + } + return details; + } + + private int getNumberOfParts(Collection values) { + int count = 0; + for (Long val : values) { + if (val != 0) { + count++; + } + } + return count; + } + + private boolean isNoTargets(Collection values) { + for (Long count : values) { + if (count != 0) { + return false; + } + } + return true; + } + + private void setBarPartSize(final GwtDistributionBar bar, final String statusName, final int count, + final int index) { + bar.setPartSize(index, count); + bar.setPartTooltip(index, statusName); + bar.setPartStyleName(index, index, STATUS_BAR_PART + statusName); + } + + public String getUiWidgetClassName() { + return uiWidgetClassName; + } + + public void setUiWidgetClassName(String uiWidgetClassName) { + this.uiWidgetClassName = uiWidgetClassName; + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlButtonRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlButtonRenderer.java new file mode 100644 index 000000000..205eab5db --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlButtonRenderer.java @@ -0,0 +1,14 @@ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import com.vaadin.ui.renderers.ButtonRenderer; + +public class HtmlButtonRenderer extends ButtonRenderer { + private static final long serialVersionUID = -1242995370043404892L; + public HtmlButtonRenderer() { + super(); + } + public HtmlButtonRenderer(RendererClickListener listener) { + super(listener); + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlLabelRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlLabelRenderer.java new file mode 100644 index 000000000..bc519ce8a --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/HtmlLabelRenderer.java @@ -0,0 +1,14 @@ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import com.vaadin.ui.Grid.AbstractRenderer; + +public class HtmlLabelRenderer extends AbstractRenderer { + + private static final long serialVersionUID = -7675588068526774915L; + /** + * Creates a new text renderer + */ + public HtmlLabelRenderer() { + super(String.class, null); + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java new file mode 100644 index 000000000..ad9a5f371 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/LinkRenderer.java @@ -0,0 +1,14 @@ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + +import com.vaadin.ui.renderers.ButtonRenderer; + +public class LinkRenderer extends ButtonRenderer { + private static final long serialVersionUID = -1242995370043404892L; + public LinkRenderer() { + super(); + } + public LinkRenderer(RendererClickListener listener) { + super(listener); + } + +} \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/StringDistributionBarRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/StringDistributionBarRenderer.java new file mode 100644 index 000000000..3f6f301d2 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/StringDistributionBarRenderer.java @@ -0,0 +1,18 @@ +package org.eclipse.hawkbit.ui.customrenderers.renderers; + + +import com.vaadin.ui.Grid.AbstractRenderer; + +public class StringDistributionBarRenderer extends AbstractRenderer { + private static final long serialVersionUID = -4543220859821576209L; + + /** + * Creates a new text renderer + */ + public StringDistributionBarRenderer() { + super(String.class, null); + } + + +} + diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleGrid.java new file mode 100644 index 000000000..f825bf4cd --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleGrid.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.rollout; + +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; + +import com.vaadin.data.Container; +import com.vaadin.data.Container.Indexed; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.ui.Grid; +import com.vaadin.ui.themes.ValoTheme; + +/** + * Abstract table class. + * + */ +public abstract class AbstractSimpleGrid extends Grid { + + private static final long serialVersionUID = 4856562746502217630L; + + /** + * Initialize the components. + */ + protected void init() { + setSizeFull(); + setImmediate(true); + setId(getTableId()); + addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES); + addStyleName(ValoTheme.TABLE_SMALL); + + setHeight("100%"); + setHeightMode(HeightMode.CSS); + setSelectionMode(SelectionMode.NONE); + setColumnReorderingAllowed(true); + + addNewContainerDS(); + } + + public void addNewContainerDS() { + final Container container = createContainer(); + setContainerDataSource((Indexed) container); + addContainerProperties(); + setColumnExpandRatio(); + setColumnProperties(); + setColumnHeaderNames(); + addColumnRenderes(); + + CellDescriptionGenerator cellDescriptionGenerator = getDescriptionGenerator(); + if (getDescriptionGenerator() != null) { + setCellDescriptionGenerator(cellDescriptionGenerator); + } + + // Allow column hiding + for (Column c : getColumns()) { + c.setHidable(true); + } + setHiddenColumns(); + int size = 0; + if (container != null) { + size = container.size(); + } + if (size == 0) { + setData(SPUIDefinitions.NO_DATA); + } + } + + protected abstract Container createContainer(); + + protected abstract void addContainerProperties(); + + protected abstract void setColumnExpandRatio(); + + protected abstract void setColumnHeaderNames(); + + protected abstract String getTableId(); + + protected abstract void setColumnProperties(); + + protected abstract void addColumnRenderes(); + + protected abstract void setHiddenColumns(); + + protected abstract CellDescriptionGenerator getDescriptionGenerator(); +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java index 560e4040e..9f28122b4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/AbstractSimpleTableLayout.java @@ -28,11 +28,13 @@ public abstract class AbstractSimpleTableLayout extends VerticalLayout { private AbstractSimpleTableHeader tableHeader; - private AbstractSimpleTable table; + + private AbstractSimpleGrid grid; - protected void init(final AbstractSimpleTableHeader tableHeader, final AbstractSimpleTable table) { + + protected void init(final AbstractSimpleTableHeader tableHeader,final AbstractSimpleGrid grid) { this.tableHeader = tableHeader; - this.table = table; + this.grid = grid; buildLayout(); } @@ -50,9 +52,10 @@ public abstract class AbstractSimpleTableLayout extends VerticalLayout { tableHeaderLayout.addComponent(tableHeader); tableHeaderLayout.setComponentAlignment(tableHeader, Alignment.TOP_CENTER); - tableHeaderLayout.addComponent(table); - tableHeaderLayout.setComponentAlignment(table, Alignment.TOP_CENTER); - tableHeaderLayout.setExpandRatio(table, 1.0f); +// grid.setSizeFull(); + tableHeaderLayout.addComponent(grid); + tableHeaderLayout.setComponentAlignment(grid, Alignment.TOP_CENTER); + tableHeaderLayout.setExpandRatio(grid, 1.0f); addComponent(tableHeaderLayout); @@ -66,10 +69,6 @@ public abstract class AbstractSimpleTableLayout extends VerticalLayout { } - /** - * @return - * - */ private HorizontalLayout createCountMessageComponent() { final HorizontalLayout rolloutGroupTargetsCountLayout = new HorizontalLayout(); final Label countMessageLabel = getCountMessageLabel(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarDetails.java new file mode 100644 index 000000000..342b0eba1 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/DistributionBarDetails.java @@ -0,0 +1,23 @@ +package org.eclipse.hawkbit.ui.rollout; + +import java.util.HashMap; +import java.util.Map; + +public class DistributionBarDetails { + + private Map details = new HashMap<>(); + + + public DistributionBarDetails( Map details){ + this.details = details; + } + + public Map getDetails() { + return details; + } + + public void setDetails(Map details) { + this.details = details; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java index 92f30293a..c3080b789 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/ProxyRollout.java @@ -8,8 +8,13 @@ */ package org.eclipse.hawkbit.ui.rollout; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.hawkbit.repository.model.Rollout; +import com.vaadin.server.FontAwesome; + /** * Proxy rollout with suctome properties. * @@ -26,21 +31,16 @@ public class ProxyRollout extends Rollout { private Long numberOfGroups; - private Long runningTargetsCount; - - private Long scheduledTargetsCount; - - private Long cancelledTargetsCount; - - private Long errorTargetsCount; - - private Long finishedTargetsCount; - - private Long notStartedTargetsCount; - private Boolean isActionRecieved = Boolean.FALSE; private String totalTargetsCount; + + //TODO remove this + private DistributionBarDetails distributionBarDetails ; + + //TODO remove this + private Map statusTotalCountMap = new HashMap<>(); + /** * @return the distributionSetNameVersion @@ -102,81 +102,6 @@ public class ProxyRollout extends Rollout { this.modifiedDate = modifiedDate; } - /** - * @return the runningTargetsCount - */ - public Long getRunningTargetsCount() { - return runningTargetsCount; - } - - /** - * @param runningTargetsCount - * the runningTargetsCount to set - */ - public void setRunningTargetsCount(final Long runningTargetsCount) { - this.runningTargetsCount = runningTargetsCount; - } - - /** - * @return the scheduledTargetsCount - */ - public Long getScheduledTargetsCount() { - return scheduledTargetsCount; - } - - /** - * @param scheduledTargetsCount - * the scheduledTargetsCount to set - */ - public void setScheduledTargetsCount(final Long scheduledTargetsCount) { - this.scheduledTargetsCount = scheduledTargetsCount; - } - - /** - * @return the cancelledTargetsCount - */ - public Long getCancelledTargetsCount() { - return cancelledTargetsCount; - } - - /** - * @param cancelledTargetsCount - * the cancelledTargetsCount to set - */ - public void setCancelledTargetsCount(final Long cancelledTargetsCount) { - this.cancelledTargetsCount = cancelledTargetsCount; - } - - /** - * @return the errorTargetsCount - */ - public Long getErrorTargetsCount() { - return errorTargetsCount; - } - - /** - * @param errorTargetsCount - * the errorTargetsCount to set - */ - public void setErrorTargetsCount(final Long errorTargetsCount) { - this.errorTargetsCount = errorTargetsCount; - } - - /** - * @return the finishedTargetsCount - */ - public Long getFinishedTargetsCount() { - return finishedTargetsCount; - } - - /** - * @param finishedTargetsCount - * the finishedTargetsCount to set - */ - public void setFinishedTargetsCount(final Long finishedTargetsCount) { - this.finishedTargetsCount = finishedTargetsCount; - } - /** * @return the isActionRecieved */ @@ -192,21 +117,6 @@ public class ProxyRollout extends Rollout { this.isActionRecieved = isActionRecieved; } - /** - * @return the notStartedTargetsCount - */ - public Long getNotStartedTargetsCount() { - return notStartedTargetsCount; - } - - /** - * @param notStartedTargetsCount - * the notStartedTargetsCount to set - */ - public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { - this.notStartedTargetsCount = notStartedTargetsCount; - } - /** * @return the totalTargetsCount */ @@ -221,4 +131,27 @@ public class ProxyRollout extends Rollout { public void setTotalTargetsCount(final String totalTargetsCount) { this.totalTargetsCount = totalTargetsCount; } + + public Map getStatusTotalCountMap() { + return statusTotalCountMap; + } + + public void setStatusTotalCountMap(Map statusTotalCountMap) { + this.statusTotalCountMap = statusTotalCountMap; + } + + public DistributionBarDetails getDistributionBarDetails() { + return distributionBarDetails; + } + + public void setDistributionBarDetails(DistributionBarDetails distributionBarDetails) { + this.distributionBarDetails = distributionBarDetails; + } + + public String getAction() { + return FontAwesome.CIRCLE_O.getHtml(); + } + + + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutBeanQuery.java index 8dfdca4b5..254e17352 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutBeanQuery.java @@ -132,23 +132,10 @@ public class RolloutBeanQuery extends AbstractBeanQuery { proxyRollout.setStatus(rollout.getStatus()); final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); - - proxyRollout.setRunningTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)); - proxyRollout.setErrorTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)); - proxyRollout.setCancelledTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)); - proxyRollout.setFinishedTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)); - proxyRollout.setScheduledTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)); - proxyRollout.setNotStartedTargetsCount(totalTargetCountActionStatus - .getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)); - proxyRolloutList.add(proxyRollout); - + proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - + + proxyRolloutList.add(proxyRollout); } return proxyRolloutList; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java index 7d6a3a46f..a42618c24 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupBeanQuery.java @@ -15,7 +15,6 @@ import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -122,22 +121,8 @@ public class RolloutGroupBeanQuery extends AbstractBeanQuery proxyRolloutGroup.setSuccessConditionExp(rolloutGroup.getSuccessConditionExp()); proxyRolloutGroup.setFinishedPercentage(calculateFinishedPercentage(rolloutGroup)); - final TotalTargetCountStatus totalTargetCountActionStatus = rolloutGroup.getTotalTargetCountStatus(); - - proxyRolloutGroup.setRunningTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.RUNNING)); - proxyRolloutGroup.setErrorTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.ERROR)); - proxyRolloutGroup.setCancelledTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.CANCELLED)); - proxyRolloutGroup.setFinishedTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.FINISHED)); - proxyRolloutGroup.setScheduledTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.SCHEDULED)); - proxyRolloutGroup.setNotStartedTargetsCount( - totalTargetCountActionStatus.getTotalTargetCountByStatus(TotalTargetCountStatus.Status.NOTSTARTED)); - proxyRolloutGroup.setTotalTargetsCount(String.valueOf(rolloutGroup.getTotalTargets())); + proxyRolloutGroup.setTotalTargetCountStatus(rolloutGroup.getTotalTargetCountStatus()); proxyRolloutGroupsList.add(proxyRolloutGroup); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListGrid.java new file mode 100644 index 000000000..eb7ec1390 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListGrid.java @@ -0,0 +1,390 @@ +package org.eclipse.hawkbit.ui.rollout; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; +import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.StringDistributionBarRenderer; +import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; +import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; +import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.server.FontAwesome; +import com.vaadin.server.Page; +import com.vaadin.server.Page.BrowserWindowResizeEvent; +import com.vaadin.server.Page.BrowserWindowResizeListener; +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.Grid.CellDescriptionGenerator; +import com.vaadin.ui.Grid.CellReference; +import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; + +@SpringComponent +@ViewScope +public class RolloutGroupListGrid extends AbstractSimpleGrid implements BrowserWindowResizeListener { + private static final long serialVersionUID = 4060904914954370524L; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutGroupManagement rolloutGroupManagement; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + @Override + @PostConstruct + protected void init() { + super.init(); + Page.getCurrent().addBrowserWindowResizeListener(this); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (event == RolloutEvent.SHOW_ROLLOUT_GROUPS) { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + } + + /** + * + * Handles the RolloutGroupChangeEvent to refresh the item in the table. + * + * + * @param rolloutGroupChangeEvent + * the event which contains the rollout group which has been + * change + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutGroupChangeEvent rolloutGroupChangeEvent) { + if (rolloutUIState.isShowRolloutGroups()) { + final RolloutGroup rolloutGroup = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupChangeEvent.getRolloutGroupId()); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutGroup.getId()); + if (item != null) { + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rolloutGroup.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(rolloutGroup.getTotalTargetCountStatus()); + + } + } + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, + null, false, false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, + false, false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, + false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + } + + @Override + protected void setColumnExpandRatio() { + getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(200); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD).setMaximumWidth(100); + + setFrozenColumnCount(7); + } + + @Override + protected void setColumnHeaderNames() { + getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE) + .setHeaderCaption(i18n.get("header.rolloutgroup.installed.percentage")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold.error")); + getColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD) + .setHeaderCaption(i18n.get("header.rolloutgroup.threshold")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + } + + @Override + protected String getTableId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_LIST_TABLE_ID; + } + + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD); + columnList.add(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + @Override + protected void addColumnRenderes() { + addDetailStatusColumn(); + addStatusCoulmn(); + if (permissionChecker.hasRolloutTargetsReadPermission()) { + getColumn(SPUILabelDefinitions.VAR_NAME) + .setRenderer(new LinkRenderer(event -> onClickOfRolloutGroupName(event))); + } + } + + private void onClickOfRolloutGroupName(RendererClickEvent event) { + rolloutUIState + .setRolloutGroup(rolloutGroupManagement.findRolloutGroupWithDetailedStatus((Long) event.getItemId())); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS); + } + + private void addStatusCoulmn() { + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public RolloutGroupStatus convertToModel(final String value, + final Class targetType, final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutGroupStatus value, + final Class targetType, final Locale locale) { + return convertRolloutGroupStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutGroupStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + } + + private String convertRolloutGroupStatusToString(final RolloutGroupStatus value) { + String result = null; + switch (value) { + case FINISHED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.CHECK_CIRCLE.getCodepoint()), "statusIconGreen", + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case SCHEDULED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.BULLSEYE.getCodepoint()), "statusIconBlue", + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case RUNNING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.ADJUST.getCodepoint()), "statusIconYellow", + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case READY: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + case ERROR: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), "statusIconRed", + SPUIComponetIdProvider.ROLLOUT_GROUP_STATUS_LABEL_ID); + break; + default: + break; + } + return result; + + } + + private void addDetailStatusColumn() { + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer(new StringDistributionBarRenderer(), + new Converter() { + private static final long serialVersionUID = 2660476405836705932L; + + @Override + public TotalTargetCountStatus convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(TotalTargetCountStatus value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return HawkbitCommonUtil.getFormattedString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + } + + @Override + protected void setHiddenColumns() { + List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + } + + @Override + public void browserWindowResized(BrowserWindowResizeEvent event) { + // Intermediate solution for the column width problem for + // SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS column + // Readding the column + recalculateColumnWidths(); + removeColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + addColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + setColumnProperties(); + addDetailStatusColumn(); + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + }; + + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (SPUILabelDefinitions.VAR_NAME.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString(); + } else { + return null; + } + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java index cf1a004d8..6bfcc70b2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupListTable.java @@ -145,11 +145,11 @@ public class RolloutGroupListTable extends AbstractSimpleTable { columnList.add(new TableColumn(SPUIDefinitions.DETAIL_STATUS, i18n.get("header.detail.status"), 0.42f)); columnList .add(new TableColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS, i18n.get("header.total.targets"), 0.08f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, + columnList.add(new TableColumn(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, i18n.get("header.rolloutgroup.installed.percentage"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, + columnList.add(new TableColumn(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, i18n.get("header.rolloutgroup.threshold.error"), 0.1f)); - columnList.add(new TableColumn(SPUIDefinitions.ROLLOUT_GROUP_THRESHOLD, + columnList.add(new TableColumn(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, i18n.get("header.rolloutgroup.threshold"), 0.1f)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_DATE, i18n.get("header.createdDate"), 0.15f)); columnList.add(new TableColumn(SPUILabelDefinitions.VAR_CREATED_USER, i18n.get("header.createdBy"), 0.15f)); @@ -167,45 +167,48 @@ public class RolloutGroupListTable extends AbstractSimpleTable { @Override protected void addContainerProperties(final Container container) { - final LazyQueryContainer rolloutTableContainer = (LazyQueryContainer) container; - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_ID, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, + final LazyQueryContainer rolloutGroupGridContainer = (LazyQueryContainer) container; + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_ID, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutGroupStatus.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUIDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, String.class, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_INSTALLED_PERCENTAGE, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUIDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, null, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_ERROR_THRESHOLD, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUIDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.ROLLOUT_GROUP_THRESHOLD, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED, Long.class, 0L, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED, Long.class, 0L, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING, Long.class, 0L, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING, Long.class, 0L, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED, Long.class, 0L, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED, Long.class, 0L, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR, Long.class, 0L, false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR, Long.class, 0L, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED, Long.class, 0L, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED, Long.class, 0L, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED, Long.class, 0L, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED, Long.class, 0L, false, false); - rolloutTableContainer.addContainerProperty(IS_ACTION_RECIEVED, Boolean.class, false, false, false); + rolloutGroupGridContainer.addContainerProperty(IS_ACTION_RECIEVED, Boolean.class, false, false, false); - rolloutTableContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, false); + + rolloutGroupGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListGrid.java new file mode 100644 index 000000000..c96d93d77 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListGrid.java @@ -0,0 +1,297 @@ +package org.eclipse.hawkbit.ui.rollout; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; +import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; +import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; + +import com.vaadin.data.Container; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.server.FontAwesome; +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.Grid.CellDescriptionGenerator; +import com.vaadin.ui.Grid.CellReference; + +@SpringComponent +@ViewScope +public class RolloutGroupTargetsListGrid extends AbstractSimpleGrid { + + private static final long serialVersionUID = -2244756637458984597L; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Override + @PostConstruct + protected void init() { + super.init(); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (event == RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS) { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUP_TARGETS_COUNT); + } + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutgrouBeanQueryFactory = new BeanQueryFactory<>( + RolloutGroupTargetsBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), + rolloutgrouBeanQueryFactory); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGroupTargetGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, + true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, Status.class, + Status.RETRIEVED, false, false); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_BY, String.class, null, + false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY, String.class, + null, false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, + false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE, String.class, + null, false, true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, "", false, + true); + rolloutGroupTargetGridContainer.addContainerProperty(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER, + String.class, "", false, true); + } + + @Override + protected void setColumnExpandRatio() { + getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(20); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(250); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(50); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setMaximumWidth(150); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setMinimumWidth(50); + + getColumn(SPUILabelDefinitions.VAR_CREATED_BY).setMaximumWidth(150); + getColumn(SPUILabelDefinitions.VAR_CREATED_BY).setMinimumWidth(50); + + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE).setMaximumWidth(150); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE).setMinimumWidth(20); + + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setMaximumWidth(150); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setMinimumWidth(20); + + setFrozenColumnCount(getColumns().size()); + + } + + @Override + protected void setColumnHeaderNames() { + getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_BY).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER).setHeaderCaption(i18n.get("header.assigned.ds")); + + } + + @Override + protected String getTableId() { + return SPUIComponetIdProvider.ROLLOUT_GROUP_TARGETS_LIST_TABLE_ID; + } + + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_BY); + columnList.add(SPUILabelDefinitions.VAR_LAST_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_LAST_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + @Override + protected void addColumnRenderes() { + addStatusCoulmn(); + } + + @Override + protected void setHiddenColumns() { + getColumn(SPUILabelDefinitions.ASSIGNED_DISTRIBUTION_NAME_VER).setHidden(true); + } + + private void addStatusCoulmn() { + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public Status convertToModel(final String value, final Class targetType, + final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final Status status, final Class targetType, + final Locale locale) { + String result = null; + if (status == null) { + // Actions are not created for targets when + // rollout's status + // is READY and when duplicate assignment is done. + // In these cases display a appropriate status with + // description + return getStatus(); + } else { + switch (status) { + case FINISHED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.CHECK_CIRCLE.getCodepoint()), "statusIconGreen", + null); + break; + case SCHEDULED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.BULLSEYE.getCodepoint()), "statusIconBlue", null); + break; + case RUNNING: + case RETRIEVED: + case WARNING: + case DOWNLOAD: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.ADJUST.getCodepoint()), "statusIconYellow", null); + break; + case CANCELING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.TIMES_CIRCLE.getCodepoint()), "statusIconPending", + null); + break; + case CANCELED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.TIMES_CIRCLE.getCodepoint()), "statusIconGreen", + null); + break; + case ERROR: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), + "statusIconRed", null); + break; + default: + break; + } + return result; + } + } + + @Override + public Class getModelType() { + return Status.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + } + + private String getStatus() { + final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() + ? rolloutUIState.getRolloutGroup().get() : null; + if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", null); + } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.MINUS_CIRCLE.getCodepoint()), "statusIconBlue", null); + } else { + return HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.QUESTION_CIRCLE.getCodepoint()), "statusIconBlue", null); + } + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + }; + + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + if (null != cell.getProperty().getValue()) { + return cell.getProperty().getValue().toString().toLowerCase(); + + } else { + final RolloutGroup rolloutGroup = rolloutUIState.getRolloutGroup().isPresent() + ? rolloutUIState.getRolloutGroup().get() : null; + if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.READY) { + return RolloutGroupStatus.READY.toString().toLowerCase(); + } else if (rolloutGroup != null && rolloutGroup.getStatus() == RolloutGroupStatus.FINISHED) { + String ds = rolloutUIState.getRolloutDistributionSet().isPresent() + ? rolloutUIState.getRolloutDistributionSet().get() : ""; + return i18n.get("message.dist.already.assigned", new Object[] { ds }); + } else { + return "unknown"; + } + } + } + return null; + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java index bb037231b..a8ad99ec5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListTable.java @@ -195,7 +195,7 @@ public class RolloutGroupTargetsListTable extends AbstractSimpleTable { } } - private void setRolloutStatusIcon(final Status targetUpdateStatus, final Label statusLabel) { + private void setRolloutStatusIcon(final Status targetUpdateStatus, final Label statusLabel) { switch (targetUpdateStatus) { case ERROR: statusLabel.setValue(FontAwesome.EXCLAMATION_CIRCLE.getHtml()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java index 40b8f6eb7..67f2cbe19 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupTargetsListView.java @@ -29,28 +29,28 @@ public class RolloutGroupTargetsListView extends AbstractSimpleTableLayout { private RolloutGroupTargetsListHeader rolloutGroupTargetsListHeader; @Autowired - private RolloutGroupTargetsListTable rolloutGroupTargetsListTable; + private RolloutGroupTargetsCountLabelMessage rolloutGroupTargetsCountLabelMessage; @Autowired - private RolloutGroupTargetsCountLabelMessage rolloutGroupTargetsCountLabelMessage; + private RolloutGroupTargetsListGrid rolloutListGrid; /** * Initialization of Rollout group component. */ @PostConstruct protected void init() { - super.init(rolloutGroupTargetsListHeader, rolloutGroupTargetsListTable); + super.init(rolloutGroupTargetsListHeader, rolloutListGrid); } @Override protected boolean hasCountMessage() { - + return true; } - + @Override protected Label getCountMessageLabel() { - + return rolloutGroupTargetsCountLabelMessage; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java index 0725da6ee..17583d9e3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutGroupsListView.java @@ -30,22 +30,20 @@ public class RolloutGroupsListView extends AbstractSimpleTableLayout { private RolloutGroupsListHeader rolloutGroupListHeader; @Autowired - private RolloutGroupListTable rolloutGroupListTable; + private RolloutGroupListGrid rolloutListGrid; @PostConstruct protected void init() { - super.init(rolloutGroupListHeader, rolloutGroupListTable); + super.init(rolloutGroupListHeader, rolloutListGrid); } @Override protected boolean hasCountMessage() { - return false; } @Override protected Label getCountMessageLabel() { - return null; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListGrid.java new file mode 100644 index 000000000..06a67913f --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListGrid.java @@ -0,0 +1,503 @@ +package org.eclipse.hawkbit.ui.rollout; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; +import org.eclipse.hawkbit.ui.customrenderers.renderers.LinkRenderer; +import org.eclipse.hawkbit.ui.rollout.RolloutListTable.ACTION; +import org.eclipse.hawkbit.ui.rollout.RolloutListTable.ContextMenuData; +import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; +import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; +import org.eclipse.hawkbit.ui.utils.I18N; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.UINotification; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; +import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; +import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; +import org.vaadin.peter.contextmenu.ContextMenu; +import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItem; +import org.vaadin.peter.contextmenu.ContextMenu.ContextMenuItemClickEvent; +import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.PropertyValueGenerator; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.server.AbstractClientConnector; +import com.vaadin.server.FontAwesome; +import com.vaadin.server.Page; +import com.vaadin.server.Page.BrowserWindowResizeEvent; +import com.vaadin.server.Page.BrowserWindowResizeListener; +import com.vaadin.spring.annotation.SpringComponent; +import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.UI; +import com.vaadin.ui.Window; +import com.vaadin.ui.Grid.CellReference; +import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; + +@SpringComponent +@ViewScope +public class RolloutListGrid extends AbstractSimpleGrid implements BrowserWindowResizeListener { + private static final long serialVersionUID = 4060904914954370524L; + + @Autowired + private I18N i18n; + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private transient RolloutManagement rolloutManagement; + + @Autowired + private AddUpdateRolloutWindowLayout addUpdateRolloutWindow; + + @Autowired + private UINotification uiNotification; + + @Autowired + private transient RolloutUIState rolloutUIState; + + @Autowired + private transient SpPermissionChecker permissionChecker; + + @Override + @PostConstruct + protected void init() { + super.init(); + eventBus.subscribe(this); + Page.getCurrent().addBrowserWindowResizeListener(this); + + } + + @PreDestroy + void destroy() { + eventBus.unsubscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final RolloutEvent event) { + if (event == RolloutEvent.FILTER_BY_TEXT || event == RolloutEvent.CREATE_ROLLOUT + || event == RolloutEvent.UPDATE_ROLLOUT || event == RolloutEvent.SHOW_ROLLOUTS) { + refreshTable(); + } + } + + /** + * Handles the RolloutChangeEvent to refresh the item in the table. + * + * @param rolloutChangeEvent + * the event which contains the rollout which has been changed + */ + @SuppressWarnings("unchecked") + @EventBusListenerMethod(scope = EventScope.SESSION) + public void onEvent(final RolloutChangeEvent rolloutChangeEvent) { + if (rolloutUIState.isShowRollOuts()) { + final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutChangeEvent.getRolloutId()); + final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); + final LazyQueryContainer rolloutContainer = (LazyQueryContainer) getContainerDataSource(); + final Item item = rolloutContainer.getItem(rolloutChangeEvent.getRolloutId()); + if (null != item) { + item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); + item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setValue(totalTargetCountStatus); + final Long groupCount = (Long) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .getValue(); + if (null != rollout.getRolloutGroups() && groupCount != rollout.getRolloutGroups().size()) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) + .setValue(Long.valueOf(rollout.getRolloutGroups().size())); + } + } + } + } + + @Override + protected Container createContainer() { + final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutBeanQuery.class); + return new LazyQueryContainer( + new LazyQueryDefinition(true, SPUIDefinitions.PAGE_SIZE, SPUILabelDefinitions.VAR_ID), rolloutQf); + } + + @Override + protected void addContainerProperties() { + final LazyQueryContainer rolloutGridContainer = (LazyQueryContainer) getContainerDataSource(); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NAME, String.class, "", false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DESC, String.class, null, false, false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_STATUS, RolloutStatus.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_DATE, String.class, null, false, + false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_DATE, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_CREATED_USER, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_MODIFIED_BY, String.class, null, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS, Integer.class, 0, false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS, String.class, "0", false, + false); + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, + TotalTargetCountStatus.class, null, false, false); + + rolloutGridContainer.addContainerProperty(SPUILabelDefinitions.ACTION, String.class, + FontAwesome.CIRCLE_O.getHtml(), false, false); + + } + + @Override + protected void setColumnExpandRatio() { + getColumn(SPUILabelDefinitions.VAR_NAME).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NAME).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setMaximumWidth(150); + + getColumn(SPUILabelDefinitions.VAR_STATUS).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.VAR_STATUS).setMaximumWidth(75); + + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMinimumWidth(40); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setMaximumWidth(100); + + getColumn(SPUILabelDefinitions.ACTION).setMinimumWidth(75); + getColumn(SPUILabelDefinitions.ACTION).setMaximumWidth(75); + + setFrozenColumnCount(getColumns().size()); + } + + @Override + protected void setColumnHeaderNames() { + getColumn(SPUILabelDefinitions.VAR_NAME).setHeaderCaption(i18n.get("header.name")); + getColumn(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).setHeaderCaption(i18n.get("header.distributionset")); + getColumn(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setHeaderCaption(i18n.get("header.numberofgroups")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS).setHeaderCaption(i18n.get("header.total.targets")); + getColumn(SPUILabelDefinitions.VAR_CREATED_DATE).setHeaderCaption(i18n.get("header.createdDate")); + getColumn(SPUILabelDefinitions.VAR_CREATED_USER).setHeaderCaption(i18n.get("header.createdBy")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_DATE).setHeaderCaption(i18n.get("header.modifiedDate")); + getColumn(SPUILabelDefinitions.VAR_MODIFIED_BY).setHeaderCaption(i18n.get("header.modifiedBy")); + getColumn(SPUILabelDefinitions.VAR_DESC).setHeaderCaption(i18n.get("header.description")); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + getColumn(SPUILabelDefinitions.VAR_STATUS).setHeaderCaption(i18n.get("header.status")); + getColumn(SPUILabelDefinitions.ACTION).setHeaderCaption(i18n.get("upload.action")); + } + + @Override + protected String getTableId() { + return SPUIComponetIdProvider.ROLLOUT_LIST_TABLE_ID; + } + + @Override + protected void setColumnProperties() { + List columnList = new ArrayList<>(); + columnList.add(SPUILabelDefinitions.VAR_NAME); + columnList.add(SPUILabelDefinitions.VAR_DIST_NAME_VERSION); + columnList.add(SPUILabelDefinitions.VAR_STATUS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + columnList.add(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS); + columnList.add(SPUILabelDefinitions.VAR_TOTAL_TARGETS); + columnList.add(SPUILabelDefinitions.ACTION); + + columnList.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnList.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnList.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnList.add(SPUILabelDefinitions.VAR_DESC); + setColumnOrder(columnList.toArray()); + alignColumns(); + } + + private void alignColumns() { + setCellStyleGenerator(new CellStyleGenerator() { + private static final long serialVersionUID = 5573570647129792429L; + + @Override + public String getStyle(final CellReference cellReference) { + String[] coulmnNames = { SPUILabelDefinitions.VAR_STATUS, + SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS, SPUILabelDefinitions.ACTION }; + if (Arrays.asList(coulmnNames).contains(cellReference.getPropertyId())) { + return "centeralign"; + } + return null; + } + }); + } + + @Override + protected void addColumnRenderes() { + addDetailStatusColumn(); + addStatusCoulmn(); + getColumn(SPUILabelDefinitions.ACTION).setRenderer(new HtmlButtonRenderer(event -> onClickOfActionBtn(event))); + getColumn(SPUILabelDefinitions.VAR_NAME).setRenderer(new LinkRenderer(event -> onClickOfRolloutName(event))); + } + + private void onClickOfRolloutName(RendererClickEvent event) { + rolloutUIState.setRolloutId((long) event.getItemId()); + final String rolloutName = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + rolloutUIState.setRolloutName(rolloutName); + String ds = (String) getContainerDataSource().getItem(event.getItemId()) + .getItemProperty(SPUILabelDefinitions.VAR_DIST_NAME_VERSION).getValue(); + rolloutUIState.setRolloutDistributionSet(ds); + eventBus.publish(this, RolloutEvent.SHOW_ROLLOUT_GROUPS); + } + + private void onClickOfActionBtn(RendererClickEvent event) { + final ContextMenu contextMenu = createContextMenu((Long) event.getItemId()); + contextMenu.setAsContextMenuOf((AbstractClientConnector) event.getComponent()); + contextMenu.open(event.getClientX(), event.getClientY()); + } + + private ContextMenu createContextMenu(final Long rolloutId) { + final Item row = getContainerDataSource().getItem(rolloutId); + final RolloutStatus rolloutStatus = (RolloutStatus) row.getItemProperty(SPUILabelDefinitions.VAR_STATUS) + .getValue(); + final ContextMenu context = new ContextMenu(); + context.addItemClickListener(event -> menuItemClicked(event)); + if (rolloutStatus == RolloutStatus.READY) { + final ContextMenuItem startItem = context.addItem("Start"); + startItem.setData(new ContextMenuData(rolloutId, ACTION.START)); + } else if (rolloutStatus == RolloutStatus.RUNNING) { + final ContextMenuItem pauseItem = context.addItem("Pause"); + pauseItem.setData(new ContextMenuData(rolloutId, ACTION.PAUSE)); + } else if (rolloutStatus == RolloutStatus.PAUSED) { + final ContextMenuItem resumeItem = context.addItem("Resume"); + resumeItem.setData(new ContextMenuData(rolloutId, ACTION.RESUME)); + } else if (rolloutStatus == RolloutStatus.STARTING || rolloutStatus == RolloutStatus.CREATING) { + return context; + } + if (permissionChecker.hasRolloutUpdatePermission()) { + final ContextMenuItem cancelItem = context.addItem("Update"); + cancelItem.setData(new ContextMenuData(rolloutId, ACTION.UPDATE)); + } + return context; + } + + private void addDetailStatusColumn() { + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setRenderer( + new org.eclipse.hawkbit.ui.customrenderers.renderers.StringDistributionBarRenderer(), + new Converter() { + private static final long serialVersionUID = 2660476405836705932L; + + @Override + public TotalTargetCountStatus convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + + @Override + public String convertToPresentation(TotalTargetCountStatus value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return HawkbitCommonUtil.getFormattedString(value.getStatusTotalCountMap()); + } + + @Override + public Class getModelType() { + return TotalTargetCountStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + } + + private void addStatusCoulmn() { + getColumn(SPUILabelDefinitions.VAR_STATUS).setRenderer(new HtmlLabelRenderer(), + new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public RolloutStatus convertToModel(final String value, + final Class targetType, final Locale locale) { + return null; + } + + @Override + public String convertToPresentation(final RolloutStatus value, + final Class targetType, final Locale locale) { + return convertRolloutStatusToString(value); + } + + @Override + public Class getModelType() { + return RolloutStatus.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + } + + private String convertRolloutStatusToString(final RolloutStatus value) { + String result = null; + switch (value) { + case FINISHED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.CHECK_CIRCLE.getCodepoint()), "statusIconGreen", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case PAUSED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(Integer.toString(FontAwesome.PAUSE.getCodepoint()), + "statusIconBlue", SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case RUNNING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(null, "yellowSpinner", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case READY: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.DOT_CIRCLE_O.getCodepoint()), "statusIconLightBlue", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case STOPPED: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(Integer.toString(FontAwesome.STOP.getCodepoint()), + "statusIconRed", SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case CREATING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(null, "greySpinner", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case STARTING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString(null, "blueSpinner", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case ERROR_CREATING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), "statusIconRed", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + case ERROR_STARTING: + result = HawkbitCommonUtil.getStatusLabelDetailsInString( + Integer.toString(FontAwesome.EXCLAMATION_CIRCLE.getCodepoint()), "statusIconRed", + SPUIComponetIdProvider.ROLLOUT_STATUS_LABEL_ID); + break; + default: + break; + } + return result; + } + + private void menuItemClicked(final ContextMenuItemClickEvent event) { + final ContextMenuItem item = (ContextMenuItem) event.getSource(); + final ContextMenuData contextMenuData = (ContextMenuData) item.getData(); + final Item row = getContainerDataSource().getItem(contextMenuData.getRolloutId()); + final String rolloutName = (String) row.getItemProperty(SPUILabelDefinitions.VAR_NAME).getValue(); + if (contextMenuData.getAction() == ACTION.PAUSE) { + rolloutManagement.pauseRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.paused", rolloutName)); + } else if (contextMenuData.getAction() == ACTION.RESUME) { + rolloutManagement.resumeRollout(rolloutManagement.findRolloutById(contextMenuData.getRolloutId())); + uiNotification.displaySuccess(i18n.get("message.rollout.resumed", rolloutName)); + } else if (contextMenuData.getAction() == ACTION.START) { + rolloutManagement.startRolloutAsync(rolloutManagement.findRolloutByName(rolloutName)); + uiNotification.displaySuccess(i18n.get("message.rollout.started", rolloutName)); + } else if (contextMenuData.getAction() == ACTION.UPDATE) { + addUpdateRolloutWindow.populateData(contextMenuData.getRolloutId()); + final Window addTargetWindow = addUpdateRolloutWindow.getWindow(); + addTargetWindow.setCaption(i18n.get("caption.update.rollout")); + UI.getCurrent().addWindow(addTargetWindow); + addTargetWindow.setVisible(Boolean.TRUE); + } + } + + private void refreshTable() { + ((LazyQueryContainer) getContainerDataSource()).refresh(); + } + + public final class FontIconGenerator extends PropertyValueGenerator { + + private static final long serialVersionUID = 2544026030795375748L; + private final FontAwesome fontIcon; + + public FontIconGenerator(FontAwesome icon) { + this.fontIcon = icon; + } + + @Override + public String getValue(Item item, Object itemId, Object propertyId) { + return fontIcon.getHtml(); + } + + @Override + public Class getType() { + return String.class; + } + } + + @Override + public void browserWindowResized(BrowserWindowResizeEvent event) { + // Intermediate solution for the column width problem for + // SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS column + // Readding the column + recalculateColumnWidths(); + removeColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + addColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS); + getColumn(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS) + .setHeaderCaption(i18n.get("header.detail.status")); + setColumnProperties(); + addDetailStatusColumn(); + } + + @Override + protected void setHiddenColumns() { + List columnsToBeHidden = new ArrayList<>(); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_CREATED_USER); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_DATE); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_MODIFIED_BY); + columnsToBeHidden.add(SPUILabelDefinitions.VAR_DESC); + for (Object propertyId : columnsToBeHidden) { + getColumn(propertyId).setHidden(true); + } + + } + + @Override + protected CellDescriptionGenerator getDescriptionGenerator() { + return cell -> getDescription(cell); + }; + + private String getDescription(CellReference cell) { + if (SPUILabelDefinitions.VAR_STATUS.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString().toLowerCase(); + } else if (SPUILabelDefinitions.ACTION.equals(cell.getPropertyId())) { + return SPUILabelDefinitions.ACTION.toLowerCase(); + } else if (SPUILabelDefinitions.VAR_NAME.equals(cell.getPropertyId())) { + return cell.getProperty().getValue().toString(); + } else { + return null; + } + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java index 462bfd081..196133683 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutListView.java @@ -31,24 +31,22 @@ public class RolloutListView extends AbstractSimpleTableLayout { private RolloutListHeader rolloutListHeader; @Autowired - private RolloutListTable rolloutListTable; + private RolloutListGrid rolloutListGrid; @PostConstruct void init() { - super.init(rolloutListHeader, rolloutListTable); + super.init(rolloutListHeader, rolloutListGrid); } - @Override protected boolean hasCountMessage() { - + return false; } - @Override protected Label getCountMessageLabel() { - + return null; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java index 8dc5b1e17..0647e01bb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/state/RolloutUIState.java @@ -44,6 +44,8 @@ public class RolloutUIState implements Serializable { private long rolloutGroupTargetsTotalCount; + private String rolloutDistributionSet; + /** * @return the searchText */ @@ -178,4 +180,20 @@ public class RolloutUIState implements Serializable { public void setRolloutGroupTargetsTotalCount(final long rolloutGroupTargetsTotalCount) { this.rolloutGroupTargetsTotalCount = rolloutGroupTargetsTotalCount; } + + /** + * @return rolloutDistributionSet + */ + public Optional getRolloutDistributionSet() { + return rolloutDistributionSet == null ? Optional.empty() : Optional.of(rolloutDistributionSet); + } + + /** + * + * @param rolloutDistributionSet + * the distribution set of the rollout + */ + public void setRolloutDistributionSet(String rolloutDistributionSet) { + this.rolloutDistributionSet = rolloutDistributionSet; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 47336dd34..e9e287fe3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TimeZone; @@ -33,6 +34,7 @@ import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; import org.eclipse.hawkbit.ui.management.dstable.DistributionTable; import org.eclipse.hawkbit.ui.management.targettable.TargetTable; import org.slf4j.Logger; @@ -46,6 +48,7 @@ import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; import org.vaadin.alump.distributionbar.DistributionBar; +import com.google.common.base.Strings; import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.server.Sizeable.Unit; @@ -1348,4 +1351,48 @@ public final class HawkbitCommonUtil { private static Long getStatusCount(final String propertName, final Item item) { return (Long) item.getItemProperty(propertName).getValue(); } + + /** + * Get the formatted string of status and target count details. + * + * @param details + * details of status and count + * @return String + */ + public static String getFormattedString(Map details) { + StringBuilder val = new StringBuilder(); + String finalVal = null; + if (null != details && !details.isEmpty()) { + for (Entry entry : details.entrySet()) { + val.append(entry.getKey()).append(":").append(entry.getValue()).append(","); + } + finalVal = val.substring(0, val.length() - 1); + } + return finalVal; + } + + /** + * Returns a formatted string as needed by label custom render .This string + * holds the properties of a status label. + * + * @param value + * label value + * @param style + * label style + * @param id + * label id + * @return + */ + public static String getStatusLabelDetailsInString(String value, String style, String id) { + StringBuilder val = new StringBuilder(); + if (!Strings.isNullOrEmpty(value)) { + val.append("value:").append(value).append(","); + } + if (!Strings.isNullOrEmpty(style)) { + val.append("style:").append(style).append(","); + } + val.append("id:").append(id); + return val.toString(); + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java index 56e76c123..84346149c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java @@ -827,6 +827,11 @@ public final class SPUIComponetIdProvider { * Rollout status label id. */ public static final String ROLLOUT_STATUS_LABEL_ID = "rollout.status.id"; + + /** + * Rollout group status label id. + */ + public static final String ROLLOUT_GROUP_STATUS_LABEL_ID = "rollout.group.status.id"; /** * Rollout % or count option group id. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java index 1d3e97168..b29283ef8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIDefinitions.java @@ -1001,20 +1001,6 @@ public final class SPUIDefinitions { */ public static final String ROLLOUT_GROUP_STARTED_DATE = "Started date"; - /** - * Rollout group started date column property. - */ - public static final String ROLLOUT_GROUP_ERROR_THRESHOLD = "errorConditionExp"; - - /** - * Rollout group started date column property. - */ - public static final String ROLLOUT_GROUP_THRESHOLD = "successConditionExp"; - - /** - * Rollout group installed percentage column property. - */ - public static final String ROLLOUT_GROUP_INSTALLED_PERCENTAGE = "finishedPercentage"; /** * Rollout group status column property. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java index f5848e650..937a53adc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java @@ -539,6 +539,27 @@ public final class SPUILabelDefinitions { * Total target coulmn property name. */ public static final String VAR_TOTAL_TARGETS = "totalTargetsCount"; + + + /** + * Total target count status coulmn property name. + */ + public static final String VAR_TOTAL_TARGETS_COUNT_STATUS = "totalTargetCountStatus"; + + /** + * Rollout group started date column property. + */ + public static final String ROLLOUT_GROUP_ERROR_THRESHOLD = "errorConditionExp"; + + /** + * Rollout group started date column property. + */ + public static final String ROLLOUT_GROUP_THRESHOLD = "successConditionExp"; + + /** + * Rollout group installed percentage column property. + */ + public static final String ROLLOUT_GROUP_INSTALLED_PERCENTAGE = "finishedPercentage"; /** * Constructor. diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss index 1a5fedba4..87ea5b0b9 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/common.scss @@ -276,4 +276,10 @@ .links { padding-left: 22px; } + + .font-icon{ + font-family:FontAwesome; + font-style:normal; + font-weight:normal; + } } diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss index 1c7714061..712e04ec1 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/rollout.scss @@ -56,5 +56,26 @@ } } + .v-grid-cell.centeralign { + text-align: center; + } + + .v-grid-cell { + font-size: $v-font-size--small !important; + height: 34px !important; + } + + .v-grid-row{ + height: 34px !important; + } + + .v-grid-cell.frozen{ + box-shadow: none !important; + } + + .v-grid-cell.frozen + th{ + border-left: $v-grid-border-size solid $widget-border-color ; + } + } \ No newline at end of file diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss index 867fa0151..9cc628022 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/statusprogressbar.scss @@ -61,4 +61,5 @@ -moz-box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2); -webkit-box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2); } + } \ No newline at end of file diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss index 1c2235e5b..a344cb5ae 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/hawkbittheme.scss @@ -30,7 +30,13 @@ $v-selection-color: $app-selection-color; $v-app-background-color: $app-background-color; //Table header,body border colors are calculated based on this -$v-table-border-color: $widget-border-color; +$v-table-border-color: $widget-border-color ; + +$v-grid-border:$v-grid-border-size solid $widget-border-color ; +$v-grid-cell-vertical-border: 0px ; +$v-grid-cell-horizontal-border: 0px ; +$v-grid-cell-focused-border: 0px ; +$v-grid-cell-padding-horizontal:6px; @import '../valo/valo'; @import 'customstyles/table'; diff --git a/pom.xml b/pom.xml index d481a56fb..64a4f0431 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ 1.0.0 0.0.6.RELEASE - 7.5.10 + 7.6.3 ${vaadin.version} 7.4.0.1 2.2.0 @@ -382,6 +382,11 @@ vaadin-push ${vaadin.version} + + com.vaadin + vaadin-client + ${vaadin.version} + com.vaadin vaadin-themes