Skip to content

Commit

Permalink
saved filters list reload + sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 29, 2022
1 parent 7efce5e commit afd20ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {
}
saveCustomQuery(ajaxRequestTarget);
getPageBase().hideMainPopup(ajaxRequestTarget);
saveSearchFilterPerformed(ajaxRequestTarget);
}
};
saveButton.setOutputMarkupId(true);
Expand All @@ -113,6 +114,9 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {
buttonsPanel.add(cancelButton);
}

protected void saveSearchFilterPerformed(AjaxRequestTarget target) {
}

private void saveCustomQuery(AjaxRequestTarget ajaxRequestTarget) {
Search<C> search = getModelObject();
AvailableFilterType availableFilter = new AvailableFilterType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public abstract class SearchPanel<C extends Containerable> extends BasePanel<Sea

private LoadableModel<List<AbstractSearchItemWrapper>> basicSearchItemsModel;
private LoadableModel<List<AbstractSearchItemWrapper>> morePopupModel;
private LoadableDetachableModel<List<AvailableFilterType>> savedSearchListModel;
private static final Trace LOG = TraceManager.getTrace(SearchPanel.class);

public SearchPanel(String id, IModel<Search<C>> searchModel) {
Expand Down Expand Up @@ -221,6 +222,15 @@ protected VisibleEnableBehaviour getSearchButtonVisibleEnableBehavior() {
saveSearchContainer.add(new VisibleBehaviour(() -> !isPopupWindow() && isCollectionInstancePage()));
saveSearchContainer.setOutputMarkupId(true);
form.add(saveSearchContainer);
savedSearchListModel = new LoadableDetachableModel<List<AvailableFilterType>>() {
private static final long serialVersionUID = 1L;

@Override
protected List<AvailableFilterType> load() {
return getSavedFilterList();
}
};

AjaxButton saveSearchButton = new AjaxButton(ID_SAVE_SEARCH_BUTTON) {

private static final long serialVersionUID = 1L;
Expand All @@ -230,23 +240,20 @@ public void onClick(AjaxRequestTarget target) {
SaveSearchPanel<C> panel = new SaveSearchPanel<>(getPageBase().getMainPopupBodyId(),
Model.of(SearchPanel.this.getModelObject()),
SearchPanel.this.getModelObject().getTypeClass(),
getCollectionInstanceDefaultIdentifier());
getCollectionInstanceDefaultIdentifier()) {

@Override
protected void saveSearchFilterPerformed(AjaxRequestTarget target) {
SearchPanel.this.saveSearchFilterPerformed(target);
}
};
getPageBase().showMainPopup(panel, target);
}
};
saveSearchButton.add(AttributeAppender.append("title", getPageBase().createStringResource("SearchPanel.saveFilterButton.title")));
saveSearchButton.setOutputMarkupId(true);
saveSearchContainer.add(saveSearchButton);

LoadableModel<List<AvailableFilterType>> savedSearchListModel = new LoadableModel<List<AvailableFilterType>>() {
private static final long serialVersionUID = 1L;

@Override
protected List<AvailableFilterType> load() {
return getSavedFilterList();
}
};

SelectableItemListPopoverPanel<AvailableFilterType> savedFiltersPopover =
new SelectableItemListPopoverPanel<>(ID_SAVED_FILTERS_POPOVER, savedSearchListModel) {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -299,6 +306,11 @@ public void onClick(AjaxRequestTarget target) {
saveSearchContainer.add(savedSearchMenu);
}

private void saveSearchFilterPerformed(AjaxRequestTarget target) {
savedSearchListModel.detach();
target.add(SearchPanel.this.get(ID_FORM));
}

private VisibleEnableBehaviour getSearchButtonVisibleEnableBehavior() {
return new VisibleEnableBehaviour() {

Expand Down Expand Up @@ -341,6 +353,10 @@ private void selectSavedFilterPerformed(List<AvailableFilterType> filterList, Aj
searchPerformed(target);
}

private Component getSavedSearchContainer() {
return get(ID_FORM).get(ID_SAVE_SEARCH_CONTAINER);
}

private Component getSavedSearchMenuButton() {
return get(ID_FORM).get(ID_SAVE_SEARCH_CONTAINER).get(ID_SAVED_SEARCH_MENU);
}
Expand Down Expand Up @@ -541,14 +557,14 @@ private SearchConfigurationWrapper getSearchConfigurationWrapper() {
private List<AvailableFilterType> getSavedFilterList() {
ContainerableListPanel listPanel = findParent(ContainerableListPanel.class);
List<AvailableFilterType> availableFilterList = null;
if (listPanel != null) {
CompiledObjectCollectionView view = listPanel.getObjectCollectionView();
availableFilterList = view != null ? getAvailableFilterList(view.getSearchBoxConfiguration()) : null;
} else {
// if (listPanel != null) {
// CompiledObjectCollectionView view = listPanel.getObjectCollectionView();
// availableFilterList = view != null ? getAvailableFilterList(view.getSearchBoxConfiguration()) : null;
// } else {
FocusType principalFocus = getPageBase().getPrincipalFocus();
GuiObjectListViewType view = WebComponentUtil.getPrincipalUserObjectListView(getPageBase(), principalFocus, getModelObject().getTypeClass(), false);
availableFilterList = view != null ? getAvailableFilterList(view.getSearchBoxConfiguration()) : null;
}
// }
return availableFilterList;
}

Expand Down Expand Up @@ -640,10 +656,15 @@ private void applyBasicModeSearchItem(SearchItemType searchItem) {
}

private List<AvailableFilterType> getAvailableFilterList(SearchBoxConfigurationType config) {
if (config == null) {
if (config == null || CollectionUtils.isEmpty(config.getAvailableFilter())) {
return null;
}
return config.getAvailableFilter();
return config.getAvailableFilter().stream().sorted((filter1, filter2) -> {
String label1 = WebComponentUtil.getTranslatedPolyString(WebComponentUtil.getLabel(filter1.getDisplay()));
String label2 = WebComponentUtil.getTranslatedPolyString(WebComponentUtil.getLabel(filter2.getDisplay()));
return String.CASE_INSENSITIVE_ORDER.compare(label1, label2);

}).collect(Collectors.toList());
}

class BasicSearchFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public abstract class AbstractSearchConfigurationPanel<F extends SearchFilter, O
protected static final String ID_CONFIGURATION_PANEL = "configurationPanel";
private static final String ID_BUTTONS_PANEL = "buttonsPanel";
private static final String ID_OK_BUTTON = "okButton";
// private static final String ID_APPLY_FILTER_BUTTON = "applyFilterButton";
// private static final String ID_SAVE_FILTER_BUTTON = "saveFilterButton";
private static final String ID_CANCEL_BUTTON = "cancelButton";

private LoadableModel<Class<O>> typeModel;
Expand Down

0 comments on commit afd20ad

Please sign in to comment.