Merge branch 'master' into 'feature/localProduce_and_publicTransport'
# Conflicts: # src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java # src/Client/src/main/resources/fxml/extraActivities.fxml
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
package greenify.client;
|
||||
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleFloatProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
public class Friend {
|
||||
|
||||
private SimpleStringProperty friend;
|
||||
private SimpleFloatProperty score;
|
||||
private SimpleDoubleProperty score;
|
||||
|
||||
public Friend(String friend, Float friendScore) {
|
||||
public Friend(String friend, Double friendScore) {
|
||||
this.friend = new SimpleStringProperty(friend);
|
||||
this.score = new SimpleFloatProperty(friendScore);
|
||||
this.score = new SimpleDoubleProperty(friendScore);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +23,11 @@ public class Friend {
|
||||
this.friend = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
public Float getScore() {
|
||||
public Double getScore() {
|
||||
return score.get();
|
||||
}
|
||||
|
||||
public void setScore(Float score) {
|
||||
this.score = new SimpleFloatProperty(score);
|
||||
public void setScore(Double score) {
|
||||
this.score = new SimpleDoubleProperty(score);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,26 +12,28 @@ public class Hints {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds all the Strings to the arraylist.
|
||||
* This method adds all the Strings to the array list.
|
||||
*/
|
||||
private void initHints() {
|
||||
this.hints.add("Buying local produce will not only decrease your carbon "
|
||||
+ "footprint, but also help your local economy: A win-win!");
|
||||
this.hints.add("Did you know that a gas oven only uses 6% of its energy "
|
||||
+ "to cook? And an electric oven is not much better at 12%.");
|
||||
this.hints.add("70% of the deforestation of the Amazon is to provide land for cattle ranches.");
|
||||
this.hints.add("70% of the deforestation of the Amazon is to provide land for "
|
||||
+ "cattle ranches.");
|
||||
this.hints.add("Research shows that reducing meat consumption can increase"
|
||||
+ " your life span by 3.6 years");
|
||||
this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood pressure, "
|
||||
+ "diabetes and cancer than meat eaters.");
|
||||
this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood "
|
||||
+ "pressure, diabetes and cancer than meat eaters.");
|
||||
this.hints.add("Did you know? The carbon footprint of a vegetarian diet is about half "
|
||||
+ "that of a meat-lover’s diet!");
|
||||
this.hints.add("Cycling is good for the environment AND for your body, "
|
||||
+ "so why not grab your bike instead of your car?");
|
||||
this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just one "
|
||||
+ "hour, we could power the entire world for one year!");
|
||||
this.hints.add("If we could capture all of the sun’s energy shining on the Earth"
|
||||
+ " for just one hour, we could power the entire world for one year!");
|
||||
this.hints.add("27,000 trees are cut down each day so we can have toilet paper.");
|
||||
this.hints.add("A glass bottle made in our time will take more than 4,000 years to decompose.");
|
||||
this.hints.add("A glass bottle made in our time will take more than 4,000 years "
|
||||
+ "to decompose.");
|
||||
this.hints.add("Don't forget to turn off the lights and heating in rooms"
|
||||
+ " you're not using at the moment!");
|
||||
this.hints.add("Did you know that about 4.5% of the Dutch population does not eat meat?");
|
||||
@@ -53,7 +55,7 @@ public class Hints {
|
||||
+ "utensils and napkins, it saves plastic and paper.");
|
||||
this.hints.add("It takes about 66 days to form a new habit, keep going!");
|
||||
this.hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for "
|
||||
+ "the environment to refill than to buy a new one every time it's empty.");
|
||||
+ "the environment to refill than to buy a new one every time it's empty.");
|
||||
this.hints.add("Recycle glass bottles!"
|
||||
+ " A glass bottle made in our time will take more than 4,000 years"
|
||||
+ " to decompose.");
|
||||
@@ -63,7 +65,7 @@ public class Hints {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a random String.
|
||||
* This method gets a random String.
|
||||
* @return the random hint.
|
||||
*/
|
||||
public String randomHint() {
|
||||
@@ -73,3 +75,4 @@ public class Hints {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Slider;
|
||||
@@ -34,7 +33,6 @@ import java.text.DecimalFormat;
|
||||
|
||||
@Controller
|
||||
public class CalculatorController {
|
||||
private static UserController.AlertHelper AlertHelper;
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@@ -146,15 +144,6 @@ public class CalculatorController {
|
||||
//extra pane
|
||||
@FXML
|
||||
private AnchorPane extraPane;
|
||||
@FXML
|
||||
private CheckBox localProduceCheckbox;
|
||||
@FXML
|
||||
private CheckBox bikeCheckbox;
|
||||
@FXML
|
||||
private CheckBox temperatureCheckbox;
|
||||
@FXML
|
||||
private CheckBox solarPanelsCheckbox;
|
||||
|
||||
|
||||
/**
|
||||
* initializes the window, performs some actions before loading all other things.
|
||||
@@ -372,7 +361,6 @@ public class CalculatorController {
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,46 +382,65 @@ public class CalculatorController {
|
||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
}
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
checkTransportLabels();
|
||||
checkHousingLabels();
|
||||
checkFoodLabels();
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
|
||||
owner, "Footprint saved!", "Your footprint is saved!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the food labels.
|
||||
*/
|
||||
public void checkFoodLabels() {
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the house labels.
|
||||
*/
|
||||
public void checkHousingLabels() {
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_electricity_dollars",
|
||||
@@ -464,69 +471,51 @@ public class CalculatorController {
|
||||
"input_footprint_housing_watersewage",
|
||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||
}
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the transport labels.
|
||||
*/
|
||||
public void checkTransportLabels() {
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
}
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (localProduceCheckbox.isSelected()) {
|
||||
localProduceCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"local_produce", true);
|
||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||
}
|
||||
if (bikeCheckbox.isSelected()) {
|
||||
bikeCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike", true);
|
||||
}
|
||||
if (temperatureCheckbox.isSelected()) {
|
||||
temperatureCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"temperature", true);
|
||||
}
|
||||
if (solarPanelsCheckbox.isSelected()) {
|
||||
solarPanelsCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels", true);
|
||||
}
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
CalculatorController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
|
||||
owner, "Footprint saved!", "Your footprint is saved!");
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
@@ -168,16 +167,16 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private ImageView achiev1image;
|
||||
@FXML
|
||||
private CheckBox localProduce;
|
||||
@FXML
|
||||
private CheckBox loweringTemp;
|
||||
@FXML
|
||||
private CheckBox bike;
|
||||
@FXML
|
||||
private CheckBox solarPanels;
|
||||
@FXML
|
||||
private Label hintText;
|
||||
@FXML
|
||||
private Label solarPanels;
|
||||
@FXML
|
||||
private Label localProduce;
|
||||
@FXML
|
||||
private Label bike;
|
||||
@FXML
|
||||
private Label loweringTemp;
|
||||
@FXML
|
||||
private Button refreshHintsButton;
|
||||
|
||||
/**
|
||||
@@ -249,8 +248,8 @@ public class DashBoardController {
|
||||
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));
|
||||
Double firstScore = userService.getFootprint(users.get(i));
|
||||
Double secondScore = userService.getFootprint(users.get(j));
|
||||
if (i > j && firstScore < secondScore) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
@@ -272,9 +271,9 @@ public class DashBoardController {
|
||||
public void sortDiffScores(List<String> users) throws InterruptedException {
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
for (int j = 0; j < users.size(); j++) {
|
||||
Float firstDiff = userService.getFirstFootprint(users.get(i)) - userService
|
||||
Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService
|
||||
.getFootprint(users.get(i));
|
||||
Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
||||
Double secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
||||
.getFootprint(users.get(j));
|
||||
if (i < j && firstDiff < secondDiff) {
|
||||
String temp = users.get(i);
|
||||
@@ -356,18 +355,11 @@ public class DashBoardController {
|
||||
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
|
||||
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
|
||||
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("local_produce")) {
|
||||
localProduce.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("bike")) {
|
||||
bike.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("temperature")) {
|
||||
loweringTemp.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("solar_panels")) {
|
||||
solarPanels.setSelected(true);
|
||||
}
|
||||
Map<String, String> extraMap = userService.getExtraInputs(userService.currentUser.getName());
|
||||
localProduce.setText(extraMap.get("local_produce"));
|
||||
bike.setText(extraMap.get("bike"));
|
||||
solarPanels.setText(extraMap.get("solar_panels"));
|
||||
loweringTemp.setText(extraMap.get("temperature"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,9 +372,9 @@ public class DashBoardController {
|
||||
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
|
||||
firstFootprintLabel.setText("" + userService
|
||||
.getFirstFootprint(userService.currentUser.getName()));
|
||||
Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
||||
Double diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
||||
.getFootprint(userService.currentUser.getName());
|
||||
differenceLabel.setText( "" + diff);
|
||||
differenceLabel.setText( "" + Math.round(diff * 10) / 10.0);
|
||||
usernameLabel.setText("" + userService.currentUser.getName());
|
||||
addFadeTransition(userPane);
|
||||
System.out.println("display user");
|
||||
@@ -390,7 +382,6 @@ public class DashBoardController {
|
||||
userPane.setVisible(true);
|
||||
activitiesPane.setVisible(false);
|
||||
friendsPane.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,6 +411,13 @@ public class DashBoardController {
|
||||
current.close();
|
||||
System.out.println("User is logged out");
|
||||
|
||||
//global leaderboard
|
||||
globalLeaderboard.getItems().clear();
|
||||
globalLeaderData.removeAll();
|
||||
//development leaderboard
|
||||
developmentLeaderboard.getItems().clear();
|
||||
developmentData.removeAll();
|
||||
|
||||
//load the fxml file
|
||||
Parent dash = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/LoginWindow.fxml"));
|
||||
@@ -457,6 +455,9 @@ public class DashBoardController {
|
||||
calcStage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a random hint to the left.
|
||||
*/
|
||||
public void addRandomHints() {
|
||||
FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText);
|
||||
fadeOut.setFromValue(1.0);
|
||||
@@ -516,9 +517,9 @@ public class DashBoardController {
|
||||
sortDiffScores(userList);
|
||||
for (int j = 0; j < userList.size(); j++) {
|
||||
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
|
||||
Friend diffUser = new Friend(userList.get(j), userService
|
||||
.getFirstFootprint(userList.get(j))
|
||||
- userService.getFootprint(userList.get(j)));
|
||||
double diff = Math.round((userService.getFirstFootprint(userList.get(j))
|
||||
- userService.getFootprint(userList.get(j))) * 10) / 10.0;
|
||||
Friend diffUser = new Friend(userList.get(j), diff);
|
||||
globalLeaderData.add(user);
|
||||
developmentData.add(diffUser);
|
||||
}
|
||||
@@ -548,9 +549,9 @@ public class DashBoardController {
|
||||
data.add(user);
|
||||
}
|
||||
for (int j = 0; j < wholeList.size(); j++) {
|
||||
Friend diffUser = new Friend(wholeList.get(j),
|
||||
userService.getFirstFootprint(wholeList.get(j))
|
||||
- userService.getFootprint(wholeList.get(j)));
|
||||
double diff = Math.round((userService.getFirstFootprint(wholeList.get(j))
|
||||
- userService.getFootprint(wholeList.get(j))) * 10) / 10.0;
|
||||
Friend diffUser = new Friend(wholeList.get(j), diff);
|
||||
friendLeaderData.add(diffUser);
|
||||
}
|
||||
friendsTable.setItems(data);
|
||||
@@ -632,6 +633,4 @@ public class DashBoardController {
|
||||
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,20 +8,28 @@ import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class ExtraActivityController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
CalculatorController calculatorController;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
@FXML
|
||||
private AnchorPane veganMealPane;
|
||||
@FXML
|
||||
@@ -254,7 +262,44 @@ public class ExtraActivityController {
|
||||
"solar_panels", true);
|
||||
}
|
||||
|
||||
private class TranslateButtonSkin extends ButtonSkin {
|
||||
/**
|
||||
* The method updates the values
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void save(ActionEvent event) throws InterruptedException {
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
controller.updateLeaderboard();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Activities are added!",
|
||||
"Your new activities are added!");
|
||||
}
|
||||
|
||||
/**
|
||||
* The method updates the values of extras.
|
||||
* @param event user clicks to button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateExtras(ActionEvent event) throws InterruptedException {
|
||||
if (!bikeLabel.getText().replace(" km", "").equals("0")) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike",
|
||||
bikeLabel.getText().replace(" km", ""));
|
||||
}
|
||||
if (!solarPanelsLabel.getText().equals("0")) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels",
|
||||
solarPanelsLabel.getText());
|
||||
}
|
||||
if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike",
|
||||
temperatureLabel.getText().replace(" Degrees", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TranslateButtonSkin extends ButtonSkin {
|
||||
/**
|
||||
* button skin that sets a translate animation on entering and exiting the button.
|
||||
* @param button the button to set the animation for
|
||||
|
||||
@@ -2,9 +2,11 @@ package greenify.client.controller;
|
||||
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.KeyValue;
|
||||
import javafx.animation.ParallelTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
@@ -16,7 +18,6 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
@@ -39,12 +40,11 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@Controller
|
||||
public class RegisterWindowController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
ExtraActivityController extraActivityController;
|
||||
|
||||
//navigation panes
|
||||
@FXML
|
||||
@@ -151,15 +151,6 @@ public class RegisterWindowController {
|
||||
//extra pane
|
||||
@FXML
|
||||
private AnchorPane extraPane;
|
||||
@FXML
|
||||
private CheckBox localProduceCheckbox;
|
||||
@FXML
|
||||
private CheckBox bikeCheckbox;
|
||||
@FXML
|
||||
private CheckBox temperatureCheckbox;
|
||||
@FXML
|
||||
private CheckBox solarPanelsCheckbox;
|
||||
|
||||
@FXML
|
||||
private TextField userNameText;
|
||||
@FXML
|
||||
@@ -230,8 +221,7 @@ public class RegisterWindowController {
|
||||
//register the user with the provided username and password
|
||||
try {
|
||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
} catch (RuntimeException ex) {
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
|
||||
"This username has already been taken!");
|
||||
return;
|
||||
@@ -270,9 +260,9 @@ public class RegisterWindowController {
|
||||
}
|
||||
});
|
||||
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
|
||||
|
||||
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
@@ -315,6 +305,7 @@ public class RegisterWindowController {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@@ -336,6 +327,23 @@ public class RegisterWindowController {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a fade transition to the given node.
|
||||
* @param node the node to add the transition to
|
||||
*/
|
||||
public void addFadeTransAnimation(Node node) {
|
||||
FadeTransition fade = new FadeTransition(Duration.millis(350), node);
|
||||
fade.setFromValue(0);
|
||||
fade.setToValue(1.0);
|
||||
TranslateTransition trans = new TranslateTransition(Duration.millis(350), node);
|
||||
trans.setFromY(800);
|
||||
trans.setToY(0);
|
||||
ParallelTransition par = new ParallelTransition();
|
||||
par.setNode(travelPane);
|
||||
par.getChildren().addAll(fade, trans);
|
||||
par.play();
|
||||
}
|
||||
|
||||
private void addSlideInAnimation(Node node) {
|
||||
Timeline timeline = new Timeline();
|
||||
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
||||
@@ -351,6 +359,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayGetStarted(ActionEvent event) {
|
||||
addFadeTransAnimation(getStartedPane);
|
||||
getStartedPane.setVisible(true);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -366,7 +375,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayTravel(ActionEvent event) {
|
||||
addSlideInAnimation(travelPane);
|
||||
addFadeTransAnimation(travelPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(true);
|
||||
homePane.setVisible(false);
|
||||
@@ -383,6 +392,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayHome(ActionEvent event) {
|
||||
addFadeTransAnimation(homePane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(true);
|
||||
@@ -398,6 +408,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayFood(ActionEvent event) {
|
||||
addFadeTransAnimation(foodPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -413,6 +424,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayShopping(ActionEvent event) {
|
||||
addFadeTransAnimation(shoppingPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -427,7 +439,10 @@ public class RegisterWindowController {
|
||||
* @param event the click of the designated button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayExtra(ActionEvent event) {
|
||||
public void displayExtra(ActionEvent event) throws IOException {
|
||||
addFadeTransAnimation(extraPane);
|
||||
extraPane.getChildren().setAll((Node) Application.load(this.getClass()
|
||||
.getClassLoader().getResource("fxml/extraActivities.fxml")));
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -456,46 +471,65 @@ public class RegisterWindowController {
|
||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
}
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
checkTransportLabels();
|
||||
checkHousingLabels();
|
||||
checkFoodLabels();
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
|
||||
owner, "Footprint saved!", "Your footprint is saved!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the food labels.
|
||||
*/
|
||||
public void checkFoodLabels() {
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the housing labels.
|
||||
*/
|
||||
public void checkHousingLabels() {
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_electricity_dollars",
|
||||
@@ -526,63 +560,51 @@ public class RegisterWindowController {
|
||||
"input_footprint_housing_watersewage",
|
||||
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().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
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().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
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().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (localProduceCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"local_produce", true);
|
||||
}
|
||||
if (bikeCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike", true);
|
||||
}
|
||||
if (temperatureCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"temperature", true);
|
||||
}
|
||||
if (solarPanelsCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels", true);
|
||||
}
|
||||
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the transport labels.
|
||||
*/
|
||||
public void checkTransportLabels() {
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,8 +67,7 @@ public class UserController {
|
||||
//log the user in with the userService method
|
||||
try {
|
||||
userService.loginUser(usernameField.getText(), passwordField.getText());
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
} catch (RuntimeException ex) {
|
||||
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
|
||||
"Your username or password is incorrect!");
|
||||
return;
|
||||
@@ -143,3 +142,4 @@ public class UserController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,13 +109,13 @@ public class UserService {
|
||||
* @param value value of the input
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateExtraInput(String name, String inputName, Boolean value) {
|
||||
public void updateExtraInput(String name, String inputName, String value) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
|
||||
.queryParam("name", name)
|
||||
.queryParam("inputName", inputName)
|
||||
.queryParam("value",value);
|
||||
.queryParam("value", value);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||
@@ -128,15 +128,16 @@ public class UserService {
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Float getFootprint(String name) {
|
||||
public double getFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float result = this.restTemplate.getForObject(builder
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
double result = Math.round(footprint * 10) / 10.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ public class UserService {
|
||||
* @param name name of the user
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
public Float getFirstFootprint(String name) {
|
||||
public double getFirstFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
|
||||
@@ -154,7 +155,8 @@ public class UserService {
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
return footprint;
|
||||
double result = Math.round(footprint * 10) / 10.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,14 +272,14 @@ public class UserService {
|
||||
* @param name the username of the current user.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Map<String, Boolean> getExtraInputs(String name) {
|
||||
public Map<String, String> getExtraInputs(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
|
||||
.queryParam("name", name);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build()
|
||||
Map<String, String> result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), Map.class);
|
||||
return result;
|
||||
}
|
||||
@@ -313,4 +315,4 @@ public class UserService {
|
||||
.build().encode().toUri(), List.class);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,13 @@
|
||||
<?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?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.CalculatorController">
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
|
||||
<children>
|
||||
<AnchorPane fx:id="calculatorTabs" prefHeight="92.0" prefWidth="820.0" style="-fx-background-color: #677069;">
|
||||
<children>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
<?import javafx.scene.chart.PieChart?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.CheckBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
@@ -54,6 +53,7 @@
|
||||
<Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
|
||||
<Line endX="104.0" layoutX="105.0" layoutY="271.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
|
||||
<Line endX="104.0" layoutX="106.0" layoutY="270.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
<Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
@@ -276,25 +276,25 @@
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
</children>
|
||||
</Pane>
|
||||
<Button fx:id="addExtraActivityButton2" contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219">
|
||||
@@ -474,7 +474,7 @@
|
||||
<ImageView fx:id="achiev1image" fitHeight="150.0" fitWidth="200.0" layoutX="579.0" layoutY="396.0" pickOnBounds="true" preserveRatio="true">
|
||||
|
||||
<image>
|
||||
<Image url="@../achiev1pic.jpg" />
|
||||
<Image url="@../icons/achiev1pic.jpg" />
|
||||
<!-- image from shutterstock.com - 1038138760 -->
|
||||
</image>
|
||||
</ImageView>
|
||||
@@ -518,4 +518,4 @@
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</AnchorPane>
|
||||
@@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
|
||||
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
|
||||
<children>
|
||||
<AnchorPane prefHeight="611.0" prefWidth="107.0">
|
||||
<children>
|
||||
@@ -77,7 +78,7 @@
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#confirmVeganMeal" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<graphic>
|
||||
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
@@ -105,7 +106,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#confirmBike" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<font>
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
@@ -151,7 +152,7 @@
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#confirmTemperature" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<font>
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
|
||||
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
@@ -47,15 +47,6 @@
|
||||
#friendsButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
#logOutButton {
|
||||
-fx-background-color: #5a635c;
|
||||
}
|
||||
#logOutButton:hover {
|
||||
-fx-background-color: #677069;
|
||||
}
|
||||
#logOutButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
|
||||
#addNewActivityButton:pressed {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#signUpButton {
|
||||
-fx-background-color: #005e07;
|
||||
-fx-text-fill: #c4eec9;
|
||||
}
|
||||
|
||||
#signUpButton:hover {
|
||||
-fx-background-color: #11911b;
|
||||
}
|
||||
|
||||
#signUpButton:pressed {
|
||||
-fx-background-color: #1a8c23;
|
||||
}
|
||||
16
src/Client/src/test/java/FriendTest.java
Normal file
16
src/Client/src/test/java/FriendTest.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import greenify.client.Friend;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class FriendTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
Friend test = new Friend("ceren", 10.0);
|
||||
test.setFriend("greenify");
|
||||
test.setScore(15.0);
|
||||
assertEquals(test.getFriend(), "greenify");
|
||||
Assertions.assertEquals(test.getScore(), 15.0);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import greenify.client.rest.UserService;
|
||||
import greenify.common.UserDto;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -15,6 +14,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserServiceTest {
|
||||
|
||||
@@ -33,7 +35,7 @@ public class UserServiceTest {
|
||||
.thenReturn(testUser);
|
||||
|
||||
UserDto user = userService.registerUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +45,7 @@ public class UserServiceTest {
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDto user = userService.loginUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,8 +54,8 @@ public class UserServiceTest {
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
double result = (5 * 10) / 10.0;
|
||||
assertTrue(result == userService.getFootprint("Eric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,8 +64,8 @@ public class UserServiceTest {
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
double result = (5 * 10) / 10.0;
|
||||
assertTrue(result == userService.getFirstFootprint("Eric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +75,7 @@ public class UserServiceTest {
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +85,7 @@ public class UserServiceTest {
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +96,7 @@ public class UserServiceTest {
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getFriendNames("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +107,7 @@ public class UserServiceTest {
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getAllUsers();
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,18 +118,18 @@ public class UserServiceTest {
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, String> result = userService.getInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraInputsTest() throws Exception {
|
||||
Map<String, Boolean> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", true);
|
||||
Map<String, String> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", "5");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, Boolean> result = userService.getExtraInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
Map<String, String> result = userService.getExtraInputs("Eric");
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,8 +140,8 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void setExtraInputTest() throws Exception {
|
||||
userService.updateExtraInput("Eric", "solar_panels", true);
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
|
||||
userService.updateExtraInput("Eric", "solar_panels", "8");
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", "8");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user