Added total data refresh on account page when navigating to it, and added additional sorts for the transactions search so order is more consistent.

This commit is contained in:
Andrew Lalis 2024-05-31 12:35:35 -04:00
parent 20eed2108f
commit 77f2966291
2 changed files with 30 additions and 17 deletions

View File

@ -91,23 +91,19 @@ public class AccountViewController implements RouteSelectionListener {
Popups.message(balanceCheckerButton, msg); Popups.message(balanceCheckerButton, msg);
})); }));
}); });
accountProperty.addListener((observable, oldValue, newValue) -> {
accountHistory.clear();
if (newValue == null) {
balanceTextProperty.set(null);
} else {
accountHistory.setAccountId(newValue.id);
accountHistory.loadMoreHistory();
Profile.getCurrent().dataSource().getAccountBalanceText(newValue)
.thenAccept(s -> Platform.runLater(() -> balanceTextProperty.set(s)));
}
});
} }
@Override @Override
public void onRouteSelected(Object context) { public void onRouteSelected(Object context) {
this.accountProperty.set((Account) context); accountHistory.clear();
balanceTextProperty.set(null);
if (context instanceof Account account) {
this.accountProperty.set(account);
accountHistory.setAccountId(account.id);
accountHistory.loadMoreHistory();
Profile.getCurrent().dataSource().getAccountBalanceText(account)
.thenAccept(s -> Platform.runLater(() -> balanceTextProperty.set(s)));
}
} }
@FXML @FXML

View File

@ -47,7 +47,11 @@ import static com.andrewlalis.perfin.PerfinApp.router;
* to a specific page. * to a specific page.
*/ */
public class TransactionsViewController implements RouteSelectionListener { public class TransactionsViewController implements RouteSelectionListener {
public static List<Sort> DEFAULT_SORTS = List.of(Sort.desc("timestamp")); public static List<Sort> DEFAULT_SORTS = List.of(
Sort.desc("timestamp"),
Sort.desc("amount"),
Sort.desc("currency")
);
public record RouteContext(Long selectedTransactionId) {} public record RouteContext(Long selectedTransactionId) {}
@FXML public BorderPane transactionsListBorderPane; @FXML public BorderPane transactionsListBorderPane;
@ -188,15 +192,28 @@ public class TransactionsViewController implements RouteSelectionListener {
private List<SearchFilter> getCurrentSearchFilters() { private List<SearchFilter> getCurrentSearchFilters() {
List<SearchFilter> filters = new ArrayList<>(); List<SearchFilter> filters = new ArrayList<>();
if (searchField.getText() != null && !searchField.getText().isBlank()) { if (searchField.getText() != null && !searchField.getText().isBlank()) {
final String text = searchField.getText().strip();
// Special case: for input like "#123", search directly for the transaction id. // Special case: for input like "#123", search directly for the transaction id.
if (searchField.getText().strip().matches("#\\d+")) { if (text.matches("#\\d+")) {
int idQuery = Integer.parseInt(searchField.getText().strip().substring(1)); int idQuery = Integer.parseInt(text.substring(1));
var filter = new SearchFilter.Builder().where("id = ?").withArg(idQuery).build(); var filter = new SearchFilter.Builder().where("id = ?").withArg(idQuery).build();
return List.of(filter); return List.of(filter);
} }
// Special case: for input like "tag: abc", search directly for transactions with tags like that.
if (text.matches("tag:\\s*.+")) {
String tagQuery = "%" + text.substring(4).strip().toLowerCase() + "%";
var filter = new SearchFilter.Builder().where("""
id IN (
SELECT ttj.transaction_id
FROM transaction_tag_join ttj
LEFT JOIN transaction_tag tt ON tt.id = ttj.tag_id
WHERE LOWER(tt.name) LIKE ?
)""").withArg(tagQuery).build();
return List.of(filter);
}
// General case: split the input into a list of terms, then apply each term in a LIKE %term% query. // General case: split the input into a list of terms, then apply each term in a LIKE %term% query.
var likeTerms = Arrays.stream(searchField.getText().strip().toLowerCase().split("\\s+")) var likeTerms = Arrays.stream(text.toLowerCase().split("\\s+"))
.map(t -> '%'+t+'%') .map(t -> '%'+t+'%')
.toList(); .toList();
var builder = new SearchFilter.Builder(); var builder = new SearchFilter.Builder();