Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 new columns to vote result #3822

Merged
merged 3 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1613,10 +1613,12 @@ dao.results.cycles.table.header.issuance=Issuance
dao.results.results.table.item.cycle=Cycle {0} started: {1}

dao.results.proposals.header=Proposals of selected cycle
dao.results.proposals.table.header.proposalOwnerName=Name
dao.results.proposals.table.header.nameLink=Name/link
dao.results.proposals.table.header.details=Details
dao.results.proposals.table.header.myVote=My vote
dao.results.proposals.table.header.result=Vote result
dao.results.proposals.table.header.threshold=Threshold
dao.results.proposals.table.header.quorum=Quorum

dao.results.proposals.voting.detail.header=Vote results for selected proposal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.desktop.util.FormBuilder;

import bisq.core.dao.governance.proposal.ProposalType;
import bisq.core.dao.state.model.governance.Ballot;
import bisq.core.dao.state.model.governance.ChangeParamProposal;
import bisq.core.dao.state.model.governance.CompensationProposal;
Expand Down Expand Up @@ -122,6 +123,10 @@ public AwesomeIcon getIcon() {
return evaluatedProposal.isAccepted() ? AwesomeIcon.OK_SIGN : AwesomeIcon.BAN_CIRCLE;
}

public boolean isAccepted() {
return evaluatedProposal.isAccepted();
}

public String getColorStyleClass() {
return evaluatedProposal.isAccepted() ? "dao-accepted-icon" : "dao-rejected-icon";
}
Expand All @@ -130,11 +135,38 @@ public String getDetails() {
return ProposalListItem.getProposalDetails(evaluatedProposal, bsqFormatter);
}

public long getIssuedAmount() {
if (evaluatedProposal.getProposal().getType() == ProposalType.COMPENSATION_REQUEST) {
CompensationProposal compensationProposal = (CompensationProposal) proposal;
Coin requestedBsq = evaluatedProposal.isAccepted() ? compensationProposal.getRequestedBsq() : Coin.ZERO;
return requestedBsq.value;
}
return 0;
}

public String getThresholdAsString() {
return (evaluatedProposal.getProposalVoteResult().getThreshold() / 100D) + "%";
}

public long getThreshold() {
return evaluatedProposal.getProposalVoteResult().getThreshold();
}

public String getQuorumAsString() {
return bsqFormatter.formatCoinWithCode(Coin.valueOf(evaluatedProposal.getProposalVoteResult().getQuorum()));
}

public long getQuorum() {
return evaluatedProposal.getProposalVoteResult().getQuorum();
}

private static String getProposalDetails(EvaluatedProposal evaluatedProposal, BsqFormatter bsqFormatter) {
return getProposalDetails(evaluatedProposal, bsqFormatter, true);
}

