Skip to content

Commit

Permalink
fixed the styling of the vote component. We now also get a result res…
Browse files Browse the repository at this point in the history
…ponse in the Notifications window on results. This can be added to later.
  • Loading branch information
dekm committed Sep 15, 2023
1 parent 264aa4a commit bad152e
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="625.0" maxWidth="714.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="516.0" prefWidth="714.0" style="-fx-background-color: linear-gradient(from 75px 75px to 200px 150px, #00001c, #000024);" styleClass="mainFxmlClass" stylesheets="@updateview.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.unigrid.bootstrap.controller.DebugViewController">
<AnchorPane maxHeight="625.0" maxWidth="714.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="516.0" prefWidth="714.0" style="-fx-background-color: linear-gradient(from 75px 75px to 200px 150px, #00001c, #000024);" styleClass="mainFxmlClass" stylesheets="@updateview.css" xmlns="http://javafx.com/javafx/" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.unigrid.bootstrap.controller.DebugViewController">
<children>
<FlowPane alignment="TOP_CENTER" columnHalignment="CENTER" layoutY="2.0" orientation="VERTICAL" prefHeight="523.0" prefWidth="657.0" rowValignment="TOP" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="1.0">
<children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ of the License (see COPYING and COPYING.addendum).
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
//import java.util.stream.Collectors;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -82,6 +82,7 @@ protected void updateItem(BudgetGetVote.Result item, boolean empty) {
}
}
});
dataList.setMinHeight(0);
}

