Compare commits
118 Commits
v0.2
...
update/not
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5653800d47 | ||
|
|
a715babcd9 | ||
|
|
9fc42247da | ||
|
|
3cc01e4f4a | ||
|
|
7043f7253d | ||
|
|
83611c4ecc | ||
|
|
b99b66b87b | ||
|
|
3e7fbeae75 | ||
|
|
839292ad91 | ||
|
|
6ba21c331d | ||
|
|
0cda63cacb | ||
|
|
79fd69503c | ||
|
|
cbf15d9574 | ||
|
|
8667f65e33 | ||
|
|
544b756e70 | ||
|
|
18a0973af4 | ||
|
|
9e37421d6d | ||
|
|
31def99398 | ||
|
|
dbe6fc4e33 | ||
|
|
231c580f7a | ||
|
|
7867853cdb | ||
|
|
39b108626b | ||
|
|
8195650226 | ||
|
|
9310674301 | ||
|
|
2025fd02cc | ||
|
|
55fe2b6795 | ||
|
|
b05b0ecaf7 | ||
|
|
e1489bda27 | ||
|
|
a2805c2a9f | ||
|
|
16fb86c513 | ||
|
|
1cd46940cf | ||
|
|
e9efdf5f24 | ||
|
|
86ec4bbd7d | ||
|
|
d210e22788 | ||
|
|
1cf3af45be | ||
|
|
24be00d28a | ||
|
|
e30f312c6a | ||
|
|
95d5b2b971 | ||
|
|
c0e0063465 | ||
|
|
61a99d47d1 | ||
|
|
6cbabbdf8d | ||
|
|
2a873a78c9 | ||
|
|
0e546bc25c | ||
|
|
4293790ece | ||
|
|
290694c5f1 | ||
|
|
eeb0fd9d57 | ||
|
|
733c0c5920 | ||
|
|
238c00ff46 | ||
|
|
4433d509bb | ||
|
|
0f9cd14036 | ||
|
|
9af14e6015 | ||
|
|
bce08eb6f2 | ||
|
|
dcb8404ae7 | ||
|
|
82fd016590 | ||
|
|
ccbe5968da | ||
|
|
adb8406d4e | ||
|
|
7228252169 | ||
|
|
27a18659f8 | ||
|
|
f2501f3624 | ||
|
|
2b7d51a5ed | ||
|
|
75faf4ae8c | ||
|
|
06daa4776f | ||
|
|
4b07aa8072 | ||
|
|
8927b78098 | ||
|
|
1f12291398 | ||
|
|
1684068385 | ||
|
|
e929680477 | ||
|
|
f23fc2cbea | ||
|
|
4fa2707add | ||
|
|
7ac5b1efda | ||
|
|
b08174b2ee | ||
|
|
04db410293 | ||
|
|
c5e7ff2884 | ||
|
|
c8521feaf8 | ||
|
|
25a66832a5 | ||
|
|
a55e4cecef | ||
|
|
5c85c56d78 | ||
|
|
c79a98c57d | ||
|
|
81701758d7 | ||
|
|
4b04487a25 | ||
|
|
50c27cf420 | ||
|
|
5526c8f467 | ||
|
|
922a7d1fae | ||
|
|
6ced05278b | ||
|
|
9e6505dfa3 | ||
|
|
86f1b724c7 | ||
|
|
90d50624f6 | ||
|
|
82eb5575ee | ||
|
|
84154fca3a | ||
|
|
3aad682394 | ||
|
|
b5c834fc52 | ||
|
|
1ff84ce3d8 | ||
|
|
c5f7cac9db | ||
|
|
19fef1d4c8 | ||
|
|
28f9f72f07 | ||
|
|
f5250aa2a0 | ||
|
|
d5af8816e9 | ||
|
|
6a2eb27627 | ||
|
|
01e03782c2 | ||
|
|
bb6d887036 | ||
|
|
7b6457b286 | ||
|
|
54d0537f95 | ||
|
|
b781727703 | ||
|
|
4c50eea99a | ||
|
|
a38cd45e2a | ||
|
|
e48264a667 | ||
|
|
12b05f3b73 | ||
|
|
6d37b99c14 | ||
|
|
52291ac10f | ||
|
|
ae5d4a1496 | ||
|
|
d7454345be | ||
|
|
973e8aba69 | ||
|
|
7656b60fcf | ||
|
|
ca11cd3c9a | ||
|
|
f5d9bd5010 | ||
|
|
3d61cd061a | ||
|
|
393bfc9445 | ||
|
|
c62e4719ea |
@@ -35,3 +35,13 @@ test:
|
|||||||
- build
|
- build
|
||||||
- .gradle
|
- .gradle
|
||||||
|
|
||||||
|
# Code coverage badge
|
||||||
|
# code-coverage:
|
||||||
|
# stage: code-coverage
|
||||||
|
# script:
|
||||||
|
# - mvn -B clean verify
|
||||||
|
# after_script:
|
||||||
|
# - awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% instructrions covered" }' target/site/jacoco/jacoco.csv
|
||||||
|
# - awk -F"," '{ instructions += $6 + $7; covered += $7 } END { print covered, "/", instructions, " branches covered"; print 100*covered/instructions, "% branches covered" }' target/site/jacoco/jacoco.csv
|
||||||
|
# - echo \"$(cat target/site/jacoco/jacoco.csv)% covered\"
|
||||||
|
# coverage: '/(\d+.\d+) % +branches covered/'
|
||||||
|
|||||||
BIN
doc/meetings/week8/20190401_notes.pdf
Normal file
BIN
doc/meetings/week9/20190408_notes.pdf
Normal file
|
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 257 KiB |
BIN
doc/reports/checkstyle/20190408_checkstyle.jpg
Normal file
|
After Width: | Height: | Size: 774 KiB |
@@ -1,5 +0,0 @@
|
|||||||
# Checkstyle folder
|
|
||||||
|
|
||||||
At the end of the week, please commit a readable screenshot that shows the Checkstyle results.
|
|
||||||
Make sure that the file follows the naming convention; `20190213_checkstyle.xyz` for February 13th.
|
|
||||||
`.xyz` can be either `.jpg` or `.png`.
|
|
||||||
BIN
doc/reports/coverage/20190401_coverage.png
Normal file
|
After Width: | Height: | Size: 210 KiB |
BIN
doc/reports/coverage/20190408_coverage.jpg
Normal file
|
After Width: | Height: | Size: 176 KiB |
14
doc/reports/sprint-reviews/20190408_sprint_review.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
# Sprint Review
|
||||||
|
|
||||||
|
## Main problems Encountered
|
||||||
|
|
||||||
|
### Problem 1:
|
||||||
|
|
||||||
|
## Adjustments from previous sprints
|
||||||
|
There were no big problems this week. We made some last minute changes and added some extra features. Next week we're going to focus on our other exams, so we're
|
||||||
|
not really working on the project anymore.
|
||||||
|
|
||||||
|
## Adjustments for next sprint
|
||||||
|
|
||||||
|
|
||||||
BIN
doc/sprints/sprint6/20190408_scrumboard.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
doc/sprints/sprint6/retrospective_sprint6.pdf
Normal file
BIN
doc/sprints/sprint7/backlog_sprint7.pdf
Normal file
@@ -1,3 +0,0 @@
|
|||||||
<module name="SuppressionFilter">
|
|
||||||
<property name="file" value="quality/checkstyle/suppressions.xml" />
|
|
||||||
</module>
|
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package greenify.client;
|
package greenify.client;
|
||||||
|
|
||||||
import javafx.beans.property.SimpleFloatProperty;
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
public class Friend {
|
public class Friend {
|
||||||
|
|
||||||
private SimpleStringProperty 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.friend = new SimpleStringProperty(friend);
|
||||||
this.score = new SimpleFloatProperty(friendScore);
|
this.score = new SimpleDoubleProperty(friendScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -22,11 +22,11 @@ public class Friend {
|
|||||||
this.friend = new SimpleStringProperty(name);
|
this.friend = new SimpleStringProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getScore() {
|
public Double getScore() {
|
||||||
return score.get();
|
return score.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(Float score) {
|
public void setScore(Double score) {
|
||||||
this.score = new SimpleFloatProperty(score);
|
this.score = new SimpleDoubleProperty(score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
78
src/Client/src/main/java/greenify/client/Hints.java
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package greenify.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Hints {
|
||||||
|
public ArrayList<String> hints;
|
||||||
|
|
||||||
|
public Hints() {
|
||||||
|
this.hints = new ArrayList<String>();
|
||||||
|
initHints();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("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("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("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("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?");
|
||||||
|
this.hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags!");
|
||||||
|
this.hints.add("An estimated 250 million trees can be saved each year "
|
||||||
|
+ "if every published newspaper would be recycled.");
|
||||||
|
this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector.");
|
||||||
|
this.hints.add("You can use LED lights in your home to save energy!");
|
||||||
|
this.hints.add("If you isolate your home well, it will be warmer, "
|
||||||
|
+ "and you'll save energy as well!");
|
||||||
|
this.hints.add("Do you have leftovers? Donate them to food kitchens."
|
||||||
|
+ " This way you won't waste"
|
||||||
|
+ " food, and you'll help people at the same time!");
|
||||||
|
this.hints.add("A lot of coffee places give you a discount if you bring your own cup. "
|
||||||
|
+ "Get rid of those disposable cups!");
|
||||||
|
this.hints.add("When shopping, look for products with minimal to no packaging, "
|
||||||
|
+ "or at least packaging made from recycled items. ");
|
||||||
|
this.hints.add("If you order food, you can ask the restaurant to not include "
|
||||||
|
+ "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.");
|
||||||
|
this.hints.add("Recycle glass bottles!"
|
||||||
|
+ " A glass bottle made in our time will take more than 4,000 years"
|
||||||
|
+ " to decompose.");
|
||||||
|
this.hints.add("Only 1% of our planet’s water supply can be used."
|
||||||
|
+ " 97% is ocean water and 2% is frozen solid in the Arctic, for now.");
|
||||||
|
this.hints.add("Plastic bad");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets a random String.
|
||||||
|
* @return the random hint.
|
||||||
|
*/
|
||||||
|
public String randomHint() {
|
||||||
|
Random rand = new Random();
|
||||||
|
int index = rand.nextInt(this.hints.size());
|
||||||
|
return this.hints.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,17 +1,21 @@
|
|||||||
package greenify.client.controller;
|
package greenify.client.controller;
|
||||||
|
|
||||||
|
import greenify.client.Application;
|
||||||
import greenify.client.rest.UserService;
|
import greenify.client.rest.UserService;
|
||||||
|
import javafx.animation.FadeTransition;
|
||||||
import javafx.animation.Interpolator;
|
import javafx.animation.Interpolator;
|
||||||
import javafx.animation.KeyFrame;
|
import javafx.animation.KeyFrame;
|
||||||
import javafx.animation.KeyValue;
|
import javafx.animation.KeyValue;
|
||||||
|
import javafx.animation.ParallelTransition;
|
||||||
import javafx.animation.Timeline;
|
import javafx.animation.Timeline;
|
||||||
|
import javafx.animation.TranslateTransition;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.Slider;
|
import javafx.scene.control.Slider;
|
||||||
@@ -24,6 +28,7 @@ import javafx.util.Duration;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@@ -34,6 +39,9 @@ public class CalculatorController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
DashBoardController controller;
|
DashBoardController controller;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ExtraActivityController extraActivityController;
|
||||||
|
|
||||||
//navigation panes
|
//navigation panes
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane getStartedPane;
|
private AnchorPane getStartedPane;
|
||||||
@@ -139,20 +147,13 @@ public class CalculatorController {
|
|||||||
//extra pane
|
//extra pane
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane extraPane;
|
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.
|
* initializes the window, performs some actions before loading all other things.
|
||||||
* it sets the sliders to snap to the ticks.
|
* it sets the sliders to snap to the ticks.
|
||||||
* it adds listeners to all the sliders for updating the label they are associated with.
|
* it adds listeners to all the sliders for updating the label they are associated with.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
peopleInHouseholdSlider.setSnapToTicks(true);
|
peopleInHouseholdSlider.setSnapToTicks(true);
|
||||||
//add listener to slider for amount of people in household
|
//add listener to slider for amount of people in household
|
||||||
@@ -173,9 +174,9 @@ public class CalculatorController {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
|
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
|
||||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
|
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
|
||||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
|
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
|
||||||
|
|
||||||
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -218,6 +219,7 @@ public class CalculatorController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
||||||
DecimalFormat df = new DecimalFormat("0.0");
|
DecimalFormat df = new DecimalFormat("0.0");
|
||||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||||
@@ -239,6 +241,23 @@ public class CalculatorController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
private void addSlideInAnimation(Node node) {
|
||||||
Timeline timeline = new Timeline();
|
Timeline timeline = new Timeline();
|
||||||
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
||||||
@@ -254,6 +273,7 @@ public class CalculatorController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayGetStarted(ActionEvent event) {
|
public void displayGetStarted(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(getStartedPane);
|
||||||
getStartedPane.setVisible(true);
|
getStartedPane.setVisible(true);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -270,7 +290,7 @@ public class CalculatorController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayTravel(ActionEvent event) {
|
public void displayTravel(ActionEvent event) {
|
||||||
addSlideInAnimation(travelPane);
|
addFadeTransAnimation(travelPane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(true);
|
travelPane.setVisible(true);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -287,6 +307,7 @@ public class CalculatorController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayHome(ActionEvent event) {
|
public void displayHome(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(homePane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(true);
|
homePane.setVisible(true);
|
||||||
@@ -302,6 +323,7 @@ public class CalculatorController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayFood(ActionEvent event) {
|
public void displayFood(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(foodPane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -317,6 +339,7 @@ public class CalculatorController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayShopping(ActionEvent event) {
|
public void displayShopping(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(shoppingPane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -331,14 +354,16 @@ public class CalculatorController {
|
|||||||
* @param event the click of the designated button
|
* @param event the click of the designated button
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@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);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
foodPane.setVisible(false);
|
foodPane.setVisible(false);
|
||||||
shoppingPane.setVisible(false);
|
shoppingPane.setVisible(false);
|
||||||
extraPane.setVisible(true);
|
extraPane.setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,46 +385,69 @@ public class CalculatorController {
|
|||||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||||
peopleInHouseHoldLabel.getText());
|
peopleInHouseHoldLabel.getText());
|
||||||
}
|
}
|
||||||
if (!publicTransitField.getText().equals("0")) {
|
checkTransportLabels();
|
||||||
|
checkHousingLabels();
|
||||||
|
checkFoodLabels();
|
||||||
|
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_publictrans",
|
"input_footprint_shopping_goods_total",
|
||||||
publicTransitField.getText());
|
goodsLabel.getText().replace("€ / month", ""));
|
||||||
}
|
}
|
||||||
if (!airplaneTravelField.getText().equals("0")) {
|
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_airtotal",
|
"input_footprint_shopping_services_total",
|
||||||
airplaneTravelField.getText());
|
servicesLabel.getText().replace("€ / month", ""));
|
||||||
}
|
}
|
||||||
if (!carTravelGasolineField.getText().equals("0")) {
|
extraActivityController.updateExtras();
|
||||||
|
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||||
|
Window owner = saveButton.getScene().getWindow();
|
||||||
|
controller.updateLeaderboard();
|
||||||
|
controller.updateAchievements();
|
||||||
|
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
|
||||||
|
owner, "Footprint saved!", "Your footprint is saved!");
|
||||||
|
Stage current = (Stage) owner;
|
||||||
|
current.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the food labels.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
private void checkFoodLabels() {
|
||||||
|
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles1",
|
"input_footprint_shopping_food_meatfisheggs",
|
||||||
carTravelGasolineField.getText());
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg1",
|
"input_footprint_shopping_food_cereals",
|
||||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles2",
|
"input_footprint_shopping_food_dairy",
|
||||||
carTravelDieselField.getText());
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg2",
|
"input_footprint_shopping_food_fruitvegetables",
|
||||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles3",
|
"input_footprint_shopping_food_otherfood",
|
||||||
carTravelElectricField.getText());
|
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
|
||||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
|
||||||
"input_footprint_transportation_mpg3",
|
|
||||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the house labels.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
private void checkHousingLabels() {
|
||||||
if (!electricityField.getText().equals("0")) {
|
if (!electricityField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_housing_electricity_dollars",
|
"input_footprint_housing_electricity_dollars",
|
||||||
@@ -430,67 +478,52 @@ public class CalculatorController {
|
|||||||
"input_footprint_housing_watersewage",
|
"input_footprint_housing_watersewage",
|
||||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||||
}
|
}
|
||||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the transport labels.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
private void checkTransportLabels() {
|
||||||
|
if (!publicTransitField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_meatfisheggs",
|
"input_footprint_transportation_publictrans",
|
||||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
publicTransitField.getText());
|
||||||
}
|
}
|
||||||
if (!grainsBakedGoodsLabel.getText()
|
if (!airplaneTravelField.getText().equals("0")) {
|
||||||
.replace(" daily servings per person", "").equals("4.4")) {
|
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_cereals",
|
"input_footprint_transportation_airtotal",
|
||||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
airplaneTravelField.getText());
|
||||||
}
|
}
|
||||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
if (!carTravelGasolineField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_dairy",
|
"input_footprint_transportation_miles1",
|
||||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
carTravelGasolineField.getText());
|
||||||
}
|
}
|
||||||
if (!fruitsVegetablesLabel.getText()
|
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||||
.replace(" daily servings per person", "").equals("3.9")) {
|
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_fruitvegetables",
|
"input_footprint_transportation_mpg1",
|
||||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_otherfood",
|
"input_footprint_transportation_miles2",
|
||||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
carTravelDieselField.getText());
|
||||||
}
|
}
|
||||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_goods_total",
|
"input_footprint_transportation_mpg2",
|
||||||
goodsLabel.getText().replace("€ / month", ""));
|
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||||
}
|
}
|
||||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
if (!carTravelElectricField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_services_total",
|
"input_footprint_transportation_miles3",
|
||||||
servicesLabel.getText().replace("€ / month", ""));
|
carTravelElectricField.getText());
|
||||||
}
|
}
|
||||||
if (localProduceCheckbox.isSelected()) {
|
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||||
localProduceCheckbox.setSelected(true);
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
userService.updateExtraInput(userService.currentUser.getName(),
|
"input_footprint_transportation_mpg3",
|
||||||
"local_produce", true);
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,13 @@ package greenify.client.controller;
|
|||||||
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
||||||
import greenify.client.Application;
|
import greenify.client.Application;
|
||||||
import greenify.client.Friend;
|
import greenify.client.Friend;
|
||||||
|
import greenify.client.Hints;
|
||||||
import greenify.client.rest.UserService;
|
import greenify.client.rest.UserService;
|
||||||
import javafx.animation.FadeTransition;
|
import javafx.animation.FadeTransition;
|
||||||
|
import javafx.animation.KeyFrame;
|
||||||
import javafx.animation.PathTransition;
|
import javafx.animation.PathTransition;
|
||||||
import javafx.animation.ScaleTransition;
|
import javafx.animation.ScaleTransition;
|
||||||
|
import javafx.animation.Timeline;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
@@ -15,22 +18,28 @@ import javafx.scene.Node;
|
|||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.chart.PieChart;
|
import javafx.scene.chart.PieChart;
|
||||||
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.scene.effect.ColorAdjust;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.shape.Line;
|
import javafx.scene.shape.Line;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Window;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that controls the dashboard fxml file (the GUI Screen).
|
* Class that controls the dashboard fxml file (the GUI Screen).
|
||||||
@@ -45,6 +54,8 @@ public class DashBoardController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
Hints hints = new Hints();
|
||||||
|
|
||||||
private FadeTransition fadeTrans; //transition for switching between the different panels
|
private FadeTransition fadeTrans; //transition for switching between the different panels
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -66,6 +77,8 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button friendsButton;
|
private Button friendsButton;
|
||||||
@FXML
|
@FXML
|
||||||
|
private Button logOutButton;
|
||||||
|
@FXML
|
||||||
private Line pathLine;
|
private Line pathLine;
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane menuBar;
|
private AnchorPane menuBar;
|
||||||
@@ -80,6 +93,10 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button addFriendButton;
|
private Button addFriendButton;
|
||||||
@FXML
|
@FXML
|
||||||
|
private Button addExtraActivityButton;
|
||||||
|
@FXML
|
||||||
|
private Button addExtraActivityButton2;
|
||||||
|
@FXML
|
||||||
private TableView<Friend> friendsTable;
|
private TableView<Friend> friendsTable;
|
||||||
@FXML
|
@FXML
|
||||||
private TableColumn<Friend, String> friendsColumn;
|
private TableColumn<Friend, String> friendsColumn;
|
||||||
@@ -154,21 +171,54 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Label snacks;
|
private Label snacks;
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox localProduce;
|
private ImageView achieve1;
|
||||||
@SuppressWarnings("CheckStyle")
|
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox loweringTemp;
|
private ImageView achieve2;
|
||||||
@SuppressWarnings("CheckStyle")
|
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox bike;
|
private ImageView achieve3;
|
||||||
@SuppressWarnings("CheckStyle")
|
|
||||||
@FXML
|
@FXML
|
||||||
private CheckBox solarPanels;
|
private ImageView achieve4;
|
||||||
|
@FXML
|
||||||
|
private ImageView achieve5;
|
||||||
|
@FXML
|
||||||
|
private ImageView achieve6;
|
||||||
|
@FXML
|
||||||
|
private Label hintText;
|
||||||
|
@FXML
|
||||||
|
private Label solarPanels;
|
||||||
|
@FXML
|
||||||
|
private Label localProduce;
|
||||||
|
@FXML
|
||||||
|
private Label bike;
|
||||||
|
@FXML
|
||||||
|
private Label loweringTemp;
|
||||||
|
@FXML
|
||||||
|
private Button achiev1Tip;
|
||||||
|
@FXML
|
||||||
|
private Button achiev2Tip;
|
||||||
|
@FXML
|
||||||
|
private Button achiev3Tip;
|
||||||
|
@FXML
|
||||||
|
private Button achiev4Tip;
|
||||||
|
@FXML
|
||||||
|
private Button achiev5Tip;
|
||||||
|
@FXML
|
||||||
|
private Button achiev6Tip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the the necessary things before anything else.
|
* Loads the the necessary things before anything else.
|
||||||
|
* @throws InterruptedException exception if interrupted
|
||||||
*/
|
*/
|
||||||
public void initialize() throws InterruptedException {
|
public void initialize() throws InterruptedException {
|
||||||
|
|
||||||
|
|
||||||
|
hintText.setWrapText(true);
|
||||||
|
hintText.setText(hints.randomHint());
|
||||||
|
//set the dashboardPane to visible
|
||||||
|
dashboardPane.setVisible(true);
|
||||||
|
userPane.setVisible(false);
|
||||||
|
activitiesPane.setVisible(false);
|
||||||
|
friendsPane.setVisible(false);
|
||||||
//sets the text of the 'welcome back' text to include the username
|
//sets the text of the 'welcome back' text to include the username
|
||||||
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
|
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
|
||||||
//adds the slide transition to the menu bar
|
//adds the slide transition to the menu bar
|
||||||
@@ -178,6 +228,7 @@ public class DashBoardController {
|
|||||||
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
|
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
|
||||||
userButton.setSkin(new MyButtonSkin(userButton));
|
userButton.setSkin(new MyButtonSkin(userButton));
|
||||||
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
||||||
|
logOutButton.setSkin(new MyButtonSkin(logOutButton));
|
||||||
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||||
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||||
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||||
@@ -208,23 +259,75 @@ public class DashBoardController {
|
|||||||
}
|
}
|
||||||
friendsTable.setItems(data);
|
friendsTable.setItems(data);
|
||||||
updateLeaderboard();
|
updateLeaderboard();
|
||||||
|
updateAchievements();
|
||||||
|
calculateFootPrintButton.setSkin(new ClickButtonSkin(calculateFootPrintButton));
|
||||||
|
addFriendButton.setSkin(new ClickButtonSkin(addFriendButton));
|
||||||
|
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
|
||||||
|
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
|
||||||
|
addRandomHints();
|
||||||
|
|
||||||
|
Tooltip tooltip = new Tooltip("tip");
|
||||||
|
hackTooltipStartTiming(tooltip);
|
||||||
|
|
||||||
|
addToolTip(achiev1Tip, "Starting off \n You did your first green activity!");
|
||||||
|
addToolTip(achiev2Tip, "Social Butterfly \n You added three friends");
|
||||||
|
addToolTip(achiev3Tip, "Green Saver \n You saved 20 tonnes of CO2");
|
||||||
|
addToolTip(achiev4Tip, "Animal Friend \n You have eaten 10 vegetarian meals");
|
||||||
|
addToolTip(achiev5Tip, "Tom Dumoulin \n You have biked 15 km");
|
||||||
|
addToolTip(achiev6Tip, "Let it shine \n You installed solar panels");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds a tooltip to the button.
|
||||||
|
* @param button the button to add the tooltip to.
|
||||||
|
* @param message the message to be displayed in the tooltip.
|
||||||
|
*/
|
||||||
|
private void addToolTip(Button button, String message) {
|
||||||
|
button.setTooltip(new Tooltip(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* changes the delay time between hovering over something with a tooltip and when the
|
||||||
|
* tooltip is displayed.
|
||||||
|
* @param tooltip the tooltip to change the delay of
|
||||||
|
*/
|
||||||
|
private static void hackTooltipStartTiming(Tooltip tooltip) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");
|
||||||
|
fieldBehavior.setAccessible(true);
|
||||||
|
Object objBehavior = fieldBehavior.get(tooltip);
|
||||||
|
|
||||||
|
Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");
|
||||||
|
fieldTimer.setAccessible(true);
|
||||||
|
Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);
|
||||||
|
|
||||||
|
objTimer.getKeyFrames().clear();
|
||||||
|
objTimer.getKeyFrames().add(new KeyFrame(new Duration(150)));
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
e.getMessage();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.getMessage();
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the scores of users.
|
* Sorts the scores of users.
|
||||||
* @param users the list of users
|
* @param users the list of users
|
||||||
*/
|
*/
|
||||||
public void sortScores(List<String> users) throws InterruptedException {
|
private void sortScores(List<String> users) {
|
||||||
for (int i = 0; i < users.size(); i++) {
|
for (int i = 0; i < users.size(); i++) {
|
||||||
for (int j = 0; j < users.size(); j++) {
|
for (int j = 0; j < users.size(); j++) {
|
||||||
Float firstScore = userService.getFootprint(users.get(i));
|
Double first = userService.getFootprint(users.get(i));
|
||||||
Float secondScore = userService.getFootprint(users.get(j));
|
Double second = userService.getFootprint(users.get(j));
|
||||||
if (i > j && firstScore < secondScore) {
|
if (i < j && (first.compareTo(second) < 0)) {
|
||||||
String temp = users.get(i);
|
String temp = users.get(i);
|
||||||
users.set(i, users.get(j));
|
users.set(i, users.get(j));
|
||||||
users.set(j, temp);
|
users.set(j, temp);
|
||||||
}
|
}
|
||||||
if (i < j && firstScore > secondScore) {
|
if (i > j && (first.compareTo(second) > 0)) {
|
||||||
String temp = users.get(i);
|
String temp = users.get(i);
|
||||||
users.set(i, users.get(j));
|
users.set(i, users.get(j));
|
||||||
users.set(j, temp);
|
users.set(j, temp);
|
||||||
@@ -237,12 +340,12 @@ public class DashBoardController {
|
|||||||
* Sorts the scores of users.
|
* Sorts the scores of users.
|
||||||
* @param users the list of users
|
* @param users the list of users
|
||||||
*/
|
*/
|
||||||
public void sortDiffScores(List<String> users) throws InterruptedException {
|
private List<String> sortDiffScores(List<String> users) throws InterruptedException {
|
||||||
for (int i = 0; i < users.size(); i++) {
|
for (int i = 0; i < users.size(); i++) {
|
||||||
for (int j = 0; j < users.size(); j++) {
|
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));
|
.getFootprint(users.get(i));
|
||||||
Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
Double secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
||||||
.getFootprint(users.get(j));
|
.getFootprint(users.get(j));
|
||||||
if (i < j && firstDiff < secondDiff) {
|
if (i < j && firstDiff < secondDiff) {
|
||||||
String temp = users.get(i);
|
String temp = users.get(i);
|
||||||
@@ -256,13 +359,14 @@ public class DashBoardController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a fade transition for switching between the different panes.
|
* Adds a fade transition for switching between the different panes.
|
||||||
* @param node the node on which the transition needs to act
|
* @param node the node on which the transition needs to act
|
||||||
*/
|
*/
|
||||||
public void addFadeTransition(Node node) {
|
private void addFadeTransition(Node node) {
|
||||||
fadeTrans = new FadeTransition(Duration.millis(400), node);
|
fadeTrans = new FadeTransition(Duration.millis(400), node);
|
||||||
fadeTrans.setFromValue(0);
|
fadeTrans.setFromValue(0);
|
||||||
fadeTrans.setToValue(1.0);
|
fadeTrans.setToValue(1.0);
|
||||||
@@ -282,6 +386,7 @@ public class DashBoardController {
|
|||||||
activitiesPane.setVisible(false);
|
activitiesPane.setVisible(false);
|
||||||
friendsPane.setVisible(false);
|
friendsPane.setVisible(false);
|
||||||
updateLeaderboard();
|
updateLeaderboard();
|
||||||
|
updateAchievements();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -314,8 +419,8 @@ public class DashBoardController {
|
|||||||
electricMiles.setText(inputMap.get("input_footprint_transportation_miles3"));
|
electricMiles.setText(inputMap.get("input_footprint_transportation_miles3"));
|
||||||
electricMpg.setText(inputMap.get("input_footprint_transportation_mpg3"));
|
electricMpg.setText(inputMap.get("input_footprint_transportation_mpg3"));
|
||||||
publicTransportation.setText(inputMap.get("input_footprint_transportation_publictrans")
|
publicTransportation.setText(inputMap.get("input_footprint_transportation_publictrans")
|
||||||
+ " mi/yr");
|
+ " km/yr");
|
||||||
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " mi/yr");
|
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " km/yr");
|
||||||
goodShopping.setText(inputMap.get("input_footprint_shopping_goods_total") + " €/mo");
|
goodShopping.setText(inputMap.get("input_footprint_shopping_goods_total") + " €/mo");
|
||||||
serviceShopping.setText(inputMap.get("input_footprint_shopping_services_total") + " €/mo");
|
serviceShopping.setText(inputMap.get("input_footprint_shopping_services_total") + " €/mo");
|
||||||
meat.setText(inputMap.get("input_footprint_shopping_food_meatfisheggs"));
|
meat.setText(inputMap.get("input_footprint_shopping_food_meatfisheggs"));
|
||||||
@@ -323,18 +428,12 @@ public class DashBoardController {
|
|||||||
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
|
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
|
||||||
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
|
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
|
||||||
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
|
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
|
||||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("local_produce")) {
|
Map<String, String> extraMap = userService
|
||||||
localProduce.setSelected(true);
|
.getExtraInputs(userService.currentUser.getName());
|
||||||
}
|
localProduce.setText(extraMap.get("local_produce"));
|
||||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("bike")) {
|
bike.setText(extraMap.get("bike"));
|
||||||
bike.setSelected(true);
|
solarPanels.setText(extraMap.get("solar_panels"));
|
||||||
}
|
loweringTemp.setText(extraMap.get("temperature"));
|
||||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("temperature")) {
|
|
||||||
loweringTemp.setSelected(true);
|
|
||||||
}
|
|
||||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("solar_panels")) {
|
|
||||||
solarPanels.setSelected(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -347,9 +446,9 @@ public class DashBoardController {
|
|||||||
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
|
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
|
||||||
firstFootprintLabel.setText("" + userService
|
firstFootprintLabel.setText("" + userService
|
||||||
.getFirstFootprint(userService.currentUser.getName()));
|
.getFirstFootprint(userService.currentUser.getName()));
|
||||||
Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
Double diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
||||||
.getFootprint(userService.currentUser.getName());
|
.getFootprint(userService.currentUser.getName());
|
||||||
differenceLabel.setText( "" + diff);
|
differenceLabel.setText( "" + Math.round(diff * 10) / 10.0);
|
||||||
usernameLabel.setText("" + userService.currentUser.getName());
|
usernameLabel.setText("" + userService.currentUser.getName());
|
||||||
addFadeTransition(userPane);
|
addFadeTransition(userPane);
|
||||||
System.out.println("display user");
|
System.out.println("display user");
|
||||||
@@ -357,7 +456,6 @@ public class DashBoardController {
|
|||||||
userPane.setVisible(true);
|
userPane.setVisible(true);
|
||||||
activitiesPane.setVisible(false);
|
activitiesPane.setVisible(false);
|
||||||
friendsPane.setVisible(false);
|
friendsPane.setVisible(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -374,6 +472,40 @@ public class DashBoardController {
|
|||||||
updateFriends();
|
updateFriends();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs out the user.
|
||||||
|
* @param event the event (clicking the button)
|
||||||
|
* @throws IOException if the Application doesn't load.
|
||||||
|
*/
|
||||||
|
public void logOut(ActionEvent event) throws IOException {
|
||||||
|
//get the current window
|
||||||
|
Window owner = logOutButton.getScene().getWindow();
|
||||||
|
Stage current = (Stage) owner;
|
||||||
|
//close current window (log out)
|
||||||
|
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"));
|
||||||
|
Scene scene = new Scene(dash);
|
||||||
|
//add the stylesheet for the CSS
|
||||||
|
scene.getStylesheets().add(Objects.requireNonNull(getClass().getClassLoader()
|
||||||
|
.getResource("stylesheets/LoginWindowStyle.css")).toExternalForm());
|
||||||
|
Stage appStage = new Stage();
|
||||||
|
appStage.setScene(scene);
|
||||||
|
//set the title
|
||||||
|
appStage.setTitle("Greenify");
|
||||||
|
appStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
//sets the slide in transition for startup
|
//sets the slide in transition for startup
|
||||||
public void addSlideTransition(Node node, Line path1) {
|
public void addSlideTransition(Node node, Line path1) {
|
||||||
PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node);
|
PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node);
|
||||||
@@ -398,7 +530,39 @@ public class DashBoardController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method opend addFriend scene.
|
* Adds a random hint to the left.
|
||||||
|
*/
|
||||||
|
public void addRandomHints() {
|
||||||
|
FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText);
|
||||||
|
fadeOut.setFromValue(1.0);
|
||||||
|
fadeOut.setToValue(0.0);
|
||||||
|
fadeOut.play();
|
||||||
|
hintText.setWrapText(true);
|
||||||
|
hintText.setText(hints.randomHint());
|
||||||
|
FadeTransition fadeIn = new FadeTransition(Duration.millis(400), hintText);
|
||||||
|
fadeIn.setFromValue(0.0);
|
||||||
|
fadeIn.setToValue(1.0);
|
||||||
|
fadeIn.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens extra activities.
|
||||||
|
* @param event the event (clicking the button)
|
||||||
|
* @throws IOException if the Application doesn't load.
|
||||||
|
*/
|
||||||
|
public void openExtraActivities(ActionEvent event) throws IOException {
|
||||||
|
Parent extra = Application.load(this.getClass().getClassLoader()
|
||||||
|
.getResource("fxml/extraActivities.fxml"));
|
||||||
|
Scene scene = new Scene(extra);
|
||||||
|
Stage extraStage = new Stage();
|
||||||
|
extraStage.setScene(scene);
|
||||||
|
extraStage.setTitle("Add extra activity - " + userService.currentUser.getName());
|
||||||
|
extraStage.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* method opens addFriend scene.
|
||||||
* @throws IOException when file is not found
|
* @throws IOException when file is not found
|
||||||
*/
|
*/
|
||||||
public void openAddFriend() throws IOException {
|
public void openAddFriend() throws IOException {
|
||||||
@@ -416,21 +580,23 @@ public class DashBoardController {
|
|||||||
* @throws InterruptedException throws exception
|
* @throws InterruptedException throws exception
|
||||||
*/
|
*/
|
||||||
public void updateLeaderboard() throws InterruptedException {
|
public void updateLeaderboard() throws InterruptedException {
|
||||||
List<String> userList = userService.getAllUsers();
|
|
||||||
//global leaderboard
|
//global leaderboard
|
||||||
globalLeaderboard.getItems().clear();
|
globalLeaderboard.getItems().clear();
|
||||||
globalLeaderData.removeAll();
|
globalLeaderData.removeAll();
|
||||||
sortScores(userList);
|
|
||||||
//development leaderboard
|
//development leaderboard
|
||||||
developmentLeaderboard.getItems().clear();
|
developmentLeaderboard.getItems().clear();
|
||||||
developmentData.removeAll();
|
developmentData.removeAll();
|
||||||
sortDiffScores(userList);
|
List<String> userList = userService.getAllUsers();
|
||||||
for (int j = 0; j < userList.size(); j++) {
|
sortScores(userList);
|
||||||
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
|
for (int i = userList.size() - 1; i >= 0; i--) {
|
||||||
Friend diffUser = new Friend(userList.get(j), userService
|
Friend user = new Friend(userList.get(i), userService.getFootprint(userList.get(i)));
|
||||||
.getFirstFootprint(userList.get(j))
|
|
||||||
- userService.getFootprint(userList.get(j)));
|
|
||||||
globalLeaderData.add(user);
|
globalLeaderData.add(user);
|
||||||
|
}
|
||||||
|
List<String> secondList = sortDiffScores(userList);
|
||||||
|
for (int j = 0; j < userList.size(); j++) {
|
||||||
|
double diff = Math.round((userService.getFirstFootprint(secondList.get(j))
|
||||||
|
- userService.getFootprint(secondList.get(j))) * 10) / 10.0;
|
||||||
|
Friend diffUser = new Friend(secondList.get(j), diff);
|
||||||
developmentData.add(diffUser);
|
developmentData.add(diffUser);
|
||||||
}
|
}
|
||||||
globalLeaderboard.setItems(globalLeaderData);
|
globalLeaderboard.setItems(globalLeaderData);
|
||||||
@@ -453,31 +619,75 @@ public class DashBoardController {
|
|||||||
friendLeaderboard.getItems().clear();
|
friendLeaderboard.getItems().clear();
|
||||||
friendLeaderData.removeAll();
|
friendLeaderData.removeAll();
|
||||||
sortDiffScores(wholeList);
|
sortDiffScores(wholeList);
|
||||||
for (int i = 0; i < friendList.size(); i++) {
|
for (int i = friendList.size() - 1; i >= 0 ; i--) {
|
||||||
Friend user = new Friend(friendList.get(i), userService
|
Friend user = new Friend(friendList.get(i), userService
|
||||||
.getFootprint(friendList.get(i)));
|
.getFootprint(friendList.get(i)));
|
||||||
data.add(user);
|
data.add(user);
|
||||||
}
|
}
|
||||||
for (int j = 0; j < wholeList.size(); j++) {
|
for (int j = 0; j < wholeList.size(); j++) {
|
||||||
Friend diffUser = new Friend(wholeList.get(j),
|
double diff = Math.round((userService.getFirstFootprint(wholeList.get(j))
|
||||||
userService.getFirstFootprint(wholeList.get(j))
|
- userService.getFootprint(wholeList.get(j))) * 10) / 10.0;
|
||||||
- userService.getFootprint(wholeList.get(j)));
|
Friend diffUser = new Friend(wholeList.get(j), diff);
|
||||||
friendLeaderData.add(diffUser);
|
friendLeaderData.add(diffUser);
|
||||||
}
|
}
|
||||||
friendsTable.setItems(data);
|
friendsTable.setItems(data);
|
||||||
friendLeaderboard.setItems(friendLeaderData);
|
friendLeaderboard.setItems(friendLeaderData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the achievements.
|
||||||
|
*/
|
||||||
|
public void updateAchievements() {
|
||||||
|
Map achievements = userService.getAchievements(userService.currentUser.getName());
|
||||||
|
ColorAdjust desaturate = new ColorAdjust();
|
||||||
|
desaturate.setSaturation(-0.75);
|
||||||
|
if ((Boolean)achievements.get("Starting off")) {
|
||||||
|
achieve1.setOpacity(1);
|
||||||
|
} else {
|
||||||
|
achieve1.setEffect(desaturate);
|
||||||
|
achieve1.setOpacity(0.3);
|
||||||
|
}
|
||||||
|
if ((Boolean)achievements.get("Social butterfly")) {
|
||||||
|
achieve2.setOpacity(1);
|
||||||
|
} else {
|
||||||
|
achieve2.setEffect(desaturate);
|
||||||
|
achieve2.setOpacity(0.3);
|
||||||
|
}
|
||||||
|
if ((Boolean)achievements.get("Green saver")) {
|
||||||
|
achieve3.setOpacity(1);
|
||||||
|
} else {
|
||||||
|
achieve3.setEffect(desaturate);
|
||||||
|
achieve3.setOpacity(0.3);
|
||||||
|
}
|
||||||
|
if ((Boolean)achievements.get("Animal friend")) {
|
||||||
|
achieve4.setOpacity(1);
|
||||||
|
} else {
|
||||||
|
achieve4.setEffect(desaturate);
|
||||||
|
achieve4.setOpacity(0.3);
|
||||||
|
}
|
||||||
|
if ((Boolean)achievements.get("Tom Dumoulin")) {
|
||||||
|
achieve5.setOpacity(1);
|
||||||
|
} else {
|
||||||
|
achieve5.setEffect(desaturate);
|
||||||
|
achieve5.setOpacity(0.3);
|
||||||
|
}
|
||||||
|
if ((Boolean)achievements.get("Let it shine")) {
|
||||||
|
achieve6.setOpacity(1);
|
||||||
|
} else {
|
||||||
|
achieve6.setEffect(desaturate);
|
||||||
|
achieve6.setOpacity(0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//class for the animations on the navigation buttons
|
//class for the animations on the navigation buttons
|
||||||
public class MyButtonSkin extends ButtonSkin {
|
private class MyButtonSkin extends ButtonSkin {
|
||||||
/**
|
/**
|
||||||
* adds a skin and scale animation to a button.
|
* adds a skin and scale animation to a button.
|
||||||
* the scale transition is for hovering over it so it then scales up
|
* the scale transition is for hovering over it so it then scales up
|
||||||
* and scales down when you stop hovering over it.
|
* and scales down when you stop hovering over it.
|
||||||
* @param button the button to add the animation to
|
* @param button the button to add the animation to
|
||||||
*/
|
*/
|
||||||
public MyButtonSkin(Button button) {
|
private MyButtonSkin(Button button) {
|
||||||
//inherit the button properties
|
//inherit the button properties
|
||||||
super(button);
|
super(button);
|
||||||
//transition to scale up on hover
|
//transition to scale up on hover
|
||||||
@@ -493,6 +703,45 @@ public class DashBoardController {
|
|||||||
scaleDown.setToX(1.0);
|
scaleDown.setToX(1.0);
|
||||||
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
private class ClickButtonSkin extends ButtonSkin {
|
||||||
|
/**
|
||||||
|
* button skin for the 'add activity' buttons.
|
||||||
|
* adds scale animations on entering, clicking and exiting the button
|
||||||
|
* @param button the button to set the skin of
|
||||||
|
*/
|
||||||
|
private ClickButtonSkin(Button button) {
|
||||||
|
super(button);
|
||||||
|
|
||||||
|
//transition to scale up on hover
|
||||||
|
final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(100));
|
||||||
|
//add the node and the position to scale to
|
||||||
|
scaleUp.setNode(button);
|
||||||
|
scaleUp.setToX(1.1);
|
||||||
|
scaleUp.setToY(1.1);
|
||||||
|
//play the transition when hovered over the button
|
||||||
|
button.setOnMouseEntered(e -> scaleUp.playFromStart());
|
||||||
|
|
||||||
|
final ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
|
||||||
|
scaleMiddleDown.setNode(button);
|
||||||
|
scaleMiddleDown.setToX(1.05);
|
||||||
|
scaleMiddleDown.setToY(1.05);
|
||||||
|
|
||||||
|
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
|
||||||
|
|
||||||
|
final ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
|
||||||
|
scaleMiddleUp.setNode(button);
|
||||||
|
scaleMiddleUp.setToX(1.1);
|
||||||
|
scaleMiddleUp.setToY(1.1);
|
||||||
|
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
|
||||||
|
|
||||||
|
final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(100));
|
||||||
|
scaleDown.setNode(button);
|
||||||
|
scaleDown.setToX(1.0);
|
||||||
|
scaleDown.setToY(1.0);
|
||||||
|
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
package greenify.client.controller;
|
||||||
|
|
||||||
|
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
||||||
|
import greenify.client.rest.UserService;
|
||||||
|
import javafx.animation.ScaleTransition;
|
||||||
|
import javafx.animation.TranslateTransition;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.Slider;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
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
|
||||||
|
private AnchorPane bikePane;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane temperaturePane;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane solarPanelPane;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane localProducePane;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane publicTransportPane;
|
||||||
|
@FXML
|
||||||
|
private Button displayVeganMealButton;
|
||||||
|
@FXML
|
||||||
|
private Button displayBikeButton;
|
||||||
|
@FXML
|
||||||
|
private Button displayTemperatureButton;
|
||||||
|
@FXML
|
||||||
|
private Button displaySolarPanelButton;
|
||||||
|
@FXML
|
||||||
|
private Button displayLocalProduceButton;
|
||||||
|
@FXML
|
||||||
|
private Button displayPublicTransportButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button addVeganMealButton;
|
||||||
|
@FXML
|
||||||
|
private Button addBikeButton;
|
||||||
|
@FXML
|
||||||
|
private Button addTemperatureButton;
|
||||||
|
@FXML
|
||||||
|
private Button addSolarPanelsButton;
|
||||||
|
@FXML
|
||||||
|
private Button addLocalProduceButton;
|
||||||
|
@FXML
|
||||||
|
private Button addPublicTransportButton;
|
||||||
|
@FXML
|
||||||
|
private Slider bikeSlider;
|
||||||
|
@FXML
|
||||||
|
private Label bikeLabel;
|
||||||
|
@FXML
|
||||||
|
private Slider temperatureSlider;
|
||||||
|
@FXML
|
||||||
|
private Label temperatureLabel;
|
||||||
|
@FXML
|
||||||
|
private Slider solarPanelsSlider;
|
||||||
|
@FXML
|
||||||
|
private Label solarPanelsLabel;
|
||||||
|
@FXML
|
||||||
|
private Label publicTransportLabel;
|
||||||
|
@FXML
|
||||||
|
private Slider publicTransportSlider;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializes the sliders and labels before loading.
|
||||||
|
* sets the labels to display the outputs of the designated sliders.
|
||||||
|
*/
|
||||||
|
public void initialize() {
|
||||||
|
coupleSliderToLabel(bikeSlider, bikeLabel, " km", false);
|
||||||
|
coupleSliderToLabel(temperatureSlider, temperatureLabel, " Degrees", true);
|
||||||
|
coupleSliderToLabel(solarPanelsSlider, solarPanelsLabel, "", true);
|
||||||
|
coupleSliderToLabel(publicTransportSlider, publicTransportLabel, " km", false);
|
||||||
|
|
||||||
|
addVeganMealButton.setSkin(new ActivityButtonSkin(addVeganMealButton));
|
||||||
|
addBikeButton.setSkin(new ActivityButtonSkin(addBikeButton));
|
||||||
|
addTemperatureButton.setSkin(new ActivityButtonSkin(addTemperatureButton));
|
||||||
|
addSolarPanelsButton.setSkin(new ActivityButtonSkin(addSolarPanelsButton));
|
||||||
|
addLocalProduceButton.setSkin(new ActivityButtonSkin(addLocalProduceButton));
|
||||||
|
addPublicTransportButton.setSkin(new ActivityButtonSkin(addPublicTransportButton));
|
||||||
|
|
||||||
|
displayVeganMealButton.setSkin(new TranslateButtonSkin(displayVeganMealButton));
|
||||||
|
displayBikeButton.setSkin(new TranslateButtonSkin(displayBikeButton));
|
||||||
|
displayTemperatureButton.setSkin(new TranslateButtonSkin(displayTemperatureButton));
|
||||||
|
displaySolarPanelButton.setSkin(new TranslateButtonSkin(displaySolarPanelButton));
|
||||||
|
displayLocalProduceButton.setSkin(new TranslateButtonSkin(displayLocalProduceButton));
|
||||||
|
displayPublicTransportButton.setSkin(new TranslateButtonSkin(displayPublicTransportButton));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the label to display the value of the designated slider.
|
||||||
|
* sets the text to be displayed after the value of the slider.
|
||||||
|
* sets whether the slider should snap to ticks
|
||||||
|
* @param slider the slider to read the value from
|
||||||
|
* @param label the label to display the value of the slider
|
||||||
|
* @param string the string to be placed after the outputted value of the slider
|
||||||
|
* @param snapToTicks whether the slider should snap to ticks or not
|
||||||
|
*/
|
||||||
|
private void coupleSliderToLabel(Slider slider, Label label, String string,
|
||||||
|
boolean snapToTicks) {
|
||||||
|
slider.setSnapToTicks(snapToTicks);
|
||||||
|
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends Number> observable,
|
||||||
|
Number oldValue, Number newValue) {
|
||||||
|
label.setText(newValue.intValue() + string);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays the vegetarian meal section.
|
||||||
|
* @param event the click of the designated button
|
||||||
|
*/
|
||||||
|
public void displayVeganMeal(ActionEvent event) {
|
||||||
|
// System.out.println("display vm");
|
||||||
|
veganMealPane.setVisible(true);
|
||||||
|
bikePane.setVisible(false);
|
||||||
|
temperaturePane.setVisible(false);
|
||||||
|
solarPanelPane.setVisible(false);
|
||||||
|
localProducePane.setVisible(false);
|
||||||
|
publicTransportPane.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays the bike section.
|
||||||
|
* @param event the click of the designated button
|
||||||
|
*/
|
||||||
|
public void displayBike(ActionEvent event) {
|
||||||
|
// System.out.println("display b");
|
||||||
|
veganMealPane.setVisible(false);
|
||||||
|
bikePane.setVisible(true);
|
||||||
|
temperaturePane.setVisible(false);
|
||||||
|
solarPanelPane.setVisible(false);
|
||||||
|
localProducePane.setVisible(false);
|
||||||
|
publicTransportPane.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays the temperature section.
|
||||||
|
* @param event the click of the designated button
|
||||||
|
*/
|
||||||
|
public void displayTemperature(ActionEvent event) {
|
||||||
|
// System.out.println("display t");
|
||||||
|
veganMealPane.setVisible(false);
|
||||||
|
bikePane.setVisible(false);
|
||||||
|
temperaturePane.setVisible(true);
|
||||||
|
solarPanelPane.setVisible(false);
|
||||||
|
localProducePane.setVisible(false);
|
||||||
|
publicTransportPane.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays the solar panels section.
|
||||||
|
* @param event the click of the designated button
|
||||||
|
*/
|
||||||
|
public void displaySolarPanel(ActionEvent event) {
|
||||||
|
// System.out.println("display sp");
|
||||||
|
veganMealPane.setVisible(false);
|
||||||
|
bikePane.setVisible(false);
|
||||||
|
temperaturePane.setVisible(false);
|
||||||
|
solarPanelPane.setVisible(true);
|
||||||
|
localProducePane.setVisible(false);
|
||||||
|
publicTransportPane.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays the local produce section.
|
||||||
|
* @param event the click of the designated button
|
||||||
|
*/
|
||||||
|
public void displayLocalProduce(ActionEvent event) {
|
||||||
|
veganMealPane.setVisible(false);
|
||||||
|
bikePane.setVisible(false);
|
||||||
|
temperaturePane.setVisible(false);
|
||||||
|
solarPanelPane.setVisible(false);
|
||||||
|
localProducePane.setVisible(true);
|
||||||
|
publicTransportPane.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays the public transport section.
|
||||||
|
* @param event the click of the designated button
|
||||||
|
*/
|
||||||
|
public void displayPublicTransport(ActionEvent event) {
|
||||||
|
veganMealPane.setVisible(false);
|
||||||
|
bikePane.setVisible(false);
|
||||||
|
temperaturePane.setVisible(false);
|
||||||
|
solarPanelPane.setVisible(false);
|
||||||
|
localProducePane.setVisible(false);
|
||||||
|
publicTransportPane.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method updates the values.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public void save(ActionEvent event) {
|
||||||
|
try {
|
||||||
|
updateExtras();
|
||||||
|
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||||
|
controller.updateLeaderboard();
|
||||||
|
controller.updateAchievements();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("continue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method updates the values of extras.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public void updateExtras() 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(),
|
||||||
|
"temperature",
|
||||||
|
temperatureLabel.getText().replace(" Degrees", ""));
|
||||||
|
}
|
||||||
|
if (!publicTransportLabel.getText().replace(" km", "").equals("0")) {
|
||||||
|
userService.updateExtraInput(userService.currentUser.getName(),
|
||||||
|
"public_transport",
|
||||||
|
publicTransportLabel.getText().replace(" km", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method updates the values of extras.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public void updateExtraVegan() throws InterruptedException {
|
||||||
|
try {
|
||||||
|
userService.updateExtraInput(userService.currentUser.getName(), "vegan", "1");
|
||||||
|
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||||
|
controller.updateAchievements();
|
||||||
|
controller.updateLeaderboard();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("continue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method updates the values of extras.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public void updateExtraLocal() throws InterruptedException {
|
||||||
|
try {
|
||||||
|
userService.updateExtraInput(userService.currentUser.getName(), "local_produce", "1");
|
||||||
|
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||||
|
controller.updateAchievements();
|
||||||
|
controller.updateLeaderboard();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("continue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
private TranslateButtonSkin(Button button) {
|
||||||
|
super(button);
|
||||||
|
|
||||||
|
TranslateTransition transEnter = new TranslateTransition(Duration.millis(50));
|
||||||
|
transEnter.setNode(button);
|
||||||
|
transEnter.setToX(10);
|
||||||
|
button.setOnMouseEntered(e -> transEnter.playFromStart());
|
||||||
|
|
||||||
|
TranslateTransition transExit = new TranslateTransition(Duration.millis(50));
|
||||||
|
transExit.setNode(button);
|
||||||
|
transExit.setToX(1.0);
|
||||||
|
button.setOnMouseExited(e -> transExit.playFromStart());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
private class ActivityButtonSkin extends ButtonSkin {
|
||||||
|
/**
|
||||||
|
* button skin for the 'add activity' buttons.
|
||||||
|
* adds scale animations on entering, clicking and exiting the button
|
||||||
|
* @param button the button to set the skin of
|
||||||
|
*/
|
||||||
|
private ActivityButtonSkin(Button button) {
|
||||||
|
super(button);
|
||||||
|
|
||||||
|
//transition to scale up on hover
|
||||||
|
final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(100));
|
||||||
|
//add the node and the position to scale to
|
||||||
|
scaleUp.setNode(button);
|
||||||
|
scaleUp.setToX(1.1);
|
||||||
|
scaleUp.setToY(1.1);
|
||||||
|
//play the transition when hovered over the button
|
||||||
|
button.setOnMouseEntered(e -> scaleUp.playFromStart());
|
||||||
|
|
||||||
|
final ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
|
||||||
|
scaleMiddleDown.setNode(button);
|
||||||
|
scaleMiddleDown.setToX(1.05);
|
||||||
|
scaleMiddleDown.setToY(1.05);
|
||||||
|
|
||||||
|
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
|
||||||
|
|
||||||
|
final ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
|
||||||
|
scaleMiddleUp.setNode(button);
|
||||||
|
scaleMiddleUp.setToX(1.1);
|
||||||
|
scaleMiddleUp.setToY(1.1);
|
||||||
|
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
|
||||||
|
|
||||||
|
final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(100));
|
||||||
|
scaleDown.setNode(button);
|
||||||
|
scaleDown.setToX(1.0);
|
||||||
|
scaleDown.setToY(1.0);
|
||||||
|
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,9 @@ public class FriendController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
DashBoardController dashBoardController;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button addButton;
|
private Button addButton;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -52,7 +55,11 @@ public class FriendController {
|
|||||||
//add friend to the current user
|
//add friend to the current user
|
||||||
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
||||||
//close the register window after the user has entered all the credentials
|
//close the register window after the user has entered all the credentials
|
||||||
|
String friendName = userNameText.getText();
|
||||||
Stage current = (Stage) owner;
|
Stage current = (Stage) owner;
|
||||||
|
dashBoardController.updateAchievements();
|
||||||
current.close();
|
current.close();
|
||||||
|
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend added!",
|
||||||
|
userNameText.getText() + " is now your friend!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package greenify.client.controller;
|
|||||||
|
|
||||||
import greenify.client.Application;
|
import greenify.client.Application;
|
||||||
import greenify.client.rest.UserService;
|
import greenify.client.rest.UserService;
|
||||||
|
import javafx.animation.FadeTransition;
|
||||||
import javafx.animation.Interpolator;
|
import javafx.animation.Interpolator;
|
||||||
import javafx.animation.KeyFrame;
|
import javafx.animation.KeyFrame;
|
||||||
import javafx.animation.KeyValue;
|
import javafx.animation.KeyValue;
|
||||||
|
import javafx.animation.ParallelTransition;
|
||||||
import javafx.animation.Timeline;
|
import javafx.animation.Timeline;
|
||||||
import javafx.animation.TranslateTransition;
|
import javafx.animation.TranslateTransition;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
@@ -16,7 +18,6 @@ import javafx.scene.Parent;
|
|||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
@@ -39,12 +40,11 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
public class RegisterWindowController {
|
public class RegisterWindowController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
DashBoardController controller;
|
ExtraActivityController extraActivityController;
|
||||||
|
|
||||||
//navigation panes
|
//navigation panes
|
||||||
@FXML
|
@FXML
|
||||||
@@ -151,15 +151,6 @@ public class RegisterWindowController {
|
|||||||
//extra pane
|
//extra pane
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane extraPane;
|
private AnchorPane extraPane;
|
||||||
@FXML
|
|
||||||
private CheckBox localProduceCheckbox;
|
|
||||||
@FXML
|
|
||||||
private CheckBox bikeCheckbox;
|
|
||||||
@FXML
|
|
||||||
private CheckBox temperatureCheckbox;
|
|
||||||
@FXML
|
|
||||||
private CheckBox solarPanelsCheckbox;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField userNameText;
|
private TextField userNameText;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -228,7 +219,13 @@ public class RegisterWindowController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//register the user with the provided username and password
|
//register the user with the provided username and password
|
||||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
try {
|
||||||
|
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
|
||||||
|
"This username has already been taken!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
//close the register window after the user has entered all the credentials
|
//close the register window after the user has entered all the credentials
|
||||||
Stage current = (Stage) owner;
|
Stage current = (Stage) owner;
|
||||||
current.close();
|
current.close();
|
||||||
@@ -263,9 +260,9 @@ public class RegisterWindowController {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
|
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
|
||||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
|
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
|
||||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
|
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
|
||||||
|
|
||||||
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -308,6 +305,7 @@ public class RegisterWindowController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
||||||
DecimalFormat df = new DecimalFormat("0.0");
|
DecimalFormat df = new DecimalFormat("0.0");
|
||||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||||
@@ -329,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) {
|
private void addSlideInAnimation(Node node) {
|
||||||
Timeline timeline = new Timeline();
|
Timeline timeline = new Timeline();
|
||||||
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
||||||
@@ -344,6 +359,7 @@ public class RegisterWindowController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayGetStarted(ActionEvent event) {
|
public void displayGetStarted(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(getStartedPane);
|
||||||
getStartedPane.setVisible(true);
|
getStartedPane.setVisible(true);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -359,7 +375,7 @@ public class RegisterWindowController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayTravel(ActionEvent event) {
|
public void displayTravel(ActionEvent event) {
|
||||||
addSlideInAnimation(travelPane);
|
addFadeTransAnimation(travelPane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(true);
|
travelPane.setVisible(true);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -376,6 +392,7 @@ public class RegisterWindowController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayHome(ActionEvent event) {
|
public void displayHome(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(homePane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(true);
|
homePane.setVisible(true);
|
||||||
@@ -391,6 +408,7 @@ public class RegisterWindowController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayFood(ActionEvent event) {
|
public void displayFood(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(foodPane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -406,6 +424,7 @@ public class RegisterWindowController {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void displayShopping(ActionEvent event) {
|
public void displayShopping(ActionEvent event) {
|
||||||
|
addFadeTransAnimation(shoppingPane);
|
||||||
getStartedPane.setVisible(false);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -420,7 +439,10 @@ public class RegisterWindowController {
|
|||||||
* @param event the click of the designated button
|
* @param event the click of the designated button
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@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);
|
getStartedPane.setVisible(false);
|
||||||
travelPane.setVisible(false);
|
travelPane.setVisible(false);
|
||||||
homePane.setVisible(false);
|
homePane.setVisible(false);
|
||||||
@@ -449,46 +471,70 @@ public class RegisterWindowController {
|
|||||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||||
peopleInHouseHoldLabel.getText());
|
peopleInHouseHoldLabel.getText());
|
||||||
}
|
}
|
||||||
if (!publicTransitField.getText().equals("0")) {
|
checkTransportLabels();
|
||||||
|
checkHousingLabels();
|
||||||
|
checkFoodLabels();
|
||||||
|
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_publictrans",
|
"input_footprint_shopping_goods_total",
|
||||||
publicTransitField.getText());
|
goodsLabel.getText().replace("€ / month", ""));
|
||||||
}
|
}
|
||||||
if (!airplaneTravelField.getText().equals("0")) {
|
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_airtotal",
|
"input_footprint_shopping_services_total",
|
||||||
airplaneTravelField.getText());
|
servicesLabel.getText().replace("€ / month", ""));
|
||||||
}
|
}
|
||||||
if (!carTravelGasolineField.getText().equals("0")) {
|
try {
|
||||||
|
extraActivityController.updateExtras();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Continue");
|
||||||
|
}
|
||||||
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles1",
|
"input_footprint_shopping_food_meatfisheggs",
|
||||||
carTravelGasolineField.getText());
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg1",
|
"input_footprint_shopping_food_cereals",
|
||||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles2",
|
"input_footprint_shopping_food_dairy",
|
||||||
carTravelDieselField.getText());
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_mpg2",
|
"input_footprint_shopping_food_fruitvegetables",
|
||||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_transportation_miles3",
|
"input_footprint_shopping_food_otherfood",
|
||||||
carTravelElectricField.getText());
|
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||||
}
|
|
||||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
|
||||||
"input_footprint_transportation_mpg3",
|
|
||||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the housing labels.
|
||||||
|
*/
|
||||||
|
public void checkHousingLabels() {
|
||||||
if (!electricityField.getText().equals("0")) {
|
if (!electricityField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_housing_electricity_dollars",
|
"input_footprint_housing_electricity_dollars",
|
||||||
@@ -519,63 +565,51 @@ public class RegisterWindowController {
|
|||||||
"input_footprint_housing_watersewage",
|
"input_footprint_housing_watersewage",
|
||||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_meatfisheggs",
|
"input_footprint_transportation_publictrans",
|
||||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
publicTransitField.getText());
|
||||||
}
|
}
|
||||||
if (!grainsBakedGoodsLabel.getText()
|
if (!airplaneTravelField.getText().equals("0")) {
|
||||||
.replace(" daily servings per person", "").equals("4.4")) {
|
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_cereals",
|
"input_footprint_transportation_airtotal",
|
||||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
airplaneTravelField.getText());
|
||||||
}
|
}
|
||||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
if (!carTravelGasolineField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_dairy",
|
"input_footprint_transportation_miles1",
|
||||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
carTravelGasolineField.getText());
|
||||||
}
|
}
|
||||||
if (!fruitsVegetablesLabel.getText()
|
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||||
.replace(" daily servings per person", "").equals("3.9")) {
|
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_fruitvegetables",
|
"input_footprint_transportation_mpg1",
|
||||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
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(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_food_otherfood",
|
"input_footprint_transportation_miles2",
|
||||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
carTravelDieselField.getText());
|
||||||
}
|
}
|
||||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_goods_total",
|
"input_footprint_transportation_mpg2",
|
||||||
goodsLabel.getText().replace("€ / month", ""));
|
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||||
}
|
}
|
||||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
if (!carTravelElectricField.getText().equals("0")) {
|
||||||
userService.updateInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"input_footprint_shopping_services_total",
|
"input_footprint_transportation_miles3",
|
||||||
servicesLabel.getText().replace("€ / month", ""));
|
carTravelElectricField.getText());
|
||||||
}
|
}
|
||||||
if (localProduceCheckbox.isSelected()) {
|
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||||
userService.updateExtraInput(userService.currentUser.getName(),
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
"local_produce", true);
|
"input_footprint_transportation_mpg3",
|
||||||
|
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||||
}
|
}
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,13 @@ public class UserController {
|
|||||||
System.out.println("Password is " + passwordField.getText());
|
System.out.println("Password is " + passwordField.getText());
|
||||||
}
|
}
|
||||||
//log the user in with the userService method
|
//log the user in with the userService method
|
||||||
userService.loginUser(usernameField.getText(), passwordField.getText());
|
try {
|
||||||
|
userService.loginUser(usernameField.getText(), passwordField.getText());
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
|
||||||
|
"Your username or password is incorrect!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Stage current = (Stage) owner;
|
Stage current = (Stage) owner;
|
||||||
//after logging in, close the login window
|
//after logging in, close the login window
|
||||||
current.close();
|
current.close();
|
||||||
@@ -136,3 +142,4 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,13 +109,13 @@ public class UserService {
|
|||||||
* @param value value of the input
|
* @param value value of the input
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public void updateExtraInput(String name, String inputName, Boolean value) {
|
public void updateExtraInput(String name, String inputName, String value) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
|
||||||
.queryParam("name", name)
|
.queryParam("name", name)
|
||||||
.queryParam("inputName", inputName)
|
.queryParam("inputName", inputName)
|
||||||
.queryParam("value",value);
|
.queryParam("value", value);
|
||||||
new HttpEntity<>(headers);
|
new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||||
@@ -128,15 +128,16 @@ public class UserService {
|
|||||||
* @return returns the footprint score
|
* @return returns the footprint score
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public Float getFootprint(String name) {
|
public double getFootprint(String name) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
|
||||||
.queryParam("name", name);
|
.queryParam("name", name);
|
||||||
new HttpEntity<>(headers);
|
new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
Float result = this.restTemplate.getForObject(builder
|
Float footprint = this.restTemplate.getForObject(builder
|
||||||
.build().encode().toUri(), Float.class);
|
.build().encode().toUri(), Float.class);
|
||||||
|
double result = Math.round(footprint * 10) / 10.0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ public class UserService {
|
|||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
* @return returns the footprint score
|
* @return returns the footprint score
|
||||||
*/
|
*/
|
||||||
public Float getFirstFootprint(String name) {
|
public double getFirstFootprint(String name) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
|
||||||
@@ -154,7 +155,8 @@ public class UserService {
|
|||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
Float footprint = this.restTemplate.getForObject(builder
|
Float footprint = this.restTemplate.getForObject(builder
|
||||||
.build().encode().toUri(), Float.class);
|
.build().encode().toUri(), Float.class);
|
||||||
return footprint;
|
double result = Math.round(footprint * 10) / 10.0;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,6 +232,24 @@ public class UserService {
|
|||||||
.encode().toUri(), String.class);
|
.encode().toUri(), String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a friend from the friendslist of the user.
|
||||||
|
* @param name the username of the current user.
|
||||||
|
* @param friend the username of the friend you want to remove.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public void removeFriend(String name, String friend) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/removeFriend")
|
||||||
|
.queryParam("name", name)
|
||||||
|
.queryParam("friend",friend);
|
||||||
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
|
System.out.println(builder.build().encode().toUri());
|
||||||
|
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||||
|
.encode().toUri(), String.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the footprint inputs of the user.
|
* Gets the footprint inputs of the user.
|
||||||
* @param name the username of the current user.
|
* @param name the username of the current user.
|
||||||
@@ -252,18 +272,35 @@ public class UserService {
|
|||||||
* @param name the username of the current user.
|
* @param name the username of the current user.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public Map<String, Boolean> getExtraInputs(String name) {
|
public Map<String, String> getExtraInputs(String name) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
|
||||||
.queryParam("name", name);
|
.queryParam("name", name);
|
||||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
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);
|
.encode().toUri(), Map.class);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the achievements of a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return Map with all achievements
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public Map getAchievements(String name) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getAchievements")
|
||||||
|
.queryParam("name", name);
|
||||||
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
|
System.out.println(builder.build().encode().toUri());
|
||||||
|
return this.restTemplate.getForObject(builder.build()
|
||||||
|
.encode().toUri(), Map.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of all users.
|
* Gets the list of all users.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,24 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.shape.*?>
|
<?import javafx.scene.shape.*?>
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import javafx.geometry.*?>
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.image.*?>
|
<?import javafx.scene.image.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.text.*?>
|
<?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.RegisterWindowController">
|
<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>
|
<children>
|
||||||
@@ -178,7 +165,7 @@
|
|||||||
</TextField>
|
</TextField>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -188,7 +175,7 @@
|
|||||||
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
|
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -197,7 +184,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
|
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -207,7 +194,7 @@
|
|||||||
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -236,7 +223,7 @@
|
|||||||
</TextField>
|
</TextField>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -246,7 +233,7 @@
|
|||||||
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpge">
|
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/Le">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -285,7 +272,7 @@
|
|||||||
</font></TextField>
|
</font></TextField>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="16.0" />
|
<Font size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -294,7 +281,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="16.0" />
|
<Font size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
|
|||||||
@@ -178,7 +178,7 @@
|
|||||||
</TextField>
|
</TextField>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
|
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -197,7 +197,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
|
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/L">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -207,7 +207,7 @@
|
|||||||
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
</TextField>
|
</TextField>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="49.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -246,7 +246,7 @@
|
|||||||
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpge">
|
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 km/Le">
|
||||||
<font>
|
<font>
|
||||||
<Font size="13.0" />
|
<Font size="13.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -285,7 +285,7 @@
|
|||||||
</font></TextField>
|
</font></TextField>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="16.0" />
|
<Font size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -294,7 +294,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
|
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="km/year" wrappingWidth="63.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="16.0" />
|
<Font size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
|
|||||||
@@ -1,21 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.chart.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.scene.shape.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
<?import javafx.scene.chart.PieChart?>
|
<?import javafx.scene.chart.PieChart?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.CheckBox?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.TableColumn?>
|
<?import javafx.scene.control.TableColumn?>
|
||||||
<?import javafx.scene.control.TableView?>
|
<?import javafx.scene.control.TableView?>
|
||||||
<?import javafx.scene.image.Image?>
|
<?import javafx.scene.image.Image?>
|
||||||
<?import javafx.scene.image.ImageView?>
|
<?import javafx.scene.image.ImageView?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.shape.Line?>
|
<?import javafx.scene.shape.Line?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
<?import javafx.scene.text.Text?>
|
<?import javafx.scene.text.Text?>
|
||||||
|
<?import javafx.scene.control.Tooltip?>
|
||||||
|
|
||||||
<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">
|
<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">
|
||||||
<children>
|
<children>
|
||||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||||
<children>
|
<children>
|
||||||
@@ -44,10 +54,36 @@
|
|||||||
<Font size="21.0" />
|
<Font size="21.0" />
|
||||||
</font>
|
</font>
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button fx:id="logOutButton" layoutX="33.0" layoutY="638.0" mnemonicParsing="false" onAction="#logOut" prefHeight="45.0" prefWidth="149.0" text="log out ">
|
||||||
|
<font>
|
||||||
|
<Font size="21.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
<Line endX="104.0" layoutX="102.0" layoutY="133.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
<Line endX="104.0" layoutX="102.0" layoutY="133.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||||
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||||
<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 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 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" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Text fill="#002c0c" layoutX="14.0" layoutY="415.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Random hint!">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Button fx:id="refreshHintsButton" layoutX="157.0" layoutY="390.0" mnemonicParsing="false" onAction="#addRandomHints" style="-fx-background-color: transparent;">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="26.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/refresh2.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
<AnchorPane fx:id="activitiesPane" layoutX="214.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">
|
<AnchorPane fx:id="activitiesPane" layoutX="214.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">
|
||||||
<children>
|
<children>
|
||||||
@@ -129,32 +165,32 @@
|
|||||||
</Label>
|
</Label>
|
||||||
<Pane layoutX="290.0" layoutY="130.0" prefHeight="342.0" prefWidth="230.0" style="-fx-background-color: #f4fff4;">
|
<Pane layoutX="290.0" layoutY="130.0" prefHeight="342.0" prefWidth="230.0" style="-fx-background-color: #f4fff4;">
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline miles">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="11.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline km">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline mpg">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="27.0" prefWidth="149.0" text="Gasoline km/L">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="99.0" prefHeight="27.0" prefWidth="149.0" text="Diesel miles">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="99.0" prefHeight="27.0" prefWidth="149.0" text="Diesel km">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="143.0" prefHeight="27.0" prefWidth="149.0" text="Diesel mpg">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="143.0" prefHeight="27.0" prefWidth="149.0" text="Diesel km/L">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="187.0" prefHeight="27.0" prefWidth="149.0" text="Electric miles">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="187.0" prefHeight="27.0" prefWidth="149.0" text="Electric km">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="231.0" prefHeight="27.0" prefWidth="149.0" text="Electric mpg">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="231.0" prefHeight="27.0" prefWidth="149.0" text="Electric km/Le">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
@@ -251,28 +287,41 @@
|
|||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</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">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</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">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</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">
|
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
|
||||||
<font>
|
<font>
|
||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</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>
|
</children>
|
||||||
</Pane>
|
</Pane>
|
||||||
</children></AnchorPane>
|
<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">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="69.0" fitWidth="61.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold Italic" size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.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">
|
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.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">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutX="94.0" layoutY="72.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Your Profile" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
<Text layoutX="94.0" layoutY="72.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Your Profile" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
||||||
@@ -420,6 +469,95 @@
|
|||||||
<Font size="20.0" />
|
<Font size="20.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
|
<Button fx:id="addExtraActivityButton" contentDisplay="RIGHT" layoutX="568.0" layoutY="223.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity" textFill="#147219">
|
||||||
|
<font>
|
||||||
|
<Font name="Corbel Bold" size="14.0" />
|
||||||
|
</font>
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="80.0" fitWidth="79.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Label fx:id="achiev1text" alignment="CENTER" layoutX="555.0" layoutY="350.0" prefHeight="30.0" prefWidth="250.0" text="ACHIEVEMENTS" textAlignment="CENTER">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<GridPane layoutX="539.0" layoutY="380.0" prefHeight="303.0" prefWidth="258.0">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Button fx:id="achiev1Tip" mnemonicParsing="false" styleClass="toolTipButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fx:id="achieve1" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/Clover.png" />
|
||||||
|
<!-- image from pngall.com - 3548 -->
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="achiev4Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fx:id="achieve4" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/alternate_foods.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="achiev2Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="1">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fx:id="achieve2" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/Friendship.png" />
|
||||||
|
<!-- image from pngall.com - 24498 -->
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="achiev3Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="2">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fx:id="achieve3" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/co2dev.png" />
|
||||||
|
<!-- image from exceldryer.com -->
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="achiev5Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fx:id="achieve5" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/achiev1pic.jpg" />
|
||||||
|
<!-- image from shutterstock.com - 1038138760 -->
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="achiev6Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fx:id="achieve6" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/solar_panels.jpeg" />
|
||||||
|
<!-- image from moregreenenergy.com -->
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</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">
|
<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">
|
||||||
|
|||||||
261
src/Client/src/main/resources/fxml/extraActivities.fxml
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.scene.shape.*?>
|
||||||
|
<?import javafx.scene.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">
|
||||||
|
<children>
|
||||||
|
<AnchorPane prefHeight="611.0" prefWidth="107.0">
|
||||||
|
<children>
|
||||||
|
<Button fx:id="displayVeganMealButton" contentDisplay="TOP" layoutX="14.0" layoutY="62.0" mnemonicParsing="false" onAction="#displayVeganMeal" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/icons8-vegan-food-100.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="displayLocalProduceButton" contentDisplay="TOP" layoutX="14.0" layoutY="143.0" mnemonicParsing="false" onAction="#displayLocalProduce" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/localProduce.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="displayBikeButton" contentDisplay="TOP" layoutX="14.0" layoutY="224.0" mnemonicParsing="false" onAction="#displayBike" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/icons8-bicycle-filled-100.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic></Button>
|
||||||
|
<Button fx:id="displaySolarPanelButton" contentDisplay="TOP" layoutX="14.0" layoutY="467.0" mnemonicParsing="false" onAction="#displaySolarPanel" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/icons8-solar-panel-filled-100.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="displayTemperatureButton" contentDisplay="TOP" layoutX="14.0" layoutY="386.0" mnemonicParsing="false" onAction="#displayTemperature" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="45.0" fitWidth="48.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/icons8-temperature-inside-64.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="displayPublicTransportButton" contentDisplay="TOP" layoutX="14.0" layoutY="305.0" mnemonicParsing="false" onAction="#displayPublicTransport" prefHeight="70.0" prefWidth="82.0" styleClass="navButton">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="45.0" fitWidth="45.0" pickOnBounds="true" preserveRatio="true" styleClass="navButton">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/publicTransport.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<AnchorPane fx:id="veganMealPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0">
|
||||||
|
<children>
|
||||||
|
<Line fx:id="line1" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
|
||||||
|
<Text layoutX="248.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Eating a vegetarian meal">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtraVegan" 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>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
<font>
|
||||||
|
<Font name="System Bold Italic" size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<AnchorPane fx:id="bikePane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
|
||||||
|
<children>
|
||||||
|
<Line fx:id="line2" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
|
||||||
|
<Text layoutX="203.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Using your bike instead of your car">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Slider fx:id="bikeSlider" layoutX="144.0" layoutY="271.0" majorTickUnit="20.0" max="200.0" minorTickCount="0" prefHeight="24.0" prefWidth="427.0" showTickLabels="true" showTickMarks="true" />
|
||||||
|
<Text fill="#727272" layoutX="179.0" layoutY="144.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many km did you travel using your bike that you would have traveled with your car?" textAlignment="CENTER">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#save" 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>
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<HBox alignment="CENTER" layoutX="305.0" layoutY="204.0" prefHeight="36.0" prefWidth="107.0" styleClass="textHolder">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="bikeLabel" text="0 km">
|
||||||
|
<font>
|
||||||
|
<Font size="17.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<AnchorPane fx:id="temperaturePane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
|
||||||
|
<children>
|
||||||
|
<Line fx:id="line3" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
|
||||||
|
<Text layoutX="179.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Lowering the temperature of your home">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Text fill="#727272" layoutX="187.0" layoutY="133.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many degrees (Celcius) did you lower your home temperature?" textAlignment="CENTER">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Slider fx:id="temperatureSlider" blockIncrement="1.0" layoutX="176.0" layoutY="266.0" majorTickUnit="1.0" max="15.0" minorTickCount="0" prefHeight="24.0" prefWidth="360.0" showTickLabels="true" showTickMarks="true" />
|
||||||
|
<HBox alignment="CENTER" layoutX="316.0" layoutY="194.0" prefHeight="36.0" prefWidth="107.0" styleClass="textHolder">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="temperatureLabel" text="0 Degrees">
|
||||||
|
<font>
|
||||||
|
<Font size="17.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#save" 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>
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<AnchorPane fx:id="solarPanelPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
|
||||||
|
<children>
|
||||||
|
<Line fx:id="line4" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
|
||||||
|
<Text layoutX="262.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Installing solar panels">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Text fill="#727272" layoutX="202.0" layoutY="150.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many solar panels did you install?" textAlignment="CENTER">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<HBox alignment="CENTER" layoutX="329.0" layoutY="201.0" prefHeight="36.0" prefWidth="56.0" styleClass="textHolder">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="solarPanelsLabel" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="17.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" />
|
||||||
|
<Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" onAction="#save" 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>
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<AnchorPane fx:id="localProducePane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
|
||||||
|
<children>
|
||||||
|
<Line fx:id="line11" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
|
||||||
|
<Text layoutX="264.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Buying local produce">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Button fx:id="addLocalProduceButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtraLocal" 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>
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<AnchorPane fx:id="publicTransportPane" layoutX="107.0" prefHeight="611.0" prefWidth="713.0" visible="false">
|
||||||
|
<children>
|
||||||
|
<Line fx:id="line21" endX="79.0" layoutX="465.0" layoutY="7.0" stroke="#545b54" />
|
||||||
|
<Text layoutX="153.0" layoutY="56.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Using your public transport instead of your car">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Slider fx:id="publicTransportSlider" layoutX="144.0" layoutY="271.0" majorTickUnit="20.0" max="200.0" minorTickCount="0" prefHeight="24.0" prefWidth="427.0" showTickLabels="true" showTickMarks="true" />
|
||||||
|
<Text fill="#727272" layoutX="151.0" layoutY="145.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How many km did you travel using public transport that you would have traveled with your car?" textAlignment="CENTER">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Button fx:id="addPublicTransportButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#save" 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>
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<image>
|
||||||
|
<Image url="@../icons/addActivity1.png" />
|
||||||
|
</image>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<HBox alignment="CENTER" layoutX="305.0" layoutY="204.0" prefHeight="36.0" prefWidth="107.0" styleClass="textHolder">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="publicTransportLabel" text="0 km">
|
||||||
|
<font>
|
||||||
|
<Font size="17.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
BIN
src/Client/src/main/resources/icons/Clover.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
src/Client/src/main/resources/icons/Friendship.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
src/Client/src/main/resources/icons/achiev1pic.jpg
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
src/Client/src/main/resources/icons/alternate_foods.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
src/Client/src/main/resources/icons/co2dev.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 825 B |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
BIN
src/Client/src/main/resources/icons/icons8-vegan-food-100.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
src/Client/src/main/resources/icons/localProduce.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
src/Client/src/main/resources/icons/publicTransport.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
src/Client/src/main/resources/icons/refresh.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
src/Client/src/main/resources/icons/refresh2.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/Client/src/main/resources/icons/solar_panels.jpeg
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
@@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
.slider {
|
.slider {
|
||||||
-show-value-on-interaction: true;
|
-show-value-on-interaction: true;
|
||||||
-fx-text-fill: red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.km-yearBox {
|
.km-yearBox {
|
||||||
|
|||||||
@@ -53,8 +53,15 @@
|
|||||||
-fx-border-color: #497251;
|
-fx-border-color: #497251;
|
||||||
}
|
}
|
||||||
|
|
||||||
#calculateFootPrintButton:pressed {
|
#logOutButton {
|
||||||
-fx-border-color: #497251;
|
-fx-background-color: #5a635c;
|
||||||
|
-fx-text-fill: #e3efe4;
|
||||||
|
}
|
||||||
|
#logOutButton:hover {
|
||||||
|
-fx-background-color: #e08f8f;
|
||||||
|
}
|
||||||
|
#logOutButton:pressed {
|
||||||
|
-fx-background-color: #ba3737;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*friends table*/
|
/*friends table*/
|
||||||
@@ -85,5 +92,16 @@
|
|||||||
-fx-font-size: 14px;
|
-fx-font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toolTipButton {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-padding: 0 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip {
|
||||||
|
-fx-background-color: #d0f2d3;
|
||||||
|
-fx-text-fill: #364c38;
|
||||||
|
-fx-font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
.navButton {
|
||||||
|
-fx-background-color: #6a7a6d;
|
||||||
|
}
|
||||||
|
.navButton:hover {
|
||||||
|
-fx-background-color: #728475;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navButton:pressed {
|
||||||
|
-fx-background-color: #8cad91;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider .track {
|
||||||
|
-fx-background-color: #d3d3d3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider .thumb {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-background-image: url('../icons/leaficon.png');
|
||||||
|
-fx-padding: 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
.textHolder {
|
||||||
|
-fx-background-color: #89a888;
|
||||||
|
-fx-background-radius: 5px;
|
||||||
|
-fx-border-radius: 5px;
|
||||||
|
}
|
||||||
@@ -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
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Client/src/test/java/HintsTest.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
import greenify.client.Hints;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HintsTest {
|
||||||
|
@Test
|
||||||
|
public void initHintsTest() {
|
||||||
|
Hints test = new Hints();
|
||||||
|
assertFalse(test.hints.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hintsContainsTest() {
|
||||||
|
Hints test = new Hints();
|
||||||
|
assertTrue(test.hints.contains("27,000 trees are cut down "
|
||||||
|
+ "each day so we can have toilet paper."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void randomHintTest() {
|
||||||
|
Hints test = new Hints();
|
||||||
|
String random = test.randomHint();
|
||||||
|
assertTrue(test.hints.contains(random));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import greenify.client.rest.UserService;
|
import greenify.client.rest.UserService;
|
||||||
import greenify.common.UserDto;
|
import greenify.common.UserDto;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
@@ -15,6 +14,9 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class UserServiceTest {
|
public class UserServiceTest {
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ public class UserServiceTest {
|
|||||||
.thenReturn(testUser);
|
.thenReturn(testUser);
|
||||||
|
|
||||||
UserDto user = userService.registerUser("Eric", "password");
|
UserDto user = userService.registerUser("Eric", "password");
|
||||||
Assert.assertEquals(testUser, user);
|
assertEquals(testUser, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -43,7 +45,7 @@ public class UserServiceTest {
|
|||||||
UserDto.class))
|
UserDto.class))
|
||||||
.thenReturn(testUser);
|
.thenReturn(testUser);
|
||||||
UserDto user = userService.loginUser("Eric", "password");
|
UserDto user = userService.loginUser("Eric", "password");
|
||||||
Assert.assertEquals(testUser, user);
|
assertEquals(testUser, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -52,8 +54,8 @@ public class UserServiceTest {
|
|||||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
|
||||||
Float.class))
|
Float.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
Float result = userService.getFootprint("Eric");
|
double result = (5 * 10) / 10.0;
|
||||||
Assert.assertEquals(estimate, result);
|
assertTrue(result == userService.getFootprint("Eric"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -62,8 +64,8 @@ public class UserServiceTest {
|
|||||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
|
||||||
Float.class))
|
Float.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
Float result = userService.getFirstFootprint("Eric");
|
double result = (5 * 10) / 10.0;
|
||||||
Assert.assertEquals(estimate, result);
|
assertTrue(result == userService.getFirstFootprint("Eric"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -73,7 +75,7 @@ public class UserServiceTest {
|
|||||||
Float.class))
|
Float.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
Float result = userService.saveFootprint("Eric");
|
Float result = userService.saveFootprint("Eric");
|
||||||
Assert.assertEquals(estimate, result);
|
assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,7 +85,7 @@ public class UserServiceTest {
|
|||||||
Float.class))
|
Float.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
Float result = userService.saveFirstFootprint("Eric");
|
Float result = userService.saveFirstFootprint("Eric");
|
||||||
Assert.assertEquals(estimate, result);
|
assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -94,7 +96,7 @@ public class UserServiceTest {
|
|||||||
List.class))
|
List.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
List<String> result = userService.getFriendNames("Eric");
|
List<String> result = userService.getFriendNames("Eric");
|
||||||
Assert.assertEquals(estimate, result);
|
assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -105,7 +107,7 @@ public class UserServiceTest {
|
|||||||
List.class))
|
List.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
List<String> result = userService.getAllUsers();
|
List<String> result = userService.getAllUsers();
|
||||||
Assert.assertEquals(estimate, result);
|
assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -116,18 +118,18 @@ public class UserServiceTest {
|
|||||||
Map.class))
|
Map.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
Map<String, String> result = userService.getInputs("Eric");
|
Map<String, String> result = userService.getInputs("Eric");
|
||||||
Assert.assertEquals(estimate, result);
|
assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getExtraInputsTest() throws Exception {
|
public void getExtraInputsTest() throws Exception {
|
||||||
Map<String, Boolean> estimate = new HashMap<>();
|
Map<String, String> estimate = new HashMap<>();
|
||||||
estimate.put("solar_panels", true);
|
estimate.put("solar_panels", "5");
|
||||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
|
||||||
Map.class))
|
Map.class))
|
||||||
.thenReturn(estimate);
|
.thenReturn(estimate);
|
||||||
Map<String, Boolean> result = userService.getExtraInputs("Eric");
|
Map<String, String> result = userService.getExtraInputs("Eric");
|
||||||
Assert.assertEquals(estimate, result);
|
assertEquals(estimate, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -138,8 +140,8 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setExtraInputTest() throws Exception {
|
public void setExtraInputTest() throws Exception {
|
||||||
userService.updateExtraInput("Eric", "solar_panels", true);
|
userService.updateExtraInput("Eric", "solar_panels", "8");
|
||||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
|
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", "8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -147,6 +149,20 @@ public class UserServiceTest {
|
|||||||
userService.addFriend("Eric", "Ceren");
|
userService.addFriend("Eric", "Ceren");
|
||||||
Mockito.verify(userService).addFriend("Eric", "Ceren");
|
Mockito.verify(userService).addFriend("Eric", "Ceren");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeFriendTest() throws Exception {
|
||||||
|
userService.addFriend("Eric", "Ceren");
|
||||||
|
Mockito.verify(userService).addFriend("Eric", "Ceren");
|
||||||
|
userService.removeFriend("Eric", "Ceren");
|
||||||
|
Mockito.verify(userService).removeFriend("Eric", "Ceren");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAchievementsTest() throws Exception {
|
||||||
|
userService.getAchievements("mika");
|
||||||
|
Mockito.verify(userService).getAchievements("mika");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package greenify.server;
|
||||||
|
|
||||||
|
import greenify.server.data.model.Achievement;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class AllAchievements {
|
||||||
|
private static final List<Achievement> allAchievements = Arrays.asList(
|
||||||
|
new Achievement("Starting off", "You did your first green activity", false),
|
||||||
|
new Achievement("Social butterfly", "You added three friends", false),
|
||||||
|
new Achievement("Green saver", "You saved * of CO2", false),
|
||||||
|
new Achievement("Animal friend", "You have eaten 10 vegetarian meals", false),
|
||||||
|
new Achievement("Tom Dumoulin", "You have biked * km", false),
|
||||||
|
new Achievement("Let it shine", "You installed solar panels", false)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method checks whether the achievement name is valid or not.
|
||||||
|
* @param achievementName the name of the achievement
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
public static Boolean isValidAchievement(String achievementName) {
|
||||||
|
return allAchievements.stream().anyMatch(i -> i.getName().equals(achievementName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets default achievements.
|
||||||
|
* @return the list of default achievements
|
||||||
|
*/
|
||||||
|
public static Map<String, Boolean> getDefaults() {
|
||||||
|
Map<String, Boolean> all = new HashMap<>();
|
||||||
|
for (Achievement achievement : allAchievements) {
|
||||||
|
all.put(achievement.getName(), achievement.isAchieved());
|
||||||
|
}
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -185,12 +185,14 @@ public class InputValidator {
|
|||||||
* This method gets extra values.
|
* This method gets extra values.
|
||||||
* @return the map of default values
|
* @return the map of default values
|
||||||
*/
|
*/
|
||||||
public static Map<String, Boolean> getExtraValues() {
|
public static Map<String, String> getExtraValues() {
|
||||||
Map<String, Boolean> map = new HashMap<String, Boolean>() { };
|
Map<String, String> map = new HashMap<String, String>() { };
|
||||||
map.put("local_produce", false);
|
map.put("vegan", "0");
|
||||||
map.put("bike", false);
|
map.put("local_produce", "0");
|
||||||
map.put("temperature", false);
|
map.put("bike", "0");
|
||||||
map.put("solar_panels", false);
|
map.put("public_transport", "0");
|
||||||
|
map.put("temperature", "0");
|
||||||
|
map.put("solar_panels", "0");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package greenify.server.data.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Achievement {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private boolean achieved;
|
||||||
|
|
||||||
|
public Achievement() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for an achievement.
|
||||||
|
* @param name name of the achievement
|
||||||
|
* @param description description of the achievement
|
||||||
|
* @param achieved whether the achievement is achieved or not
|
||||||
|
*/
|
||||||
|
public Achievement(String name, String description, boolean achieved) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.achieved = achieved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the name of an achievement.
|
||||||
|
* @return name of the achievement
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the name of an achievement.
|
||||||
|
* @param name name of the achievement
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the description of an achievement.
|
||||||
|
* @return the description of the achievement
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the name of an achievement.
|
||||||
|
* @param description the description of an achievement
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the state of an achievement.
|
||||||
|
* @return achievement is (not) achieved
|
||||||
|
*/
|
||||||
|
public boolean isAchieved() {
|
||||||
|
return achieved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the state of an achievement.
|
||||||
|
* @param achieved achievement is (not) achieved
|
||||||
|
*/
|
||||||
|
public void setAchieved(boolean achieved) {
|
||||||
|
this.achieved = achieved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets a human readable (JSON) object.
|
||||||
|
* @return the JSON form of the object
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Achievement(name=" + name + ", description=" + description
|
||||||
|
+ ", achieved=" + achieved + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method checks whether two users are equal or not.
|
||||||
|
* @param other another achievement
|
||||||
|
* @return achievements are (not) equal
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (other instanceof Achievement) {
|
||||||
|
Achievement that = (Achievement) other;
|
||||||
|
return achieved == that.achieved
|
||||||
|
&& name.equals(that.name)
|
||||||
|
&& description.equals(that.description);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the hashcode of an achievement.
|
||||||
|
* @return hashcode of an achievement
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(name, description, achieved);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package greenify.server.data.model;
|
package greenify.server.data.model;
|
||||||
|
|
||||||
import greenify.common.ApplicationException;
|
import greenify.common.ApplicationException;
|
||||||
|
import greenify.server.AllAchievements;
|
||||||
import greenify.server.InputValidator;
|
import greenify.server.InputValidator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -45,11 +46,14 @@ public class User {
|
|||||||
private Map<String, String> footPrintInputs = new HashMap<>();
|
private Map<String, String> footPrintInputs = new HashMap<>();
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
private Map<String, Boolean> extraInputs = new HashMap<>();
|
private Map<String, String> extraInputs = new HashMap<>();
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
private List<User> friends;
|
private List<User> friends;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
private Map<String, Boolean> achievements;
|
||||||
|
|
||||||
public User() {}
|
public User() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +69,7 @@ public class User {
|
|||||||
this.setFootPrintInputs(InputValidator.getDefaultValues());
|
this.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||||
this.setExtraInputs(InputValidator.getExtraValues());
|
this.setExtraInputs(InputValidator.getExtraValues());
|
||||||
this.friends = new ArrayList<User>();
|
this.friends = new ArrayList<User>();
|
||||||
|
this.setAchievements(AllAchievements.getDefaults());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +172,7 @@ public class User {
|
|||||||
* This method gets the extra inputs of the user.
|
* This method gets the extra inputs of the user.
|
||||||
* @return extra inputs of the user
|
* @return extra inputs of the user
|
||||||
*/
|
*/
|
||||||
public Map<String, Boolean> getExtraInputs() {
|
public Map<String, String> getExtraInputs() {
|
||||||
return extraInputs;
|
return extraInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +180,7 @@ public class User {
|
|||||||
* This method sets the extra inputs of the user.
|
* This method sets the extra inputs of the user.
|
||||||
* @param extraInputs footprint inputs of the user
|
* @param extraInputs footprint inputs of the user
|
||||||
*/
|
*/
|
||||||
public void setExtraInputs(Map<String, Boolean> extraInputs) {
|
public void setExtraInputs(Map<String, String> extraInputs) {
|
||||||
this.extraInputs = extraInputs;
|
this.extraInputs = extraInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +213,35 @@ public class User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a friend from the friendslist of the user.
|
||||||
|
* @param user the friend you want to remove.
|
||||||
|
*/
|
||||||
|
public void removeFriend(User user) {
|
||||||
|
if (!friends.contains(user)) {
|
||||||
|
throw new ApplicationException("This user is not your friend!");
|
||||||
|
} else {
|
||||||
|
friends.remove(user);
|
||||||
|
System.out.print("Friend removed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the achievements of the user.
|
||||||
|
* @param achievements achievements of the user
|
||||||
|
*/
|
||||||
|
public void setAchievements(Map<String, Boolean> achievements) {
|
||||||
|
this.achievements = achievements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets the achievements of the user.
|
||||||
|
* @return achievements of the user
|
||||||
|
*/
|
||||||
|
public Map<String, Boolean> getAchievements() {
|
||||||
|
return this.achievements;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets a human readable (JSON) object.
|
* This method gets a human readable (JSON) object.
|
||||||
* @return the JSON form of the object.
|
* @return the JSON form of the object.
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class UserController {
|
|||||||
@RequestMapping("/setExtraInput")
|
@RequestMapping("/setExtraInput")
|
||||||
public void setExtraInput(@RequestParam(value = "name") String name,
|
public void setExtraInput(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "inputName") String inputName,
|
@RequestParam(value = "inputName") String inputName,
|
||||||
@RequestParam(value = "value") Boolean value) {
|
@RequestParam(value = "value") String value) {
|
||||||
userService.setExtraInput(name, inputName, value);
|
userService.setExtraInput(name, inputName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,18 +150,40 @@ public class UserController {
|
|||||||
* This method gets the extra inputs map of the user.
|
* This method gets the extra inputs map of the user.
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/getExtraInputs")
|
@RequestMapping("/getExtraInputs")
|
||||||
public Map<String, Boolean> getExtraInputs(@RequestParam(value = "name") String name) {
|
public Map<String, String> getExtraInputs(@RequestParam(value = "name") String name) {
|
||||||
return userService.getExtraInputMap(name);
|
return userService.getExtraInputMap(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds friend for a user.
|
* This method adds a friend to a user.
|
||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
*
|
* @param friend the name of the user you want to add as a friend.
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/addFriend")
|
@RequestMapping("/addFriend")
|
||||||
public void addFriend(@RequestParam(value = "name") String name,
|
public void addFriend(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "friend") String friend) {
|
@RequestParam(value = "friend") String friend) {
|
||||||
userService.addFriend(name, friend);
|
userService.addFriend(name, friend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method removes a friend from a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @param friend name of the friend you want to remove
|
||||||
|
*/
|
||||||
|
@RequestMapping("/removeFriend")
|
||||||
|
public void removeFriend(@RequestParam(value = "name") String name,
|
||||||
|
@RequestParam(value = "friend") String friend) {
|
||||||
|
userService.removeFriend(name, friend);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets all achievements of a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return map of all achievements of the user
|
||||||
|
*/
|
||||||
|
@RequestMapping("/getAchievements")
|
||||||
|
public Map<String, Boolean> getAchievements(@RequestParam(value = "name") String name) {
|
||||||
|
return userService.getAchievements(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package greenify.server.service;
|
||||||
|
|
||||||
|
import greenify.server.data.model.User;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AchievementService {
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method updates all achievements of a user.
|
||||||
|
* @param user the user for whom the achievements change
|
||||||
|
*/
|
||||||
|
public void updateAchievements(User user) {
|
||||||
|
achieveGettingStarted(user);
|
||||||
|
achieveSocialButterfly(user);
|
||||||
|
achieveGreenSaver(user);
|
||||||
|
achieveAnimalFriend(user);
|
||||||
|
achieveTomDumoulin(user);
|
||||||
|
achieveLetItShine(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method makes sure the user gets an achievement
|
||||||
|
* upon calculating their footprint for the first time.
|
||||||
|
* @param user user for whom achiev1 changes
|
||||||
|
*/
|
||||||
|
public void achieveGettingStarted(User user) {
|
||||||
|
userService.setAchievement(user.getName(), "Starting off", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method changes achiev2 when this is the case.
|
||||||
|
* @param user user for whom achiev2 changes
|
||||||
|
*/
|
||||||
|
public void achieveSocialButterfly(User user) {
|
||||||
|
if (user.getFriends().size() >= 3) {
|
||||||
|
userService.setAchievement(user.getName(), "Social butterfly", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method changes achiev3 when this is the case.
|
||||||
|
* @param user user for whom achiev3 changes
|
||||||
|
*/
|
||||||
|
public void achieveGreenSaver(User user) {
|
||||||
|
if (20 > user.getFootPrint()) {
|
||||||
|
userService.setAchievement(user.getName(), "Green saver", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method changes achiev4 when this is the case.
|
||||||
|
* @param user user for whom achiev4 changes
|
||||||
|
*/
|
||||||
|
public void achieveAnimalFriend(User user) {
|
||||||
|
int vegan = Integer.parseInt(user.getExtraInputs().get("vegan"));
|
||||||
|
if (vegan > 10) {
|
||||||
|
userService.setAchievement(user.getName(), "Animal friend", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method changes achiev5 when this is the case.
|
||||||
|
* @param user user for whom achiev5 changes
|
||||||
|
*/
|
||||||
|
public void achieveTomDumoulin(User user) {
|
||||||
|
int bike = Integer.parseInt(user.getExtraInputs().get("bike"));
|
||||||
|
if (bike > 15) {
|
||||||
|
userService.setAchievement(user.getName(), "Tom Dumoulin", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method changes achiev6 when this is the case.
|
||||||
|
* @param user user for whom achiev6 changes
|
||||||
|
*/
|
||||||
|
public void achieveLetItShine(User user) {
|
||||||
|
int solar_panels = Integer.parseInt(user.getExtraInputs().get("solar_panels"));
|
||||||
|
if (solar_panels >= 2) {
|
||||||
|
userService.setAchievement(user.getName(), "Let it shine", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -72,21 +72,41 @@ public class CalculatorService {
|
|||||||
* @return the footprint of the user
|
* @return the footprint of the user
|
||||||
*/
|
*/
|
||||||
public Float calculateFootprint(User user) {
|
public Float calculateFootprint(User user) {
|
||||||
Float footprint = invokeExternalService(user.getFootPrintInputs());
|
|
||||||
addExtras(user);
|
addExtras(user);
|
||||||
|
Float footprint = invokeExternalService(user.getFootPrintInputs());
|
||||||
|
footprint = footprint - (float) (Float.parseFloat(user
|
||||||
|
.getExtraInputs().get("solar_panels")) * 1.2);
|
||||||
|
footprint = footprint - Float.parseFloat(user
|
||||||
|
.getExtraInputs().get("temperature")) / 4;
|
||||||
|
footprint = footprint - (float) (Float.parseFloat(user
|
||||||
|
.getExtraInputs().get("local_produce")) * 0.1);
|
||||||
return footprint;
|
return footprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method adds extra input to the user.
|
||||||
|
* @param user name of the user
|
||||||
|
*/
|
||||||
public void addExtras(User user) {
|
public void addExtras(User user) {
|
||||||
if (user.getExtraInputs().get("local_produce")) {
|
Map<String, String> inputs = user.getFootPrintInputs();
|
||||||
user.setFootPrint(user.getFootPrint() - 2);
|
Float netPublic = Float.parseFloat(user.getFootPrintInputs()
|
||||||
} else if (user.getExtraInputs().get("bike")) {
|
.get("input_footprint_transportation_publictrans"))
|
||||||
user.setFootPrint(user.getFootPrint() - 2);
|
+ Float.parseFloat(user.getExtraInputs().get("public_transport"));
|
||||||
} else if (user.getExtraInputs().get("temperature")) {
|
Float netCar = Float.parseFloat(user.getFootPrintInputs()
|
||||||
user.setFootPrint(user.getFootPrint() - 2);
|
.get("input_footprint_transportation_miles1"))
|
||||||
} else if (user.getExtraInputs().get("solar_panels")) {
|
- Float.parseFloat(user.getExtraInputs().get("public_transport"))
|
||||||
user.setFootPrint(user.getFootPrint() - 2);
|
- Float.parseFloat(user.getExtraInputs().get("bike"));
|
||||||
}
|
Float netVegan = Float.parseFloat(user.getFootPrintInputs()
|
||||||
|
.get("input_footprint_shopping_food_fruitvegetables"))
|
||||||
|
+ Float.parseFloat(user.getExtraInputs().get("vegan"));
|
||||||
|
Float netShopping = Float.parseFloat(user.getFootPrintInputs()
|
||||||
|
.get("input_footprint_shopping_goods_total"))
|
||||||
|
- Float.parseFloat(user.getExtraInputs().get("local_produce")) * 100;
|
||||||
|
inputs.put("input_footprint_transportation_publictrans", netPublic + "");
|
||||||
|
inputs.put("input_footprint_transportation_miles1", netCar + "");
|
||||||
|
inputs.put("input_footprint_shopping_food_fruitvegetables", netVegan + "");
|
||||||
|
inputs.put("input_footprint_shopping_goods_total", netShopping + "");
|
||||||
|
user.setFootPrintInputs(inputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package greenify.server.service;
|
|||||||
|
|
||||||
import greenify.common.ApplicationException;
|
import greenify.common.ApplicationException;
|
||||||
import greenify.common.UserDto;
|
import greenify.common.UserDto;
|
||||||
|
import greenify.server.AllAchievements;
|
||||||
import greenify.server.InputValidator;
|
import greenify.server.InputValidator;
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
import greenify.server.data.repository.UserRepository;
|
import greenify.server.data.repository.UserRepository;
|
||||||
@@ -19,6 +20,9 @@ public class UserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
CalculatorService calculatorService;
|
CalculatorService calculatorService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AchievementService achievementService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserRepository userRepository;
|
UserRepository userRepository;
|
||||||
|
|
||||||
@@ -37,6 +41,7 @@ public class UserService {
|
|||||||
user.setFootPrintInputs(InputValidator.getDefaultValues());
|
user.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||||
Float footprint = calculatorService.calculateFootprint(user);
|
Float footprint = calculatorService.calculateFootprint(user);
|
||||||
user.setFootPrint(footprint);
|
user.setFootPrint(footprint);
|
||||||
|
user.setAchievements(AllAchievements.getDefaults());
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("User already exists");
|
throw new ApplicationException("User already exists");
|
||||||
@@ -64,21 +69,37 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
<<<<<<< HEAD
|
|
||||||
* Adds a friend to the friendlist of the user.
|
* Adds a friend to the friendlist of the user.
|
||||||
* @param name the username of the user
|
* @param name the username of the user
|
||||||
* @param friend the name of the friend you want to add.
|
* @param friend the name of the friend you want to add.
|
||||||
|
* @throws ApplicationException if the user is not in the database.
|
||||||
*/
|
*/
|
||||||
public void addFriend(String name, String friend) {
|
public void addFriend(String name, String friend) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
User add = userRepository.findByName(friend);
|
User add = userRepository.findByName(friend);
|
||||||
if (user == null || add == null ) {
|
if (add == null ) {
|
||||||
throw new ApplicationException("User does not exist");
|
throw new ApplicationException("User does not exist");
|
||||||
}
|
}
|
||||||
user.addFriend(add);
|
user.addFriend(add);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a friend from the friendlist of the user.
|
||||||
|
* @param name the username of the user
|
||||||
|
* @param friend the name of the friend you want to remove.
|
||||||
|
* @throws ApplicationException if the user is not in the database.
|
||||||
|
*/
|
||||||
|
public void removeFriend(String name, String friend) {
|
||||||
|
User user = userRepository.findByName(name);
|
||||||
|
User remove = userRepository.findByName(friend);
|
||||||
|
if (remove == null ) {
|
||||||
|
throw new ApplicationException("User does not exist");
|
||||||
|
}
|
||||||
|
user.removeFriend(remove);
|
||||||
|
userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets input for a user.
|
* This method sets input for a user.
|
||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
@@ -93,6 +114,7 @@ public class UserService {
|
|||||||
if (InputValidator.isValidItem(inputName)
|
if (InputValidator.isValidItem(inputName)
|
||||||
&& InputValidator.isValidItemValue(inputName, value)) {
|
&& InputValidator.isValidItemValue(inputName, value)) {
|
||||||
user.getFootPrintInputs().put(inputName, value);
|
user.getFootPrintInputs().put(inputName, value);
|
||||||
|
achievementService.updateAchievements(user);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
} else {
|
} else {
|
||||||
throw new ApplicationException("Invalid input");
|
throw new ApplicationException("Invalid input");
|
||||||
@@ -106,12 +128,14 @@ public class UserService {
|
|||||||
* @param inputName name of the input of the user
|
* @param inputName name of the input of the user
|
||||||
* @param value value of the input
|
* @param value value of the input
|
||||||
*/
|
*/
|
||||||
public void setExtraInput(String name, String inputName, Boolean value) {
|
public void setExtraInput(String name, String inputName, String value) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new ApplicationException("User does not exist");
|
throw new ApplicationException("User does not exist");
|
||||||
} else {
|
} else {
|
||||||
user.getExtraInputs().put(inputName, value);
|
String oldValue = user.getExtraInputs().get(inputName);
|
||||||
|
Integer total = Integer.parseInt(oldValue) + Integer.parseInt(value);
|
||||||
|
user.getExtraInputs().put(inputName, total + "");
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +170,7 @@ public class UserService {
|
|||||||
* @param name of the user
|
* @param name of the user
|
||||||
* @return extra input map
|
* @return extra input map
|
||||||
*/
|
*/
|
||||||
public Map<String, Boolean> getExtraInputMap(String name) {
|
public Map<String, String> getExtraInputMap(String name) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
return user.getExtraInputs();
|
return user.getExtraInputs();
|
||||||
}
|
}
|
||||||
@@ -210,6 +234,52 @@ public class UserService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This methods sets a achievement.
|
||||||
|
* @param name name of the user
|
||||||
|
* @param achievement name of the achievement
|
||||||
|
* @param achieved (not) achieved
|
||||||
|
*/
|
||||||
|
public void setAchievement(String name, String achievement, Boolean achieved) {
|
||||||
|
User user = userRepository.findByName(name);
|
||||||
|
if (user == null) {
|
||||||
|
throw new ApplicationException("User does not exist");
|
||||||
|
}
|
||||||
|
if (!AllAchievements.isValidAchievement(achievement)) {
|
||||||
|
throw new ApplicationException("Invalid achievement");
|
||||||
|
}
|
||||||
|
Map<String, Boolean> temp = user.getAchievements();
|
||||||
|
temp.put(achievement, achieved);
|
||||||
|
user.setAchievements(temp);
|
||||||
|
userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets whether the achievement is achieved.
|
||||||
|
* @param name of the user
|
||||||
|
* @param achievement name of the achievement
|
||||||
|
* @return (not) achieved
|
||||||
|
*/
|
||||||
|
public Boolean getAchievement(String name, String achievement) {
|
||||||
|
User user = userRepository.findByName(name);
|
||||||
|
if (AllAchievements.isValidAchievement(achievement)) {
|
||||||
|
return user.getAchievements().get(achievement);
|
||||||
|
} else {
|
||||||
|
throw new ApplicationException("Invalid achievement");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method gets all achievements of a user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return map with all achievements of a user
|
||||||
|
*/
|
||||||
|
public Map<String, Boolean> getAchievements(String name) {
|
||||||
|
User user = userRepository.findByName(name);
|
||||||
|
achievementService.updateAchievements(user);
|
||||||
|
return user.getAchievements();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the list of all users.
|
* This method gets the list of all users.
|
||||||
* @return list of all users
|
* @return list of all users
|
||||||
|
|||||||
39
src/Server/src/test/java/AllAchievementsTest.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import greenify.server.AllAchievements;
|
||||||
|
import greenify.server.data.model.Achievement;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class AllAchievementsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void isValidAchievementTest() {
|
||||||
|
new AllAchievements();
|
||||||
|
assertEquals(true, AllAchievements.isValidAchievement(
|
||||||
|
"Starting off"));
|
||||||
|
assertEquals(false, AllAchievements.isValidAchievement("test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDefaultsTest() {
|
||||||
|
List<Achievement> all = new ArrayList<Achievement>() {{
|
||||||
|
add(new Achievement(
|
||||||
|
"Starting off", "You did your first green activity", false));
|
||||||
|
add(new Achievement(
|
||||||
|
"Social butterfly", "You added three friends", false));
|
||||||
|
add(new Achievement(
|
||||||
|
"Green saver", "You saved * of CO2", false));
|
||||||
|
add(new Achievement(
|
||||||
|
"Animal friend", "You have eaten 10 vegetarian meals", false));
|
||||||
|
add(new Achievement(
|
||||||
|
"Tom Dumoulin", "You have biked * km", false));
|
||||||
|
add(new Achievement(
|
||||||
|
"Let it shine", "You installed solar panels", false));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assertEquals(all.size(), AllAchievements.getDefaults().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -151,7 +151,7 @@ public class InputValidatorTest {
|
|||||||
put("input_footprint_shopping_services_charity", "146");
|
put("input_footprint_shopping_services_charity", "146");
|
||||||
put("input_footprint_shopping_services_miscservices", "114");
|
put("input_footprint_shopping_services_miscservices", "114");
|
||||||
put("internal_state_abbreviation", "US");
|
put("internal_state_abbreviation", "US");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
assertTrue(map.size() == InputValidator.getDefaultValues().size());
|
assertTrue(map.size() == InputValidator.getDefaultValues().size());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package greenify.server.data.model;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class AchievementTest {
|
||||||
|
private Achievement achievement = new Achievement("SavedCO2",
|
||||||
|
"You saved 100 cow farts of CO2!", true);
|
||||||
|
private Achievement other = new Achievement("SavedCO2",
|
||||||
|
"You saved 100 cow farts of CO2!", true);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAndSetTest() {
|
||||||
|
Achievement testAchievement = new Achievement();
|
||||||
|
testAchievement.setName("SavedCO2");
|
||||||
|
testAchievement.setDescription("You saved 100 cow farts of CO2!");
|
||||||
|
testAchievement.setAchieved(true);
|
||||||
|
assertEquals("SavedCO2", achievement.getName());
|
||||||
|
assertEquals("You saved 100 cow farts of CO2!", achievement.getDescription());
|
||||||
|
assertTrue(achievement.isAchieved());
|
||||||
|
assertEquals(achievement, testAchievement);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toStringTest() {
|
||||||
|
assertEquals("Achievement(name=SavedCO2, "
|
||||||
|
+ "description=You saved 100 cow farts of CO2!, achieved=true)",
|
||||||
|
achievement.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void equalsTest() {
|
||||||
|
assertEquals(achievement.getName(), other.getName());
|
||||||
|
assertEquals(achievement.getDescription(), other.getDescription());
|
||||||
|
assertEquals(achievement.isAchieved(), other.isAchieved());
|
||||||
|
assertEquals(achievement, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notEqualAchievedTest() {
|
||||||
|
Achievement first = new Achievement("greenify", "description", true);
|
||||||
|
Achievement second = new Achievement("greenify", "description", false);
|
||||||
|
assertNotEquals(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notEqualNameTest() {
|
||||||
|
Achievement first = new Achievement("greenify", "description", true);
|
||||||
|
Achievement second = new Achievement("ceren", "description", true);
|
||||||
|
assertNotEquals(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notEqualDescriptionTest() {
|
||||||
|
Achievement first = new Achievement("greenify", "hello", false);
|
||||||
|
Achievement second = new Achievement("greenify", "description", false);
|
||||||
|
assertNotEquals(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void instanceOfTest() {
|
||||||
|
Achievement first = new Achievement();
|
||||||
|
Object second = new Object();
|
||||||
|
assertNotEquals(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hashCodeTest() {
|
||||||
|
assertEquals(achievement, other);
|
||||||
|
assertEquals(achievement.hashCode(), other.hashCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@ package greenify.server.data.model;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import greenify.common.ApplicationException;
|
import greenify.common.ApplicationException;
|
||||||
|
import greenify.server.AllAchievements;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -125,6 +127,27 @@ public class UserTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeFriendValidTest() {
|
||||||
|
User test = new User(1L, "greenify", "password");
|
||||||
|
List<User> friendList = new ArrayList<>();
|
||||||
|
friendList.add(test);
|
||||||
|
User user = new User(1L, "green", "pass");
|
||||||
|
user.setFriends(friendList);
|
||||||
|
assertEquals(user.getFriends(), friendList);
|
||||||
|
user.removeFriend(test);
|
||||||
|
assertEquals(user.getFriends(), new ArrayList<User>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeFriendInvalidTest() {
|
||||||
|
User user = new User(1L, "greenify", "password");
|
||||||
|
User test = new User(2L, "user", "pass");
|
||||||
|
assertThrows(ApplicationException.class, () -> {
|
||||||
|
user.removeFriend(test);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setFriendTest() {
|
public void setFriendTest() {
|
||||||
List<User> friends = new ArrayList<User>();
|
List<User> friends = new ArrayList<User>();
|
||||||
@@ -134,4 +157,17 @@ public class UserTest {
|
|||||||
first.setFriends(friends);
|
first.setFriends(friends);
|
||||||
assertEquals(friends, first.getFriends());
|
assertEquals(friends, first.getFriends());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAchievementsTest() {
|
||||||
|
User user = new User(1L, "greenify", "password");
|
||||||
|
assertEquals(user.getAchievements(), AllAchievements.getDefaults());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAchievementsTest() {
|
||||||
|
User user = new User(1L, "greenify", "password");
|
||||||
|
user.setAchievements(null);
|
||||||
|
assertNull(user.getAchievements());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,11 +82,11 @@ public class UserControllerTest {
|
|||||||
public void setExtraInputTest() throws Exception {
|
public void setExtraInputTest() throws Exception {
|
||||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||||
ArgumentCaptor<Boolean> arg3Captor = ArgumentCaptor.forClass(Boolean.class);
|
ArgumentCaptor<String> arg3Captor = ArgumentCaptor.forClass(String.class);
|
||||||
mvc.perform(get("/setExtraInput")
|
mvc.perform(get("/setExtraInput")
|
||||||
.param("name", "ceren")
|
.param("name", "ceren")
|
||||||
.param("inputName", "input_size")
|
.param("inputName", "input_size")
|
||||||
.param("value", "true")
|
.param("value", "5")
|
||||||
.accept(MediaType.APPLICATION_JSON))
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
.andDo(print())
|
.andDo(print())
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
@@ -94,7 +94,7 @@ public class UserControllerTest {
|
|||||||
.setExtraInput(arg1Captor.capture(), arg2Captor.capture(), arg3Captor.capture());
|
.setExtraInput(arg1Captor.capture(), arg2Captor.capture(), arg3Captor.capture());
|
||||||
assertEquals("ceren", arg1Captor.getValue());
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
assertEquals("input_size", arg2Captor.getValue());
|
assertEquals("input_size", arg2Captor.getValue());
|
||||||
assertEquals(true, arg3Captor.getValue());
|
assertEquals("5", arg3Captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -113,6 +113,22 @@ public class UserControllerTest {
|
|||||||
assertEquals("merel", arg2Captor.getValue());
|
assertEquals("merel", arg2Captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeFriendTest() throws Exception {
|
||||||
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
mvc.perform(get("/removeFriend")
|
||||||
|
.param("name", "ceren")
|
||||||
|
.param("friend", "merel")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
verify(userService, times(1))
|
||||||
|
.removeFriend(arg1Captor.capture(), arg2Captor.capture());
|
||||||
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
|
assertEquals("merel", arg2Captor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInputMapTest() throws Exception {
|
public void getInputMapTest() throws Exception {
|
||||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
@@ -221,4 +237,17 @@ public class UserControllerTest {
|
|||||||
verify(userService, times(1)).saveFirstFootprint(arg1Captor.capture());
|
verify(userService, times(1)).saveFirstFootprint(arg1Captor.capture());
|
||||||
assertEquals("ceren", arg1Captor.getValue());
|
assertEquals("ceren", arg1Captor.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAchievementsTest() throws Exception {
|
||||||
|
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
mvc.perform(get("/getAchievements")
|
||||||
|
.param("name", "mika")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
|
.andDo(print())
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
verify(userService, times(1)).getAchievements(arg1Captor.capture());
|
||||||
|
assertEquals("mika", arg1Captor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package greenify.server.service;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import greenify.server.data.model.User;
|
||||||
|
import greenify.server.data.repository.UserRepository;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
public class AchievementServiceTest {
|
||||||
|
@TestConfiguration
|
||||||
|
static class UserServiceConfiguration {
|
||||||
|
@Bean
|
||||||
|
public UserService userService() {
|
||||||
|
return new UserService();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
static class AchievementServiceConfiguration {
|
||||||
|
@Bean
|
||||||
|
public AchievementService achievementService() {
|
||||||
|
return new AchievementService();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private CalculatorService calculatorService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AchievementService achievementService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp method for test.
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
User alex = new User(1L, "alex", "password");
|
||||||
|
when(userRepository.findByName(alex.getName()))
|
||||||
|
.thenReturn(alex);
|
||||||
|
userService.setExtraInput("alex", "vegan", "25");
|
||||||
|
userService.setExtraInput("alex", "solar_panels", "3");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateAchievementsTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
achievementService.updateAchievements(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Starting off"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void achieveGettingStartedTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
achievementService.achieveGettingStarted(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Starting off"));
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void achieveSocialButterflyTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
alex.addFriend(new User(2L, "Bubbles", "Bubbles"));
|
||||||
|
alex.addFriend(new User(3L, "Cheese", "crackers"));
|
||||||
|
alex.addFriend(new User(4L, "Perry", "Doofenshmirtz"));
|
||||||
|
achievementService.achieveSocialButterfly(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Social butterfly"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notAchieveSocialButterflyTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
alex.addFriend(new User(2L, "Bubbles", "Bubbles"));
|
||||||
|
achievementService.achieveSocialButterfly(alex);
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void achieveGreenSaverTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
achievementService.achieveGreenSaver(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Green saver"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notAchieveGreenSaverTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
alex.setFootPrint(90f);
|
||||||
|
achievementService.achieveGreenSaver(alex);
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Green saver"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void achieveAnimalFriendTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
achievementService.achieveAnimalFriend(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Animal friend"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notAchieveAnimalFriendTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
alex.getExtraInputs().put("vegan", "0");
|
||||||
|
achievementService.achieveAnimalFriend(alex);
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Animal friend"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void achieveTomDumoulinTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
achievementService.achieveTomDumoulin(alex);
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Tom Dumoulin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void successfulAchieveTomDumoulinTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
alex.getExtraInputs().put("bike", "25");
|
||||||
|
achievementService.achieveTomDumoulin(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Tom Dumoulin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void achieveLetItShineTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
achievementService.achieveLetItShine(alex);
|
||||||
|
assertEquals(true, userService.getAchievement("alex", "Let it shine"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notAchieveLetItShineTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
alex.getExtraInputs().put("solar_panels", "0");
|
||||||
|
achievementService.achieveLetItShine(alex);
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Let it shine"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
package greenify.server.service;
|
package greenify.server.service;
|
||||||
|
|
||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
|
|
||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
|
|
||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
|
|
||||||
|
|
||||||
import greenify.server.data.model.User;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -14,16 +7,10 @@ import org.junit.runner.RunWith;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.client.ExpectedCount;
|
|
||||||
import org.springframework.test.web.client.MockRestServiceServer;
|
import org.springframework.test.web.client.MockRestServiceServer;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -59,62 +46,6 @@ public class CalculatorServiceTest {
|
|||||||
mockServer = MockRestServiceServer.createServer(restTemplate);
|
mockServer = MockRestServiceServer.createServer(restTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void calculateFootprintTest() throws URISyntaxException {
|
|
||||||
Map<String,String> map = new HashMap<String, String>() {{
|
|
||||||
put("input_location_mode", "1");
|
|
||||||
put("input_location", "48001");
|
|
||||||
put("input_income", "1");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
User user = new User(1L,"greenify", "password");
|
|
||||||
user.setFootPrintInputs(map);
|
|
||||||
mockServer.expect(ExpectedCount.once(),
|
|
||||||
requestTo(new URI("https://apis.berkeley.edu/coolclimate/footprint?"
|
|
||||||
+ "input_location=48001&input_location_mode=1&input_income=1")))
|
|
||||||
.andExpect(method(HttpMethod.GET))
|
|
||||||
.andExpect(header("app_id", "a98272e3"))
|
|
||||||
.andExpect(header("app_key", "b9167c4918cb2b3143614b595065d83b"))
|
|
||||||
.andRespond(withStatus(HttpStatus.OK)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
||||||
+ "<response>\n"
|
|
||||||
+ " <result_motor_vehicles_direct>5.0765</result_motor_vehicles_direct>\n"
|
|
||||||
+ " <result_motor_vehicles_indirect>1.167595"
|
|
||||||
+ "</result_motor_vehicles_indirect>\n"
|
|
||||||
+ " <result_goods_total>2.481474</result_goods_total>\n"
|
|
||||||
+ " <result_services_total>2.478352</result_services_total>\n"
|
|
||||||
+ " <result_grand_total>19.259982</result_grand_total>\n"
|
|
||||||
+ "</response>")
|
|
||||||
);
|
|
||||||
Float footPrint = calculatorService.calculateFootprint(user);
|
|
||||||
mockServer.verify();
|
|
||||||
Assert.assertEquals(new Float(19.259982), footPrint);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addExtrasTest() throws URISyntaxException {
|
|
||||||
User user = new User(1L,"greenify", "password");
|
|
||||||
Map<String,Boolean> map = new HashMap<String, Boolean>() {{
|
|
||||||
put("local_produce", false);
|
|
||||||
put("bike", false);
|
|
||||||
put("temperature", false);
|
|
||||||
put("solar_panels", false);
|
|
||||||
}};
|
|
||||||
user.setExtraInputs(map);
|
|
||||||
user.setFootPrint(50f);
|
|
||||||
Map<String,Boolean> secondMap = new HashMap<String, Boolean>() {{
|
|
||||||
put("local_produce", true);
|
|
||||||
put("bike", true);
|
|
||||||
put("temperature", true);
|
|
||||||
put("solar_panels", true);
|
|
||||||
}};
|
|
||||||
user.setExtraInputs(secondMap);
|
|
||||||
calculatorService.addExtras(user);
|
|
||||||
mockServer.verify();
|
|
||||||
Assert.assertEquals(new Float(48f), user.getFootPrint());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invokeExternalServiceTest() {
|
public void invokeExternalServiceTest() {
|
||||||
CalculatorService service = new CalculatorService();
|
CalculatorService service = new CalculatorService();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import greenify.common.ApplicationException;
|
import greenify.common.ApplicationException;
|
||||||
import greenify.common.UserDto;
|
import greenify.common.UserDto;
|
||||||
|
import greenify.server.AllAchievements;
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
import greenify.server.data.repository.UserRepository;
|
import greenify.server.data.repository.UserRepository;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@@ -43,6 +44,9 @@ public class UserServiceTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
private CalculatorService calculatorService;
|
private CalculatorService calculatorService;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private AchievementService achievementService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp method for test.
|
* setUp method for test.
|
||||||
*/
|
*/
|
||||||
@@ -97,8 +101,8 @@ public class UserServiceTest {
|
|||||||
User alex = new User(1L, "alex", "password");
|
User alex = new User(1L, "alex", "password");
|
||||||
when(userRepository.findByName(alex.getName()))
|
when(userRepository.findByName(alex.getName()))
|
||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
userService.setExtraInput("alex", "solar_panels", true);
|
userService.setExtraInput("alex", "solar_panels", "5");
|
||||||
assertEquals(true, alex.getExtraInputs()
|
assertEquals("5", alex.getExtraInputs()
|
||||||
.get("solar_panels"));
|
.get("solar_panels"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +113,8 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setExtraInputNullTest() {
|
public void setExtraInputNullTest() {
|
||||||
assertThrows(ApplicationException.class, () -> userService.setExtraInput(null, "hello", true));
|
assertThrows(ApplicationException.class, () -> userService
|
||||||
|
.setExtraInput(null, "hello", "6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -166,7 +171,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getExtraInputMapTest() {
|
public void getExtraInputMapTest() {
|
||||||
Map<String, Boolean> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
User alex = new User(1L, "alex", "password");
|
User alex = new User(1L, "alex", "password");
|
||||||
when(userRepository.findByName(alex.getName()))
|
when(userRepository.findByName(alex.getName()))
|
||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
@@ -265,13 +270,60 @@ public class UserServiceTest {
|
|||||||
assertEquals(alex.getFriends(), test);
|
assertEquals(alex.getFriends(), test);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeFriendTest() {
|
||||||
|
User alex = userRepository.findByName("alex");
|
||||||
|
User lola = userRepository.findByName("lola");
|
||||||
|
assertEquals(lola.getFriends(), alex.getFriends());
|
||||||
|
userService.addFriend("alex", "lola");
|
||||||
|
ArrayList<User> test = new ArrayList<User>();
|
||||||
|
test.add(lola);
|
||||||
|
assertEquals(alex.getFriends(), test);
|
||||||
|
userService.removeFriend("alex", "lola");
|
||||||
|
assertEquals(lola.getFriends(), alex.getFriends());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeFriendNullTest() {
|
||||||
|
assertThrows(ApplicationException.class, () -> userService.removeFriend("alex", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAchievementNullUserTest() {
|
||||||
|
assertThrows(ApplicationException.class, () -> userService
|
||||||
|
.setAchievement("ceren", "Starting off", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invalidAchievementTest() {
|
||||||
|
assertThrows(ApplicationException.class, () -> userService
|
||||||
|
.setAchievement("alex", "greenify", true));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addFriendNullFriendTest() {
|
public void addFriendNullFriendTest() {
|
||||||
assertThrows(ApplicationException.class, () -> userService.addFriend("alex", null));
|
assertThrows(ApplicationException.class, () -> userService.addFriend("alex", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addFriendNullUserTest() {
|
public void setAchievementTest() {
|
||||||
assertThrows(ApplicationException.class, () -> userService.addFriend(null, "password"));
|
User alex = new User(1L, "alex", "password");
|
||||||
|
when(userRepository.findByName(alex.getName()))
|
||||||
|
.thenReturn(alex);
|
||||||
|
userService.setAchievement("alex",
|
||||||
|
"Starting off", true);
|
||||||
|
assertEquals(true, userService
|
||||||
|
.getAchievement("alex", "Starting off"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAchievementTest() {
|
||||||
|
assertThrows(ApplicationException.class, () -> userService.getAchievement("alex", "hello"));
|
||||||
|
assertEquals(false, userService.getAchievement("alex", "Starting off"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAchievementsTest() {
|
||||||
|
assertEquals(AllAchievements.getDefaults(), userService.getAchievements("alex"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||