private static String getProposalDetails(EvaluatedProposal evaluatedProposal, BsqFormatter bsqFormatter, boolean useDisplayString) {
private static String getProposalDetails(EvaluatedProposal evaluatedProposal,
BsqFormatter bsqFormatter,
boolean useDisplayString) {
Proposal proposal = evaluatedProposal.getProposal();
switch (proposal.getType()) {
case COMPENSATION_REQUEST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ private void createProposalsColumns(TableView<ProposalListItem> votesTableView)
TableColumn<ProposalListItem, ProposalListItem> column;

column = new AutoTooltipTableColumn<>(Res.get("shared.dateTime"));
column.setMinWidth(190);
column.setMaxWidth(column.getMinWidth());
column.setMinWidth(160);
column.getStyleClass().add("first-column");
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(
Expand All @@ -678,36 +677,8 @@ public void updateItem(final ProposalListItem item, boolean empty) {
votesTableView.getSortOrder().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.proposalOwnerName"));
column.setMinWidth(80);
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(
new Callback<>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(
TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<>() {

@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
item.setTableRow(getTableRow());
setText(item.getProposalOwnerName());
} else {
setText("");
}
}
};
}
});
column.setComparator(Comparator.comparing(ProposalListItem::getProposalOwnerName));
votesTableView.getColumns().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.proposal.table.header.link"));
column.setMinWidth(100);
column.setMaxWidth(column.getMinWidth());
column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.nameLink"));
column.setMinWidth(130);
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(
new Callback<>() {
Expand All @@ -722,10 +693,19 @@ public TableCell<ProposalListItem, ProposalListItem> call(TableColumn<ProposalLi
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
final Proposal proposal = item.getProposal();
field = new ExternalHyperlink(proposal.getLink());
field.setOnAction(event -> GUIUtil.openWebPage(proposal.getLink()));
field.setTooltip(new Tooltip(proposal.getLink()));
Proposal proposal = item.getProposal();
String link = proposal.getLink();
String proposalOwnerName = item.getProposalOwnerName();
String[] tokens = link.split("/");
String nameLink = proposalOwnerName;
if (tokens.length > 0) {
String proposalNr = tokens[tokens.length - 1];
nameLink += " (#" + proposalNr + ")";
}

field = new ExternalHyperlink(nameLink);
field.setOnAction(event -> GUIUtil.openWebPage(link));
field.setTooltip(new Tooltip(proposalOwnerName + " (" + link + ")"));
setGraphic(field);
} else {
setGraphic(null);
Expand All @@ -736,7 +716,7 @@ public void updateItem(final ProposalListItem item, boolean empty) {
};
}
});
column.setComparator(Comparator.comparing(o -> o.getProposal().getTxId()));
column.setComparator(Comparator.comparing((evaluatedProposal -> evaluatedProposal.getProposal().getName().toLowerCase())));
votesTableView.getColumns().add(column);


Expand All @@ -760,12 +740,12 @@ public void updateItem(final ProposalListItem item, boolean empty) {
};
}
});
column.setComparator(Comparator.comparing(o2 -> o2.getProposal().getName()));
column.setComparator(Comparator.comparing(o2 -> o2.getProposal().getType().getDisplayName()));
votesTableView.getColumns().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.details"));
column.setMinWidth(180);
column.setMinWidth(100);
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(
new Callback<>() {
Expand All @@ -784,12 +764,13 @@ public void updateItem(final ProposalListItem item, boolean empty) {
};
}
});
column.setComparator(Comparator.comparing(ProposalListItem::getDetails));
// We sort by issued amount
column.setComparator(Comparator.comparing(ProposalListItem::getIssuedAmount));
votesTableView.getColumns().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.myVote"));
column.setMinWidth(70);
column.setMinWidth(60);
column.setMaxWidth(column.getMinWidth());
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(new Callback<>() {
Expand All @@ -811,11 +792,60 @@ public void updateItem(final ProposalListItem item, boolean empty) {
};
}
});
column.setSortable(false);
votesTableView.getColumns().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.result"));
column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.threshold"));
column.setMinWidth(80);
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(
new Callback<>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(
TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(item.getThresholdAsString());
else
setText("");
}
};
}
});
column.setComparator(Comparator.comparing(ProposalListItem::getThreshold));
votesTableView.getColumns().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.quorum"));
column.setMinWidth(90);
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setCellFactory(
new Callback<>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(
TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(item.getQuorumAsString());
else
setText("");
}
};
}
});
column.setComparator(Comparator.comparing(ProposalListItem::getQuorum));
votesTableView.getColumns().add(column);


column = new AutoTooltipTableColumn<>(Res.get("dao.results.proposals.table.header.result"));
column.setMinWidth(80);
column.setMaxWidth(column.getMinWidth());
column.getStyleClass().add("last-column");
column.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
Expand All @@ -840,6 +870,7 @@ public void updateItem(final ProposalListItem item, boolean empty) {
};
}
});
column.setComparator(Comparator.comparing(ProposalListItem::isAccepted));
votesTableView.getColumns().add(column);
}

Expand Down