From e80d9698c74c7a049e677f577248489059ae6397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Lindo?= Date: Thu, 26 Sep 2024 17:24:02 +0100 Subject: [PATCH] added scroll and search to db permissions panel --- .../common/client/common/dialogs/Dialogs.java | 52 ++++++++ .../browse/DatabaseSearchPanel.java | 2 - .../PermissionsNavigationPanel.java | 116 +++++++++++++----- .../common/public/main.css | 4 + .../common/public/roda_main.css | 16 +++ 5 files changed, 159 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/databasepreservation/common/client/common/dialogs/Dialogs.java b/src/main/java/com/databasepreservation/common/client/common/dialogs/Dialogs.java index 918c064e..018f9bf7 100644 --- a/src/main/java/com/databasepreservation/common/client/common/dialogs/Dialogs.java +++ b/src/main/java/com/databasepreservation/common/client/common/dialogs/Dialogs.java @@ -49,6 +49,7 @@ public class Dialogs { private static final String WUI_DIALOG_LAYOUT_FOOTER = "wui-dialog-layout-footer"; private static final String WUI_DIALOG_LAYOUT = "wui-dialog-layout"; private static final String WUI_DIALOG_INFORMATION = "wui-dialog-information"; + private static final String WUI_DIALOG_EDIT_PERMISSIONS = "wui-dialog-edit-permissions"; private static final String WUI_DIALOG_MESSAGE = "wui-dialog-message"; private Dialogs() { @@ -835,4 +836,55 @@ public static void showCustomConfirmationDialog(String title, SafeHtml descripti dialogBox.center(); dialogBox.show(); } + + public static void showPermissionsDialog(String title, SafeHtml description, String width, Widget helper, + String cancelButtonText, String confirmButtonText, final AsyncCallback callback) { + final DialogBox dialogBox = new DialogBox(false, true); + final Button cancelButton = new Button(cancelButtonText); + final Button confirmButton = new Button(confirmButtonText); + + FlowPanel layout = new FlowPanel(); + FlowPanel footer = new FlowPanel(); + + footer.add(cancelButton); + footer.add(confirmButton); + footer.addStyleName(WUI_DIALOG_LAYOUT_FOOTER); + + HTML messageLabel = new HTML(description); + messageLabel.addStyleName(WUI_DIALOG_INFORMATION); + + layout.add(messageLabel); + + layout.add(helper); + layout.addStyleName(WUI_DIALOG_LAYOUT); + layout.add(footer); + + cancelButton.addStyleName(BTN_LINK_STYLE); + cancelButton.addClickHandler(event -> { + dialogBox.hide(); + callback.onSuccess(false); + }); + + confirmButton.addStyleName(BTN_PLAY_STYLE); + confirmButton.addClickHandler(event -> { + dialogBox.hide(); + callback.onSuccess(true); + }); + + dialogBox.setText(title); + dialogBox.setWidget(layout); + if (width != null && !width.isEmpty()) { + dialogBox.setWidth(width); + } else { + dialogBox.setWidth("360px"); + } + dialogBox.setGlassEnabled(true); + dialogBox.setAnimationEnabled(false); + dialogBox.addStyleName(WUI_DIALOG_EDIT_PERMISSIONS); + + dialogBox.center(); + dialogBox.show(); + } + + } diff --git a/src/main/java/com/databasepreservation/common/client/common/visualization/browse/DatabaseSearchPanel.java b/src/main/java/com/databasepreservation/common/client/common/visualization/browse/DatabaseSearchPanel.java index c9906b18..66c01bcc 100644 --- a/src/main/java/com/databasepreservation/common/client/common/visualization/browse/DatabaseSearchPanel.java +++ b/src/main/java/com/databasepreservation/common/client/common/visualization/browse/DatabaseSearchPanel.java @@ -19,7 +19,6 @@ import com.databasepreservation.common.client.common.breadcrumb.BreadcrumbPanel; import com.databasepreservation.common.client.common.lists.TableRowList; import com.databasepreservation.common.client.common.utils.CommonClientUtils; -import com.databasepreservation.common.client.common.utils.TableRowListWrapper; import com.databasepreservation.common.client.configuration.observer.ICollectionStatusObserver; import com.databasepreservation.common.client.index.IndexResult; import com.databasepreservation.common.client.index.filter.BasicSearchFilterParameter; @@ -43,7 +42,6 @@ import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; diff --git a/src/main/java/com/databasepreservation/common/client/common/visualization/manager/SIARDPanel/navigation/PermissionsNavigationPanel.java b/src/main/java/com/databasepreservation/common/client/common/visualization/manager/SIARDPanel/navigation/PermissionsNavigationPanel.java index f782dcc4..a100934c 100644 --- a/src/main/java/com/databasepreservation/common/client/common/visualization/manager/SIARDPanel/navigation/PermissionsNavigationPanel.java +++ b/src/main/java/com/databasepreservation/common/client/common/visualization/manager/SIARDPanel/navigation/PermissionsNavigationPanel.java @@ -10,8 +10,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import com.databasepreservation.common.client.common.NavigationPanel; import com.databasepreservation.common.client.common.NoAsyncCallback; @@ -27,6 +29,7 @@ import com.databasepreservation.common.client.models.structure.ViewerDatabase; import com.databasepreservation.common.client.models.structure.ViewerDatabaseStatus; import com.databasepreservation.common.client.services.DatabaseService; +import com.databasepreservation.common.client.tools.ViewerStringUtils; import com.databasepreservation.common.client.widgets.Alert; import com.databasepreservation.common.client.widgets.SwitchBtn; import com.databasepreservation.common.client.widgets.Toast; @@ -40,6 +43,7 @@ import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.TextBox; import config.i18n.client.ClientMessages; /** @@ -56,8 +60,11 @@ public class PermissionsNavigationPanel { private boolean hasPermissionsOrGroups = true; private FlowPanel body; private FlowPanel bottom; + TextBox searchInputBox; private Button btnEdit; private SwitchBtn btnSwitch; + Column checkbox; + BasicTablePanel cellTable; private boolean overrideMissingGroups = false; @@ -90,7 +97,8 @@ public NavigationPanel build() { panel.addButton(bottom); if (database.getStatus().equals(ViewerDatabaseStatus.AVAILABLE)) { - btnSwitch = new SwitchBtn(messages.SIARDHomePageTitleForPermissionsSwitchButton(), database.isAvailableToSearchAll()); + btnSwitch = new SwitchBtn(messages.SIARDHomePageTitleForPermissionsSwitchButton(), + database.isAvailableToSearchAll()); handleSwitchBottom(); } @@ -147,8 +155,8 @@ private void updateBottom() { btnEdit.addClickHandler(clickEvent -> { overrideMissingGroups = false; - Dialogs.showCustomConfirmationDialog(messages.SIARDHomePageDialogTitleForPermissionsList(), - messages.SIARDHomePageDialogDescriptionForPermissionsList(), "620px", getGroupsTables(), + Dialogs.showPermissionsDialog(messages.SIARDHomePageDialogTitleForPermissionsList(), + messages.SIARDHomePageDialogDescriptionForPermissionsList(), "900px", getGroupsTables(), messages.basicActionCancel(), messages.basicActionConfirm(), new NoAsyncCallback() { @Override public void onSuccess(Boolean confirmation) { @@ -185,10 +193,17 @@ private void handleSwitchBottom() { private FlowPanel getGroupsTables() { FlowPanel permissionListPanel = new FlowPanel(); + TextBox searchBox = new TextBox(); + searchBox.getElement().setPropertyString("placeholder", messages.searchPlaceholder()); + searchBox.addStyleName("searchBox-permissions"); + + permissionListPanel.addStyleName("scrollable-panel"); + permissionListPanel.add(searchBox); + permissionListPanel .add(new Alert(Alert.MessageAlertType.INFO, messages.SIARDHomePageDialogDetailsForPermissionsList())); - Column checkbox = new Column( + checkbox = new Column( new CheckboxCell(true, true)) { @Override public Boolean getValue(AuthorizationGroup group) { @@ -210,10 +225,44 @@ public Boolean getValue(AuthorizationGroup group) { } }); - BasicTablePanel cellTable = new BasicTablePanel<>(new FlowPanel(), - SafeHtmlUtils.EMPTY_SAFE_HTML, groups.iterator(), + buildGroupsTable(groups, checkbox); + permissionListPanel.add(cellTable); + + searchBox.addChangeHandler(event -> { + doSearch(searchBox.getValue(), permissionListPanel); + }); + + searchBox.addKeyUpHandler(event -> { + doSearch(searchBox.getValue(), permissionListPanel); + }); + + Set missingGroups = retrieveMissingGroups(); + if (!missingGroups.isEmpty()) { + CheckBox checkBoxOverrideMissingGroups = new CheckBox(); + checkBoxOverrideMissingGroups.setValue(false); + checkBoxOverrideMissingGroups.setText(messages.SIARDHomePageDialogActionForOverridePermissions()); + checkBoxOverrideMissingGroups.addValueChangeHandler(event -> { + if (event.getValue()) { + overrideMissingGroups = true; + } else { + overrideMissingGroups = false; + } + }); + Alert alert = new Alert(Alert.MessageAlertType.WARNING, + messages.SIARDHomePageDialogDetailsForUnknownPermissions(String.join(", ", missingGroups)), + checkBoxOverrideMissingGroups); + + permissionListPanel.add(alert); + + } + return permissionListPanel; + } + + private void buildGroupsTable(Set groups, + Column checkbox) { + cellTable = new BasicTablePanel<>(new FlowPanel(), SafeHtmlUtils.EMPTY_SAFE_HTML, groups.iterator(), new BasicTablePanel.ColumnInfo("", 3, checkbox), - new BasicTablePanel.ColumnInfo(messages.SIARDHomePageLabelForPermissionsTableGroupLabel(), 7, + new BasicTablePanel.ColumnInfo(messages.SIARDHomePageLabelForPermissionsTableGroupLabel(), 15, new TooltipColumn() { @Override public SafeHtml getValue(AuthorizationGroup group) { @@ -221,14 +270,15 @@ public SafeHtml getValue(AuthorizationGroup group) { } }, "force_column_ellipsis"), new BasicTablePanel.ColumnInfo( - messages.SIARDHomePageLabelForPermissionsTableGroupAttributeName(), 7, new TooltipColumn() { + messages.SIARDHomePageLabelForPermissionsTableGroupAttributeName(), 12, + new TooltipColumn() { @Override public SafeHtml getValue(AuthorizationGroup group) { return SafeHtmlUtils.fromString(group.getAttributeName()); } }, "force_column_ellipsis"), new BasicTablePanel.ColumnInfo( - messages.SIARDHomePageLabelForPermissionsTableGroupAttributeOperator(), 7, + messages.SIARDHomePageLabelForPermissionsTableGroupAttributeOperator(), 12, new TooltipColumn() { @Override public SafeHtml getValue(AuthorizationGroup group) { @@ -236,34 +286,42 @@ public SafeHtml getValue(AuthorizationGroup group) { } }, "force_column_ellipsis"), new BasicTablePanel.ColumnInfo( - messages.SIARDHomePageLabelForPermissionsTableGroupAttributeValue(), 0, new TooltipColumn() { + messages.SIARDHomePageLabelForPermissionsTableGroupAttributeValue(), 0, + new TooltipColumn() { @Override public SafeHtml getValue(AuthorizationGroup group) { return SafeHtmlUtils.fromString(group.getAttributeValue()); } }, "force_column_ellipsis")); + } - permissionListPanel.add(cellTable); - Set missingGroups = retrieveMissingGroups(); - if (!missingGroups.isEmpty()) { - CheckBox checkBoxOverrideMissingGroups = new CheckBox(); - checkBoxOverrideMissingGroups.setValue(false); - checkBoxOverrideMissingGroups.setText(messages.SIARDHomePageDialogActionForOverridePermissions()); - checkBoxOverrideMissingGroups.addValueChangeHandler(event -> { - if (event.getValue()) { - overrideMissingGroups = true; - } else { - overrideMissingGroups = false; - } - }); - Alert alert = new Alert(Alert.MessageAlertType.WARNING, - messages.SIARDHomePageDialogDetailsForUnknownPermissions(String.join(", ", missingGroups)), - checkBoxOverrideMissingGroups); - - permissionListPanel.add(alert); + private void doSearch(String searchValue, FlowPanel permissionListPanel) { + permissionListPanel.remove(cellTable); + if (ViewerStringUtils.isBlank(searchValue)) { + showAll(); + permissionListPanel.add(cellTable); + } else { + showMatching(searchValue); + permissionListPanel.add(cellTable); } - return permissionListPanel; + } + + private void showAll() { + // Show all the groups + buildGroupsTable(groups, checkbox); + } + + private void showMatching(final String searchValue) { + // Filter the groups based on the search value + List matchingGroups = groups.stream() + .filter(group -> group.getLabel().toLowerCase().contains(searchValue.toLowerCase()) + || group.getAttributeName().toLowerCase().contains(searchValue.toLowerCase()) + || group.getAttributeOperator().toLowerCase().contains(searchValue.toLowerCase()) + || group.getAttributeValue().toLowerCase().contains(searchValue.toLowerCase())) + .collect(Collectors.toList()); + + buildGroupsTable(new HashSet<>(matchingGroups), checkbox); } private Set retrieveMissingGroups() { diff --git a/src/main/resources/com/databasepreservation/common/public/main.css b/src/main/resources/com/databasepreservation/common/public/main.css index 88d1c879..fdf72413 100644 --- a/src/main/resources/com/databasepreservation/common/public/main.css +++ b/src/main/resources/com/databasepreservation/common/public/main.css @@ -2281,6 +2281,10 @@ html, body { /*********************************************** CHECKBOX ************************************************/ +.scrollable-panel { + max-height: 500px; + overflow-y: auto; +} /* .my-asyncdatagrid-display-scroll-wrapper input[type="checkbox"] { padding-left: 5px; diff --git a/src/main/resources/com/databasepreservation/common/public/roda_main.css b/src/main/resources/com/databasepreservation/common/public/roda_main.css index 70f88f3a..81e046d9 100644 --- a/src/main/resources/com/databasepreservation/common/public/roda_main.css +++ b/src/main/resources/com/databasepreservation/common/public/roda_main.css @@ -3333,6 +3333,18 @@ td.datePickerMonth, td.datePickerYear { background-color: #eee; } +.searchBox-permissions { + margin-bottom: 10px; + box-sizing: border-box; + width: 100%; + height: 4rem; + line-height: 4rem; + font-size: 2rem; + border: none; + padding: 0 1rem; + background-color: #eee; +} + .searchBox::-webkit-input-placeholder, .searchBox:placeholder-shown { color: rgba(0, 0, 0, 0.5); @@ -3576,6 +3588,10 @@ td.datePickerMonth, td.datePickerYear { } +.wui-dialog-edit-permissions { + top: 15% !important +} + .wui-dialog-layout { padding: 10px; }