From 1aee32999f40c6441bb7307e6ccc5cd6a8547070 Mon Sep 17 00:00:00 2001 From: Bondar Bogdan <36962546+bogdan-bondar@users.noreply.github.com> Date: Thu, 2 Aug 2018 15:15:14 +0200 Subject: [PATCH] Feature update target attributes ui (#711) * Added update attributes button with label for status description to target attributes details tab * Positioned the request attributes update button to the upper right corner using absolute positioning * DDIFinalResult enum typo fix * PR review findings Signed-off-by: Bogdan Bondar --- .../hawkbit/ddi/json/model/DdiResult.java | 2 +- .../AbstractTableDetailsLayout.java | 18 ----- .../management/targettable/TargetDetails.java | 81 +++++++++++++++++-- .../ui/utils/UIComponentIdProvider.java | 5 ++ .../themes/hawkbit/customstyles/others.scss | 12 ++- .../src/main/resources/messages.properties | 4 + 6 files changed, 94 insertions(+), 28 deletions(-) diff --git a/hawkbit-rest/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/json/model/DdiResult.java b/hawkbit-rest/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/json/model/DdiResult.java index d5b2d8845..333d9a78a 100644 --- a/hawkbit-rest/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/json/model/DdiResult.java +++ b/hawkbit-rest/hawkbit-ddi-api/src/main/java/org/eclipse/hawkbit/ddi/json/model/DdiResult.java @@ -58,7 +58,7 @@ public class DdiResult { /** * Execution was successful. */ - SUCESS("success"), + SUCCESS("success"), /** * Execution terminated with errors or without the expected result. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 0ccc011f1..933ae44e0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -8,8 +8,6 @@ */ package org.eclipse.hawkbit.ui.common.detailslayout; -import java.util.Map; - import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; @@ -186,22 +184,6 @@ public abstract class AbstractTableDetailsLayout extends descriptionLayout.addComponent(descLabel); } - /* - * display Attributes details in Target details. - */ - protected void updateAttributesLayout(final Map attributes) { - if (null != attributes) { - attributesLayout.removeAllComponents(); - for (final Map.Entry entry : attributes.entrySet()) { - final Label conAttributeLabel = SPUIComponentProvider.createNameValueLabel( - entry.getKey().concat(" : "), entry.getValue() == null ? "" : entry.getValue()); - conAttributeLabel.setDescription(entry.getKey().concat(" : ") + entry.getValue()); - conAttributeLabel.addStyleName("label-style"); - attributesLayout.addComponent(conAttributeLabel); - } - } - } - protected VerticalLayout getLogLayout() { return logLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java index 5418a751f..b5ea69de4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetDetails.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.net.URI; +import java.util.Map; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.EntityFactory; @@ -21,6 +22,7 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout; import org.eclipse.hawkbit.ui.common.tagdetails.TargetTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorder; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; @@ -32,7 +34,9 @@ import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; +import com.vaadin.server.FontAwesome; import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; @@ -134,17 +138,20 @@ public class TargetDetails extends AbstractTableDetailsLayout { @Override protected void populateDetailsWidget() { if (getSelectedBaseEntity() != null) { - updateAttributesLayout(targetManagement.getControllerAttributes(getSelectedBaseEntity().getControllerId())); + final String controllerId = getSelectedBaseEntity().getControllerId(); - updateDetailsLayout(getSelectedBaseEntity().getControllerId(), getSelectedBaseEntity().getAddress(), + updateAttributesLayout(controllerId); + + updateDetailsLayout(controllerId, getSelectedBaseEntity().getAddress(), getSelectedBaseEntity().getSecurityToken(), SPDateTimeUtil.getFormattedDate(getSelectedBaseEntity().getLastTargetQuery())); - populateDistributionDtls(assignedDistLayout, deploymentManagement - .getAssignedDistributionSet(getSelectedBaseEntity().getControllerId()).orElse(null)); - populateDistributionDtls(installedDistLayout, deploymentManagement - .getInstalledDistributionSet(getSelectedBaseEntity().getControllerId()).orElse(null)); + populateDistributionDtls(assignedDistLayout, + deploymentManagement.getAssignedDistributionSet(controllerId).orElse(null)); + populateDistributionDtls(installedDistLayout, + deploymentManagement.getInstalledDistributionSet(controllerId).orElse(null)); } else { + updateAttributesLayout(null); updateDetailsLayout(null, null, null, null); populateDistributionDtls(installedDistLayout, null); populateDistributionDtls(assignedDistLayout, null); @@ -222,6 +229,68 @@ public class TargetDetails extends AbstractTableDetailsLayout { .forEach(module -> layout.addComponent(getSWModlabel(module.getType().getName(), module))); } + private void updateAttributesLayout(final String controllerId) { + final VerticalLayout attributesLayout = getAttributesLayout(); + attributesLayout.removeAllComponents(); + + if (controllerId == null) { + return; + } + + final Map attributes = targetManagement.getControllerAttributes(controllerId); + updateAttributesLabelsList(attributesLayout, attributes); + updateAttributesUpdateComponents(attributesLayout, controllerId); + } + + private void updateAttributesLabelsList(final VerticalLayout attributesLayout, + final Map attributes) { + for (final Map.Entry entry : attributes.entrySet()) { + final Label conAttributeLabel = SPUIComponentProvider.createNameValueLabel(entry.getKey().concat(" : "), + entry.getValue() == null ? "" : entry.getValue()); + conAttributeLabel.setDescription(entry.getKey().concat(" : ") + entry.getValue()); + conAttributeLabel.addStyleName("label-style"); + attributesLayout.addComponent(conAttributeLabel); + } + } + + private void updateAttributesUpdateComponents(final VerticalLayout attributesLayout, final String controllerId) { + final boolean isRequestAttributes = targetManagement.isControllerAttributesRequested(controllerId); + + if (isRequestAttributes) { + attributesLayout.addComponent(buildAttributesUpdateLabel(), 0); + } + + attributesLayout.addComponent(buildRequestAttributesUpdateButton(controllerId, isRequestAttributes)); + } + + private Label buildAttributesUpdateLabel() { + final Label attributesUpdateLabel = new Label(); + attributesUpdateLabel.setStyleName(ValoTheme.LABEL_SMALL); + attributesUpdateLabel.setValue(getI18n().getMessage("label.target.attributes.update.pending")); + + return attributesUpdateLabel; + } + + private Button buildRequestAttributesUpdateButton(final String controllerId, final boolean isRequestAttributes) { + final Button requestAttributesUpdateButton = SPUIComponentProvider.getButton( + UIComponentIdProvider.TARGET_ATTRIBUTES_UPDATE, "", "", "", false, FontAwesome.REFRESH, + SPUIButtonStyleNoBorder.class); + + requestAttributesUpdateButton.addClickListener(e -> targetManagement.requestControllerAttributes(controllerId)); + + if (isRequestAttributes) { + requestAttributesUpdateButton + .setDescription(getI18n().getMessage("tooltip.target.attributes.update.requested")); + requestAttributesUpdateButton.setEnabled(false); + } else { + requestAttributesUpdateButton + .setDescription(getI18n().getMessage("tooltip.target.attributes.update.request")); + requestAttributesUpdateButton.setEnabled(true); + } + + return requestAttributesUpdateButton; + } + /** * Create Label for SW Module. * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UIComponentIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UIComponentIdProvider.java index 9ddf23416..4dc8beaad 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UIComponentIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/UIComponentIdProvider.java @@ -639,6 +639,11 @@ public final class UIComponentIdProvider { */ public static final String TARGET_SECURITY_TOKEN = "target.security.token"; + /** + * Id of attributes update button in target details. + */ + public static final String TARGET_ATTRIBUTES_UPDATE = "target.attributes.update"; + /** * Id of maximize/minimize icon of table - Software module table. */ diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss index ed09af636..4dcc45098 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss @@ -293,8 +293,8 @@ background-repeat: no-repeat; } - .app-loading:before { - background: none; + .app-loading:before { + background: none; height: 20px !important; width: 20px !important; -webkit-box-sizing: border-box; @@ -313,5 +313,11 @@ position: fixed; margin-top: 12px; margin-left: -10px; - } + } + + #target\.attributes\.update { + position: absolute; + top: 12px; + right: 6px; + } } diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index 2d842a91e..4fa8aa9db 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -225,6 +225,7 @@ label.target.security.token = Security token : label.filter.by.status = Filter by Status label.filter.by.overdue = Filter by Overdue label.target.controller.attrs = Controller attributes +label.target.attributes.update.pending = Update pending.. label.target.lastpolldate = Last poll : label.tag.name = Tag name label.configuration.auth.header = Allow targets to authenticate via a certificate authenticated by an reverse proxy @@ -280,6 +281,9 @@ tooltip.artifact.icon=Show Artifact Details tooltip.click.to.edit = Click to edit tooltip.metadata.icon = Manage Metadata.. tooltip.next.maintenance.window = next on {0} +tooltip.target.attributes.update.request = Request attributes update +tooltip.target.attributes.update.requested = Update already requested + #rollout action tooltip.rollout.run = Run tooltip.rollout.approve = Approve