diff --git a/ui/src/main/java/io/xeres/ui/controller/file/FileTrendViewController.java b/ui/src/main/java/io/xeres/ui/controller/file/FileTrendViewController.java index 6f5f0037..a3205c63 100644 --- a/ui/src/main/java/io/xeres/ui/controller/file/FileTrendViewController.java +++ b/ui/src/main/java/io/xeres/ui/controller/file/FileTrendViewController.java @@ -24,7 +24,10 @@ import io.xeres.ui.controller.TabActivation; import io.xeres.ui.support.util.UiUtils; import javafx.application.Platform; +import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; @@ -35,26 +38,36 @@ import reactor.core.Disposable; import java.io.IOException; +import java.time.Instant; +import java.util.LinkedList; @Component @FxmlView(value = "/view/file/trend.fxml") public class FileTrendViewController implements Controller, TabActivation { + private static final String NAME_CONTAINS_ALL = "NAME CONTAINS ALL "; + private static final int MAXIMUM_BACKLOG = 300; + + private final NotificationClient notificationClient; private Disposable notificationDisposable; + private final ObservableList trendResult = FXCollections.observableList(new LinkedList<>()); + @FXML private TableView trendTableView; -// @FXML -// private TableColumn tableHits; -// -@FXML -private TableColumn tableFrom; + // XXX: make sure the table is NOT sortable!! + + @FXML + private TableColumn tableFrom; @FXML private TableColumn tableTerms; + @FXML + private TableColumn tableTime; + public FileTrendViewController(NotificationClient notificationClient) { this.notificationClient = notificationClient; @@ -63,8 +76,12 @@ public FileTrendViewController(NotificationClient notificationClient) @Override public void initialize() throws IOException { + trendTableView.setItems(trendResult); + tableTerms.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().keywords())); tableFrom.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().senderName())); + tableTime.setCellFactory(param -> new TimeCell()); + tableTime.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().when())); setupFileTrendNotifications(); } @@ -75,10 +92,17 @@ private void setupFileTrendNotifications() .doOnError(UiUtils::showAlertError) .doOnNext(sse -> Platform.runLater(() -> { assert sse.data() != null; - trendTableView.getItems().add(new TrendResult(sse.data().keywords(), sse.data().senderName())); - if (trendTableView.getItems().size() > 255) // XXX: maybe not optimal... + var keywords = sse.data().keywords(); + + if (keywords.startsWith(NAME_CONTAINS_ALL)) + { + keywords = keywords.substring(NAME_CONTAINS_ALL.length()); + } + + trendResult.addFirst(new TrendResult(keywords, sse.data().senderName(), Instant.now())); + if (trendTableView.getItems().size() > MAXIMUM_BACKLOG) { - trendTableView.getItems().remove(0, 10); + trendTableView.getItems().removeLast(); } })) .subscribe(); diff --git a/ui/src/main/java/io/xeres/ui/controller/file/TimeCell.java b/ui/src/main/java/io/xeres/ui/controller/file/TimeCell.java new file mode 100644 index 00000000..41d9096b --- /dev/null +++ b/ui/src/main/java/io/xeres/ui/controller/file/TimeCell.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 by David Gerber - https://zapek.com + * + * This file is part of Xeres. + * + * Xeres is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Xeres is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Xeres. If not, see . + */ + +package io.xeres.ui.controller.file; + +import javafx.scene.control.TableCell; + +import java.time.Instant; + +import static io.xeres.ui.support.util.DateUtils.TIME_DISPLAY_WITH_SECONDS; + +class TimeCell extends TableCell +{ + @Override + protected void updateItem(Instant item, boolean empty) + { + super.updateItem(item, empty); + if (empty) + { + setText(null); + } + else + { + setText(TIME_DISPLAY_WITH_SECONDS.format(item)); + } + } +} diff --git a/ui/src/main/java/io/xeres/ui/controller/file/TrendResult.java b/ui/src/main/java/io/xeres/ui/controller/file/TrendResult.java index 6c441da9..c3b70f07 100644 --- a/ui/src/main/java/io/xeres/ui/controller/file/TrendResult.java +++ b/ui/src/main/java/io/xeres/ui/controller/file/TrendResult.java @@ -19,6 +19,8 @@ package io.xeres.ui.controller.file; -public record TrendResult(String keywords, String senderName) +import java.time.Instant; + +record TrendResult(String keywords, String senderName, Instant when) { } diff --git a/ui/src/main/java/io/xeres/ui/controller/forum/DateCell.java b/ui/src/main/java/io/xeres/ui/controller/forum/DateCell.java index 47920c29..4586f696 100644 --- a/ui/src/main/java/io/xeres/ui/controller/forum/DateCell.java +++ b/ui/src/main/java/io/xeres/ui/controller/forum/DateCell.java @@ -26,7 +26,7 @@ import static io.xeres.ui.support.util.DateUtils.DATE_TIME_DISPLAY; -public class DateCell extends TreeTableCell +class DateCell extends TreeTableCell { public DateCell() { diff --git a/ui/src/main/java/io/xeres/ui/support/util/DateUtils.java b/ui/src/main/java/io/xeres/ui/support/util/DateUtils.java index df0f9b19..2cb40fcd 100644 --- a/ui/src/main/java/io/xeres/ui/support/util/DateUtils.java +++ b/ui/src/main/java/io/xeres/ui/support/util/DateUtils.java @@ -36,6 +36,10 @@ public final class DateUtils .withLocale(Locale.ROOT) .withZone(ZoneId.systemDefault()); + public static final DateTimeFormatter TIME_DISPLAY_WITH_SECONDS = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM) + .withLocale(Locale.ROOT) + .withZone(ZoneId.systemDefault()); + public static final DateTimeFormatter DATE_TIME_FILENAME = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss") .withZone(ZoneId.systemDefault()); diff --git a/ui/src/main/resources/view/file/trend.fxml b/ui/src/main/resources/view/file/trend.fxml index 4c3e7315..5b7aefd4 100644 --- a/ui/src/main/resources/view/file/trend.fxml +++ b/ui/src/main/resources/view/file/trend.fxml @@ -36,9 +36,9 @@