Provide target quicklinks from Target Filters and Rollout views to Deployment view (#1270)
* Adapted GridComponentBuilder#addControllerIdColumn to create a link * Do not hard-code target link ID prefix * Encode controller ID * Introduce HTML encoder for controller IDs * Remove unused imports
This commit is contained in:
@@ -10,8 +10,6 @@ package org.eclipse.hawkbit.ddi.json.model;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.ui.common.data.proxies.ProxyIdentifiableEntity;
|
|||||||
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyNamedEntity;
|
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyNamedEntity;
|
||||||
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
|
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyTarget;
|
||||||
import org.eclipse.hawkbit.ui.common.grid.support.DeleteSupport;
|
import org.eclipse.hawkbit.ui.common.grid.support.DeleteSupport;
|
||||||
|
import org.eclipse.hawkbit.ui.utils.ControllerIdHtmlEncoder;
|
||||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||||
import org.eclipse.hawkbit.ui.utils.UIMessageIdProvider;
|
import org.eclipse.hawkbit.ui.utils.UIMessageIdProvider;
|
||||||
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
|
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
|
||||||
@@ -34,6 +35,7 @@ import com.vaadin.ui.Component;
|
|||||||
import com.vaadin.ui.Grid;
|
import com.vaadin.ui.Grid;
|
||||||
import com.vaadin.ui.Grid.Column;
|
import com.vaadin.ui.Grid.Column;
|
||||||
import com.vaadin.ui.StyleGenerator;
|
import com.vaadin.ui.StyleGenerator;
|
||||||
|
import com.vaadin.ui.UI;
|
||||||
import com.vaadin.ui.components.grid.HeaderRow;
|
import com.vaadin.ui.components.grid.HeaderRow;
|
||||||
import com.vaadin.ui.themes.ValoTheme;
|
import com.vaadin.ui.themes.ValoTheme;
|
||||||
|
|
||||||
@@ -41,6 +43,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
|||||||
* Builder class for grid components
|
* Builder class for grid components
|
||||||
*/
|
*/
|
||||||
public final class GridComponentBuilder {
|
public final class GridComponentBuilder {
|
||||||
|
|
||||||
public static final double DEFAULT_MIN_WIDTH = 100D;
|
public static final double DEFAULT_MIN_WIDTH = 100D;
|
||||||
|
|
||||||
public static final String CREATED_BY_ID = "createdBy";
|
public static final String CREATED_BY_ID = "createdBy";
|
||||||
@@ -134,9 +137,17 @@ public final class GridComponentBuilder {
|
|||||||
* column ID
|
* column ID
|
||||||
* @return the created column
|
* @return the created column
|
||||||
*/
|
*/
|
||||||
public static Column<ProxyTarget, String> addControllerIdColumn(final Grid<ProxyTarget> grid,
|
public static Column<ProxyTarget, Button> addControllerIdColumn(final Grid<ProxyTarget> grid,
|
||||||
final VaadinMessageSource i18n, final String columnId) {
|
final VaadinMessageSource i18n, final String columnId) {
|
||||||
return addColumn(i18n, grid, ProxyTarget::getControllerId, "header.controllerId", columnId, DEFAULT_MIN_WIDTH);
|
return addComponentColumn(grid, t -> GridComponentBuilder.buildControllerIdLink(t, columnId)).setId(columnId)
|
||||||
|
.setCaption(i18n.getMessage("header.controllerId")).setHidable(false)
|
||||||
|
.setMinimumWidth(DEFAULT_MIN_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Button buildControllerIdLink(final ProxyTarget target, final String linkIdPrefix) {
|
||||||
|
final String idSuffix = ControllerIdHtmlEncoder.encode(target.getControllerId());
|
||||||
|
return buildLink(idSuffix, linkIdPrefix, target.getControllerId(), true, clickEvent -> UI.getCurrent()
|
||||||
|
.getNavigator().navigateTo("deployment/target=" + target.getControllerId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,8 +184,10 @@ public final class GridComponentBuilder {
|
|||||||
final List<Column<E, String>> columns = new ArrayList<>();
|
final List<Column<E, String>> columns = new ArrayList<>();
|
||||||
columns.add(addColumn(i18n, grid, E::getCreatedBy, "header.createdBy", CREATED_BY_ID, DEFAULT_MIN_WIDTH));
|
columns.add(addColumn(i18n, grid, E::getCreatedBy, "header.createdBy", CREATED_BY_ID, DEFAULT_MIN_WIDTH));
|
||||||
columns.add(addColumn(i18n, grid, E::getCreatedDate, "header.createdDate", CREATED_DATE_ID, DEFAULT_MIN_WIDTH));
|
columns.add(addColumn(i18n, grid, E::getCreatedDate, "header.createdDate", CREATED_DATE_ID, DEFAULT_MIN_WIDTH));
|
||||||
columns.add(addColumn(i18n, grid, E::getLastModifiedBy, "header.modifiedBy", MODIFIED_BY_ID, DEFAULT_MIN_WIDTH));
|
columns.add(
|
||||||
columns.add(addColumn(i18n, grid, E::getModifiedDate, "header.modifiedDate", MODIFIED_DATE_ID, DEFAULT_MIN_WIDTH));
|
addColumn(i18n, grid, E::getLastModifiedBy, "header.modifiedBy", MODIFIED_BY_ID, DEFAULT_MIN_WIDTH));
|
||||||
|
columns.add(
|
||||||
|
addColumn(i18n, grid, E::getModifiedDate, "header.modifiedDate", MODIFIED_DATE_ID, DEFAULT_MIN_WIDTH));
|
||||||
return columns;
|
return columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,4 +458,5 @@ public final class GridComponentBuilder {
|
|||||||
|
|
||||||
return actionButton;
|
return actionButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ public class TargetGrid extends AbstractGrid<ProxyTarget, TargetManagementFilter
|
|||||||
Arrays.asList(addPinColumn(), addDeleteColumn()));
|
Arrays.asList(addPinColumn(), addDeleteColumn()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Column<ProxyTarget, String> addControllerIdColumn() {
|
private Column<ProxyTarget, Button> addControllerIdColumn() {
|
||||||
return GridComponentBuilder.addControllerIdColumn(this, i18n, TARGET_CONTROLLER_ID);
|
return GridComponentBuilder.addControllerIdColumn(this, i18n, TARGET_CONTROLLER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2022 Bosch.IO 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.utils;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Base64.Encoder;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes controller IDs to make them embeddable into HTML as element
|
||||||
|
* identifiers.
|
||||||
|
*/
|
||||||
|
public class ControllerIdHtmlEncoder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base64 encoder which suppresses trailing padding characters.
|
||||||
|
*/
|
||||||
|
private static Encoder BASE64 = Base64.getEncoder().withoutPadding();
|
||||||
|
|
||||||
|
private ControllerIdHtmlEncoder() {
|
||||||
|
// class should not be instantiated
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes the given controller ID so that it can be used as part of DOM
|
||||||
|
* element IDs.
|
||||||
|
*
|
||||||
|
* @param controllerId
|
||||||
|
* The controller ID to be encoded. Must not be
|
||||||
|
* <code>null</code>.
|
||||||
|
*
|
||||||
|
* @return The encoded controller ID.
|
||||||
|
*/
|
||||||
|
public static String encode(final String controllerId) {
|
||||||
|
Objects.requireNonNull(controllerId);
|
||||||
|
return BASE64.encodeToString(controllerId.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user