Skip to content

Commit

Permalink
Progress on #1333: fix superfluous searches
Browse files Browse the repository at this point in the history
Searching only occurs when the list is attached and visible;
Pressing enter on the search box or clicking the magnifying glass icon shows the list and triggers a refresh (effectively a first fetch if there was no data in the list yet).
  • Loading branch information
chalkos committed Sep 5, 2018
1 parent b63c750 commit 141faa7
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ public abstract class AsyncTableCell<T extends IsIndexed> extends FlowPanel
static final ClientMessages messages = GWT.create(ClientMessages.class);
private static final ClientLogger LOGGER = new ClientLogger(AsyncTableCell.class.getName());

private AsyncTableCellOptions<T> options;

private Class<T> classToReturn;
private String listId;
private Actionable<T> actionable;
Expand Down Expand Up @@ -177,6 +175,8 @@ AsyncTableCell<T> initialize(AsyncTableCellOptions<T> options) {

this.fieldsToReturn = options.getFieldsToReturn();

this.setVisible(options.isStartHidden());

display = new AccessibleCellTable<>(getInitialPageSize(), GWT.create(MyCellTableResources.class), getKeyProvider(),
options.getSummary());
display.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
Expand Down Expand Up @@ -341,10 +341,6 @@ public void onValueChange(ValueChangeEvent<IndexResult<T>> event) {
autoUpdate(options.getAutoUpdate());
}

if (options.isStartHidden()) {
this.setVisible(false);
}

return this;
}

