Set version to 1.2.0, fixed formatting for pagination for the most part.

This commit is contained in:
Andrew Lalis 2024-01-08 12:06:39 -05:00
parent a94666a8d6
commit 4370d8221f
6 changed files with 38 additions and 11 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.andrewlalis</groupId> <groupId>com.andrewlalis</groupId>
<artifactId>perfin</artifactId> <artifactId>perfin</artifactId>
<version>1.1.0</version> <version>1.2.0</version>
<properties> <properties>
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>

View File

@ -24,7 +24,7 @@ module_path="$module_path:target/modules/h2-2.2.224.jar"
jpackage \ jpackage \
--name "Perfin" \ --name "Perfin" \
--app-version "1.1.0" \ --app-version "1.2.0" \
--description "Desktop application for personal finance. Add your accounts, track transactions, and store receipts, invoices, and more." \ --description "Desktop application for personal finance. Add your accounts, track transactions, and store receipts, invoices, and more." \
--icon design/perfin-logo_256.png \ --icon design/perfin-logo_256.png \
--vendor "Andrew Lalis" \ --vendor "Andrew Lalis" \

View File

@ -12,7 +12,7 @@ $modulePath = "$modulePath;target\modules\h2-2.2.224.jar"
jpackage ` jpackage `
--name "Perfin" ` --name "Perfin" `
--app-version "1.1.0" ` --app-version "1.2.0" `
--description "Desktop application for personal finance. Add your accounts, track transactions, and store receipts, invoices, and more." ` --description "Desktop application for personal finance. Add your accounts, track transactions, and store receipts, invoices, and more." `
--icon design\perfin-logo_256.ico ` --icon design\perfin-logo_256.ico `
--vendor "Andrew Lalis" ` --vendor "Andrew Lalis" `

View File

