Skip to content

Commit

Permalink
Merge pull request #2752 from ManfredKarrer/add-filter-to-trade-history
Browse files Browse the repository at this point in the history
Add filter to trade history
  • Loading branch information
ManfredKarrer authored Apr 27, 2019
2 parents 87cbc47 + ca0387a commit b1a8429
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ support.tab.support=Support tickets
support.tab.ArbitratorsSupportTickets=Arbitrator's support tickets
support.tab.TradersSupportTickets=Trader's support tickets
support.filter=Filter list
support.filter.prompt=Enter trade ID, date, onion address or account data
support.noTickets=There are no open tickets
support.sendingMessage=Sending Message...
support.receiverNotOnline=Receiver is not online. Message is saved to his mailbox.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
-->

<?import bisq.desktop.components.AutoTooltipButton?>
<?import bisq.desktop.components.AutoTooltipLabel?>
<?import bisq.desktop.components.InputTextField?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<VBox fx:id="root" fx:controller="bisq.desktop.main.portfolio.closedtrades.ClosedTradesView"
Expand All @@ -41,5 +45,10 @@
<TableColumn fx:id="avatarColumn" minWidth="40" maxWidth="40"/>
</columns>
</TableView>
<AutoTooltipButton fx:id="exportButton"/>
<HBox fx:id="footerBox">
<AutoTooltipLabel fx:id="filterLabel"/>
<InputTextField fx:id="filterTextField" minWidth="300"/>
<Pane fx:id="spacer"/>
<AutoTooltipButton fx:id="exportButton"/>
</HBox>
</VBox>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.components.InputTextField;
import bisq.desktop.components.PeerInfoIcon;
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
Expand All @@ -33,6 +34,7 @@
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;
import bisq.core.offer.OpenOffer;
import bisq.core.trade.Contract;
import bisq.core.trade.Tradable;
import bisq.core.trade.Trade;
import bisq.core.user.Preferences;
Expand All @@ -57,13 +59,18 @@
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import javafx.geometry.Insets;

import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;

import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;

import javafx.util.Callback;
Expand All @@ -73,19 +80,31 @@
@FxmlView
public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTradesViewModel> {
private final boolean useDevPrivilegeKeys;

@FXML
TableView<ClosedTradableListItem> tableView;
@FXML
TableColumn<ClosedTradableListItem, ClosedTradableListItem> priceColumn, amountColumn, volumeColumn,
marketColumn, directionColumn, dateColumn, tradeIdColumn, stateColumn, avatarColumn;
@FXML
HBox footerBox;
@FXML
AutoTooltipLabel filterLabel;
@FXML
InputTextField filterTextField;
@FXML
Pane spacer;
@FXML
AutoTooltipButton exportButton;

private final OfferDetailsWindow offerDetailsWindow;
private Preferences preferences;
private final BSFormatter formatter;
private final TradeDetailsWindow tradeDetailsWindow;
private final PrivateNotificationManager privateNotificationManager;
private SortedList<ClosedTradableListItem> sortedList;
private FilteredList<ClosedTradableListItem> filteredList;
private ChangeListener<String> filterTextFieldListener;

@Inject
public ClosedTradesView(ClosedTradesViewModel model,
Expand Down Expand Up @@ -175,13 +194,24 @@ public void initialize() {

dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);

filterLabel.setText(Res.getWithCol("support.filter"));
filterTextField.setPromptText(Res.get("support.filter.prompt"));
HBox.setMargin(filterLabel, new Insets(5, 0, 0, 10));
filterTextFieldListener = (observable, oldValue, newValue) -> applyFilteredListPredicate(filterTextField.getText());
footerBox.setSpacing(5);
HBox.setHgrow(spacer, Priority.ALWAYS);
exportButton.updateText(Res.get("shared.exportCSV"));
HBox.setMargin(exportButton, new Insets(0, 10, 0, 0));
}

@Override
protected void activate() {
sortedList = new SortedList<>(model.getList());
filteredList = new FilteredList<>(model.getList());

sortedList = new SortedList<>(filteredList);
sortedList.comparatorProperty().bind(tableView.comparatorProperty());

tableView.setItems(sortedList);

exportButton.setOnAction(event -> {
Expand All @@ -208,14 +238,52 @@ protected void activate() {
GUIUtil.exportCSV("tradeHistory.csv", headerConverter, contentConverter,
new ClosedTradableListItem(null), sortedList, (Stage) root.getScene().getWindow());
});

filterTextField.textProperty().addListener(filterTextFieldListener);
applyFilteredListPredicate(filterTextField.getText());
}

@Override
protected void deactivate() {
sortedList.comparatorProperty().unbind();
exportButton.setOnAction(null);

filterTextField.textProperty().removeListener(filterTextFieldListener);
}

private void applyFilteredListPredicate(String filterString) {
filteredList.setPredicate(item -> {
if (filterString.isEmpty())
return true;

Offer offer = item.getTradable().getOffer();
boolean matchesId = offer.getId().contains(filterString);
boolean matchesOfferDate = formatter.formatDate(offer.getDate()).contains(filterString);
boolean isMakerOnion = offer.getMakerNodeAddress().getFullAddress().contains(filterString);

if (item.getTradable() instanceof Trade) {
boolean isBuyerOnion = false;
boolean isSellerOnion = false;
boolean matchesBuyersPaymentAccountData = false;
boolean matchesSellersPaymentAccountData = false;

Trade trade = (Trade) item.getTradable();
boolean matchesTradeDate = formatter.formatDate(trade.getTakeOfferDate()).contains(filterString);
Contract contract = trade.getContract();
if (contract != null) {
isBuyerOnion = contract.getBuyerNodeAddress().getFullAddress().contains(filterString);
isSellerOnion = contract.getSellerNodeAddress().getFullAddress().contains(filterString);
matchesBuyersPaymentAccountData = contract.getBuyerPaymentAccountPayload().getPaymentDetails().contains(filterString);
matchesSellersPaymentAccountData = contract.getSellerPaymentAccountPayload().getPaymentDetails().contains(filterString);
}
return matchesId || matchesOfferDate || isMakerOnion ||
matchesTradeDate || isBuyerOnion || isSellerOnion ||
matchesBuyersPaymentAccountData || matchesSellersPaymentAccountData;
} else {
return matchesId || matchesOfferDate || isMakerOnion;
}
});
}

private void setTradeIdColumnCellFactory() {
tradeIdColumn.getStyleClass().add("first-column");
Expand Down

0 comments on commit b1a8429

Please sign in to comment.