Fix some sonar findings (#2433)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -48,5 +48,9 @@ public interface Constants {
|
|||||||
String AUTO = "Auto";
|
String AUTO = "Auto";
|
||||||
String DYNAMIC = "Dynamic";
|
String DYNAMIC = "Dynamic";
|
||||||
|
|
||||||
|
// dialog
|
||||||
|
String CANCEL = "Cancel";
|
||||||
|
String CANCEL_ESC = "Cancel (Esc)";
|
||||||
|
|
||||||
String NAME_ASC = "name:asc";
|
String NAME_ASC = "name:asc";
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ public class DistributionSetView extends TableView<MgmtDistributionSet, Long> {
|
|||||||
create.setEnabled(false);
|
create.setEnabled(false);
|
||||||
addCreateClickListener();
|
addCreateClickListener();
|
||||||
create.addClickShortcut(Key.ENTER);
|
create.addClickShortcut(Key.ENTER);
|
||||||
final Button cancel = Utils.tooltip(new Button("Cancel"), "Cancel (Esc)");
|
final Button cancel = Utils.tooltip(new Button(CANCEL), CANCEL_ESC);
|
||||||
cancel.addClickListener(e -> close());
|
cancel.addClickListener(e -> close());
|
||||||
create.addClickShortcut(Key.ESCAPE);
|
create.addClickShortcut(Key.ESCAPE);
|
||||||
create.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
create.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ public class RolloutView extends TableView<MgmtRolloutResponseBody, Long> {
|
|||||||
create.setEnabled(false);
|
create.setEnabled(false);
|
||||||
create.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
create.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
addCreateClickListener(hawkbitClient);
|
addCreateClickListener(hawkbitClient);
|
||||||
final Button cancel = Utils.tooltip(new Button("Cancel"), "Cancel (Esc)");
|
final Button cancel = Utils.tooltip(new Button(CANCEL), CANCEL_ESC);
|
||||||
cancel.addClickListener(e -> close());
|
cancel.addClickListener(e -> close());
|
||||||
cancel.addClickShortcut(Key.ESCAPE);
|
cancel.addClickShortcut(Key.ESCAPE);
|
||||||
getFooter().add(cancel);
|
getFooter().add(cancel);
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ public class SoftwareModuleView extends TableView<MgmtSoftwareModule, Long> {
|
|||||||
addCreateClickListener(hawkbitClient);
|
addCreateClickListener(hawkbitClient);
|
||||||
create.addClickShortcut(Key.ENTER);
|
create.addClickShortcut(Key.ENTER);
|
||||||
create.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
create.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
final Button cancel = Utils.tooltip(new Button("Cancel"), "Cancel (Esc)");
|
final Button cancel = Utils.tooltip(new Button(CANCEL), CANCEL_ESC);
|
||||||
cancel.addClickListener(e -> close());
|
cancel.addClickListener(e -> close());
|
||||||
cancel.addClickShortcut(Key.ESCAPE);
|
cancel.addClickShortcut(Key.ESCAPE);
|
||||||
getFooter().add(cancel);
|
getFooter().add(cancel);
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ import com.vaadin.flow.router.PageTitle;
|
|||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.shared.Registration;
|
import com.vaadin.flow.shared.Registration;
|
||||||
import com.vaadin.flow.theme.lumo.LumoUtility;
|
import com.vaadin.flow.theme.lumo.LumoUtility;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtPollStatus;
|
import org.eclipse.hawkbit.mgmt.json.model.MgmtPollStatus;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
|
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
|
||||||
@@ -70,6 +71,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentR
|
|||||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
|
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
|
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
|
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
|
||||||
|
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAttributes;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
|
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
|
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
|
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
|
||||||
@@ -101,7 +103,9 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addColumns(final Grid<MgmtTarget> grid) {
|
protected void addColumns(final Grid<MgmtTarget> grid) {
|
||||||
grid.addColumn(new ComponentRenderer<Component, MgmtTarget>(TargetStatusCell::new)).setHeader(STATUS).setAutoWidth(true)
|
grid.addColumn(new ComponentRenderer<>(TargetStatusCell::new))
|
||||||
|
.setHeader(STATUS)
|
||||||
|
.setAutoWidth(true)
|
||||||
.setFlexGrow(0);
|
.setFlexGrow(0);
|
||||||
grid.addColumn(MgmtTarget::getControllerId).setHeader(CONTROLLER_ID).setAutoWidth(true);
|
grid.addColumn(MgmtTarget::getControllerId).setHeader(CONTROLLER_ID).setAutoWidth(true);
|
||||||
grid.addColumn(MgmtTarget::getName).setHeader(Constants.NAME).setAutoWidth(true);
|
grid.addColumn(MgmtTarget::getName).setHeader(Constants.NAME).setAutoWidth(true);
|
||||||
@@ -109,34 +113,29 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(query, filter) -> hawkbitClient.getTargetRestApi()
|
(query, filter) -> hawkbitClient.getTargetRestApi()
|
||||||
.getTargets(
|
.getTargets(query.getOffset(), query.getPageSize(), Constants.NAME_ASC, filter)
|
||||||
query.getOffset(), query.getPageSize(), Constants.NAME_ASC,
|
|
||||||
filter
|
|
||||||
)
|
|
||||||
.getBody()
|
.getBody()
|
||||||
.getContent()
|
.getContent()
|
||||||
.stream(),
|
.stream(),
|
||||||
source -> new RegisterDialog(hawkbitClient).result(),
|
source -> new RegisterDialog(hawkbitClient).result(),
|
||||||
selectionGrid -> {
|
selectionGrid -> {
|
||||||
selectionGrid.getSelectedItems().forEach(toDelete ->
|
selectionGrid.getSelectedItems()
|
||||||
hawkbitClient.getTargetRestApi().deleteTarget(toDelete.getControllerId()));
|
.forEach(toDelete -> hawkbitClient.getTargetRestApi().deleteTarget(toDelete.getControllerId()));
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
},
|
},
|
||||||
(target) -> {
|
target -> {
|
||||||
var targetDetailedView = new TargetDetailedView(hawkbitClient);
|
final TargetDetailedView targetDetailedView = new TargetDetailedView(hawkbitClient);
|
||||||
targetDetailedView.setItem(target);
|
targetDetailedView.setItem(target);
|
||||||
return targetDetailedView;
|
return targetDetailedView;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Function<SelectionGrid<MgmtTarget, String>, CompletionStage<Void>> assignHandler = source -> new AssignDialog(
|
final Function<SelectionGrid<MgmtTarget, String>, CompletionStage<Void>> assignHandler =
|
||||||
hawkbitClient, source.getSelectedItems()).result();
|
source -> new AssignDialog(hawkbitClient, source.getSelectedItems()).result();
|
||||||
|
|
||||||
final Button assignBtn = Utils.tooltip(new Button(VaadinIcon.LINK.create()), "Assign");
|
final Button assignBtn = Utils.tooltip(new Button(VaadinIcon.LINK.create()), "Assign");
|
||||||
assignBtn.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
assignBtn.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
assignBtn.addClickListener(e -> assignHandler
|
assignBtn.addClickListener(e -> assignHandler.apply(selectionGrid).thenAccept(v -> selectionGrid.refreshGrid(false)));
|
||||||
.apply(selectionGrid)
|
|
||||||
.thenAccept(v -> selectionGrid.refreshGrid(false)));
|
|
||||||
controlsLayout.addComponentAtIndex(0, assignBtn);
|
controlsLayout.addComponentAtIndex(0, assignBtn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +180,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
"controllerid", controllerId.getOptionalValue(),
|
"controllerid", controllerId.getOptionalValue(),
|
||||||
"targettype.name", type.getSelectedItems().stream().map(MgmtTargetType::getName)
|
"targettype.name", type.getSelectedItems().stream().map(MgmtTargetType::getName)
|
||||||
.toList(),
|
.toList(),
|
||||||
"tag", tag.getSelectedItems()
|
"tag", tag.getSelectedItems()));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,8 +210,8 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
});
|
});
|
||||||
savedFilters.setEmptySelectionAllowed(true);
|
savedFilters.setEmptySelectionAllowed(true);
|
||||||
savedFilters.setItems(listFilters(hawkbitClient));
|
savedFilters.setItems(listFilters(hawkbitClient));
|
||||||
savedFilters.setItemLabelGenerator(
|
savedFilters.setItemLabelGenerator(query ->
|
||||||
query -> Optional.ofNullable(query).map(MgmtTargetFilterQuery::getName).orElse("<select saved filter>"));
|
Optional.ofNullable(query).map(MgmtTargetFilterQuery::getName).orElse("<select saved filter>"));
|
||||||
savedFilters.setWidthFull();
|
savedFilters.setWidthFull();
|
||||||
|
|
||||||
textFilter.setWidthFull();
|
textFilter.setWidthFull();
|
||||||
@@ -230,81 +228,72 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<MgmtTargetFilterQuery> listFilters(HawkbitMgmtClient hawkbitClient) {
|
private static List<MgmtTargetFilterQuery> listFilters(HawkbitMgmtClient hawkbitClient) {
|
||||||
return Optional.ofNullable(
|
return Optional
|
||||||
hawkbitClient.getTargetFilterQueryRestApi()
|
.ofNullable(
|
||||||
.getFilters(0, 30, null, null, null)
|
hawkbitClient.getTargetFilterQueryRestApi()
|
||||||
.getBody().getContent()
|
.getFilters(0, 30, null, null, null)
|
||||||
).orElse(Collections.emptyList());
|
.getBody()
|
||||||
|
.getContent())
|
||||||
|
.orElse(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ComponentEventListener<ClickEvent<Button>> createBtnListener(HawkbitMgmtClient hawkbitClient) {
|
private ComponentEventListener<ClickEvent<Button>> createBtnListener(HawkbitMgmtClient hawkbitClient) {
|
||||||
return e ->
|
return e ->
|
||||||
new Utils.BaseDialog<Void>("Create New Filter") {
|
new Utils.BaseDialog<Void>("Create New Filter") {{
|
||||||
|
final Button finishBtn = Utils.tooltip(new Button("Save"), "Save (Enter)");
|
||||||
{
|
final TextField name = Utils.textField(Constants.NAME, e -> finishBtn.setEnabled(!e.getHasValue().isEmpty()));
|
||||||
final Button finishBtn = Utils.tooltip(new Button("Save"), "Save (Enter)");
|
name.focus();
|
||||||
final TextField name = Utils.textField(
|
finishBtn.addClickShortcut(Key.ENTER);
|
||||||
Constants.NAME,
|
finishBtn.setEnabled(false);
|
||||||
e -> finishBtn.setEnabled(!e.getHasValue().isEmpty())
|
finishBtn.addClickListener(e -> {
|
||||||
);
|
final MgmtTargetFilterQueryRequestBody createRequest = new MgmtTargetFilterQueryRequestBody();
|
||||||
name.focus();
|
createRequest.setName(name.getValue());
|
||||||
finishBtn.addClickShortcut(Key.ENTER);
|
createRequest.setQuery(textFilter.getValue());
|
||||||
finishBtn.setEnabled(false);
|
hawkbitClient.getTargetFilterQueryRestApi().createFilter(createRequest);
|
||||||
finishBtn.addClickListener(e -> {
|
savedFilters.setItems(listFilters(hawkbitClient));
|
||||||
final MgmtTargetFilterQueryRequestBody createRequest = new MgmtTargetFilterQueryRequestBody();
|
close();
|
||||||
createRequest.setName(name.getValue());
|
});
|
||||||
createRequest.setQuery(textFilter.getValue());
|
getFooter().add(finishBtn);
|
||||||
hawkbitClient.getTargetFilterQueryRestApi().createFilter(createRequest);
|
add(name);
|
||||||
savedFilters.setItems(
|
open();
|
||||||
listFilters(hawkbitClient));
|
}};
|
||||||
close();
|
|
||||||
});
|
|
||||||
getFooter().add(finishBtn);
|
|
||||||
add(name);
|
|
||||||
open();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ComponentEventListener<ClickEvent<Button>> updateBtnListener(HawkbitMgmtClient hawkbitClient) {
|
private ComponentEventListener<ClickEvent<Button>> updateBtnListener(HawkbitMgmtClient hawkbitClient) {
|
||||||
return e -> {
|
return e -> {
|
||||||
final MgmtTargetFilterQuery selected = savedFilters.getValue();
|
final MgmtTargetFilterQuery selected = savedFilters.getValue();
|
||||||
if (selected == null) return;
|
if (selected == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
new Utils.BaseDialog<Void>("Update Filter") {
|
new Utils.BaseDialog<Void>("Update Filter") {{
|
||||||
|
final Button finishBtn = Utils.tooltip(new Button("Update"), "Update (Enter)");
|
||||||
|
finishBtn.setEnabled(false);
|
||||||
|
|
||||||
{
|
final TextField name = Utils.textField(Constants.NAME, e -> finishBtn.setEnabled(!e.getHasValue().isEmpty()));
|
||||||
final Button finishBtn = Utils.tooltip(new Button("Update"), "Update (Enter)");
|
name.focus();
|
||||||
finishBtn.setEnabled(false);
|
name.setValue(selected.getName());
|
||||||
|
|
||||||
final TextField name = Utils.textField(
|
final TextArea filterValue = new TextArea("Filter Value");
|
||||||
Constants.NAME,
|
filterValue.setReadOnly(true);
|
||||||
e -> finishBtn.setEnabled(!e.getHasValue().isEmpty())
|
filterValue.setValue(textFilter.getValue());
|
||||||
);
|
filterValue.setWidthFull();
|
||||||
name.focus();
|
|
||||||
name.setValue(selected.getName());
|
|
||||||
|
|
||||||
final TextArea filterValue = new TextArea("Filter Value");
|
finishBtn.addClickShortcut(Key.ENTER);
|
||||||
filterValue.setReadOnly(true);
|
finishBtn.addClickListener(e -> {
|
||||||
filterValue.setValue(textFilter.getValue());
|
final MgmtTargetFilterQueryRequestBody updateRequest = new MgmtTargetFilterQueryRequestBody();
|
||||||
filterValue.setWidthFull();
|
updateRequest.setName(name.getValue());
|
||||||
|
updateRequest.setQuery(textFilter.getValue());
|
||||||
|
hawkbitClient.getTargetFilterQueryRestApi().updateFilter(selected.getId(), updateRequest);
|
||||||
|
savedFilters.setItems(listFilters(hawkbitClient));
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
getFooter().add(finishBtn);
|
||||||
|
|
||||||
finishBtn.addClickShortcut(Key.ENTER);
|
add(name);
|
||||||
finishBtn.addClickListener(e -> {
|
add(filterValue);
|
||||||
final MgmtTargetFilterQueryRequestBody updateRequest = new MgmtTargetFilterQueryRequestBody();
|
open();
|
||||||
updateRequest.setName(name.getValue());
|
}};
|
||||||
updateRequest.setQuery(textFilter.getValue());
|
|
||||||
hawkbitClient.getTargetFilterQueryRestApi().updateFilter(selected.getId(), updateRequest);
|
|
||||||
savedFilters.setItems(listFilters(hawkbitClient));
|
|
||||||
close();
|
|
||||||
});
|
|
||||||
getFooter().add(finishBtn);
|
|
||||||
|
|
||||||
add(name);
|
|
||||||
add(filterValue);
|
|
||||||
open();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +315,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
private final TargetTags targetTags;
|
private final TargetTags targetTags;
|
||||||
private final TargetActions targetActions;
|
private final TargetActions targetActions;
|
||||||
|
|
||||||
private TargetDetailedView(HawkbitMgmtClient hawkbitClient) {
|
private TargetDetailedView(final HawkbitMgmtClient hawkbitClient) {
|
||||||
targetDetails = new TargetDetails(hawkbitClient);
|
targetDetails = new TargetDetails(hawkbitClient);
|
||||||
targetAssignedInstalled = new TargetAssignedInstalled(hawkbitClient);
|
targetAssignedInstalled = new TargetAssignedInstalled(hawkbitClient);
|
||||||
targetTags = new TargetTags(hawkbitClient);
|
targetTags = new TargetTags(hawkbitClient);
|
||||||
@@ -357,17 +346,16 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
private final TextField lastModifiedAt = Utils.textField(Constants.LAST_MODIFIED_AT);
|
private final TextField lastModifiedAt = Utils.textField(Constants.LAST_MODIFIED_AT);
|
||||||
private final TextField securityToken = Utils.textField(Constants.SECURITY_TOKEN);
|
private final TextField securityToken = Utils.textField(Constants.SECURITY_TOKEN);
|
||||||
private final TextArea targetAttributes = new TextArea(Constants.ATTRIBUTES);
|
private final TextArea targetAttributes = new TextArea(Constants.ATTRIBUTES);
|
||||||
private MgmtTarget target;
|
private transient MgmtTarget target;
|
||||||
|
|
||||||
private TargetDetails(HawkbitMgmtClient hawkbitClient) {
|
private TargetDetails(final HawkbitMgmtClient hawkbitClient) {
|
||||||
this.hawkbitClient = hawkbitClient;
|
this.hawkbitClient = hawkbitClient;
|
||||||
description.setMinLength(2);
|
description.setMinLength(2);
|
||||||
Stream.of(
|
Stream.of(
|
||||||
description,
|
description,
|
||||||
createdBy, createdAt,
|
createdBy, createdAt,
|
||||||
lastModifiedBy, lastModifiedAt,
|
lastModifiedBy, lastModifiedAt,
|
||||||
securityToken, targetAttributes
|
securityToken, targetAttributes)
|
||||||
)
|
|
||||||
.forEach(field -> {
|
.forEach(field -> {
|
||||||
field.setReadOnly(true);
|
field.setReadOnly(true);
|
||||||
add(field);
|
add(field);
|
||||||
@@ -382,18 +370,18 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttach(AttachEvent attachEvent) {
|
protected void onAttach(final AttachEvent attachEvent) {
|
||||||
description.setValue(target.getDescription() == null ? "N/A" : target.getDescription());
|
description.setValue(target.getDescription() == null ? "N/A" : target.getDescription());
|
||||||
createdBy.setValue(target.getCreatedBy());
|
createdBy.setValue(target.getCreatedBy());
|
||||||
createdAt.setValue(new Date(target.getCreatedAt()).toString());
|
createdAt.setValue(new Date(target.getCreatedAt()).toString());
|
||||||
lastModifiedBy.setValue(target.getLastModifiedBy());
|
lastModifiedBy.setValue(target.getLastModifiedBy());
|
||||||
lastModifiedAt.setValue(new Date(target.getLastModifiedAt()).toString());
|
lastModifiedAt.setValue(new Date(target.getLastModifiedAt()).toString());
|
||||||
securityToken.setValue(target.getSecurityToken());
|
securityToken.setValue(target.getSecurityToken());
|
||||||
var response = hawkbitClient.getTargetRestApi().getAttributes(target.getControllerId());
|
final ResponseEntity<MgmtTargetAttributes> response = hawkbitClient.getTargetRestApi().getAttributes(target.getControllerId());
|
||||||
if (response.getStatusCode().is2xxSuccessful()) {
|
if (response.getStatusCode().is2xxSuccessful()) {
|
||||||
targetAttributes.setValue(Objects.requireNonNullElse(response.getBody(), Collections.emptyMap()).entrySet().stream()
|
targetAttributes.setValue(Objects.requireNonNullElse(response.getBody(), Collections.emptyMap()).entrySet().stream()
|
||||||
.map(entry -> entry.getKey() + ": " +
|
.map(entry -> entry.getKey() + ": " + entry.getValue())
|
||||||
entry.getValue()).collect(Collectors.joining("\n")));
|
.collect(Collectors.joining("\n")));
|
||||||
} else {
|
} else {
|
||||||
targetAttributes.setValue("Error occurred fetching attributes from server: " + response.getStatusCode());
|
targetAttributes.setValue("Error occurred fetching attributes from server: " + response.getStatusCode());
|
||||||
}
|
}
|
||||||
@@ -405,7 +393,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
private final transient HawkbitMgmtClient hawkbitClient;
|
private final transient HawkbitMgmtClient hawkbitClient;
|
||||||
private final TextArea assigned = new TextArea("Assigned Distribution Set");
|
private final TextArea assigned = new TextArea("Assigned Distribution Set");
|
||||||
private final TextArea installed = new TextArea("Installed Distribution Set");
|
private final TextArea installed = new TextArea("Installed Distribution Set");
|
||||||
private MgmtTarget target;
|
private transient MgmtTarget target;
|
||||||
|
|
||||||
private TargetAssignedInstalled(HawkbitMgmtClient hawkbitClient) {
|
private TargetAssignedInstalled(HawkbitMgmtClient hawkbitClient) {
|
||||||
this.hawkbitClient = hawkbitClient;
|
this.hawkbitClient = hawkbitClient;
|
||||||
@@ -423,14 +411,8 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttach(AttachEvent attachEvent) {
|
protected void onAttach(AttachEvent attachEvent) {
|
||||||
updateDistributionSetInfo(
|
updateDistributionSetInfo(() -> hawkbitClient.getTargetRestApi().getInstalledDistributionSet(target.getControllerId()), installed);
|
||||||
() -> hawkbitClient.getTargetRestApi().getInstalledDistributionSet(target.getControllerId()),
|
updateDistributionSetInfo(() -> hawkbitClient.getTargetRestApi().getAssignedDistributionSet(target.getControllerId()), assigned);
|
||||||
installed
|
|
||||||
);
|
|
||||||
updateDistributionSetInfo(
|
|
||||||
() -> hawkbitClient.getTargetRestApi().getAssignedDistributionSet(target.getControllerId()),
|
|
||||||
assigned
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDistributionSetInfo(Supplier<ResponseEntity<MgmtDistributionSet>> supplier, TextArea textArea) {
|
private void updateDistributionSetInfo(Supplier<ResponseEntity<MgmtDistributionSet>> supplier, TextArea textArea) {
|
||||||
@@ -441,7 +423,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
Name: %s
|
Name: %s
|
||||||
Version: %s
|
Version: %s
|
||||||
%s
|
%s
|
||||||
""".replaceAll("\n", System.lineSeparator());
|
""".replace("\n", System.lineSeparator());
|
||||||
textArea.setValue(description.formatted(
|
textArea.setValue(description.formatted(
|
||||||
value.getName(),
|
value.getName(),
|
||||||
value.getVersion(),
|
value.getVersion(),
|
||||||
@@ -458,7 +440,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
private final ComboBox<MgmtTag> tagSelector = new ComboBox<>(TAG);
|
private final ComboBox<MgmtTag> tagSelector = new ComboBox<>(TAG);
|
||||||
private final HorizontalLayout tagsArea = new HorizontalLayout();
|
private final HorizontalLayout tagsArea = new HorizontalLayout();
|
||||||
private Registration changeListener;
|
private Registration changeListener;
|
||||||
private MgmtTarget target;
|
private transient MgmtTarget target;
|
||||||
|
|
||||||
private TargetTags(HawkbitMgmtClient hawkbitClient) {
|
private TargetTags(HawkbitMgmtClient hawkbitClient) {
|
||||||
this.hawkbitClient = hawkbitClient;
|
this.hawkbitClient = hawkbitClient;
|
||||||
@@ -478,9 +460,8 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
|
|
||||||
private HorizontalLayout buildTagSelectionLayout(HawkbitMgmtClient hawkbitClient) {
|
private HorizontalLayout buildTagSelectionLayout(HawkbitMgmtClient hawkbitClient) {
|
||||||
final Button createTagButton = new Button("Create Tag");
|
final Button createTagButton = new Button("Create Tag");
|
||||||
createTagButton.addClickListener(event -> {
|
createTagButton.addClickListener(event ->
|
||||||
new CreateTagDialog(hawkbitClient, () -> tagSelector.setItems(fetchAvailableTags())).result();
|
new CreateTagDialog(hawkbitClient, () -> tagSelector.setItems(fetchAvailableTags())).result());
|
||||||
});
|
|
||||||
|
|
||||||
tagSelector.setWidthFull();
|
tagSelector.setWidthFull();
|
||||||
tagSelector.setItemLabelGenerator(MgmtTag::getName);
|
tagSelector.setItemLabelGenerator(MgmtTag::getName);
|
||||||
@@ -565,29 +546,25 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
private static class TargetActions extends Grid<TargetActions.ActionStatusEntry> {
|
private static class TargetActions extends Grid<TargetActions.ActionStatusEntry> {
|
||||||
|
|
||||||
private final transient HawkbitMgmtClient hawkbitClient;
|
private final transient HawkbitMgmtClient hawkbitClient;
|
||||||
private MgmtTarget target;
|
private transient MgmtTarget target;
|
||||||
|
|
||||||
private TargetActions(HawkbitMgmtClient hawkbitClient) {
|
private TargetActions(final HawkbitMgmtClient hawkbitClient) {
|
||||||
this.hawkbitClient = hawkbitClient;
|
this.hawkbitClient = hawkbitClient;
|
||||||
setWidthFull();
|
setWidthFull();
|
||||||
addColumn(new ComponentRenderer<Component, ActionStatusEntry>(ActionStatusEntry::getStatusIcon)).setHeader("Status")
|
addColumn(new ComponentRenderer<>(ActionStatusEntry::getStatusIcon)).setHeader(STATUS).setAutoWidth(true).setFlexGrow(0);
|
||||||
.setAutoWidth(true)
|
|
||||||
.setFlexGrow(0);
|
|
||||||
addColumn(ActionStatusEntry::getDistributionSetName).setHeader("Distribution Set").setAutoWidth(true);
|
addColumn(ActionStatusEntry::getDistributionSetName).setHeader("Distribution Set").setAutoWidth(true);
|
||||||
addColumn(ActionStatusEntry::getLastModifiedAt).setHeader("Last Modified").setAutoWidth(true)
|
addColumn(ActionStatusEntry::getLastModifiedAt)
|
||||||
.setFlexGrow(0).setComparator(ActionStatusEntry::getLastModifiedAt);
|
.setHeader("Last Modified")
|
||||||
addColumn(new ComponentRenderer<Component, ActionStatusEntry>(ActionStatusEntry::getForceTypeIcon)).setHeader("Type")
|
|
||||||
.setAutoWidth(true)
|
.setAutoWidth(true)
|
||||||
.setFlexGrow(0);
|
.setFlexGrow(0)
|
||||||
addColumn(new ComponentRenderer<Component, ActionStatusEntry>(ActionStatusEntry::getActionsLayout)).setHeader("Actions")
|
.setComparator(ActionStatusEntry::getLastModifiedAt);
|
||||||
.setAutoWidth(true)
|
addColumn(new ComponentRenderer<>(ActionStatusEntry::getForceTypeIcon)).setHeader("Type").setAutoWidth(true).setFlexGrow(0);
|
||||||
.setFlexGrow(0);
|
addColumn(new ComponentRenderer<>(ActionStatusEntry::getActionsLayout)).setHeader("Actions").setAutoWidth(true).setFlexGrow(0);
|
||||||
addColumn(new ComponentRenderer<Component, ActionStatusEntry>(ActionStatusEntry::getForceQuitLayout)).setHeader("Force Quit")
|
addColumn(new ComponentRenderer<>(ActionStatusEntry::getForceQuitLayout)).setHeader("Force Quit").setAutoWidth(true).setFlexGrow(0);
|
||||||
.setAutoWidth(true)
|
|
||||||
.setFlexGrow(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setItem(final MgmtTarget target) {
|
private void setItem(final MgmtTarget target) {
|
||||||
@@ -595,13 +572,13 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<ActionStatusEntry> fetchActions() {
|
private List<ActionStatusEntry> fetchActions() {
|
||||||
return this.hawkbitClient.getTargetRestApi().getActionHistory(target.getControllerId(), 0, 30, null, null)
|
return hawkbitClient.getTargetRestApi().getActionHistory(target.getControllerId(), 0, 30, null, null)
|
||||||
.getBody()
|
.getBody()
|
||||||
.getContent()
|
.getContent()
|
||||||
.stream()
|
.stream()
|
||||||
.map(action -> new ActionStatusEntry(action, () -> setItems(fetchActions())))
|
.map(action -> new ActionStatusEntry(action, () -> setItems(fetchActions())))
|
||||||
.filter(value -> value.action != null)
|
.filter(value -> value.action != null)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -611,15 +588,15 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
|
|
||||||
private class ActionStatusEntry {
|
private class ActionStatusEntry {
|
||||||
|
|
||||||
MgmtAction action;
|
final MgmtAction action;
|
||||||
|
final Runnable onUpdate;
|
||||||
MgmtDistributionSet distributionSet;
|
MgmtDistributionSet distributionSet;
|
||||||
Runnable onUpdate;
|
|
||||||
|
|
||||||
public ActionStatusEntry(MgmtAction mgmtAction, Runnable onUpdate) {
|
public ActionStatusEntry(final MgmtAction mgmtAction, final Runnable onUpdate) {
|
||||||
this.action = hawkbitClient.getActionRestApi().getAction(mgmtAction.getId()).getBody();
|
this.action = hawkbitClient.getActionRestApi().getAction(mgmtAction.getId()).getBody();
|
||||||
this.onUpdate = onUpdate;
|
this.onUpdate = onUpdate;
|
||||||
if (action == null) {
|
if (action == null) {
|
||||||
LoggerFactory.getLogger(ActionStatusEntry.class).error("Unable to fetch the action with id : {}", mgmtAction.getId());
|
log.error("Unable to fetch the action with id : {}", mgmtAction.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.action.getLink("distributionset").ifPresent(link -> {
|
this.action.getLink("distributionset").ifPresent(link -> {
|
||||||
@@ -627,22 +604,22 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
Long dsId = Long.parseLong(link.getHref().substring(link.getHref().lastIndexOf("/") + 1));
|
Long dsId = Long.parseLong(link.getHref().substring(link.getHref().lastIndexOf("/") + 1));
|
||||||
this.distributionSet = hawkbitClient.getDistributionSetRestApi().getDistributionSet(dsId).getBody();
|
this.distributionSet = hawkbitClient.getDistributionSetRestApi().getDistributionSet(dsId).getBody();
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LoggerFactory.getLogger(ActionStatusEntry.class).error("Error parsing distribution set ID", e);
|
log.error("Error parsing distribution set ID", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean isActive() {
|
private boolean isActive() {
|
||||||
return action.getStatus().equals(MgmtAction.ACTION_PENDING);
|
return action.getStatus().equals(MgmtAction.ACTION_PENDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean isCancelingOrCanceled() {
|
private boolean isCancelingOrCanceled() {
|
||||||
return action.getType().equals(MgmtAction.ACTION_CANCEL);
|
return action.getType().equals(MgmtAction.ACTION_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getStatusIcon() {
|
public Component getStatusIcon() {
|
||||||
HorizontalLayout layout = new HorizontalLayout();
|
final HorizontalLayout layout = new HorizontalLayout();
|
||||||
Icon icon;
|
final Icon icon;
|
||||||
if (isActive()) {
|
if (isActive()) {
|
||||||
if (isCancelingOrCanceled()) {
|
if (isCancelingOrCanceled()) {
|
||||||
icon = Utils.tooltip(VaadinIcon.ADJUST.create(), "Pending Cancellation");
|
icon = Utils.tooltip(VaadinIcon.ADJUST.create(), "Pending Cancellation");
|
||||||
@@ -667,7 +644,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getDistributionSetName() {
|
public String getDistributionSetName() {
|
||||||
return distributionSet != null ? distributionSet.getName() : "Distribution Set not found";
|
return Optional.ofNullable(distributionSet).map(MgmtDistributionSet::getName).orElse("Distribution Set not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Instant getLastModifiedAt() {
|
public Instant getLastModifiedAt() {
|
||||||
@@ -685,24 +662,22 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HorizontalLayout getActionsLayout() {
|
public HorizontalLayout getActionsLayout() {
|
||||||
HorizontalLayout actionsLayout = new HorizontalLayout();
|
final HorizontalLayout actionsLayout = new HorizontalLayout();
|
||||||
actionsLayout.setSpacing(true);
|
actionsLayout.setSpacing(true);
|
||||||
|
|
||||||
Button cancelButton = Utils.tooltip(new Button(VaadinIcon.CLOSE.create()), "Cancel Action");
|
final Button cancelButton = Utils.tooltip(new Button(VaadinIcon.CLOSE.create()), "Cancel Action");
|
||||||
if (isActive() && !isCancelingOrCanceled()) {
|
if (isActive() && !isCancelingOrCanceled()) {
|
||||||
cancelButton.addClickListener(e -> {
|
cancelButton.addClickListener(e -> {
|
||||||
String message = "Are you sure you want to cancel the action ?";
|
String message = "Are you sure you want to cancel the action ?";
|
||||||
promptForConfirmAction(
|
promptForConfirmAction(
|
||||||
message, onUpdate, () -> {
|
message, onUpdate,
|
||||||
hawkbitClient.getTargetRestApi().cancelAction(target.getControllerId(), action.getId(), false);
|
() -> hawkbitClient.getTargetRestApi().cancelAction(target.getControllerId(), action.getId(), false)).open();
|
||||||
}
|
|
||||||
).open();
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cancelButton.setEnabled(false);
|
cancelButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Button forceButton = Utils.tooltip(new Button(VaadinIcon.BOLT.create()), "Force Action");
|
final Button forceButton = Utils.tooltip(new Button(VaadinIcon.BOLT.create()), "Force Action");
|
||||||
if (isActive() && !isCancelingOrCanceled() && action.getForceType() != MgmtActionType.FORCED) {
|
if (isActive() && !isCancelingOrCanceled() && action.getForceType() != MgmtActionType.FORCED) {
|
||||||
forceButton.addClickListener(e -> {
|
forceButton.addClickListener(e -> {
|
||||||
String message = "Are you sure you want to force the action ?";
|
String message = "Are you sure you want to force the action ?";
|
||||||
@@ -723,23 +698,21 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HorizontalLayout getForceQuitLayout() {
|
public HorizontalLayout getForceQuitLayout() {
|
||||||
HorizontalLayout forceQuitLayout = new HorizontalLayout();
|
final HorizontalLayout forceQuitLayout = new HorizontalLayout();
|
||||||
forceQuitLayout.setSpacing(true);
|
forceQuitLayout.setSpacing(true);
|
||||||
forceQuitLayout.setPadding(true);
|
forceQuitLayout.setPadding(true);
|
||||||
forceQuitLayout.setWidthFull();
|
forceQuitLayout.setWidthFull();
|
||||||
forceQuitLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
|
forceQuitLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
|
||||||
|
|
||||||
Button forceQuitButton = Utils.tooltip(new Button(VaadinIcon.CLOSE.create()), "Force Cancel");
|
final Button forceQuitButton = Utils.tooltip(new Button(VaadinIcon.CLOSE.create()), "Force Cancel");
|
||||||
forceQuitButton.addThemeVariants(ButtonVariant.LUMO_ERROR, ButtonVariant.LUMO_TERTIARY_INLINE);
|
forceQuitButton.addThemeVariants(ButtonVariant.LUMO_ERROR, ButtonVariant.LUMO_TERTIARY_INLINE);
|
||||||
|
|
||||||
if (isActive() && isCancelingOrCanceled()) {
|
if (isActive() && isCancelingOrCanceled()) {
|
||||||
forceQuitButton.addClickListener(e -> {
|
forceQuitButton.addClickListener(e -> {
|
||||||
String message = "Are you sure you want to force cancel the action ?";
|
String message = "Are you sure you want to force cancel the action ?";
|
||||||
promptForConfirmAction(
|
promptForConfirmAction(
|
||||||
message, onUpdate, () -> {
|
message, onUpdate,
|
||||||
hawkbitClient.getTargetRestApi().cancelAction(target.getControllerId(), action.getId(), true);
|
() -> hawkbitClient.getTargetRestApi().cancelAction(target.getControllerId(), action.getId(), true)).open();
|
||||||
}
|
|
||||||
).open();
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
forceQuitButton.setEnabled(false);
|
forceQuitButton.setEnabled(false);
|
||||||
@@ -782,8 +755,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
final Button register = Utils.tooltip(new Button("Register"), "Register (Enter)");
|
final Button register = Utils.tooltip(new Button("Register"), "Register (Enter)");
|
||||||
type = new Select<>(
|
type = new Select<>(
|
||||||
"Type",
|
"Type",
|
||||||
e -> {
|
e -> {},
|
||||||
},
|
|
||||||
hawkbitClient.getTargetTypeRestApi()
|
hawkbitClient.getTargetTypeRestApi()
|
||||||
.getTargetTypes(0, 30, Constants.NAME_ASC, null)
|
.getTargetTypes(0, 30, Constants.NAME_ASC, null)
|
||||||
.getBody()
|
.getBody()
|
||||||
@@ -793,10 +765,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
type.setWidthFull();
|
type.setWidthFull();
|
||||||
type.setEmptySelectionAllowed(true);
|
type.setEmptySelectionAllowed(true);
|
||||||
type.setItemLabelGenerator(item -> item == null ? "" : item.getName());
|
type.setItemLabelGenerator(item -> item == null ? "" : item.getName());
|
||||||
controllerId = Utils.textField(
|
controllerId = Utils.textField(CONTROLLER_ID,e -> register.setEnabled(!e.getHasValue().isEmpty()));
|
||||||
CONTROLLER_ID,
|
|
||||||
e -> register.setEnabled(!e.getHasValue().isEmpty())
|
|
||||||
);
|
|
||||||
controllerId.focus();
|
controllerId.focus();
|
||||||
name = Utils.textField(Constants.NAME);
|
name = Utils.textField(Constants.NAME);
|
||||||
name.setWidthFull();
|
name.setWidthFull();
|
||||||
@@ -808,7 +777,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
register.setEnabled(false);
|
register.setEnabled(false);
|
||||||
register.addClickShortcut(Key.ENTER);
|
register.addClickShortcut(Key.ENTER);
|
||||||
register.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
register.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
final Button cancel = Utils.tooltip(new Button("Cancel"), "Cancel (Esc)");
|
final Button cancel = Utils.tooltip(new Button(CANCEL), CANCEL_ESC);
|
||||||
cancel.addClickListener(e -> close());
|
cancel.addClickListener(e -> close());
|
||||||
cancel.addClickShortcut(Key.ESCAPE);
|
cancel.addClickShortcut(Key.ESCAPE);
|
||||||
getFooter().add(cancel);
|
getFooter().add(cancel);
|
||||||
@@ -874,7 +843,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
assign.setEnabled(false);
|
assign.setEnabled(false);
|
||||||
assign.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
assign.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
addAssignClickListener(hawkbitClient, selectedTargets);
|
addAssignClickListener(hawkbitClient, selectedTargets);
|
||||||
final Button cancel = Utils.tooltip(new Button("Cancel"), "Cancel (Esc)");
|
final Button cancel = Utils.tooltip(new Button(CANCEL), CANCEL_ESC);
|
||||||
cancel.addClickListener(e -> close());
|
cancel.addClickListener(e -> close());
|
||||||
cancel.addClickShortcut(Key.ESCAPE);
|
cancel.addClickShortcut(Key.ESCAPE);
|
||||||
getFooter().add(cancel);
|
getFooter().add(cancel);
|
||||||
@@ -898,11 +867,10 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
private void addAssignClickListener(final HawkbitMgmtClient hawkbitClient, final Set<MgmtTarget> selectedTargets) {
|
private void addAssignClickListener(final HawkbitMgmtClient hawkbitClient, final Set<MgmtTarget> selectedTargets) {
|
||||||
assign.addClickListener(e -> {
|
assign.addClickListener(e -> {
|
||||||
close();
|
close();
|
||||||
List<MgmtTargetAssignmentRequestBody> requests = new LinkedList<MgmtTargetAssignmentRequestBody>();
|
|
||||||
|
|
||||||
|
final List<MgmtTargetAssignmentRequestBody> requests = new LinkedList<>();
|
||||||
for (final MgmtTarget target : selectedTargets) {
|
for (final MgmtTarget target : selectedTargets) {
|
||||||
|
final MgmtTargetAssignmentRequestBody request = new MgmtTargetAssignmentRequestBody(target.getControllerId());
|
||||||
MgmtTargetAssignmentRequestBody request = new MgmtTargetAssignmentRequestBody(target.getControllerId());
|
|
||||||
|
|
||||||
request.setType(actionType.getValue());
|
request.setType(actionType.getValue());
|
||||||
if (actionType.getValue() == MgmtActionType.TIMEFORCED) {
|
if (actionType.getValue() == MgmtActionType.TIMEFORCED) {
|
||||||
@@ -928,12 +896,12 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
private CreateTagDialog(final HawkbitMgmtClient hawkbitClient, Runnable onSuccess) {
|
private CreateTagDialog(final HawkbitMgmtClient hawkbitClient, Runnable onSuccess) {
|
||||||
super("Create Tag");
|
super("Create Tag");
|
||||||
|
|
||||||
FormLayout formLayout = new FormLayout();
|
final FormLayout formLayout = new FormLayout();
|
||||||
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1));
|
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1));
|
||||||
final Button create = Utils.tooltip(new Button("Create"), "Create (Enter)");
|
final Button create = Utils.tooltip(new Button("Create"), "Create (Enter)");
|
||||||
final Button cancel = Utils.tooltip(new Button("Cancel"), "Cancel (Esc)");
|
final Button cancel = Utils.tooltip(new Button(CANCEL), CANCEL_ESC);
|
||||||
|
|
||||||
Input colorInput = new Input();
|
final Input colorInput = new Input();
|
||||||
colorInput.setType("color");
|
colorInput.setType("color");
|
||||||
name = Utils.textField("Tag Name", e -> create.setEnabled(!e.getHasValue().isEmpty()));
|
name = Utils.textField("Tag Name", e -> create.setEnabled(!e.getHasValue().isEmpty()));
|
||||||
formLayout.add(name);
|
formLayout.add(name);
|
||||||
@@ -949,8 +917,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
new MgmtTagRequestBodyPut()
|
new MgmtTagRequestBodyPut()
|
||||||
.setName(name.getValue())
|
.setName(name.getValue())
|
||||||
.setDescription(description.getValue())
|
.setDescription(description.getValue())
|
||||||
.setColour(colorInput.getValue())
|
.setColour(colorInput.getValue())));
|
||||||
));
|
|
||||||
onSuccess.run();
|
onSuccess.run();
|
||||||
close();
|
close();
|
||||||
});
|
});
|
||||||
@@ -966,15 +933,15 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
|
|
||||||
private static class TargetStatusCell extends HorizontalLayout {
|
private static class TargetStatusCell extends HorizontalLayout {
|
||||||
|
|
||||||
private TargetStatusCell(MgmtTarget target) {
|
private TargetStatusCell(final MgmtTarget target) {
|
||||||
MgmtPollStatus pollStatus = target.getPollStatus();
|
final MgmtPollStatus pollStatus = target.getPollStatus();
|
||||||
String targetUpdateStatus = Optional.ofNullable(target.getUpdateStatus()).orElse("unknown");
|
final String targetUpdateStatus = Optional.ofNullable(target.getUpdateStatus()).orElse("unknown");
|
||||||
add(pollStatusIconMapper(pollStatus), targetUpdateStatusMapper(targetUpdateStatus));
|
add(pollStatusIconMapper(pollStatus), targetUpdateStatusMapper(targetUpdateStatus));
|
||||||
setWidth(50, Unit.PIXELS);
|
setWidth(50, Unit.PIXELS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Icon targetUpdateStatusMapper(String targetUpdateStatus) {
|
private Icon targetUpdateStatusMapper(final String targetUpdateStatus) {
|
||||||
VaadinIcon icon = switch (targetUpdateStatus) {
|
final VaadinIcon icon = switch (targetUpdateStatus) {
|
||||||
case "error" -> VaadinIcon.EXCLAMATION_CIRCLE;
|
case "error" -> VaadinIcon.EXCLAMATION_CIRCLE;
|
||||||
case "in_sync" -> VaadinIcon.CHECK_CIRCLE;
|
case "in_sync" -> VaadinIcon.CHECK_CIRCLE;
|
||||||
case "pending" -> VaadinIcon.ADJUST;
|
case "pending" -> VaadinIcon.ADJUST;
|
||||||
@@ -982,7 +949,7 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
default -> VaadinIcon.QUESTION_CIRCLE;
|
default -> VaadinIcon.QUESTION_CIRCLE;
|
||||||
};
|
};
|
||||||
|
|
||||||
String color = switch (targetUpdateStatus) {
|
final String color = switch (targetUpdateStatus) {
|
||||||
case "error" -> "red";
|
case "error" -> "red";
|
||||||
case "in_sync" -> "green";
|
case "in_sync" -> "green";
|
||||||
case "pending" -> "orange";
|
case "pending" -> "orange";
|
||||||
@@ -990,14 +957,14 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
default -> "blue";
|
default -> "blue";
|
||||||
};
|
};
|
||||||
|
|
||||||
Icon statusIcon = Utils.tooltip(icon.create(), targetUpdateStatus);
|
final Icon statusIcon = Utils.tooltip(icon.create(), targetUpdateStatus);
|
||||||
statusIcon.setColor(color);
|
statusIcon.setColor(color);
|
||||||
statusIcon.addClassNames(LumoUtility.IconSize.SMALL);
|
statusIcon.addClassNames(LumoUtility.IconSize.SMALL);
|
||||||
return statusIcon;
|
return statusIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Icon pollStatusIconMapper(MgmtPollStatus pollStatus) {
|
private Icon pollStatusIconMapper(MgmtPollStatus pollStatus) {
|
||||||
Icon pollIcon;
|
final Icon pollIcon;
|
||||||
if (pollStatus == null) {
|
if (pollStatus == null) {
|
||||||
pollIcon = Utils.tooltip(VaadinIcon.QUESTION_CIRCLE.create(), "No Poll Status");
|
pollIcon = Utils.tooltip(VaadinIcon.QUESTION_CIRCLE.create(), "No Poll Status");
|
||||||
} else if (pollStatus.isOverdue()) {
|
} else if (pollStatus.isOverdue()) {
|
||||||
@@ -1009,4 +976,4 @@ public class TargetView extends TableView<MgmtTarget, String> {
|
|||||||
return pollIcon;
|
return pollIcon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,28 +35,18 @@ import org.eclipse.hawkbit.ui.simple.view.Constants;
|
|||||||
@SuppressWarnings("java:S119") // better readability
|
@SuppressWarnings("java:S119") // better readability
|
||||||
public class TableView<T, ID> extends Div implements Constants {
|
public class TableView<T, ID> extends Div implements Constants {
|
||||||
|
|
||||||
|
private static final String COLOR = "color";
|
||||||
|
private static final String VAR_LUMO_SECONDARY_TEXT_COLOR = "var(--lumo-secondary-text-color)";
|
||||||
|
private static final String VAR_LUMO_PRIMARY_COLOR = "var(--lumo-primary-color)";
|
||||||
|
private static final int DEFAULT_OPEN_POSITION_SIZE = 50;
|
||||||
|
|
||||||
protected SelectionGrid<T, ID> selectionGrid;
|
protected SelectionGrid<T, ID> selectionGrid;
|
||||||
private final Filter filter;
|
private final Filter filter;
|
||||||
final VerticalLayout gridLayout;
|
private final VerticalLayout gridLayout;
|
||||||
protected final HorizontalLayout controlsLayout;
|
protected final HorizontalLayout controlsLayout;
|
||||||
protected final SplitLayout splitLayout;
|
private final SplitLayout splitLayout;
|
||||||
protected final Div detailsPanel = new Div();
|
private final Div detailsPanel = new Div();
|
||||||
protected Button currentSelectionButton;
|
private Button currentSelectionButton;
|
||||||
|
|
||||||
public TableView(
|
|
||||||
final Filter.Rsql rsql,
|
|
||||||
final SelectionGrid.EntityRepresentation<T, ID> entityRepresentation,
|
|
||||||
final BiFunction<Query<T, Void>, String, Stream<T>> queryFn) {
|
|
||||||
this(rsql, null, entityRepresentation, queryFn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableView(
|
|
||||||
final Filter.Rsql rsql,
|
|
||||||
final Filter.Rsql alternativeRsql,
|
|
||||||
final SelectionGrid.EntityRepresentation<T, ID> entityRepresentation,
|
|
||||||
final BiFunction<Query<T, Void>, String, Stream<T>> queryFn) {
|
|
||||||
this(rsql, alternativeRsql, entityRepresentation, queryFn, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableView(
|
public TableView(
|
||||||
final Filter.Rsql rsql,
|
final Filter.Rsql rsql,
|
||||||
@@ -73,8 +63,7 @@ public class TableView<T, ID> extends Div implements Constants {
|
|||||||
final BiFunction<Query<T, Void>, String, Stream<T>> queryFn,
|
final BiFunction<Query<T, Void>, String, Stream<T>> queryFn,
|
||||||
final Function<SelectionGrid<T, ID>, CompletionStage<Void>> addHandler,
|
final Function<SelectionGrid<T, ID>, CompletionStage<Void>> addHandler,
|
||||||
final Function<SelectionGrid<T, ID>, CompletionStage<Void>> removeHandler,
|
final Function<SelectionGrid<T, ID>, CompletionStage<Void>> removeHandler,
|
||||||
final Function<T, Component> detailsButtonHandler
|
final Function<T, Component> detailsButtonHandler) {
|
||||||
) {
|
|
||||||
selectionGrid = new SelectionGrid<>(entityRepresentation, queryFn);
|
selectionGrid = new SelectionGrid<>(entityRepresentation, queryFn);
|
||||||
selectionGrid.setSizeFull();
|
selectionGrid.setSizeFull();
|
||||||
filter = new Filter(selectionGrid::setRsqlFilter, rsql, alternativeRsql);
|
filter = new Filter(selectionGrid::setRsqlFilter, rsql, alternativeRsql);
|
||||||
@@ -110,10 +99,9 @@ public class TableView<T, ID> extends Div implements Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SerializableFunction<T, Button> renderDetailsButton(final Function<T, Component> selectionHandler) {
|
private SerializableFunction<T, Button> renderDetailsButton(final Function<T, Component> selectionHandler) {
|
||||||
return (selectedItem) -> {
|
return selectedItem -> {
|
||||||
int DEFAULT_OPEN_POSITION_SIZE = 50;
|
|
||||||
final Button button = new Button(VaadinIcon.EYE.create());
|
final Button button = new Button(VaadinIcon.EYE.create());
|
||||||
button.getStyle().set("color", "var(--lumo-secondary-text-color)");
|
button.getStyle().set(COLOR, VAR_LUMO_SECONDARY_TEXT_COLOR);
|
||||||
|
|
||||||
button.addClickListener(event -> {
|
button.addClickListener(event -> {
|
||||||
final Icon eyeIcon = VaadinIcon.EYE.create();
|
final Icon eyeIcon = VaadinIcon.EYE.create();
|
||||||
@@ -121,19 +109,19 @@ public class TableView<T, ID> extends Div implements Constants {
|
|||||||
|
|
||||||
if (button == currentSelectionButton) {
|
if (button == currentSelectionButton) {
|
||||||
button.setIcon(eyeIcon);
|
button.setIcon(eyeIcon);
|
||||||
button.getStyle().set("color", "var(--lumo-secondary-text-color)");
|
button.getStyle().set(COLOR, VAR_LUMO_SECONDARY_TEXT_COLOR);
|
||||||
detailsPanel.removeAll();
|
detailsPanel.removeAll();
|
||||||
splitLayout.remove(detailsPanel);
|
splitLayout.remove(detailsPanel);
|
||||||
splitLayout.setSplitterPosition(100);
|
splitLayout.setSplitterPosition(100);
|
||||||
currentSelectionButton = null;
|
currentSelectionButton = null;
|
||||||
} else {
|
} else {
|
||||||
button.setIcon(closeIcon);
|
button.setIcon(closeIcon);
|
||||||
button.getStyle().set("color", "var(--lumo-primary-color)");
|
button.getStyle().set(COLOR, VAR_LUMO_PRIMARY_COLOR);
|
||||||
if (currentSelectionButton == null) {
|
if (currentSelectionButton == null) {
|
||||||
splitLayout.addToSecondary(detailsPanel);
|
splitLayout.addToSecondary(detailsPanel);
|
||||||
} else {
|
} else {
|
||||||
currentSelectionButton.setIcon(eyeIcon);
|
currentSelectionButton.setIcon(eyeIcon);
|
||||||
currentSelectionButton.getStyle().set("color", "var(--lumo-secondary-text-color)");
|
currentSelectionButton.getStyle().set(COLOR, VAR_LUMO_SECONDARY_TEXT_COLOR);
|
||||||
}
|
}
|
||||||
detailsPanel.removeAll();
|
detailsPanel.removeAll();
|
||||||
splitLayout.setSplitterPosition(DEFAULT_OPEN_POSITION_SIZE);
|
splitLayout.setSplitterPosition(DEFAULT_OPEN_POSITION_SIZE);
|
||||||
@@ -147,4 +135,4 @@ public class TableView<T, ID> extends Div implements Constants {
|
|||||||
return button;
|
return button;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user