@ -36,7 +36,6 @@ import static com.andrewlalis.perfin.PerfinApp.router;
*/ */
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"));
public static int DEFAULT_ITEMS_PER_PAGE = 5;
public record RouteContext(Long selectedTransactionId) {} public record RouteContext(Long selectedTransactionId) {}
@FXML public BorderPane transactionsListBorderPane; @FXML public BorderPane transactionsListBorderPane;
@ -119,7 +118,6 @@ public class TransactionsViewController implements RouteSelectionListener {
@Override @Override
public void onRouteSelected(Object context) { public void onRouteSelected(Object context) {
paginationControls.sorts.setAll(DEFAULT_SORTS); paginationControls.sorts.setAll(DEFAULT_SORTS);
paginationControls.itemsPerPage.set(DEFAULT_ITEMS_PER_PAGE);
// Refresh account filter options. // Refresh account filter options.
Thread.ofVirtual().start(() -> { Thread.ofVirtual().start(() -> {
@ -142,7 +140,7 @@ public class TransactionsViewController implements RouteSelectionListener {
Profile.getCurrent().getDataSource().useTransactionRepository(repo -> { Profile.getCurrent().getDataSource().useTransactionRepository(repo -> {
repo.findById(ctx.selectedTransactionId).ifPresent(tx -> { repo.findById(ctx.selectedTransactionId).ifPresent(tx -> {
long offset = repo.countAllAfter(tx.id); long offset = repo.countAllAfter(tx.id);
int pageNumber = (int) (offset / DEFAULT_ITEMS_PER_PAGE) + 1; int pageNumber = (int) (offset / paginationControls.getItemsPerPage()) + 1;
paginationControls.setPage(pageNumber).thenRun(() -> selectedTransaction.set(tx)); paginationControls.setPage(pageNumber).thenRun(() -> selectedTransaction.set(tx));
}); });
}); });

View File

@ -10,11 +10,15 @@ import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.layout.*; import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow; import javafx.scene.text.TextFlow;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -34,8 +38,9 @@ public class DataSourcePaginationControls extends BorderPane {
public final IntegerProperty currentPage = new SimpleIntegerProperty(1); public final IntegerProperty currentPage = new SimpleIntegerProperty(1);
public final IntegerProperty maxPages = new SimpleIntegerProperty(-1); public final IntegerProperty maxPages = new SimpleIntegerProperty(-1);
public final IntegerProperty itemsPerPage = new SimpleIntegerProperty(5);
public final ObservableList<Sort> sorts = FXCollections.observableArrayList(); public final ObservableList<Sort> sorts = FXCollections.observableArrayList();
private final IntegerProperty itemsPerPage = new SimpleIntegerProperty();
private final BooleanProperty fetching = new SimpleBooleanProperty(false); private final BooleanProperty fetching = new SimpleBooleanProperty(false);
private final ObservableList<Node> target; private final ObservableList<Node> target;
private final PageFetcherFunction fetcher; private final PageFetcherFunction fetcher;
@ -46,12 +51,16 @@ public class DataSourcePaginationControls extends BorderPane {
Text currentPageLabel = new Text(); Text currentPageLabel = new Text();
currentPageLabel.textProperty().bind(currentPage.asString()); currentPageLabel.textProperty().bind(currentPage.asString());
Text maxPagesLabel = new Text(); Text maxPagesLabel = new Text();
maxPagesLabel.textProperty().bind(maxPages.asString()); maxPagesLabel.textProperty().bind(maxPages.asString());
TextFlow maxPagesText = new TextFlow(new Text(" / "), maxPagesLabel); TextFlow maxPagesText = new TextFlow(new Text(" / "), maxPagesLabel);
maxPagesText.managedProperty().bind(maxPagesText.visibleProperty()); maxPagesText.managedProperty().bind(maxPagesText.visibleProperty());
maxPagesText.visibleProperty().bind(maxPages.greaterThan(0)); maxPagesText.visibleProperty().bind(maxPages.greaterThan(0));
TextFlow pageText = new TextFlow(new Text("Page "), currentPageLabel, maxPagesText); TextFlow pageText = new TextFlow(new Text("Page "), currentPageLabel, maxPagesText);
AnchorPane pageTextContainer = new AnchorPane(pageText); AnchorPane pageTextContainer = new AnchorPane(pageText);
AnchorPane.setTopAnchor(pageText, 4.0); AnchorPane.setTopAnchor(pageText, 4.0);
AnchorPane.setRightAnchor(pageText, 0.0); AnchorPane.setRightAnchor(pageText, 0.0);
@ -62,14 +71,30 @@ public class DataSourcePaginationControls extends BorderPane {
Button previousPageButton = new Button("Previous Page"); Button previousPageButton = new Button("Previous Page");
previousPageButton.disableProperty().bind(currentPage.lessThan(2).or(fetching)); previousPageButton.disableProperty().bind(currentPage.lessThan(2).or(fetching));
previousPageButton.setOnAction(event -> setPage(currentPage.get() - 1)); previousPageButton.setOnAction(event -> setPage(currentPage.get() - 1));
Button nextPageButton = new Button("Next Page"); Button nextPageButton = new Button("Next Page");
nextPageButton.disableProperty().bind(fetching.or(currentPage.greaterThanOrEqualTo(maxPages))); nextPageButton.disableProperty().bind(fetching.or(currentPage.greaterThanOrEqualTo(maxPages)));
nextPageButton.setOnAction(event -> setPage(currentPage.get() + 1)); nextPageButton.setOnAction(event -> setPage(currentPage.get() + 1));
ChoiceBox<Integer> itemsPerPageChoice = new ChoiceBox<>();
itemsPerPageChoice.getItems().addAll(5, 10, 20, 50, 100);
itemsPerPageChoice.getSelectionModel().select(10);
itemsPerPageChoice.setValue(10);
itemsPerPage.bind(itemsPerPageChoice.valueProperty());
itemsPerPage.addListener((observable, oldValue, newValue) -> setPage(1));
BorderPane pageSizePane = new BorderPane();
Label pageSizeLabel = new Label("Items Per Page");
pageSizeLabel.getStyleClass().add("std-padding");
BorderPane.setAlignment(pageSizeLabel, Pos.CENTER_LEFT);
pageSizePane.setLeft(pageSizeLabel);
pageSizePane.setCenter(itemsPerPageChoice);
HBox hbox = new HBox( HBox hbox = new HBox(
previousPageButton, previousPageButton,
pageTextContainer, pageTextContainer,
nextPageButton nextPageButton,
pageSizePane
); );
hbox.getStyleClass().addAll("std-padding", "std-spacing"); hbox.getStyleClass().addAll("std-padding", "std-spacing");
setCenter(hbox); setCenter(hbox);
@ -107,4 +132,8 @@ public class DataSourcePaginationControls extends BorderPane {
}); });
return cf; return cf;
} }
public int getItemsPerPage() {
return itemsPerPage.get();
}
} }

View File

@ -22,7 +22,7 @@
</top> </top>
<bottom> <bottom>
<HBox styleClass="std-padding,std-spacing"> <HBox styleClass="std-padding,std-spacing">
<Label text="Perfin Version 1.1.0"/> <Label text="Perfin Version 1.2.0"/>
</HBox> </HBox>
</bottom> </bottom>
</BorderPane> </BorderPane>