Skip to content

Commit

Permalink
added scroll and search to db permissions panel
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 committed Nov 20, 2024
1 parent f40ddda commit 5654096
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
package com.databasepreservation.common.client.common.dialogs;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.databasepreservation.common.client.common.NoAsyncCallback;
import com.databasepreservation.common.client.common.fields.GenericField;
import com.databasepreservation.common.client.common.helpers.HelperValidator;
import com.databasepreservation.common.client.common.lists.columns.IndexedColumn;
import com.databasepreservation.common.client.common.sidebar.SidebarItem;
import com.databasepreservation.common.client.common.utils.CommonClientUtils;
import com.databasepreservation.common.client.common.visualization.browse.configuration.columns.helpers.ColumnOptionsPanel;
import com.databasepreservation.common.client.models.wizard.table.ExternalLobsDialogBoxResult;
import com.databasepreservation.common.client.tools.ViewerStringUtils;
import com.databasepreservation.common.client.widgets.Alert;
import com.databasepreservation.common.client.widgets.MyCellTableResources;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
Expand All @@ -30,6 +35,7 @@
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
Expand All @@ -49,6 +55,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() {
Expand Down Expand Up @@ -835,4 +842,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<Boolean> 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();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

/**
Expand All @@ -56,6 +60,7 @@ public class PermissionsNavigationPanel {
private boolean hasPermissionsOrGroups = true;
private FlowPanel body;
private FlowPanel bottom;
TextBox searchInputBox;
private Button btnEdit;
private SwitchBtn btnSwitch;

Expand Down Expand Up @@ -90,7 +95,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();
}

Expand Down Expand Up @@ -147,8 +153,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<Boolean>() {
@Override
public void onSuccess(Boolean confirmation) {
Expand Down Expand Up @@ -185,6 +191,13 @@ 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()));

Expand All @@ -210,60 +223,105 @@ public Boolean getValue(AuthorizationGroup group) {
}
});

BasicTablePanel<AuthorizationGroup> cellTable = new BasicTablePanel<>(new FlowPanel(),
SafeHtmlUtils.EMPTY_SAFE_HTML, groups.iterator(),
BasicTablePanel<AuthorizationGroup> cellTable = buildGroupsTable(groups, checkbox);
permissionListPanel.add(cellTable);

searchBox.addChangeHandler(event -> {
doSearch(searchBox.getValue(), checkbox, permissionListPanel, cellTable);
});

searchBox.addKeyUpHandler(event -> {
doSearch(searchBox.getValue(), checkbox, permissionListPanel, cellTable);
});

Set<String> 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 BasicTablePanel<AuthorizationGroup> buildGroupsTable(Set<AuthorizationGroup> groups,
Column<AuthorizationGroup, Boolean> checkbox) {
return new BasicTablePanel<>(new FlowPanel(), SafeHtmlUtils.EMPTY_SAFE_HTML, groups.iterator(),
new BasicTablePanel.ColumnInfo<AuthorizationGroup>("", 3, checkbox),
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(messages.SIARDHomePageLabelForPermissionsTableGroupLabel(), 7,
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(messages.SIARDHomePageLabelForPermissionsTableGroupLabel(), 15,
new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getLabel());
}
}, "force_column_ellipsis"),
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeName(), 7, new TooltipColumn<AuthorizationGroup>() {
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeName(), 12,
new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getAttributeName());
}
}, "force_column_ellipsis"),
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeOperator(), 7,
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeOperator(), 12,
new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getAttributeOperator());
}
}, "force_column_ellipsis"),
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeValue(), 0, new TooltipColumn<AuthorizationGroup>() {
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeValue(), 0,
new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getAttributeValue());
}
}, "force_column_ellipsis"));
}

permissionListPanel.add(cellTable);
Set<String> 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, Column<AuthorizationGroup, Boolean> checkbox, FlowPanel permissionListPanel,
BasicTablePanel<AuthorizationGroup> cellTable) {
permissionListPanel.remove(cellTable);

if (ViewerStringUtils.isBlank(searchValue)) {
permissionListPanel.remove(1);
permissionListPanel.add(showAll(checkbox));
} else {
permissionListPanel.remove(1);
permissionListPanel.add(showMatching(searchValue, checkbox));
}
return permissionListPanel;
}

private BasicTablePanel<AuthorizationGroup> showAll(Column<AuthorizationGroup, Boolean> checkBox) {
// Clear the table and add all groups
return buildGroupsTable(groups, checkBox);
}

private BasicTablePanel<AuthorizationGroup> showMatching(final String searchValue,
Column<AuthorizationGroup, Boolean> checkbox) {
// Filter the groups based on the search value
List<AuthorizationGroup> 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());

return buildGroupsTable(new HashSet<>(matchingGroups), checkbox);
}

private Set<String> retrieveMissingGroups() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -3576,6 +3588,10 @@ td.datePickerMonth, td.datePickerYear {

}

.wui-dialog-edit-permissions {
top: 15% !important
}

.wui-dialog-layout {
padding: 10px;
}
Expand Down

0 comments on commit 5654096

Please sign in to comment.