diff --git a/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java b/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java index 9c23d85..c575eea 100644 --- a/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java +++ b/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java @@ -3,7 +3,6 @@ package com.andrewlalis.perfin.control; import com.andrewlalis.javafx_scene_router.RouteSelectionListener; import com.andrewlalis.perfin.data.AccountRepository; import com.andrewlalis.perfin.data.TransactionRepository; -import com.andrewlalis.perfin.data.TransactionVendorRepository; import com.andrewlalis.perfin.data.impl.JdbcDataSource; import com.andrewlalis.perfin.data.pagination.Page; import com.andrewlalis.perfin.data.pagination.PageRequest; @@ -14,7 +13,6 @@ import com.andrewlalis.perfin.data.util.Pair; import com.andrewlalis.perfin.model.Account; import com.andrewlalis.perfin.model.Profile; import com.andrewlalis.perfin.model.Transaction; -import com.andrewlalis.perfin.model.TransactionVendor; import com.andrewlalis.perfin.view.BindingUtil; import com.andrewlalis.perfin.view.SceneUtil; import com.andrewlalis.perfin.view.component.AccountSelectionBox; @@ -26,7 +24,8 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.Node; -import javafx.scene.control.CheckBox; +import javafx.scene.control.TabPane; +import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; @@ -34,8 +33,8 @@ import javafx.scene.layout.VBox; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; -import java.util.concurrent.CompletableFuture; import static com.andrewlalis.perfin.PerfinApp.router; @@ -54,14 +53,10 @@ public class TransactionsViewController implements RouteSelectionListener { public record RouteContext(Long selectedTransactionId) {} @FXML public BorderPane transactionsListBorderPane; + @FXML public TabPane searchTabPane; @FXML public TextField searchField; @FXML public AccountSelectionBox filterByAccountComboBox; - - @FXML public CheckBox advancedSearchFeaturesCheckBox; - @FXML public VBox advancedSearchFeaturesVBox; - @FXML public VBox advancedSearchAccountChoicesVBox; - @FXML public VBox advancedSearchTagChoicesVBox; - @FXML public VBox advancedSearchVendorChoicesVBox; + @FXML public TextArea customSearchSqlTextArea; @FXML public VBox transactionsVBox; @@ -85,13 +80,10 @@ public class TransactionsViewController implements RouteSelectionListener { selectedTransaction.set(null); }); - // Initialize advanced search feature toggling. - BindingUtil.bindManagedAndVisible(filterByAccountComboBox.getParent(), advancedSearchFeaturesCheckBox.selectedProperty().not()); - BindingUtil.bindManagedAndVisible(advancedSearchFeaturesVBox, advancedSearchFeaturesCheckBox.selectedProperty()); - advancedSearchFeaturesCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (newValue) { - initializeAdvancedSearchFeatures(); - } + // Add listener to reset search when a different search tab is selected. + searchTabPane.getSelectionModel().selectedIndexProperty().addListener((observable, oldValue, newValue) -> { + paginationControls.setPage(1); + selectedTransaction.set(null); }); this.paginationControls = new DataSourcePaginationControls( @@ -140,42 +132,6 @@ public class TransactionsViewController implements RouteSelectionListener { }); } - private void initializeAdvancedSearchFeatures() { - Profile.getCurrent().dataSource().useRepoAsync(AccountRepository.class, repo -> { - List allAccounts = repo.findAll(PageRequest.unpaged(Sort.asc("name"))).items(); - Platform.runLater(() -> { - advancedSearchAccountChoicesVBox.getChildren().clear(); - for (Account account : allAccounts) { - CheckBox checkBox = new CheckBox(account.getShortName()); - checkBox.setSelected(false); - advancedSearchAccountChoicesVBox.getChildren().add(checkBox); - } - }); - }); - Profile.getCurrent().dataSource().useRepoAsync(TransactionRepository.class, repo -> { - List tags = repo.findAllTags(); - Platform.runLater(() -> { - advancedSearchTagChoicesVBox.getChildren().clear(); - for (var tag : tags) { - CheckBox checkBox = new CheckBox(tag); - checkBox.setSelected(false); - advancedSearchTagChoicesVBox.getChildren().add(checkBox); - } - }); - }); - Profile.getCurrent().dataSource().useRepoAsync(TransactionVendorRepository.class, repo -> { - List vendors = repo.findAll(); - Platform.runLater(() -> { - advancedSearchVendorChoicesVBox.getChildren().clear(); - for (var vendor : vendors) { - CheckBox checkBox = new CheckBox(vendor.getName()); - checkBox.setSelected(false); - advancedSearchVendorChoicesVBox.getChildren().add(checkBox); - } - }); - }); - } - @Override public void onRouteSelected(Object context) { paginationControls.sorts.setAll(DEFAULT_SORTS); @@ -217,7 +173,24 @@ public class TransactionsViewController implements RouteSelectionListener { Popups.message(transactionsListBorderPane, "Exporting transactions is not yet supported."); } + @FXML public void executeSqlQuery() { + paginationControls.setPage(1); + selectedTransaction.set(null); + } + private List getCurrentSearchFilters() { + if (searchTabPane.getSelectionModel().isSelected(0)) { + return getBasicSearchFilters(); + } else if (searchTabPane.getSelectionModel().isSelected(1)) { + return Collections.emptyList(); + } else if (searchTabPane.getSelectionModel().isSelected(2) && !customSearchSqlTextArea.getText().isBlank()) { + var filter = new SearchFilter.Builder().where(customSearchSqlTextArea.getText().strip()).build(); + return List.of(filter); + } + return Collections.emptyList(); + } + + private List getBasicSearchFilters() { List filters = new ArrayList<>(); if (searchField.getText() != null && !searchField.getText().isBlank()) { final String text = searchField.getText().strip(); diff --git a/src/main/resources/transactions-view.fxml b/src/main/resources/transactions-view.fxml index 94f5a9c..6cc3329 100644 --- a/src/main/resources/transactions-view.fxml +++ b/src/main/resources/transactions-view.fxml @@ -21,33 +21,54 @@ - - - - - - - - + + + + +