private void onMessage(@Observes NewBlock update) {
Expand All @@ -97,9 +98,9 @@ private void onMessage(@Observes NewBlock update) {
listBudgetInfo.clear();
listBudgetInfo.addAll(result);
// Filter out "Pickle-DAO" using Java Streams
listBudgetInfo = result.stream()
.filter(item -> !item.getName().equals("Pickle-DAO"))
.collect(Collectors.toList());
// listBudgetInfo = result.stream()
// .filter(item -> !item.getName().equals("Pickle-DAO"))
// .collect(Collectors.toList());

if (listBudgetInfo.isEmpty()) {
dataList.setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ of the License (see COPYING and COPYING.addendum).

package org.unigrid.janus.controller.component;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

Expand All @@ -30,8 +32,10 @@ of the License (see COPYING and COPYING.addendum).
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Tooltip;
import org.controlsfx.control.Notifications;
import org.unigrid.janus.model.rpc.entity.BudgetVote;
import org.unigrid.janus.model.service.BrowserService;
import org.unigrid.janus.model.service.DebugService;
import org.unigrid.janus.model.service.RPCService;
import org.unigrid.janus.model.signal.ProposalEntry;
import org.unigrid.janus.view.FxUtils;
Expand All @@ -40,6 +44,7 @@ of the License (see COPYING and COPYING.addendum).
public class ProposalController implements Initializable {
@Inject private BrowserService browser;
@Inject private RPCService rpc;
@Inject private DebugService debug;

@Override
public void initialize(URL url, ResourceBundle rb) {
Expand All @@ -49,28 +54,71 @@ public void initialize(URL url, ResourceBundle rb) {
@FXML
public void onNo(ActionEvent e) {
FxUtils.executeParentById("container", (Node) e.getSource(), node -> {
rpc.call(
new BudgetVote.Request(new Object[]{"vote-many", (String) node.getUserData(), "no"}),
BudgetVote.class);
BudgetVote.Request voteRequest = new BudgetVote.Request(new Object[]{"vote-many",
(String) node.getUserData(), "no"});

String rawResponse = rpc.callToJson(voteRequest);
System.out.println("Raw RPC Response: " + rawResponse);

BudgetVote.Result voteResult = rpc.call(voteRequest, BudgetVote.Result.class);

if (voteResult != null) {
// Log the response for debugging
System.out.println("Received response: " + voteResult.toString());

// Access the "overall" field using the getOverall method
System.out.println("Overall: " + voteResult.getOverall());

// Further processing of the response
Notifications.create().title("Vote Results:").text(voteResult.getOverall())
.showInformation();
debug.print("no: " + voteResult.getOverall(),
ProposalController.class.getSimpleName());
} else {
// Log an error if the response is null
System.err.println("Received null response from RPC.");
}
});
}

@FXML
public void onYes(ActionEvent e) {
FxUtils.executeParentById("container", (Node) e.getSource(), node -> {
rpc.call(
new BudgetVote.Request(new Object[]{"vote-many", (String) node.getUserData(), "yes"}),
BudgetVote.class);
BudgetVote.Request voteRequest = new BudgetVote.Request(new Object[]{"vote-many",
(String) node.getUserData(), "yes"});

String rawResponse = rpc.callToJson(voteRequest);
System.out.println("Raw RPC Response: " + rawResponse);

BudgetVote.Result voteResult = rpc.call(voteRequest, BudgetVote.Result.class);

if (voteResult != null) {
System.out.println("Received response: " + voteResult.toString());

System.out.println("Overall: " + voteResult.getOverall());

Notifications.create().title("Vote Results:").text(voteResult.getOverall())
.showInformation();
debug.print("yes: " + voteResult.getOverall(),
ProposalController.class.getSimpleName());
} else {
// Log an error if the response is null
System.err.println("Received null response from RPC.");
}
});
}

@FXML
public void onAbstain(ActionEvent e) {
FxUtils.executeParentById("container", (Node) e.getSource(), node -> {
rpc.call(
new BudgetVote.Request(new Object[]{"vote-many", (String) node.getUserData(), "abstain"}),
BudgetVote.class);
});
private <T> T deserialize(String json, Class<T> clazz) {
// You would use your JSON library's methods here.
// For instance, using Jackson:
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.readValue(json, clazz);
} catch (IOException e) {
// Handle deserialization errors
e.printStackTrace();
return null;
}
}

private void onEntry(@Observes ProposalEntry item) {
Expand All @@ -79,19 +127,17 @@ private void onEntry(@Observes ProposalEntry item) {

Label lblYes = (Label) container.lookup("#lblYes");
Label lblNo = (Label) container.lookup("#lblNo");
Label lblAbstain = (Label) container.lookup("#lblAbstain");
Hyperlink proposalTitle = (Hyperlink) container.lookup("#proposalTitle");
ProgressBar voteProgress = (ProgressBar) container.lookup("#voteProgress");

proposalTitle.setText(item.getData().getName());
proposalTitle.setText("Proposal: " + item.getData().getName());
proposalTitle.setOnAction(e -> {
System.out.println(item.getData().getUrl());
browser.navigate(item.getData().getUrl());
});

lblYes.setText("Yes: " + item.getData().getYeas());
lblNo.setText("No: " + item.getData().getNays());
lblAbstain.setText("Abstain: " + item.getData().getAbstains());
voteProgress.setProgress(item.getData().getRatio());

final String toolTip = "Yes = " + item.getData().getYeas() + " No = " + item.getData().getNays();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ of the License (see COPYING and COPYING.addendum).

package org.unigrid.janus.model.rpc.entity;

import jakarta.json.bind.annotation.JsonbProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class BudgetVote {
public class BudgetVote extends BaseResult<BudgetVote.Result> {
private static final String METHOD = "gnbudget";
private Result result;

public static class Request extends BaseRequest {
public Request(Object[] args) {
Expand All @@ -31,7 +33,22 @@ public Request(Object[] args) {
}
}

@Data
public static class Result {
/* Empty on purpose */
@JsonbProperty("result")
private Response response;

public String getOverall() {
if (response != null) {
return response.getOverall();
}
return null;
}
}

@Data
public static class Response {
@JsonbProperty("overall")
private String overall;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,106 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox styleClass="bg-dark-blue" fx:id="container" stylesheets="@../main.css" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.unigrid.janus.controller.component.ProposalController">
<VBox fx:id="container" minHeight="120.0" prefHeight="120.0" prefWidth="700.0" styleClass="vote-box" stylesheets="@../main.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.unigrid.janus.controller.component.ProposalController">
<children>
<Hyperlink fx:id="proposalTitle" minHeight="48.0" stylesheets="@../main.css" text="Proposal 1" VBox.vgrow="ALWAYS">
<font>
<Font size="15.0" />
</font>
<HBox prefHeight="20.0" prefWidth="200.0">
<children>
<Hyperlink fx:id="proposalTitle" alignment="CENTER" minHeight="30.0" stylesheets="@../main.css" text="Proposal 1">
<font>
<Font size="15.0" />
</font>
<opaqueInsets>
<Insets left="5.0" />
</opaqueInsets>
<HBox.margin>
<Insets />
</HBox.margin>
</Hyperlink>
</children>
<VBox.margin>
<Insets bottom="8.0" />
<Insets left="26.0" top="5.0" />
</VBox.margin>
</Hyperlink>
</HBox>
<HBox stylesheets="@../main.css" VBox.vgrow="ALWAYS">
<ProgressBar fx:id="voteProgress" nodeOrientation="LEFT_TO_RIGHT" prefHeight="8.0" prefWidth="332.0" progress="0.48" styleClass="vote-progress-bar" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<padding>
<Insets left="5.0" right="5.0" />
</padding>
<ProgressBar fx:id="voteProgress" minHeight="5.0" nodeOrientation="LEFT_TO_RIGHT" prefHeight="5.0" prefWidth="1000.0" progress="0.48" styleClass="vote-progress-bar" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<HBox.margin>
<Insets />
<Insets left="20.0" right="20.0" />
</HBox.margin>
</ProgressBar>
<VBox.margin>
<Insets bottom="8.0" />
<Insets bottom="3.0" />
</VBox.margin>
</HBox>
<HBox prefHeight="26.0" VBox.vgrow="ALWAYS">

<HBox alignment="CENTER" prefHeight="26.0" VBox.vgrow="ALWAYS">
<children>
<Label fx:id="lblYes" style="-fx-text-fill: white;" text="Label">
<HBox.margin>
<Insets right="16.0" />
<Insets left="30.0" />
</HBox.margin>
<font>
<Font name="System Italic" size="15.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Label>

<!-- Add this Region before lblNo -->
<Region HBox.hgrow="ALWAYS" />

<!-- Add this Region after lblNo -->
<Region HBox.hgrow="ALWAYS" />

<Label fx:id="lblNo" style="-fx-text-fill: white;" text="Label">
<HBox.margin>
<Insets right="16.0" />
</HBox.margin>
<font>
<Font name="System Italic" size="15.0" />
</font>
</Label>
<Label fx:id="lblAbstain" style="-fx-text-fill: white;" text="Label">
<font>
<Font name="System Italic" size="15.0" />
</font>
<HBox.margin>
<Insets right="30.0" />
</HBox.margin>
</Label>
</children>
<VBox.margin>
<Insets bottom="12.0" />
<Insets bottom="12.0" top="5.0" />
</VBox.margin>
<opaqueInsets>
<Insets left="5.0" right="5.0" />
</opaqueInsets>
</HBox>
<HBox prefHeight="30.0" stylesheets="@../main.css" VBox.vgrow="ALWAYS">

<HBox alignment="BOTTOM_RIGHT" prefHeight="30.0" stylesheets="@../main.css" VBox.vgrow="ALWAYS">
<children>
<Button fx:id="btnYes" mnemonicParsing="false" onAction="#onYes" prefHeight="30.0" prefWidth="100.0" stylesheets="@../main.css" text="Yes">
<Button fx:id="btnYes" mnemonicParsing="false" onAction="#onYes" prefHeight="30.0" prefWidth="100.0" style="-fx-cursor: hand;" stylesheets="@../main.css" text="Yes">
<HBox.margin>
<Insets right="16.0" />
</HBox.margin>
<font>
<Font size="15.0" />
</font>
</Button>
<Button fx:id="btnNo" mnemonicParsing="false" onAction="#onNo" prefHeight="30.0" prefWidth="100.0" stylesheets="@../main.css" text="No">
<Button fx:id="btnNo" mnemonicParsing="false" onAction="#onNo" prefHeight="30.0" prefWidth="100.0" style="-fx-cursor: hand;" stylesheets="@../main.css" text="No">
<HBox.margin>
<Insets right="16.0" />
<Insets />
</HBox.margin>
<font>
<Font size="15.0" />
</font>
</Button>
<Button fx:id="btnAbstain" mnemonicParsing="false" onAction="#onAbstain" prefHeight="30.0" prefWidth="100.0" stylesheets="@../main.css" text="Abstain">
<font>
<Font size="15.0" />
</font>
</Button>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<VBox.margin>
<Insets bottom="10.0" right="25.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
21 changes: 13 additions & 8 deletions fx/src/main/resources/org/unigrid/janus/view/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@
}

.vote-progress-bar > .track {
-fx-background-color: "#F74230", "#F74230";
-fx-background-radius:0;
-fx-background-insets: 0, 1;
-fx-background-color: "#F74230", "#F74230";
-fx-background-radius: 2.5;
-fx-background-insets: 0, 1;
}

.vote-progress-bar > .bar {
-fx-accent: "#14B839";
-fx-background-insets: 0;
-fx-background-radius: 2;
-fx-padding: 0.75em;
-fx-accent: "#14B839";
-fx-background-insets: 0;
-fx-background-radius: 2.5;
-fx-padding: 0.75em;
}

.my-progress-bar > .track {
Expand Down Expand Up @@ -256,9 +256,14 @@
-fx-background-color: linear-gradient(from 75px 75px to 200px 150px, #00001c, #000024);
}

.vote-box {
-fx-background-color: #0e1011;
-fx-background-radius: 15;
}

.vote-list {
-fx-background-insets: 0;
-fx-padding: 0;
-fx-padding: 5px 0px 5px 0px;
}

.vote-list .list-cell:filled:selected:focused,
Expand Down
Loading

0 comments on commit bad152e

Please sign in to comment.