Skip to content

Commit

Permalink
Pagination basics #1764
Browse files Browse the repository at this point in the history
missing: max page count and pre-defined search doesn't work with current pagination
  • Loading branch information
Aclrian authored and jofaul committed Jul 6, 2020
1 parent 0995d71 commit 48a4fc3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public void initialize() {
BooleanBinding inSearchableState = Bindings.createBooleanBinding(() -> state.get() != State.SEARCHING, state);
searchController.setSearchButtonDisabledCondition(inSearchableState);
searchController.setOnlyShowLastYearCheckBoxVisible(true, true);

pagination.currentPageIndexProperty().addListener((observable, oldValue, newValue) -> {
enterSearchingState();
SearchConfig searchConfig = searchController.getLastSearchConfig();

onPageChange(searchConfig, newValue.intValue() + 1);
});
}

private void displaySearchResult(List<Replay> replays, boolean append) {
Expand Down Expand Up @@ -234,9 +241,15 @@ private void enterResultState() {

private void onSearch(SearchConfig searchConfig) {
enterSearchingState();
Platform.runLater(() -> pagination.setPageCount(0));
displayReplaysFromSupplier(() -> replayService.findByQuery(searchConfig.getSearchQuery(), MAX_SEARCH_RESULTS, currentPage++, searchConfig.getSortConfig()));
}

private void onPageChange(SearchConfig searchConfig, int page) {
enterSearchingState();
displayReplaysFromSupplier(() -> replayService.findByQuery(searchConfig.getSearchQuery(), MAX_SEARCH_RESULTS, page, searchConfig.getSortConfig()), false);
}

private void displaySearchResult(List<Replay> replays) {
displaySearchResult(replays, false);
}
Expand Down Expand Up @@ -281,8 +294,10 @@ public void onLoadMoreButtonClicked(ActionEvent actionEvent) {
.thenAccept(replays -> displaySearchResult(replays, true));
}

private void displayReplaysFromSupplier(Supplier<CompletableFuture<List<Replay>>> mapsSupplier) {
currentPage = 1;
private void displayReplaysFromSupplier(Supplier<CompletableFuture<List<Replay>>> mapsSupplier, boolean startFromOne) {
if (startFromOne) {
currentPage = 1;
}
currentSupplier = mapsSupplier;
mapsSupplier.get()
.thenAccept(this::displaySearchResult)
Expand All @@ -295,6 +310,10 @@ private void displayReplaysFromSupplier(Supplier<CompletableFuture<List<Replay>>
});
}

private void displayReplaysFromSupplier(Supplier<CompletableFuture<List<Replay>>> mapsSupplier) {
displayReplaysFromSupplier(mapsSupplier, true);
}

public void onMoreOwnButtonClicked() {
enterSearchingState();
displayReplaysFromSupplier(() -> replayService.getOwnReplays(TOP_MORE_ELEMENT_COUNT, currentPage++));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class SearchController implements Controller<Pane> {
* Type of the searchable entity.
*/
private Class<?> rootType;
private static String endTimeQueryStart = "endTime=ge=";
private SearchConfig lastSearchConfig;

public SearchController(UiService uiService, I18n i18n, PreferencesService preferencesService) {
this.uiService = uiService;
Expand Down Expand Up @@ -176,7 +178,12 @@ private void addInvalidationListener(LogicalNodeController logicalNodeController

public void onSearchButtonClicked() {
String sortPropertyKey = getCurrentEntityKey();
searchListener.accept(new SearchConfig(new SortConfig(sortPropertyKey, sortOrderChoiceBox.getValue()), queryTextField.getText()));
lastSearchConfig = new SearchConfig(new SortConfig(sortPropertyKey, sortOrderChoiceBox.getValue()), queryTextField.getText());
searchListener.accept(lastSearchConfig);
}

public SearchConfig getLastSearchConfig() {
return lastSearchConfig;
}

private String getCurrentEntityKey() {
Expand Down Expand Up @@ -236,15 +243,16 @@ private String buildQuery(SpecificationController initialSpecification, List<Log
}
condition = currentCondition;
}
return condition.get().query(new RSQLVisitor()) + ";" + lastYearQuery;
String queryWithoutLastYear = (String) condition.get().query(new RSQLVisitor());
return queryWithoutLastYear + ";" + lastYearQuery;
}

private String generateOnlyLastYearQuery() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -1);
Date date = calendar.getTime();
SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
return "endTime=ge=" + dateFormater.format(date);
return endTimeQueryStart + dateFormater.format(date);
}

@Override
Expand Down

0 comments on commit 48a4fc3

Please sign in to comment.