Skip to content

Commit

Permalink
Bug fixing and revert selected items behavior to default AsyncTableCe…
Browse files Browse the repository at this point in the history
…ll behavior
  • Loading branch information
SugaryLump committed Nov 28, 2024
1 parent 0f331bd commit 315e7c7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.databasepreservation.common.client.common.dialogs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -20,6 +21,7 @@
import com.databasepreservation.common.client.index.filter.OneOfManyFilterParameter;
import com.databasepreservation.common.client.index.filter.SimpleFilterParameter;
import com.databasepreservation.common.client.index.select.SelectedItems;
import com.databasepreservation.common.client.index.select.SelectedItemsFilter;
import com.databasepreservation.common.client.index.select.SelectedItemsList;
import com.databasepreservation.common.client.index.sort.Sorter;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
Expand Down Expand Up @@ -92,7 +94,6 @@ public void init(Filter defaultFilter, String allFilter, ClientMessages messages
}
});
this.list = metadataDatabaseList;
metadataDatabaseList.addSelectedResetListener(this::doParentSearch);

return metadataDatabaseList;
}, new AsyncTableCellOptions<>(ViewerDatabase.class, "DatabaseList_metadata"));
Expand Down Expand Up @@ -156,7 +157,7 @@ public void resetExcludedInfo() {
public void updateExcludedInfo() {
this.exludedInfo
.setWidget(new HTML(SafeHtmlUtils.fromSafeConstant(messages.manageDatabaseSearchAllExcludedLoaded(this.notLoaded)
+ messages.manageDatabaseSearchAllExcludedPrivacy(this.notSearchable))));
+ " " + messages.manageDatabaseSearchAllExcludedPrivacy(this.notSearchable))));
}

public void writeSelectedObjectsToLocalStorage() {
Expand All @@ -166,21 +167,22 @@ public void writeSelectedObjectsToLocalStorage() {
if (selectedItems instanceof SelectedItemsList<?>) {
localStorage.setItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION,
String.join(",", ((SelectedItemsList<ViewerDatabase>) selectedItems).getIds()));
} else if (selectedItems instanceof SelectedItemsFilter<?>) {
localStorage.setItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION, ViewerConstants.SEARCHALL_SELECTEDALL);
}
}
this.list.resetSelected();
}

public void clearSelectedObjectsInLocalStorage() {
Storage localStorage = Storage.getLocalStorageIfSupported();
if (localStorage != null) {
localStorage.removeItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION);
}
this.list.resetSelected();
}

private void confirmHandler() {
this.writeSelectedObjectsToLocalStorage();
this.doParentSearch();
this.hide();
}

