Merge branch 'fixBugs_addLeaderboard' into 'master'
Fix bugs & add leaderboard See merge request cse1105/2018-2019/oopp-group-43/template!50
This commit is contained in:
@@ -6,11 +6,11 @@ import javafx.beans.property.SimpleStringProperty;
|
||||
public class Friend {
|
||||
|
||||
private SimpleStringProperty friend;
|
||||
private SimpleFloatProperty friendScore;
|
||||
private SimpleFloatProperty score;
|
||||
|
||||
public Friend(String friend, Float friendScore) {
|
||||
this.friend = new SimpleStringProperty(friend);
|
||||
this.friendScore = new SimpleFloatProperty(friendScore);
|
||||
this.score = new SimpleFloatProperty(friendScore);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ public class Friend {
|
||||
this.friend = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
public Float getFriendScore() {
|
||||
return friendScore.get();
|
||||
public Float getScore() {
|
||||
return score.get();
|
||||
}
|
||||
|
||||
public void setScore(Float score) {
|
||||
this.friendScore = new SimpleFloatProperty(score);
|
||||
this.score = new SimpleFloatProperty(score);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
@@ -29,6 +30,9 @@ public class CalculatorController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
//navigation panes
|
||||
@FXML
|
||||
private AnchorPane getStartedPane;
|
||||
@@ -119,6 +123,10 @@ public class CalculatorController {
|
||||
|
||||
//shopping pane
|
||||
@FXML
|
||||
private Text goodsField;
|
||||
@FXML
|
||||
private Text servicesField;
|
||||
@FXML
|
||||
private Slider goodsSlider;
|
||||
@FXML
|
||||
private Label goodsLabel;
|
||||
@@ -303,8 +311,7 @@ public class CalculatorController {
|
||||
* The method saves the calculation.
|
||||
* @param event user clicks to button
|
||||
*/
|
||||
public void saveCalc(ActionEvent event) {
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
public void saveCalc(ActionEvent event) throws InterruptedException {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -336,7 +343,7 @@ public class CalculatorController {
|
||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText());
|
||||
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
@@ -346,36 +353,36 @@ public class CalculatorController {
|
||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText());
|
||||
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText());
|
||||
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||
}
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_electricity_dollars",
|
||||
"input_footprint_housing_electricity_dollars",
|
||||
electricityField.getText());
|
||||
}
|
||||
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_gco2_per_kwh",
|
||||
cleanEnergyPurchasedLabel.getText());
|
||||
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
|
||||
}
|
||||
if (!naturalGasField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_naturalgas_dollars",
|
||||
"input_footprint_housing_naturalgas_dollars",
|
||||
naturalGasField.getText());
|
||||
}
|
||||
if (!heatingOilField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_heatingoil_dollars",
|
||||
"input_footprint_housing_heatingoil_dollars",
|
||||
heatingOilField.getText());
|
||||
}
|
||||
if (!livingSpaceField.getText().equals("0")) {
|
||||
@@ -386,44 +393,49 @@ public class CalculatorController {
|
||||
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_watersewage",
|
||||
waterUsageLabel.getText());
|
||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||
}
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText());
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText().replace(" daily servings per person", "").equals("4.4")) {
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText());
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText());
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText().replace(" daily servings per person", "").equals("3.9")) {
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText());
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText());
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
snacksDrinksLabel.getText());
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
snacksDrinksLabel.getText());
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,17 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class that controls the dashboard fxml file (the GUI Screen).
|
||||
*/
|
||||
@Controller
|
||||
public class DashBoardController {
|
||||
public static ObservableList<Friend> data = FXCollections.observableArrayList();
|
||||
public ObservableList<Friend> friendLeaderData = FXCollections.observableArrayList();
|
||||
public ObservableList<Friend> globalLeaderData = FXCollections.observableArrayList();
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@@ -76,6 +81,18 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private TableColumn<Friend, Float> scoreColumn;
|
||||
@FXML
|
||||
private TableView<Friend> globalLeaderboard;
|
||||
@FXML
|
||||
private TableColumn<Friend, String> globalUser;
|
||||
@FXML
|
||||
private TableColumn<Friend, Float> globalScore;
|
||||
@FXML
|
||||
private TableView<Friend> friendLeaderboard;
|
||||
@FXML
|
||||
private TableColumn<Friend, String> friendUser;
|
||||
@FXML
|
||||
private TableColumn<Friend, Float> friendScore;
|
||||
@FXML
|
||||
private PieChart pieChart;
|
||||
@FXML
|
||||
private Label usernameLabel;
|
||||
@@ -83,7 +100,7 @@ public class DashBoardController {
|
||||
/**
|
||||
* Loads the the necessary things before anything else.
|
||||
*/
|
||||
public void initialize() {
|
||||
public void initialize() throws InterruptedException {
|
||||
//sets the text of the 'welcome back' text to include the username
|
||||
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
|
||||
//adds the slide transition to the menu bar
|
||||
@@ -95,8 +112,11 @@ public class DashBoardController {
|
||||
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
||||
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
friendsTable.setItems(FriendController.getData());
|
||||
if(pieChart != null) {
|
||||
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
globalScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
if (pieChart != null) {
|
||||
ObservableList<PieChart.Data> pieChartData =
|
||||
FXCollections.observableArrayList(
|
||||
new PieChart.Data("Vegan Meal", 100),
|
||||
@@ -110,6 +130,37 @@ public class DashBoardController {
|
||||
pieChart.setMaxSize(1000, 1000);
|
||||
pieChart.setData(pieChartData);
|
||||
}
|
||||
List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
|
||||
for (int i = 0; i < friendList.size(); i++) {
|
||||
Friend friend = new Friend(friendList.get(i),
|
||||
userService.getFootprint(friendList.get(i)));
|
||||
data.add(friend);
|
||||
}
|
||||
friendsTable.setItems(data);
|
||||
updateLeaderboard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the scores of users.
|
||||
* @param users the list of users
|
||||
*/
|
||||
public void sortScores(List<String> users) throws InterruptedException {
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
for (int j = 0; j < users.size(); j++) {
|
||||
Float firstScore = userService.getFootprint(users.get(i));
|
||||
Float secondScore = userService.getFootprint(users.get(j));
|
||||
if (i > j && firstScore < secondScore) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
users.set(j, temp);
|
||||
}
|
||||
if (i < j && firstScore > secondScore) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
users.set(j, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +168,6 @@ public class DashBoardController {
|
||||
* @param node the node on which the transition needs to act
|
||||
*/
|
||||
public void addFadeTransition(Node node) {
|
||||
|
||||
fadeTrans = new FadeTransition(Duration.millis(400), node);
|
||||
fadeTrans.setFromValue(0);
|
||||
fadeTrans.setToValue(1.0);
|
||||
@@ -129,14 +179,14 @@ public class DashBoardController {
|
||||
* Displays the dashboard pane.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void displayDashboard(ActionEvent event) {
|
||||
public void displayDashboard(ActionEvent event) throws InterruptedException {
|
||||
addFadeTransition(dashboardPane);
|
||||
System.out.println("display dashboard");
|
||||
dashboardPane.setVisible(true);
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
friendsPane.setVisible(false);
|
||||
|
||||
updateLeaderboard();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +244,7 @@ public class DashBoardController {
|
||||
* Opens the calculator.
|
||||
* @throws IOException if the Application doesn't load.
|
||||
*/
|
||||
public void openCalculator() throws IOException {
|
||||
public void openCalculator() throws IOException, InterruptedException {
|
||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/calculator.fxml"));
|
||||
Scene scene = new Scene(calc);
|
||||
@@ -207,6 +257,10 @@ public class DashBoardController {
|
||||
calcStage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* method opend addFriend scene.
|
||||
* @throws IOException when file is not found
|
||||
*/
|
||||
public void openAddFriend() throws IOException {
|
||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/AddFriend.fxml"));
|
||||
@@ -217,6 +271,37 @@ public class DashBoardController {
|
||||
calcStage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaderboard is updaating.
|
||||
* @throws InterruptedException throws exception
|
||||
*/
|
||||
public void updateLeaderboard() throws InterruptedException {
|
||||
friendLeaderboard.getItems().clear();
|
||||
globalLeaderboard.getItems().clear();
|
||||
//global leaderboard
|
||||
globalLeaderData.removeAll();
|
||||
List<String> userList = userService.getAllUsers();
|
||||
sortScores(userList);
|
||||
for (int j = 0; j < userList.size(); j++) {
|
||||
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
|
||||
globalLeaderData.add(user);
|
||||
}
|
||||
globalLeaderboard.setItems(globalLeaderData);
|
||||
// friend leaderboard
|
||||
friendLeaderData.removeAll();
|
||||
String name = userService.currentUser.getName();
|
||||
List<String> friendList = userService.getFriendNames(name);
|
||||
friendList.add(name);
|
||||
sortScores(friendList);
|
||||
for (int i = 0; i < friendList.size(); i++) {
|
||||
Friend friend = new Friend(friendList.get(i),
|
||||
userService.getFootprint(friendList.get(i)));
|
||||
friendLeaderData.add(friend);
|
||||
}
|
||||
friendLeaderboard.setItems(friendLeaderData);
|
||||
}
|
||||
|
||||
|
||||
//class for the animations on the navigation buttons
|
||||
public class MyButtonSkin extends ButtonSkin {
|
||||
/**
|
||||
|
||||
@@ -2,11 +2,11 @@ package greenify.client.controller;
|
||||
|
||||
import greenify.client.Friend;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,7 +17,8 @@ public class FriendController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
public static ObservableList<Friend> data = FXCollections.observableArrayList();
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
@FXML
|
||||
private Button addButton;
|
||||
@@ -29,7 +30,7 @@ public class FriendController {
|
||||
* @param event the click of the sign up button
|
||||
*/
|
||||
@FXML
|
||||
public void addFriend(ActionEvent event) {
|
||||
public void addFriend(ActionEvent event) throws InterruptedException {
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
Window owner = addButton.getScene().getWindow();
|
||||
//check if the username field is empty
|
||||
@@ -38,19 +39,28 @@ public class FriendController {
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
|
||||
"Please enter a username!");
|
||||
return;
|
||||
} else if (userNameText.getText().equals(userService.currentUser.getName())) {
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
|
||||
"Cannot add yourself as a friend!");
|
||||
return;
|
||||
} else if (userService.getFriendNames(userService.currentUser.getName())
|
||||
.contains(userNameText.getText())) {
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
|
||||
"Cannot add a friend twice!");
|
||||
return;
|
||||
} else if (!userService.getAllUsers().contains(userNameText.getText())) {
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Error!",
|
||||
"The user does not exist!");
|
||||
return;
|
||||
}
|
||||
//add friend to the current user
|
||||
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
||||
Friend friend = new Friend(userNameText.getText(),
|
||||
userService.getFootprint(userNameText.getText()));
|
||||
data.add(friend);
|
||||
DashBoardController.data.add(friend);
|
||||
//close the register window after the user has entered all the credentials
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
}
|
||||
|
||||
public static ObservableList<Friend> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
public UserDto currentUser;
|
||||
@@ -117,6 +119,42 @@ public class UserService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the footprint of the user.
|
||||
* @param name name of the user
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Float saveFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFootprint")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float result = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the friend list of the user.
|
||||
* @param name name of the user
|
||||
* @return returns the friend list
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public List<String> getFriendNames(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFriends")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
List<String> result = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), List.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a friend to the user.
|
||||
* @param name the username of the current user.
|
||||
@@ -134,4 +172,19 @@ public class UserService {
|
||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||
.encode().toUri(), String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of all users.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public List<String> getAllUsers() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getAllUsers");
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
List<String> result = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), List.class);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
@@ -50,9 +43,9 @@
|
||||
<Image url="@../icons/world.png" />
|
||||
<!--image credits:
|
||||
made by prettycons https://www.flaticon.com/authors/prettycons
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
@@ -108,7 +101,7 @@
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" onAction="#saveCalculation" text="Save">
|
||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" onAction="#saveCalc" mnemonicParsing="false" text="Save">
|
||||
<font>
|
||||
<Font size="17.0" />
|
||||
</font></Button>
|
||||
@@ -146,9 +139,8 @@
|
||||
</opaqueInsets>
|
||||
</Label>
|
||||
<Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="188.0" layoutY="14.0" stroke="#38573e" />
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="travelPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<AnchorPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<ScrollPane layoutX="158.0" layoutY="109.0" prefHeight="215.0" prefWidth="499.0">
|
||||
<content>
|
||||
@@ -159,7 +151,7 @@
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="carTravelGasolineField" layoutX="14.0" layoutY="38.0" prefHeight="31.0" prefWidth="405.0" promptText="16.400">
|
||||
<TextField fx:id="carTravelGasolineField" layoutX="14.0" layoutY="38.0" prefHeight="31.0" prefWidth="405.0" promptText="16.400" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -202,7 +194,7 @@
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<TextField fx:id="carTravelDieselField" layoutX="14.0" layoutY="200.0" prefHeight="31.0" prefWidth="405.0" promptText="15.400">
|
||||
<TextField fx:id="carTravelDieselField" layoutX="14.0" layoutY="200.0" prefHeight="31.0" prefWidth="405.0" promptText="15.400" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -217,7 +209,7 @@
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="carTravelElectricField" layoutX="14.0" layoutY="365.0" prefHeight="31.0" prefWidth="405.0" promptText="14.900">
|
||||
<TextField fx:id="carTravelElectricField" layoutX="14.0" layoutY="365.0" prefHeight="31.0" prefWidth="405.0" promptText="14.900" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -258,7 +250,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="publicTransitField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="394.0" prefHeight="31.0" prefWidth="499.0" promptText="0">
|
||||
<TextField fx:id="publicTransitField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="394.0" prefHeight="31.0" prefWidth="499.0" promptText="0" text="0">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font></TextField>
|
||||
@@ -267,7 +259,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="airplaneTravelField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="495.0" prefHeight="31.0" prefWidth="499.0" promptText="0">
|
||||
<TextField fx:id="airplaneTravelField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="495.0" prefHeight="31.0" prefWidth="499.0" promptText="0" text="0">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font></TextField>
|
||||
@@ -290,10 +282,9 @@
|
||||
</children>
|
||||
</HBox>
|
||||
<Button fx:id="travelNextButton" layoutX="383.0" layoutY="559.0" mnemonicParsing="false" onAction="#displayHome" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="273.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="homePane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<AnchorPane fx:id="homePane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<Text layoutX="245.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you use in your home?">
|
||||
<font>
|
||||
@@ -305,7 +296,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField layoutX="177.0" layoutY="105.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570">
|
||||
<TextField fx:id="electricityField" layoutX="177.0" layoutY="105.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -356,7 +347,7 @@
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<TextField layoutX="177.0" layoutY="262.0" prefHeight="31.0" prefWidth="434.0" promptText="2,000">
|
||||
<TextField fx:id="naturalGasField" layoutX="177.0" layoutY="262.0" prefHeight="31.0" prefWidth="434.0" promptText="2,000" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -373,7 +364,7 @@
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<TextField layoutX="177.0" layoutY="325.0" prefHeight="31.0" prefWidth="434.0" promptText="3,100">
|
||||
<TextField fx:id="heatingOilField" layoutX="177.0" layoutY="325.0" prefHeight="31.0" prefWidth="434.0" promptText="3,100" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -388,7 +379,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField layoutX="177.0" layoutY="390.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570">
|
||||
<TextField fx:id="livingSpaceField" layoutX="177.0" layoutY="390.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -419,9 +410,8 @@
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Line endX="79.0" layoutX="358.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children></AnchorPane>
|
||||
<ScrollPane fx:id="foodPane" layoutY="92.0" pannable="true" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<ScrollPane fx:id="foodPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<content>
|
||||
<AnchorPane prefHeight="1000.0" prefWidth="817.0">
|
||||
<children>
|
||||
@@ -457,7 +447,7 @@
|
||||
</Text>
|
||||
<HBox alignment="CENTER" layoutX="299.0" layoutY="310.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="grainsBakedGoodsLabel" text="4,4 daily servings per person">
|
||||
<Label fx:id="grainsBakedGoodsLabel" text="4.4 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -478,7 +468,7 @@
|
||||
<Slider fx:id="dairySlider" blockIncrement="2.5" layoutX="146.0" layoutY="527.0" majorTickUnit="2.5" max="7.5" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="299.0" layoutY="471.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="dairyLabel" text="2,4 daily servings per person">
|
||||
<Label fx:id="dairyLabel" text="2.4 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -497,7 +487,7 @@
|
||||
</Text>
|
||||
<HBox alignment="CENTER" layoutX="304.0" layoutY="810.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="snacksDrinksLabel" text="3,7 daily servings per person">
|
||||
<Label fx:id="snacksDrinksLabel" text="3.7 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -518,7 +508,7 @@
|
||||
<Slider fx:id="fruitsVegetablesSlider" blockIncrement="3.9" layoutX="151.0" layoutY="705.0" majorTickUnit="3.9" max="11.6" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="304.0" layoutY="649.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="fruitsVegetablesLabel" text="3,9 daily servings per person">
|
||||
<Label fx:id="fruitsVegetablesLabel" text="3.9 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -531,12 +521,11 @@
|
||||
</font>
|
||||
</Text>
|
||||
<Button layoutX="378.0" layoutY="926.0" mnemonicParsing="false" onAction="#displayShopping" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="443.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<AnchorPane fx:id="shoppingPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<Text layoutX="133.0" layoutY="50.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you spend on each of the following?">
|
||||
<font>
|
||||
@@ -566,7 +555,7 @@
|
||||
<Slider fx:id="goodsSlider" blockIncrement="1520.0" layoutX="133.0" layoutY="209.0" majorTickUnit="1520.0" max="4560.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="335.0" layoutY="145.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="goodsLabel" text="1.520 € / month">
|
||||
<Label fx:id="goodsLabel" text="1520 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -575,7 +564,7 @@
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" layoutX="335.0" layoutY="348.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="servicesLabel" text="3.428 € / month">
|
||||
<Label fx:id="servicesLabel" text="3428 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -583,7 +572,8 @@
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="servicesSlider" blockIncrement="3428.0" layoutX="133.0" layoutY="418.0" majorTickUnit="3428.0" max="10284.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Line endX="79.0" layoutX="528.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children></AnchorPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.chart.*?>
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.chart.PieChart?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
@@ -263,6 +267,28 @@
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<TableView fx:id="globalLeaderboard" layoutX="56.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="globalUser" prefWidth="75.0" text="User" />
|
||||
<TableColumn fx:id="globalScore" prefWidth="75.0" text="Score" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<TableView fx:id="friendLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="friendUser" prefWidth="75.0" text="User" />
|
||||
<TableColumn fx:id="friendScore" prefWidth="75.0" text="Score" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label layoutX="315.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Friends Leaderboard" textAlignment="CENTER" textFill="#5e1515">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
|
||||
@@ -10,6 +10,9 @@ import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserServiceTest {
|
||||
|
||||
@@ -51,6 +54,38 @@ public class UserServiceTest {
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFootprint() throws Exception {
|
||||
Float estimate = new Float(5);
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/saveFootprint?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFriendNamesTest() throws Exception {
|
||||
List<String> estimate = new ArrayList<String>();
|
||||
estimate.add("alex");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFriends?name=Eric"),
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getFriendNames("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllUsers() throws Exception {
|
||||
List<String> estimate = new ArrayList<String>();
|
||||
estimate.add("alex");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getAllUsers"),
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getAllUsers();
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setInputTest() throws Exception {
|
||||
userService.updateInput("Eric", "input_size", "5");
|
||||
|
||||
Reference in New Issue
Block a user