simple-ui: Also show target attributes in Target's view (#2304)

It is useful to see target attributes in the Target's view: for instance
SWUpdate can deliver values from the platform which identify some
features of it. This can include an arbitrary data, e.g. platform HW
revision, component's versions etc.
Thus, add a possibility to see those attributes in the dedicated view.

Signed-off-by: Oleksandr Andrushchenko <andr2000@gmail.com>
This commit is contained in:
Oleksandr Andrushchenko
2025-02-28 13:50:56 +02:00
committed by GitHub
parent 6bf85a2175
commit 970a434339
2 changed files with 16 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ public interface Constants {
String LAST_MODIFIED_BY = "Last modified by";
String LAST_MODIFIED_AT = "Last modified at";
String SECURITY_TOKEN = "Security Token";
String ATTRIBUTES = "Attributes";
// rollout
String GROUP_COUNT = "Group Count";

View File

@@ -14,6 +14,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
@@ -51,6 +52,7 @@ import org.eclipse.hawkbit.ui.simple.view.util.SelectionGrid;
import org.eclipse.hawkbit.ui.simple.view.util.TableView;
import org.eclipse.hawkbit.ui.simple.view.util.Utils;
import org.springframework.util.ObjectUtils;
import java.util.stream.Collectors;
@PageTitle("Targets")
@Route(value = "targets", layout = MainLayout.class)
@@ -73,7 +75,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
grid.addColumn(MgmtTarget::getTargetTypeName).setHeader(Constants.TYPE).setAutoWidth(true);
grid.setItemDetailsRenderer(new ComponentRenderer<>(
TargetDetails::new, TargetDetails::setItem));
() -> new TargetDetails(hawkbitClient), TargetDetails::setItem));
}
},
(query, filter) -> hawkbitClient.getTargetRestApi()
@@ -209,20 +211,23 @@ public class TargetView extends TableView<MgmtTarget, String> {
private static class TargetDetails extends FormLayout {
private final transient HawkbitMgmtClient hawkbitClient;
private final TextArea description = new TextArea(Constants.DESCRIPTION);
private final TextField createdBy = Utils.textField(Constants.CREATED_BY);
private final TextField createdAt = Utils.textField(Constants.CREATED_AT);
private final TextField lastModifiedBy = Utils.textField(Constants.LAST_MODIFIED_BY);
private final TextField lastModifiedAt = Utils.textField(Constants.LAST_MODIFIED_AT);
private final TextField securityToken = Utils.textField(Constants.SECURITY_TOKEN);
private final TextArea targetAttributes = new TextArea(Constants.ATTRIBUTES);
private TargetDetails() {
private TargetDetails(HawkbitMgmtClient hawkbitClient) {
this.hawkbitClient = hawkbitClient;
description.setMinLength(2);
Stream.of(
description,
createdBy, createdAt,
lastModifiedBy, lastModifiedAt,
securityToken)
securityToken, targetAttributes)
.forEach(field -> {
field.setReadOnly(true);
add(field);
@@ -239,6 +244,13 @@ public class TargetView extends TableView<MgmtTarget, String> {
lastModifiedBy.setValue(target.getLastModifiedBy());
lastModifiedAt.setValue(new Date(target.getLastModifiedAt()).toString());
securityToken.setValue(target.getSecurityToken());
var response = hawkbitClient.getTargetRestApi().getAttributes(target.getControllerId());
if (response.getStatusCode().is2xxSuccessful()) {
targetAttributes.setValue(Objects.requireNonNullElse(response.getBody(), Collections.emptyMap()).entrySet().stream().map(entry -> entry.getKey() + ": " +
entry.getValue()).collect(Collectors.joining("\n")));
} else {
targetAttributes.setValue("Error occurred fetching attributes from server: " + response.getStatusCode());
}
}
}