Expand All @@ -190,23 +192,44 @@ private void cancelHandler() {

private void clearHandler() {
this.clearSelectedObjectsInLocalStorage();
this.doParentSearch();
this.hide();
}

private void doParentSearch(List<String> selectedUUIDs) {
private void doParentSearch() {
Storage localStorage = Storage.getLocalStorageIfSupported();
List<String> selectedUUIDs = null;
boolean selectedAll = false;
if (localStorage != null) {
String uuidsString = localStorage.getItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION);
if (uuidsString != null) {
if (uuidsString.equals(ViewerConstants.SEARCHALL_SELECTEDALL)) {
selectedAll = true;
} else {
selectedUUIDs = new ArrayList<>();
if (!uuidsString.isEmpty()) {
Collections.addAll(selectedUUIDs, uuidsString.split(","));
}
}
}
}
if (selectedUUIDs != null) {
Filter newFilter = new Filter(this.defaultFilter);
newFilter.add(new OneOfManyFilterParameter(ViewerConstants.SOLR_ROWS_DATABASE_UUID, selectedUUIDs));
this.parentSearchPanel.setSearchAllTotalDatabases((long) selectedUUIDs.size());
this.parentSearchPanel.setDefaultFilter(newFilter);
this.parentSearchPanel.doSearch();
} else if (selectedAll || ClientConfigurationManager
.getStringWithDefault(ViewerConstants.SEARCHALL_SELECTEDALL, ViewerConstants.PROPERTY_SEARCHALL_DEFAULTSELECTION)
.equals(ViewerConstants.SEARCHALL_SELECTEDALL)) {
this.parentSearchPanel.setSearchAllTotalDatabases(this.list.getResult().getTotalCount());
this.parentSearchPanel.setDefaultFilter(defaultFilter);
this.parentSearchPanel.doSearch();
} else {
if (ClientConfigurationManager.getStringWithDefault(ViewerConstants.SEARCHALL_SELECTEDALL,
ViewerConstants.PROPERTY_SEARCHALL_DEFAULTSELECTION).equals(ViewerConstants.SEARCHALL_SELECTEDALL)) {
this.parentSearchPanel.setSearchAllTotalDatabases(this.list.getResult().getTotalCount());
this.parentSearchPanel.setDefaultFilter(defaultFilter);
this.parentSearchPanel.doSearch();
}
this.parentSearchPanel.setSearchAllTotalDatabases(0L);
this.parentSearchPanel.setDefaultFilter(defaultFilter);
this.parentSearchPanel.doSearch();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
*/
package com.databasepreservation.common.client.common.lists;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

Expand All @@ -28,8 +25,6 @@
import com.databasepreservation.common.client.index.IndexResult;
import com.databasepreservation.common.client.index.facets.Facets;
import com.databasepreservation.common.client.index.filter.Filter;
import com.databasepreservation.common.client.index.select.SelectedItems;
import com.databasepreservation.common.client.index.select.SelectedItemsList;
import com.databasepreservation.common.client.index.sort.Sorter;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
import com.databasepreservation.common.client.models.user.User;
Expand All @@ -40,7 +35,6 @@
import com.google.gwt.i18n.client.LocaleInfo;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.storage.client.Storage;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortList;
Expand All @@ -58,31 +52,12 @@ public class DatabaseSelectList extends BasicAsyncTableCell<ViewerDatabase> {
private static final String OPEN_VALIDATED_SPAN = "<span>&#10004;</span>";
private static final String OPEN_NOT_VALIDATED_SPAN = "<span>&#10006;</span>";

private String localStorageSelectedId;
private Collection<String> savedSelectedUUIDs;
private List<SelectedResetListener> selectedResetListeners;

public DatabaseSelectList() {
this(new Filter(), null, null, false, false);
}

public DatabaseSelectList(Filter filter, Facets facets, String summary, boolean selectable, boolean exportable) {
super(filter, facets, summary, selectable, exportable, 15, 15);
this.localStorageSelectedId = localStorageSelectedId;
loadSavedSelectedUUIDsFromLocalStorage();
addValueChangeHandler(event -> resetSelected());
this.selectedResetListeners = new ArrayList<>();
}

private void loadSavedSelectedUUIDsFromLocalStorage() {
this.savedSelectedUUIDs = new ArrayList<>();
Storage storage = Storage.getLocalStorageIfSupported();
String storageString = storage.getItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION);
if (storageString != null) {
this.savedSelectedUUIDs.addAll(List.of(storageString.split(",")));
} else {
this.savedSelectedUUIDs = null;
}
}

@Override
Expand Down Expand Up @@ -196,41 +171,4 @@ protected void getData(Sublist sublist, ColumnSortList columnSortList,
public void exportClickHandler() {
// do nothing
}

public void resetSelected() {
loadSavedSelectedUUIDsFromLocalStorage();
if (this.savedSelectedUUIDs != null) {
setSelectedByUUIDs(this.savedSelectedUUIDs);
} else {
setSelected(new HashSet<>());
redraw();
fireOnCheckboxSelectionChanged();
}
SelectedItems<ViewerDatabase> selectedItems = getSelected();
List<String> selectedUUIDs;
if (this.savedSelectedUUIDs != null && selectedItems instanceof SelectedItemsList<?>) {
selectedUUIDs = new ArrayList<>(((SelectedItemsList<?>) selectedItems).getIds());
} else {
selectedUUIDs = null;
}
for (SelectedResetListener listener : this.selectedResetListeners) {
listener.onSelectionChange(selectedUUIDs);
}
}

@Override
public void refresh() {
super.refresh();
resetSelected();
}

// LISTENER

public interface SelectedResetListener {
void onSelectionChange(List<String> selected);
}

public void addSelectedResetListener(SelectedResetListener listener) {
this.selectedResetListeners.add(listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,6 @@ public void setSelectedByUUIDs(Iterable<String> databaseUUIDs) {
fireOnCheckboxSelectionChanged();
}

public void setSelectedAll() {
this.selectAllCheckBox.setValue(true);
}

public void clearSelected() {
selected.clear();
redraw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void init(Filter defaultFilter, String allFilter, ClientMessages messages
this.messages = messages;
this.button = new Button();
this.button.addStyleName("btn-link-info btn btn-searchall-dialog");
setTotalSelectedDatabases(0L);
this.databaseSelectDialog = new DatabaseSelectDialog(defaultFilter, allFilter, messages, parentSearchPanel);
this.button.addClickHandler(event -> {
this.databaseSelectDialog.center();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ private <T extends IsIndexed> void attachComponents(String objectClassSimpleName

rootPanel.clear();
rootPanel.add(searchPanel);

if (!(searchPanel instanceof SearchPanelWithSearchAll)
|| !((SearchPanelWithSearchAll) searchPanel).getTotalSelected().equals("0")) {
|| ((SearchPanelWithSearchAll) searchPanel).getTotalSelected() != 0) {
if (scrollPanelCssClasses != null) {
ScrollPanel scrollPanel = new ScrollPanel(list);
scrollPanel.addStyleName(scrollPanelCssClasses);
Expand Down

0 comments on commit 315e7c7

Please sign in to comment.