Skip to content

Commit

Permalink
feat: changed anchor and added details
Browse files Browse the repository at this point in the history
Signed-off-by: SimoneFiorani <[email protected]>
  • Loading branch information
sfiorani committed Dec 13, 2024
1 parent 6b6265f commit a9d144c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.kura.web.client.ui.settings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
Expand All @@ -31,7 +30,7 @@

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
Expand All @@ -46,11 +45,6 @@ public class SnapshotDownloadModal extends Composite {

private static final String SELECT_ALL_PIDS_SELECTION = "Select All Pids";
private static final String REMOVE_ALL_PIDS_SELECTION = "Remove All Pids";
private static final List<String> DEFAULT_PID_SELECTION = Arrays.asList("org.eclipse.kura.cloud.CloudService",
"org.eclipse.kura.internal.rest.provider.RestService",
"org.eclipse.kura.net.admin.FirewallConfigurationService",
"org.eclipse.kura.net.admin.NetworkConfigurationService",
"org.eclipse.kura.net.admin.ipv6.FirewallConfigurationServiceIPv6", "org.eclipse.kura.web.Console");

interface SnapshotDownloadModalUiBinder extends UiBinder<Widget, SnapshotDownloadModal> {
}
Expand All @@ -60,35 +54,41 @@ interface SnapshotDownloadModalUiBinder extends UiBinder<Widget, SnapshotDownloa
@UiField
ScrollPanel pidSelectionScrollPanel;
@UiField
Anchor resetPidSelection;
Anchor selectOrRemoveAllAnchor;
@UiField
Modal modal;
@UiField
Button downloadXml;
@UiField
Button downloadJson;
@UiField
Button cancelButton;
@UiField
FormLabel noPidSelectedError;

boolean areAllPidsSelected = true;
VerticalPanel pidPanel = new VerticalPanel();

HandlerRegistration anchorClickHandler;

Consumer<SnapshotDownloadOptions> snapshotDownloadConsumer;

public SnapshotDownloadModal() {

initWidget(uiBinder.createAndBindUi(this));

this.pidSelectionScrollPanel.setVisible(false);
this.resetPidSelection.setVisible(false);
this.selectOrRemoveAllAnchor.setVisible(false);
this.noPidSelectedError.setVisible(false);
this.noPidSelectedError.setText("Please select at least one pid from the list");

this.cancelButton.addClickHandler(this::onCancelClick);

}

public void show(Consumer<SnapshotDownloadOptions> consumer) {
this.snapshotDownloadConsumer = consumer;
this.modal.setTitle(MSGS.deviceWiregraphDownloadModalTitle());
this.downloadModalDescription.setText(MSGS.deviceWiregraphDownloadModalHint());
initWiregraphDownloadButtons();
this.modal.show();
}
Expand All @@ -99,25 +99,47 @@ public void show(Consumer<SnapshotDownloadOptions> consumer, List<String> availa
this.modal.setTitle(MSGS.deviceSnapshotDownloadModalTitle());
this.downloadModalDescription.setText(MSGS.deviceSnapshotDownloadModalHint());
initSnapshotPidList(availablePids);
initSnapshotSelectAllAnchor();
initSnapshotScrollPanel();
initSnapshotDownloadButtons();
initSnapshotResetAnchor();
this.modal.show();
}

private void initWiregraphDownloadButtons() {
/*
* Snapshot Download Inits
*/

this.downloadJson.addClickHandler(e -> {
this.modal.hide();
this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("JSON"));
});
private void initSnapshotPidList(List<String> snapshotConfigs) {

this.downloadXml.addClickHandler(e -> {
this.modal.hide();
this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("XML"));
this.pidPanel.clear();

List<String> orderedPids = snapshotConfigs.stream().sorted().collect(Collectors.toList());
orderedPids.forEach(pid -> {
CheckBox box = new CheckBox(pid);
box.setValue(true);
box.addClickHandler(this::onCheckboxClick);
this.pidPanel.add(box);
});
}

private void initSnapshotSelectAllAnchor() {
if (this.anchorClickHandler != null) {
this.anchorClickHandler.removeHandler();
}
this.areAllPidsSelected = true;
this.selectOrRemoveAllAnchor.setText(REMOVE_ALL_PIDS_SELECTION);
this.anchorClickHandler = this.selectOrRemoveAllAnchor.addClickHandler(this::selectOrRemoveAllSelection);
this.selectOrRemoveAllAnchor.setVisible(true);
}

private void initSnapshotScrollPanel() {
this.pidSelectionScrollPanel.setAlwaysShowScrollBars(false);
this.pidSelectionScrollPanel.setHeight("350px");
this.pidSelectionScrollPanel.clear();
this.pidSelectionScrollPanel.add(pidPanel);
this.pidSelectionScrollPanel.setVisible(true);
}

private void initSnapshotDownloadButtons() {
this.downloadJson.addClickHandler(e -> {
if (isOnePidSelected()) {
Expand All @@ -141,68 +163,41 @@ private void initSnapshotDownloadButtons() {
});
}

private void initSnapshotResetAnchor() {
this.resetPidSelection.addClickHandler(event -> {
/*
* Wiregraph Snapshot Download Inits
*/

pidPanel.iterator().forEachRemaining(widget -> {
CheckBox checkBox = (CheckBox) widget;
checkBox.setValue(DEFAULT_PID_SELECTION.contains(checkBox.getText()));
});
});
}

private void initSnapshotPidList(List<String> snapshotConfigs) {

this.pidPanel.clear();
private void initWiregraphDownloadButtons() {

List<String> orderedPids = snapshotConfigs.stream().sorted().collect(Collectors.toList());
orderedPids.forEach(pid -> {
CheckBox box = new CheckBox(pid);
box.addClickHandler(this::hideErrorMessageOnSelection);
this.pidPanel.add(box);
this.downloadJson.addClickHandler(e -> {
this.modal.hide();
this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("JSON"));
});

CheckBox allChannelsButton = new CheckBox(SELECT_ALL_PIDS_SELECTION);
allChannelsButton.addValueChangeHandler(this::selectOrRemoveAllSelection);
allChannelsButton.addClickHandler(this::hideErrorMessageOnSelection);
this.pidPanel.insert(allChannelsButton, 0);

this.downloadXml.addClickHandler(e -> {
this.modal.hide();
this.snapshotDownloadConsumer.accept(new SnapshotDownloadOptions("XML"));
});
}

private void hideErrorMessageOnSelection(ClickEvent handler) {
/*
* Utils
*/

private void onCheckboxClick(ClickEvent handler) {
if (noPidSelectedError.isVisible()) {
noPidSelectedError.setVisible(false);
}
}

private void selectOrRemoveAllSelection(ValueChangeEvent<Boolean> event) {
Iterator<Widget> widgetIterator = pidPanel.iterator();

widgetIterator.forEachRemaining(widget -> {

CheckBox checkBox = (CheckBox) widget;
checkBox.setValue(event.getValue());

if (checkBox.getText().equals(SELECT_ALL_PIDS_SELECTION)
|| checkBox.getText().equals(REMOVE_ALL_PIDS_SELECTION)) {
checkAllPidsSelected();
updateSelectOrRemoveAllText();

if (event.getValue().booleanValue()) {
checkBox.setText(REMOVE_ALL_PIDS_SELECTION);
} else {
checkBox.setText(SELECT_ALL_PIDS_SELECTION);
}
}
});
}

private void initSnapshotScrollPanel() {
this.pidSelectionScrollPanel.setAlwaysShowScrollBars(false);
this.pidSelectionScrollPanel.setHeight("350px");
this.pidSelectionScrollPanel.clear();
this.pidSelectionScrollPanel.add(pidPanel);
this.pidSelectionScrollPanel.setVisible(true);

this.resetPidSelection.setVisible(true);
private void onCancelClick(ClickEvent handler) {
this.modal.hide();
resetScrollPanel();
this.noPidSelectedError.setVisible(false);
}

private Optional<List<String>> getSelectedPids() {
Expand All @@ -218,6 +213,12 @@ private Optional<List<String>> getSelectedPids() {
return selectedPids.isEmpty() ? Optional.empty() : Optional.of(selectedPids);
}

private void selectOrRemoveAllSelection(ClickEvent handler) {
pidPanel.iterator().forEachRemaining(widget -> ((CheckBox) widget).setValue(!this.areAllPidsSelected));
this.areAllPidsSelected = !this.areAllPidsSelected;
updateSelectOrRemoveAllText();
}

private boolean isOnePidSelected() {
boolean result = false;
Iterator<Widget> pidPanelIterator = this.pidPanel.iterator();
Expand All @@ -232,6 +233,26 @@ private boolean isOnePidSelected() {
return result;
}

private void checkAllPidsSelected() {
boolean areAllSelected = true;
Iterator<Widget> pidPanelIterator = this.pidPanel.iterator();
while (pidPanelIterator.hasNext()) {
if (!((CheckBox) pidPanelIterator.next()).getValue().booleanValue()) {
areAllSelected = false;
break;
}
}
this.areAllPidsSelected = areAllSelected;
}

private void updateSelectOrRemoveAllText() {
if (this.areAllPidsSelected) {
this.selectOrRemoveAllAnchor.setText(REMOVE_ALL_PIDS_SELECTION);
} else {
this.selectOrRemoveAllAnchor.setText(SELECT_ALL_PIDS_SELECTION);
}
}

private void resetScrollPanel() {
this.pidSelectionScrollPanel.setVerticalScrollPosition(0);
this.pidSelectionScrollPanel.setHorizontalScrollPosition(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
</b:FormGroup>
</b:FieldSet>
</g:FormPanel>
<b:Anchor text="{msgs.downloadSnapshotResetSelection}" ui:field="resetPidSelection" />
<b:Anchor ui:field="selectOrRemoveAllAnchor" />
</b:ModalBody>
<b:ModalFooter>
<b:Button addStyleNames="fa" type="PRIMARY" dataDismiss="MODAL" text="{msgs.cancelButton}" />
<b.html:Paragraph text="Choose the format in which the file will be downloaded" />
<b:Button addStyleNames="fa" type="PRIMARY" ui:field= "cancelButton" text="{msgs.cancelButton}" />
<b:Button addStyleNames="fa" type="PRIMARY" ui:field="downloadJson" text="{msgs.downloadSnapshotJsonButton}" />
<b:Button addStyleNames="fa" type="PRIMARY" ui:field="downloadXml" text="{msgs.downloadSnapshotXmlButton}" />
</b:ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,11 @@ deviceSnapshotId=Snapshot Id
deviceSnapshotCreatedOn=Created On
deviceSnapshotsNone=No Snapshots Available
deviceSnapshotRollbackConfirm=Are you sure you want to rollback to a previous configuration? During the rollback operation, the device will disconnect and reconnect. If a timeout is encountered during the reload of the device configuration, please refresh it manually.
deviceSnapshotDownloadModalTitle=Download snapshot
deviceWiregraphDownloadModalTitle=Download wiregraph
deviceSnapshotDownloadModalHint=Chose the format and which service configurations will be included in the downloaded snapshot.
deviceWiregraphDownloadModalHint=Chose in which format the wiregraph will be downloaded.
deviceSnapshotDownloadModalTitle=Snapshot download
deviceWiregraphDownloadModalTitle=Wiregraph snapshot download
deviceSnapshotDownloadModalHint=Select pids of the service configurations that will be included in the downloaded snapshot.
downloadSnapshotXmlButton=Download as XML
downloadSnapshotJsonButton=Download as JSON
downloadSnapshotResetSelection=Reset selection to default

netIntro=Select a Network Interface and configure it. DHCP Server and NAT can be configured only for interfaces enabled for LAN usage. When applying your changes, your connection to the gateway may be lost depending on your network configuration changes.
netInterfaceName=Interface Name
Expand Down

0 comments on commit a9d144c

Please sign in to comment.