Skip to content

Commit

Permalink
added scroll and search to db permissions panel (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 authored Nov 21, 2024
1 parent ea64644 commit 2e626d7
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<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 @@ -58,6 +62,8 @@ public class PermissionsNavigationPanel {
private FlowPanel bottom;
private Button btnEdit;
private SwitchBtn btnSwitch;
private Column<AuthorizationGroup, Boolean> checkbox;
private BasicTablePanel<AuthorizationGroup> cellTable;

private boolean overrideMissingGroups = false;

Expand Down Expand Up @@ -90,7 +96,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 +154,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,10 +192,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<AuthorizationGroup, Boolean> checkbox = new Column<AuthorizationGroup, Boolean>(
checkbox = new Column<AuthorizationGroup, Boolean>(
new CheckboxCell(true, true)) {
@Override
public Boolean getValue(AuthorizationGroup group) {
Expand All @@ -210,60 +224,103 @@ public Boolean getValue(AuthorizationGroup group) {
}
});

BasicTablePanel<AuthorizationGroup> 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<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 void buildGroupsTable(Set<AuthorizationGroup> groups,
Column<AuthorizationGroup, Boolean> checkbox) {
cellTable = 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, 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<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());

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 2e626d7

Please sign in to comment.