Simple UI for config (#1745)

* Add System config view

* Add System config view
This commit is contained in:
Manthan R. Tilva
2024-06-13 11:57:25 +05:30
committed by GitHub
parent 6022009525
commit 0916cc6960
4 changed files with 102 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTenantManagementRestApi;
import org.springframework.http.ResponseEntity;
import java.util.function.Supplier;
@@ -42,6 +43,7 @@ public class HawkbitMgmtClient {
private final MgmtTargetTagRestApi targetTagRestApi;
private final MgmtTargetFilterQueryRestApi targetFilterQueryRestApi;
private final MgmtRolloutRestApi rolloutRestApi;
private final MgmtTenantManagementRestApi tenantManagementRestApi;
HawkbitMgmtClient(final Tenant tenant, final HawkbitClient hawkbitClient) {
this.tenant = tenant;
@@ -57,6 +59,7 @@ public class HawkbitMgmtClient {
targetTagRestApi = service(MgmtTargetTagRestApi.class);
targetFilterQueryRestApi = service(MgmtTargetFilterQueryRestApi.class);
rolloutRestApi = service(MgmtRolloutRestApi.class);
tenantManagementRestApi = service(MgmtTenantManagementRestApi.class);
}
boolean hasSoftwareModulesRead() {
@@ -74,6 +77,9 @@ public class HawkbitMgmtClient {
boolean hasTargetRead() {
return hasRead(() -> targetRestApi.getTarget("_#ETE$ER"));
}
boolean hasConfigRead() {
return hasRead(() -> tenantManagementRestApi.getTenantConfigurationValue("_#ETE$ER"));
}
private boolean hasRead(final Supplier<ResponseEntity<?>> doCall) {
try {

View File

@@ -13,6 +13,7 @@ import org.eclipse.hawkbit.ui.simple.view.TargetView;
import org.eclipse.hawkbit.ui.simple.view.RolloutView;
import org.eclipse.hawkbit.ui.simple.security.AuthenticatedUser;
import org.eclipse.hawkbit.ui.simple.view.AboutView;
import org.eclipse.hawkbit.ui.simple.view.ConfigView;
import org.eclipse.hawkbit.ui.simple.view.DistributionSetView;
import org.eclipse.hawkbit.ui.simple.view.SoftwareModuleView;
import com.vaadin.flow.component.Unit;
@@ -102,6 +103,9 @@ public class MainLayout extends AppLayout {
if (accessChecker.hasAccess(SoftwareModuleView.class)) {
nav.addItem(new SideNavItem("Software Modules", SoftwareModuleView.class, VaadinIcon.FILE.create()));
}
if (accessChecker.hasAccess(ConfigView.class)) {
nav.addItem(new SideNavItem("Config", ConfigView.class, VaadinIcon.COG.create()));
}
if (accessChecker.hasAccess(AboutView.class)) {
nav.addItem(new SideNavItem("About", AboutView.class, VaadinIcon.INFO_CIRCLE.create()));
}

View File

@@ -110,6 +110,9 @@ public class SimpleUIApp implements AppShellConfigurator {
if (hawkbitClient.hasTargetRead()) {
roles.add("TARGET_READ");
}
if (hawkbitClient.hasConfigRead()) {
roles.add("CONFIG_READ");
}
} finally {
SecurityContextHolder.setContext(currentContext);
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.ui.simple.view;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.hawkbit.ui.simple.HawkbitMgmtClient;
import org.eclipse.hawkbit.ui.simple.MainLayout;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.RolesAllowed;
@PageTitle("Config")
@Route(value = "config", layout = MainLayout.class)
@RolesAllowed({ "CONFIG_READ" })
public class ConfigView extends VerticalLayout {
private final Map<String, MgmtSystemTenantConfigurationValueRequest> configValue = new HashMap();
public ConfigView(final HawkbitMgmtClient hawkbitClient) {
setSpacing(false);
Button saveButton = new Button("Save");
hawkbitClient.getTenantManagementRestApi().getTenantConfiguration().getBody().forEach((k, v) -> {
Component value = null;
if (v.getValue() instanceof String) {
TextField tf = new TextField(k, v.getValue().toString(), event -> {
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
vre.setValue(event.getValue());
configValue.put(k, vre);
});
tf.getElement().getStyle().set("width", "300px");
value = tf;
} else if (v.getValue() instanceof Boolean) {
value = new Checkbox(k, (Boolean) v.getValue(), event -> {
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
vre.setValue(event.getValue());
configValue.put(k, vre);
});
} else if (v.getValue() instanceof Long) {
Double d = (double) ((Long) v.getValue());
NumberField nf = new NumberField(k, d, event -> {
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
vre.setValue(event.getValue());
configValue.put(k, vre);
});
nf.getElement().getStyle().set("width", "300px");
value = nf;
} else if (v.getValue() instanceof Integer) {
Double d = (double) ((Integer) v.getValue());
NumberField nf = new NumberField(k, d, event -> {
MgmtSystemTenantConfigurationValueRequest vre = new MgmtSystemTenantConfigurationValueRequest();
vre.setValue(event.getValue());
configValue.put(k, vre);
});
nf.getElement().getStyle().set("width", "300px");
value = nf;
} else {
System.out.println(k + ":" + v);
}
if (value != null) {
add(value);
}
});
saveButton.addClickListener(click -> {
configValue.forEach((key, value) -> {
hawkbitClient.getTenantManagementRestApi().updateTenantConfigurationValue(key, value);
});
});
saveButton.addClickShortcut(Key.ENTER);
add(saveButton);
}
}