diff --git a/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java b/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java index 26d1f23..9c23d85 100644 --- a/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java +++ b/src/main/java/com/andrewlalis/perfin/control/TransactionsViewController.java @@ -3,17 +3,18 @@ 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; import com.andrewlalis.perfin.data.pagination.Sort; import com.andrewlalis.perfin.data.search.JdbcTransactionSearcher; import com.andrewlalis.perfin.data.search.SearchFilter; -import com.andrewlalis.perfin.data.util.DateUtil; 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; @@ -25,18 +26,16 @@ 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.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javafx.stage.FileChooser; -import java.io.File; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.CompletableFuture; import static com.andrewlalis.perfin.PerfinApp.router; @@ -57,7 +56,15 @@ public class TransactionsViewController implements RouteSelectionListener { @FXML public BorderPane transactionsListBorderPane; @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 VBox transactionsVBox; + private DataSourcePaginationControls paginationControls; @@ -78,6 +85,15 @@ 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(); + } + }); + this.paginationControls = new DataSourcePaginationControls( transactionsVBox.getChildren(), new DataSourcePaginationControls.PageFetcherFunction() { @@ -124,6 +140,42 @@ 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); @@ -162,31 +214,7 @@ public class TransactionsViewController implements RouteSelectionListener { } @FXML public void exportTransactions() { - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Export Transactions"); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("CSV Files", ".csv")); - File file = fileChooser.showSaveDialog(detailPanel.getScene().getWindow()); - if (file != null) { - try ( - var repo = Profile.getCurrent().dataSource().getTransactionRepository(); - var out = new PrintWriter(file, StandardCharsets.UTF_8) - ) { - out.println("id,utc-timestamp,amount,currency,description"); - - List allTransactions = repo.findAll(PageRequest.unpaged(Sort.desc("timestamp"))).items(); - for (Transaction tx : allTransactions) { - out.println("%d,%s,%s,%s,%s".formatted( - tx.id, - tx.getTimestamp().format(DateUtil.DEFAULT_DATETIME_FORMAT), - tx.getAmount().toPlainString(), - tx.getCurrency().getCurrencyCode(), - tx.getDescription() == null ? "" : tx.getDescription() - )); - } - } catch (Exception e) { - Popups.error(transactionsListBorderPane, e); - } - } + Popups.message(transactionsListBorderPane, "Exporting transactions is not yet supported."); } private List getCurrentSearchFilters() { diff --git a/src/main/resources/transactions-view.fxml b/src/main/resources/transactions-view.fxml index cc4fb89..94f5a9c 100644 --- a/src/main/resources/transactions-view.fxml +++ b/src/main/resources/transactions-view.fxml @@ -2,11 +2,8 @@ - - - + -