Skip to content

Commit

Permalink
set checkboxes for expired permissions to indeterminate state
Browse files Browse the repository at this point in the history
  • Loading branch information
SugaryLump committed Feb 5, 2025
1 parent 52409fc commit 4e5dd3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,9 @@ public static native void removeAttribute(String elementId, String attribute) /*
var element = $wnd.jQuery("#" + elementId);
element.removeAttr(attribute);
}-*/;

public static native void setIndeterminate(String checkboxesJQuery) /*-{
var checkboxes = $wnd.jQuery(checkboxesJQuery);
checkboxes.prop("indeterminate", true);
}-*/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.CheckboxCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.TimeZone;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlowPanel;
Expand Down Expand Up @@ -234,6 +236,17 @@ private FlowPanel getGroupsTables() {
public Boolean getValue(AuthorizationGroup group) {
return databasePermissionGroups.contains(group.getAttributeValue());
}

@Override
public String getCellStyleNames(Cell.Context context, AuthorizationGroup group) {
if (groupDetails.getOrDefault(group.getAttributeValue(), new AuthorizationDetails()).hasExpiryDate()) {
Date now = new Date();
if (now.after(groupDetails.get(group.getAttributeValue()).getExpiry())) {
return "expired";
}
}
return "";
}
};

checkbox.setFieldUpdater((index, group, value) -> {
Expand All @@ -242,6 +255,7 @@ public Boolean getValue(AuthorizationGroup group) {
if (!databasePermissionGroups.contains(group.getAttributeValue())) {
databasePermissionGroups.add(group.getAttributeValue());
}
deferSetIndeterminateCheckboxes();
} else {
// Remove
databasePermissionGroups.remove(group.getAttributeValue());
Expand Down Expand Up @@ -378,6 +392,7 @@ public void onSuccess(Boolean confirmation) {
}
groupDetails.put(currentGroup.getAttributeValue(), authorizationDetails);
cellTable.refresh();
deferSetIndeterminateCheckboxes();
}
}
});
Expand Down Expand Up @@ -421,6 +436,7 @@ public SafeHtml getValue(AuthorizationGroup group) {
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupExpiryDate(), 12, expiry,
"force_column_ellipsis expiry_column"));
deferSetIndeterminateCheckboxes();
}

private void doSearch(String searchValue, FlowPanel permissionListPanel) {
Expand Down Expand Up @@ -477,4 +493,12 @@ private Map<String, AuthorizationDetails> createDatabasePermissionsMap() {
}
return permissions;
}

private void deferSetIndeterminateCheckboxes() {
Scheduler.get().scheduleDeferred(new Command() {
public void execute() {
JavascriptUtils.setIndeterminate(".expired input");
}
});
}
}

0 comments on commit 4e5dd3b

Please sign in to comment.