Expand Down Expand Up @@ -478,14 +474,14 @@ public Object getKey(T item) {

private void getData(Filter filter, Sublist sublist, Sorter sorter, List<String> fieldsToReturn,
AsyncCallback<IndexResult<T>> callback) {
if (filter == null) {
if (isSearchRestricted()) {
callback.onSuccess(null);
} else {
getData(sublist, sorter, fieldsToReturn, callback);
}
}

protected void getData(Sublist sublist, Sorter sorter, List<String> fieldsToReturn,
private void getData(Sublist sublist, Sorter sorter, List<String> fieldsToReturn,
AsyncCallback<IndexResult<T>> callback) {
BrowserService.Util.getInstance().find(getClassToReturn().getName(), getFilter(), sorter, sublist, getFacets(),
LocaleInfo.getCurrentLocale().getLocaleName(), getJustActive(), fieldsToReturn, callback);
Expand Down Expand Up @@ -583,6 +579,10 @@ public Filter getFilter() {
return filter;
}

public boolean isSearchRestricted() {
return !isAttached() || !isVisible();
}

public boolean getJustActive() {
return justActive;
}
Expand Down Expand Up @@ -1128,4 +1128,12 @@ public void resumeAutoUpdate() {
setAutoUpdateState(AutoUpdateState.AUTO_UPDATE_ON);
}
}

@Override
protected void onAttach() {
super.onAttach();
if (!isSearchRestricted()) {
refresh();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface MyUiBinder extends UiBinder<Widget, CatalogueSearch> {
final Permissions permissions;

public CatalogueSearch(boolean justActive, String itemsListId, String representationsListId, String filesListId,
String parentAipId, AIPState parentAipState, Permissions permissions) {
String parentAipId, AIPState parentAipState, Permissions permissions, boolean startHidden) {

this.parentAipId = parentAipId;
this.parentAipState = parentAipState;
Expand All @@ -62,15 +62,15 @@ public CatalogueSearch(boolean justActive, String itemsListId, String representa
// prepare lists
ListBuilder<IndexedAIP> aipListBuilder = new ListBuilder<>(() -> new AIPList(),
new AsyncTableCellOptions<>(IndexedAIP.class, itemsListId).withJustActive(justActive).bindOpener()
.withStartHidden(true).withActionable(AipActions.get(parentAipId, parentAipState, permissions)));
.withStartHidden(startHidden).withActionable(AipActions.get(parentAipId, parentAipState, permissions)));

ListBuilder<IndexedRepresentation> representationListBuilder = new ListBuilder<>(() -> new RepresentationList(),
new AsyncTableCellOptions<>(IndexedRepresentation.class, representationsListId).withJustActive(justActive)
.bindOpener().withStartHidden(true).withActionable(RepresentationActions.get()));
.bindOpener().withStartHidden(startHidden).withActionable(RepresentationActions.get()));

ListBuilder<IndexedFile> fileListBuilder = new ListBuilder<>(() -> new SearchFileList(true),
new AsyncTableCellOptions<>(IndexedFile.class, filesListId).withJustActive(justActive).bindOpener()
.withStartHidden(true).withActionable(FileActions.get()));
.withStartHidden(startHidden).withActionable(FileActions.get()));

// add lists to search
searchWrapper = new SearchWrapper(true, IndexedAIP.class.getSimpleName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public void run() {
* if subsequent searches should add to or replace the existing filter
*/
public void setDefaultFilter(Filter defaultFilter, boolean incremental) {
clearSearchInputBox();
this.defaultFilter = defaultFilter;
this.defaultFilterIncremental = incremental;
doSearch(false);
Expand Down Expand Up @@ -295,11 +296,11 @@ private void doSearch() {
}

private void doSearch(boolean makeListVisible) {
list.setFilter(buildSearchFilter());
onChange(searchInputBox.getValue());
if (makeListVisible) {
list.setVisible(true);
}
list.setFilter(buildSearchFilter());
onChange(searchInputBox.getValue());
}

private void onChange(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,21 @@ private <T extends IsIndexed> void refreshList(Class<T> objectClass) {

public <T extends IsIndexed> void setFilter(String objectClassSimpleName, Filter filter) {
SearchPanel<T> searchPanel = components.getSearchPanel(objectClassSimpleName);
searchPanel.clearSearchInputBox();
searchPanel.setDefaultFilter(filter, SearchFilters.shouldBeIncremental(filter));
}

public <T extends IsIndexed> void setFilter(Class<T> objectClass, Filter filter) {
SearchPanel<T> searchPanel = components.getSearchPanel(objectClass);
searchPanel.clearSearchInputBox();
searchPanel.setDefaultFilter(filter, SearchFilters.shouldBeIncremental(filter));
}

public <T extends IsIndexed> void resetToDefaultFilter(String objectClassSimpleName) {
SearchPanel<T> searchPanel = components.getSearchPanel(objectClassSimpleName);
searchPanel.clearSearchInputBox();
searchPanel.setDefaultFilter(SearchFilters.allFilter(), false);
}

public <T extends IsIndexed> void resetToDefaultFilter(Class<T> objectClass) {
SearchPanel<T> searchPanel = components.getSearchPanel(objectClass);
searchPanel.clearSearchInputBox();
searchPanel.setDefaultFilter(SearchFilters.allFilter(), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.roda.core.data.v2.ip.AIPState;
import org.roda.wui.client.common.UserLogin;
import org.roda.wui.client.common.search.CatalogueSearch;
import org.roda.wui.client.common.utils.JavascriptUtils;
import org.roda.wui.common.client.HistoryResolver;
import org.roda.wui.common.client.widgets.HTMLWidgetWrapper;

Expand All @@ -38,7 +37,11 @@ public class Search extends Composite {

@Override
public void resolve(List<String> historyTokens, AsyncCallback<Widget> callback) {
getInstance().resolve(historyTokens, callback);
if (historyTokens.size() > 1) {
SearchWithPreFilters.getInstance().resolve(historyTokens, callback);
} else {
getInstance().resolve(callback);
}
}

@Override
Expand Down Expand Up @@ -73,7 +76,7 @@ interface MyUiBinder extends UiBinder<Widget, Search> {
private Search() {
// Create main search
catalogueSearch = new CatalogueSearch(true, "Search_AIPs", "Search_representations", "Search_files", null,
AIPState.ACTIVE, null);
AIPState.ACTIVE, null, true);

initWidget(uiBinder.createAndBindUi(this));
searchDescription.add(new HTMLWidgetWrapper("SearchDescription.html"));
Expand All @@ -86,14 +89,7 @@ public static Search getInstance() {
return instance;
}

@Override
protected void onLoad() {
super.onLoad();
JavascriptUtils.stickSidebar();
}

public void resolve(List<String> historyTokens, AsyncCallback<Widget> callback) {
catalogueSearch.setFilters(historyTokens);
public void resolve(AsyncCallback<Widget> callback) {
callback.onSuccess(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE file at the root of the source
* tree and available online at
*
* https://github.com/keeps/roda
*/
/**
*
*/
package org.roda.wui.client.search;

import java.util.Arrays;
import java.util.List;

import org.roda.core.data.v2.ip.AIPState;
import org.roda.wui.client.common.UserLogin;
import org.roda.wui.client.common.search.CatalogueSearch;
import org.roda.wui.common.client.HistoryResolver;
import org.roda.wui.common.client.widgets.HTMLWidgetWrapper;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* @author Luis Faria
*
*/
public class SearchWithPreFilters extends Composite {

// Used by Search.RESOLVER

private static SearchWithPreFilters instance = null;

interface MyUiBinder extends UiBinder<Widget, SearchWithPreFilters> {
}

private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

@UiField
FlowPanel searchDescription;

@UiField(provided = true)
CatalogueSearch catalogueSearch;

private SearchWithPreFilters() {
// Create main search
catalogueSearch = new CatalogueSearch(true, "Search_AIPs", "Search_representations", "Search_files", null,
AIPState.ACTIVE, null, false);

initWidget(uiBinder.createAndBindUi(this));
searchDescription.add(new HTMLWidgetWrapper("SearchDescription.html"));
}

public static SearchWithPreFilters getInstance() {
if (instance == null) {
instance = new SearchWithPreFilters();
}
return instance;
}

public void resolve(List<String> historyTokens, AsyncCallback<Widget> callback) {
catalogueSearch.setFilters(historyTokens);
callback.onSuccess(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:commonsearch="urn:import:org.roda.wui.client.common.search">

<ui:with field='messages' type='config.i18n.client.ClientMessages' />

<g:FlowPanel styleName="search" addStyleNames="wrapper skip_padding">
<g:FlowPanel addStyleNames="row full_width skip_padding">
<g:FlowPanel addStyleNames="col_12 content">
<g:HTML>
<h1>
<ui:text from='{messages.searchTitle}' />
</h1>
</g:HTML>
<g:FlowPanel addStyleNames="page-description" ui:field="searchDescription">
</g:FlowPanel>
<commonsearch:CatalogueSearch ui:field="catalogueSearch" />
</g:FlowPanel>
</g:FlowPanel>
</g:FlowPanel>
</ui:UiBinder>

0 comments on commit 141faa7

Please sign in to comment.