Compare commits
153 Commits
v0.2
...
add/more_a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
377db10f13 | ||
|
|
50fb2078b0 | ||
|
|
123a767a75 | ||
|
|
e0e6744c95 | ||
|
|
cfc238af73 | ||
|
|
78e050751f | ||
|
|
37d43c8247 | ||
|
|
a704522a63 | ||
|
|
cefc4d2b4b | ||
|
|
222489a316 | ||
|
|
4b949db919 | ||
|
|
c8cbb25f5d | ||
|
|
5653800d47 | ||
|
|
c8d5dd99ae | ||
|
|
6d7e73586f | ||
|
|
12ca633461 | ||
|
|
a715babcd9 | ||
|
|
7b6b8ead65 | ||
|
|
a206625082 | ||
|
|
425550c922 | ||
|
|
e6ecda5471 | ||
|
|
f6f74cd2aa | ||
|
|
d03deace57 | ||
|
|
4dd02649b8 | ||
|
|
9fd3b1cf5b | ||
|
|
9fc42247da | ||
|
|
fb22937864 | ||
|
|
dc432df120 | ||
|
|
a6a52688f2 | ||
|
|
ae7e36f757 | ||
|
|
917d3a64bb | ||
|
|
92ff0073e8 | ||
|
|
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 | ||
|
|
9ab4439f70 | ||
|
|
47c46b5458 | ||
|
|
02253cb645 | ||
|
|
b92e302f8b | ||
|
|
67b97eb331 | ||
|
|
daa1c838b4 | ||
|
|
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
|
||||
- .gradle
|
||||
|
||||
# Code coverage badge
|
||||
#deploy:
|
||||
# stage: code-coverage
|
||||
# script:
|
||||
# - gradle clean check
|
||||
# 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/'
|
||||
30
README.md
@@ -1,35 +1,33 @@
|
||||
# Greenify
|
||||
# Greenify
|
||||
The easiest way to save CO2 and help the environment! Enter your activities and find out your carbon footprint.
|
||||

|
||||

|
||||
|
||||
## Badges
|
||||
[](https://gitlab.ewi.tudelft.nl/cse1105/2018-2019/oopp-group-43/template)
|
||||
|
||||
## Getting started
|
||||
You can install greenify with gradle, if you already have gradle on your machine, run:
|
||||
You can run greenify with gradle. To start the server, run:
|
||||
|
||||
```
|
||||
gradle install something tralala
|
||||
```
|
||||
|
||||
Do you not have gradle on your machine, run:
|
||||
|
||||
```
|
||||
./gradlew install something tralala
|
||||
cd <FILE-LOCATION>/greenify/src/server
|
||||
gradle build
|
||||
gradle bootrun
|
||||
```
|
||||
|
||||
With the following you can start the application
|
||||
|
||||
```
|
||||
gradle greenify bootrun
|
||||
```
|
||||
|
||||
or without gradle on your device:
|
||||
|
||||
```
|
||||
./gradlew greenify bootrun
|
||||
cd <FILE-LOCATION>/greenify/src/client
|
||||
gradle build
|
||||
gradle bootrun
|
||||
```
|
||||
|
||||
## Running the tests
|
||||
The tests cover all non-GUI code:
|
||||
|
||||
```
|
||||
cd <FILE-LOCATION>/greenify
|
||||
gradle check
|
||||
```
|
||||
|
||||
|
||||
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;
|
||||
|
||||
import javafx.beans.property.SimpleFloatProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
public class Friend {
|
||||
|
||||
private SimpleStringProperty friend;
|
||||
private SimpleFloatProperty score;
|
||||
private SimpleDoubleProperty score;
|
||||
|
||||
public Friend(String friend, Float friendScore) {
|
||||
public Friend(String friend, Double friendScore) {
|
||||
this.friend = new SimpleStringProperty(friend);
|
||||
this.score = new SimpleFloatProperty(friendScore);
|
||||
this.score = new SimpleDoubleProperty(friendScore);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ public class Friend {
|
||||
this.friend = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
public Float getScore() {
|
||||
public Double getScore() {
|
||||
return score.get();
|
||||
}
|
||||
|
||||
public void setScore(Float score) {
|
||||
this.score = new SimpleFloatProperty(score);
|
||||
public void setScore(Double score) {
|
||||
this.score = new SimpleDoubleProperty(score);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
92
src/Client/src/main/java/greenify/client/Hints.java
Normal file
@@ -0,0 +1,92 @@
|
||||
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 it will 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 rainforest 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("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 whole year!");
|
||||
this.hints.add("27,000 trees are cut down every day so we can have toilet paper.");
|
||||
this.hints.add("Recycle glass bottles! A glass bottle made now 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. Save some energy!");
|
||||
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 and won't have a lot of unused bags at home!");
|
||||
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. "
|
||||
+ "That is a lot of jobs");
|
||||
this.hints.add("You can use LED lights in your home to save energy! "
|
||||
+ "They make light from about 85% of their energy");
|
||||
this.hints.add("If you isolate your home well, it will be warmer, "
|
||||
+ "and you'll save energy as well! No need to wear sweaters anymore");
|
||||
this.hints.add("Do you have leftovers? Donate them to food kitchens."
|
||||
+ " This way you won't waste"
|
||||
+ " food, and you'll help a lot of 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 disposable cups!");
|
||||
this.hints.add("When shopping, look for products with minimal to no packaging, "
|
||||
+ "or 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, you'll get there!");
|
||||
this.hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for "
|
||||
+ "the environment to refill than to buy one every time it's empty.");
|
||||
this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater."
|
||||
+ " 97% is ocean water and 2% is frozen solid in the Arctic, for now.");
|
||||
this.hints.add("For every two million tons of paper and glass, collected in "
|
||||
+ "the Netherlands, close to 90% gets recycled and used to make new products");
|
||||
this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household "
|
||||
+ "equipment, you will automatically be charged a ‘recycling tax’ on it. This is "
|
||||
+ "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch");
|
||||
this.hints.add("Second only to Germany, the Netherlands leads the world in recycling"
|
||||
+ ", with 65 percent of all waste recycled.");
|
||||
this.hints.add("If tbe back of your fridge is dusty, it can increase "
|
||||
+ "energy consumption by 30 per cent.");
|
||||
this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and"
|
||||
+ " lead to increased pollution and higher greenhouse gas emissions.");
|
||||
this.hints.add("Meat production is extremely resource-intensive. "
|
||||
+ "If you gave it up just once a week, you would save the 840 gallons "
|
||||
+ "of fresh water it takes to produce a single serving.");
|
||||
this.hints.add("Plastic bad, very bad.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This seeks out a random hint from the list of strings.
|
||||
* @return the random string 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;
|
||||
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.KeyValue;
|
||||
import javafx.animation.ParallelTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Slider;
|
||||
@@ -24,6 +28,7 @@ import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@Controller
|
||||
@@ -34,6 +39,9 @@ public class CalculatorController {
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
@Autowired
|
||||
ExtraActivityController extraActivityController;
|
||||
|
||||
//navigation panes
|
||||
@FXML
|
||||
private AnchorPane getStartedPane;
|
||||
@@ -139,20 +147,13 @@ public class CalculatorController {
|
||||
//extra pane
|
||||
@FXML
|
||||
private AnchorPane extraPane;
|
||||
@FXML
|
||||
private CheckBox localProduceCheckbox;
|
||||
@FXML
|
||||
private CheckBox bikeCheckbox;
|
||||
@FXML
|
||||
private CheckBox temperatureCheckbox;
|
||||
@FXML
|
||||
private CheckBox solarPanelsCheckbox;
|
||||
|
||||
/**
|
||||
* initializes the window, performs some actions before loading all other things.
|
||||
* it sets the sliders to snap to the ticks.
|
||||
* it adds listeners to all the sliders for updating the label they are associated with.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void initialize() {
|
||||
peopleInHouseholdSlider.setSnapToTicks(true);
|
||||
//add listener to slider for amount of people in household
|
||||
@@ -173,9 +174,9 @@ public class CalculatorController {
|
||||
}
|
||||
});
|
||||
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
|
||||
|
||||
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
@@ -218,6 +219,7 @@ public class CalculatorController {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
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) {
|
||||
Timeline timeline = new Timeline();
|
||||
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
||||
@@ -254,6 +273,7 @@ public class CalculatorController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayGetStarted(ActionEvent event) {
|
||||
addFadeTransAnimation(getStartedPane);
|
||||
getStartedPane.setVisible(true);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -270,7 +290,7 @@ public class CalculatorController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayTravel(ActionEvent event) {
|
||||
addSlideInAnimation(travelPane);
|
||||
addFadeTransAnimation(travelPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(true);
|
||||
homePane.setVisible(false);
|
||||
@@ -287,6 +307,7 @@ public class CalculatorController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayHome(ActionEvent event) {
|
||||
addFadeTransAnimation(homePane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(true);
|
||||
@@ -302,6 +323,7 @@ public class CalculatorController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayFood(ActionEvent event) {
|
||||
addFadeTransAnimation(foodPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -317,6 +339,7 @@ public class CalculatorController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayShopping(ActionEvent event) {
|
||||
addFadeTransAnimation(shoppingPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -331,14 +354,16 @@ public class CalculatorController {
|
||||
* @param event the click of the designated button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayExtra(ActionEvent event) {
|
||||
public void displayExtra(ActionEvent event) throws IOException {
|
||||
addFadeTransAnimation(extraPane);
|
||||
extraPane.getChildren().setAll((Node) Application.load(this.getClass()
|
||||
.getClassLoader().getResource("fxml/extraActivities.fxml")));
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,46 +385,73 @@ public class CalculatorController {
|
||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
}
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
checkTransportLabels();
|
||||
checkHousingLabels();
|
||||
checkFoodLabels();
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
try {
|
||||
extraActivityController.updateExtras();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("continue");
|
||||
}
|
||||
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(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the house labels.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void checkHousingLabels() {
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_electricity_dollars",
|
||||
@@ -430,67 +482,52 @@ public class CalculatorController {
|
||||
"input_footprint_housing_watersewage",
|
||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||
}
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the transport labels.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void checkTransportLabels() {
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
}
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (localProduceCheckbox.isSelected()) {
|
||||
localProduceCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"local_produce", true);
|
||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||
}
|
||||
if (bikeCheckbox.isSelected()) {
|
||||
bikeCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike", true);
|
||||
}
|
||||
if (temperatureCheckbox.isSelected()) {
|
||||
temperatureCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"temperature", true);
|
||||
}
|
||||
if (solarPanelsCheckbox.isSelected()) {
|
||||
solarPanelsCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels", true);
|
||||
}
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,13 @@ package greenify.client.controller;
|
||||
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
||||
import greenify.client.Application;
|
||||
import greenify.client.Friend;
|
||||
import greenify.client.Hints;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.PathTransition;
|
||||
import javafx.animation.ScaleTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
@@ -15,22 +18,28 @@ import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.chart.PieChart;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.effect.ColorAdjust;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Class that controls the dashboard fxml file (the GUI Screen).
|
||||
@@ -45,6 +54,8 @@ public class DashBoardController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
Hints hints = new Hints();
|
||||
|
||||
private FadeTransition fadeTrans; //transition for switching between the different panels
|
||||
|
||||
@FXML
|
||||
@@ -66,6 +77,8 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private Button friendsButton;
|
||||
@FXML
|
||||
private Button logOutButton;
|
||||
@FXML
|
||||
private Line pathLine;
|
||||
@FXML
|
||||
private AnchorPane menuBar;
|
||||
@@ -80,6 +93,10 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private Button addFriendButton;
|
||||
@FXML
|
||||
private Button addExtraActivityButton;
|
||||
@FXML
|
||||
private Button addExtraActivityButton2;
|
||||
@FXML
|
||||
private TableView<Friend> friendsTable;
|
||||
@FXML
|
||||
private TableColumn<Friend, String> friendsColumn;
|
||||
@@ -154,21 +171,58 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private Label snacks;
|
||||
@FXML
|
||||
private CheckBox localProduce;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
private ImageView achieve1;
|
||||
@FXML
|
||||
private CheckBox loweringTemp;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
private ImageView achieve2;
|
||||
@FXML
|
||||
private CheckBox bike;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
private ImageView achieve3;
|
||||
@FXML
|
||||
private CheckBox solarPanels;
|
||||
private ImageView achieve4;
|
||||
@FXML
|
||||
private ImageView achieve5;
|
||||
@FXML
|
||||
private ImageView achieve6;
|
||||
@FXML
|
||||
private Label hintText;
|
||||
@FXML
|
||||
private Label veganMeal;
|
||||
@FXML
|
||||
private Label localProduce;
|
||||
@FXML
|
||||
private Label bike;
|
||||
@FXML
|
||||
private Label publicTrans;
|
||||
@FXML
|
||||
private Label loweringTemp;
|
||||
@FXML
|
||||
private Label solarPanels;
|
||||
@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.
|
||||
* @throws InterruptedException exception if interrupted
|
||||
*/
|
||||
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
|
||||
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
|
||||
//adds the slide transition to the menu bar
|
||||
@@ -178,6 +232,7 @@ public class DashBoardController {
|
||||
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
|
||||
userButton.setSkin(new MyButtonSkin(userButton));
|
||||
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
||||
logOutButton.setSkin(new MyButtonSkin(logOutButton));
|
||||
friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
@@ -186,20 +241,6 @@ public class DashBoardController {
|
||||
developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
if (pieChart != null) {
|
||||
ObservableList<PieChart.Data> pieChartData =
|
||||
FXCollections.observableArrayList(
|
||||
new PieChart.Data("Vegan Meal", 100),
|
||||
new PieChart.Data("Public Transport", 200),
|
||||
new PieChart.Data("Home Temperature", 50),
|
||||
new PieChart.Data("Bike", 75),
|
||||
new PieChart.Data("Local Product", 110),
|
||||
new PieChart.Data("Solar Panel", 300)
|
||||
);
|
||||
pieChart.setTitle("FOOTPRINT DISTRIBUTION");
|
||||
pieChart.setMaxSize(1000, 1000);
|
||||
pieChart.setData(pieChartData);
|
||||
}
|
||||
List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
|
||||
for (int i = 0; i < friendList.size(); i++) {
|
||||
Friend friend = new Friend(friendList.get(i),
|
||||
@@ -208,6 +249,59 @@ public class DashBoardController {
|
||||
}
|
||||
friendsTable.setItems(data);
|
||||
updateLeaderboard();
|
||||
updateAchievements();
|
||||
updatePiechart();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,14 +311,14 @@ public class DashBoardController {
|
||||
public void sortScores(List<String> users) throws InterruptedException {
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
for (int j = 0; j < users.size(); j++) {
|
||||
Float firstScore = userService.getFootprint(users.get(i));
|
||||
Float secondScore = userService.getFootprint(users.get(j));
|
||||
if (i > j && firstScore < secondScore) {
|
||||
Double first = userService.getFootprint(users.get(i));
|
||||
Double second = userService.getFootprint(users.get(j));
|
||||
if (i < j && (first.compareTo(second) < 0)) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
users.set(j, temp);
|
||||
}
|
||||
if (i < j && firstScore > secondScore) {
|
||||
if (i > j && (first.compareTo(second) > 0)) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
users.set(j, temp);
|
||||
@@ -237,12 +331,12 @@ public class DashBoardController {
|
||||
* Sorts the scores of users.
|
||||
* @param users the list of users
|
||||
*/
|
||||
public void sortDiffScores(List<String> users) throws InterruptedException {
|
||||
public List<String> sortDiffScores(List<String> users) throws InterruptedException {
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
for (int j = 0; j < users.size(); j++) {
|
||||
Float firstDiff = userService.getFirstFootprint(users.get(i)) - userService
|
||||
Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService
|
||||
.getFootprint(users.get(i));
|
||||
Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
||||
Double secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
||||
.getFootprint(users.get(j));
|
||||
if (i < j && firstDiff < secondDiff) {
|
||||
String temp = users.get(i);
|
||||
@@ -256,6 +350,7 @@ public class DashBoardController {
|
||||
}
|
||||
}
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,6 +377,7 @@ public class DashBoardController {
|
||||
activitiesPane.setVisible(false);
|
||||
friendsPane.setVisible(false);
|
||||
updateLeaderboard();
|
||||
updateAchievements();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,8 +410,8 @@ public class DashBoardController {
|
||||
electricMiles.setText(inputMap.get("input_footprint_transportation_miles3"));
|
||||
electricMpg.setText(inputMap.get("input_footprint_transportation_mpg3"));
|
||||
publicTransportation.setText(inputMap.get("input_footprint_transportation_publictrans")
|
||||
+ " mi/yr");
|
||||
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " mi/yr");
|
||||
+ " km/yr");
|
||||
airPlane.setText(inputMap.get("input_footprint_transportation_airtotal") + " km/yr");
|
||||
goodShopping.setText(inputMap.get("input_footprint_shopping_goods_total") + " €/mo");
|
||||
serviceShopping.setText(inputMap.get("input_footprint_shopping_services_total") + " €/mo");
|
||||
meat.setText(inputMap.get("input_footprint_shopping_food_meatfisheggs"));
|
||||
@@ -323,33 +419,29 @@ public class DashBoardController {
|
||||
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
|
||||
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
|
||||
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("local_produce")) {
|
||||
localProduce.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("bike")) {
|
||||
bike.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("temperature")) {
|
||||
loweringTemp.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("solar_panels")) {
|
||||
solarPanels.setSelected(true);
|
||||
}
|
||||
Map<String, String> extraMap = userService
|
||||
.getExtraInputs(userService.currentUser.getName());
|
||||
veganMeal.setText(extraMap.get("vegan"));
|
||||
localProduce.setText(extraMap.get("local_produce"));
|
||||
bike.setText(extraMap.get("bike"));
|
||||
publicTrans.setText(extraMap.get("public_transport"));
|
||||
loweringTemp.setText(extraMap.get("temperature"));
|
||||
solarPanels.setText(extraMap.get("solar_panels"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the user profile pane.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void displayUser(ActionEvent event) {
|
||||
public void displayUser(ActionEvent event) throws InterruptedException {
|
||||
System.out.println(userService.currentUser.getName());
|
||||
System.out.println(userService.getFootprint(userService.currentUser.getName()));
|
||||
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
|
||||
firstFootprintLabel.setText("" + userService
|
||||
.getFirstFootprint(userService.currentUser.getName()));
|
||||
Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
||||
Double diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
||||
.getFootprint(userService.currentUser.getName());
|
||||
differenceLabel.setText( "" + diff);
|
||||
differenceLabel.setText( "" + Math.round(diff * 10) / 10.0);
|
||||
usernameLabel.setText("" + userService.currentUser.getName());
|
||||
addFadeTransition(userPane);
|
||||
System.out.println("display user");
|
||||
@@ -357,7 +449,7 @@ public class DashBoardController {
|
||||
userPane.setVisible(true);
|
||||
activitiesPane.setVisible(false);
|
||||
friendsPane.setVisible(false);
|
||||
|
||||
updatePiechart();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,6 +466,40 @@ public class DashBoardController {
|
||||
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
|
||||
public void addSlideTransition(Node node, Line path1) {
|
||||
PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node);
|
||||
@@ -384,6 +510,7 @@ public class DashBoardController {
|
||||
* Opens the calculator.
|
||||
* @throws IOException if the Application doesn't load.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void openCalculator() throws IOException, InterruptedException {
|
||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/calculator.fxml"));
|
||||
@@ -398,7 +525,39 @@ public class DashBoardController {
|
||||
}
|
||||
|
||||
/**
|
||||
* method opend addFriend scene.
|
||||
* This method adds a random hint to the side bar.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public void openAddFriend() throws IOException {
|
||||
@@ -415,32 +574,62 @@ public class DashBoardController {
|
||||
* Leaderboard is updating.
|
||||
* @throws InterruptedException throws exception
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateLeaderboard() throws InterruptedException {
|
||||
List<String> userList = userService.getAllUsers();
|
||||
//global leaderboard
|
||||
globalLeaderboard.getItems().clear();
|
||||
globalLeaderData.removeAll();
|
||||
sortScores(userList);
|
||||
//development leaderboard
|
||||
developmentLeaderboard.getItems().clear();
|
||||
developmentData.removeAll();
|
||||
sortDiffScores(userList);
|
||||
for (int j = 0; j < userList.size(); j++) {
|
||||
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
|
||||
Friend diffUser = new Friend(userList.get(j), userService
|
||||
.getFirstFootprint(userList.get(j))
|
||||
- userService.getFootprint(userList.get(j)));
|
||||
List<String> userList = userService.getAllUsers();
|
||||
sortScores(userList);
|
||||
for (int i = userList.size() - 1; i >= 0; i--) {
|
||||
Friend user = new Friend(userList.get(i), userService.getFootprint(userList.get(i)));
|
||||
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);
|
||||
}
|
||||
globalLeaderboard.setItems(globalLeaderData);
|
||||
developmentLeaderboard.setItems(developmentData);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method updating piechart.
|
||||
* @throws InterruptedException exception
|
||||
*/
|
||||
public void updatePiechart() throws InterruptedException {
|
||||
Map<String, String> resultMap = userService.getResults(userService.currentUser.getName());
|
||||
if (pieChart != null) {
|
||||
ObservableList<PieChart.Data> pieChartData =
|
||||
FXCollections.observableArrayList(
|
||||
new PieChart.Data("Transport",
|
||||
Double.parseDouble(resultMap.get("transport"))),
|
||||
new PieChart.Data("Housing",
|
||||
Double.parseDouble(resultMap.get("housing"))),
|
||||
new PieChart.Data("Food",
|
||||
Double.parseDouble(resultMap.get("food"))),
|
||||
new PieChart.Data("Goods",
|
||||
Double.parseDouble(resultMap.get("goods"))),
|
||||
new PieChart.Data("Services",
|
||||
Double.parseDouble(resultMap.get("services")))
|
||||
);
|
||||
pieChart.setTitle("FOOTPRINT DISTRIBUTION");
|
||||
pieChart.setMaxSize(1000, 1000);
|
||||
pieChart.setData(pieChartData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Friends tables are updating.
|
||||
* @throws InterruptedException throws exception
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateFriends() throws InterruptedException {
|
||||
List<String> wholeList = userService.getFriendNames(userService.currentUser.getName());
|
||||
wholeList.add(userService.currentUser.getName());
|
||||
@@ -453,31 +642,75 @@ public class DashBoardController {
|
||||
friendLeaderboard.getItems().clear();
|
||||
friendLeaderData.removeAll();
|
||||
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
|
||||
.getFootprint(friendList.get(i)));
|
||||
data.add(user);
|
||||
}
|
||||
for (int j = 0; j < wholeList.size(); j++) {
|
||||
Friend diffUser = new Friend(wholeList.get(j),
|
||||
userService.getFirstFootprint(wholeList.get(j))
|
||||
- userService.getFootprint(wholeList.get(j)));
|
||||
double diff = Math.round((userService.getFirstFootprint(wholeList.get(j))
|
||||
- userService.getFootprint(wholeList.get(j))) * 10) / 10.0;
|
||||
Friend diffUser = new Friend(wholeList.get(j), diff);
|
||||
friendLeaderData.add(diffUser);
|
||||
}
|
||||
friendsTable.setItems(data);
|
||||
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
|
||||
public class MyButtonSkin extends ButtonSkin {
|
||||
private class MyButtonSkin extends ButtonSkin {
|
||||
/**
|
||||
* adds a skin and scale animation to a button.
|
||||
* the scale transition is for hovering over it so it then scales up
|
||||
* and scales down when you stop hovering over it.
|
||||
* @param button the button to add the animation to
|
||||
*/
|
||||
public MyButtonSkin(Button button) {
|
||||
private MyButtonSkin(Button button) {
|
||||
//inherit the button properties
|
||||
super(button);
|
||||
//transition to scale up on hover
|
||||
@@ -493,6 +726,45 @@ public class DashBoardController {
|
||||
scaleDown.setToX(1.0);
|
||||
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,368 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.ParallelTransition;
|
||||
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.Node;
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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.setFromX(-800);
|
||||
trans.setToX(0);
|
||||
ParallelTransition par = new ParallelTransition();
|
||||
par.setNode(node);
|
||||
par.getChildren().addAll(fade, trans);
|
||||
par.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the vegetarian meal section.
|
||||
* @param event the click of the designated button
|
||||
*/
|
||||
public void displayVeganMeal(ActionEvent event) {
|
||||
// System.out.println("display vm");
|
||||
addFadeTransAnimation(veganMealPane);
|
||||
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");
|
||||
addFadeTransAnimation(bikePane);
|
||||
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");
|
||||
addFadeTransAnimation(temperaturePane);
|
||||
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");
|
||||
addFadeTransAnimation(solarPanelPane);
|
||||
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) {
|
||||
addFadeTransAnimation(localProducePane);
|
||||
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) {
|
||||
addFadeTransAnimation(publicTransportPane);
|
||||
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 (InterruptedException 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 (NullPointerException 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 (NullPointerException 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
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController dashBoardController;
|
||||
|
||||
@FXML
|
||||
private Button addButton;
|
||||
@FXML
|
||||
@@ -52,7 +55,11 @@ public class FriendController {
|
||||
//add friend to the current user
|
||||
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
||||
//close the register window after the user has entered all the credentials
|
||||
String friendName = userNameText.getText();
|
||||
Stage current = (Stage) owner;
|
||||
dashBoardController.updateAchievements();
|
||||
current.close();
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Friend added!",
|
||||
userNameText.getText() + " is now your friend!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.KeyValue;
|
||||
import javafx.animation.ParallelTransition;
|
||||
import javafx.animation.ScaleTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.animation.TranslateTransition;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
@@ -16,7 +21,6 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
@@ -29,6 +33,7 @@ import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
@@ -39,12 +44,11 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@Controller
|
||||
public class RegisterWindowController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
ExtraActivityController extraActivityController;
|
||||
|
||||
//navigation panes
|
||||
@FXML
|
||||
@@ -151,15 +155,6 @@ public class RegisterWindowController {
|
||||
//extra pane
|
||||
@FXML
|
||||
private AnchorPane extraPane;
|
||||
@FXML
|
||||
private CheckBox localProduceCheckbox;
|
||||
@FXML
|
||||
private CheckBox bikeCheckbox;
|
||||
@FXML
|
||||
private CheckBox temperatureCheckbox;
|
||||
@FXML
|
||||
private CheckBox solarPanelsCheckbox;
|
||||
|
||||
@FXML
|
||||
private TextField userNameText;
|
||||
@FXML
|
||||
@@ -180,6 +175,8 @@ public class RegisterWindowController {
|
||||
addSlideAnimation(1100, passwordField, 300);
|
||||
TimeUnit.MILLISECONDS.sleep(300);
|
||||
addSlideAnimation(1100, passwordField2, -420);
|
||||
|
||||
signUpButton.setSkin(new registerButtonSkin(signUpButton));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +225,13 @@ public class RegisterWindowController {
|
||||
}
|
||||
|
||||
//register the user with the provided username and password
|
||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||
try {
|
||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||
} catch (HttpClientErrorException 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
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
@@ -263,9 +266,9 @@ public class RegisterWindowController {
|
||||
}
|
||||
});
|
||||
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le");
|
||||
|
||||
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
@@ -308,6 +311,7 @@ public class RegisterWindowController {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@@ -329,6 +333,23 @@ public class RegisterWindowController {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a fade transition to the given node.
|
||||
* @param node the node to add the transition to
|
||||
*/
|
||||
public void addFadeTransAnimation(Node node) {
|
||||
FadeTransition fade = new FadeTransition(Duration.millis(350), node);
|
||||
fade.setFromValue(0);
|
||||
fade.setToValue(1.0);
|
||||
TranslateTransition trans = new TranslateTransition(Duration.millis(350), node);
|
||||
trans.setFromY(800);
|
||||
trans.setToY(0);
|
||||
ParallelTransition par = new ParallelTransition();
|
||||
par.setNode(travelPane);
|
||||
par.getChildren().addAll(fade, trans);
|
||||
par.play();
|
||||
}
|
||||
|
||||
private void addSlideInAnimation(Node node) {
|
||||
Timeline timeline = new Timeline();
|
||||
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
||||
@@ -344,6 +365,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayGetStarted(ActionEvent event) {
|
||||
addFadeTransAnimation(getStartedPane);
|
||||
getStartedPane.setVisible(true);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -359,7 +381,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayTravel(ActionEvent event) {
|
||||
addSlideInAnimation(travelPane);
|
||||
addFadeTransAnimation(travelPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(true);
|
||||
homePane.setVisible(false);
|
||||
@@ -376,6 +398,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayHome(ActionEvent event) {
|
||||
addFadeTransAnimation(homePane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(true);
|
||||
@@ -391,6 +414,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayFood(ActionEvent event) {
|
||||
addFadeTransAnimation(foodPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -406,6 +430,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayShopping(ActionEvent event) {
|
||||
addFadeTransAnimation(shoppingPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -420,7 +445,10 @@ public class RegisterWindowController {
|
||||
* @param event the click of the designated button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayExtra(ActionEvent event) {
|
||||
public void displayExtra(ActionEvent event) throws IOException {
|
||||
addFadeTransAnimation(extraPane);
|
||||
extraPane.getChildren().setAll((Node) Application.load(this.getClass()
|
||||
.getClassLoader().getResource("fxml/extraActivities.fxml")));
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -449,46 +477,70 @@ public class RegisterWindowController {
|
||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
}
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
checkTransportLabels();
|
||||
checkHousingLabels();
|
||||
checkFoodLabels();
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
try {
|
||||
extraActivityController.updateExtras();
|
||||
} catch (NullPointerException 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(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the housing labels.
|
||||
*/
|
||||
public void checkHousingLabels() {
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_electricity_dollars",
|
||||
@@ -519,63 +571,84 @@ public class RegisterWindowController {
|
||||
"input_footprint_housing_watersewage",
|
||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||
}
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (localProduceCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"local_produce", true);
|
||||
}
|
||||
if (bikeCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike", true);
|
||||
}
|
||||
if (temperatureCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"temperature", true);
|
||||
}
|
||||
if (solarPanelsCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels", true);
|
||||
}
|
||||
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the transport labels.
|
||||
*/
|
||||
public void checkTransportLabels() {
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class registerButtonSkin extends ButtonSkin {
|
||||
public registerButtonSkin(Button button) {
|
||||
super(button);
|
||||
|
||||
ScaleTransition scaleUp = new ScaleTransition(Duration.millis(140));
|
||||
scaleUp.setToX(1.2);
|
||||
scaleUp.setToY(1.2);
|
||||
scaleUp.setNode(button);
|
||||
button.setOnMouseEntered(e -> scaleUp.playFromStart());
|
||||
|
||||
ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
|
||||
|
||||
scaleMiddleDown.setToX(1.1);
|
||||
scaleMiddleDown.setToY(1.1);
|
||||
scaleMiddleDown.setNode(button);
|
||||
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
|
||||
|
||||
ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
|
||||
|
||||
scaleMiddleUp.setToX(1.2);
|
||||
scaleMiddleUp.setToY(1.2);
|
||||
scaleMiddleUp.setNode(button);
|
||||
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
|
||||
|
||||
ScaleTransition scaleDown = new ScaleTransition(Duration.millis(200));
|
||||
scaleDown.setToX(1.0);
|
||||
scaleDown.setToY(1.0);
|
||||
scaleDown.setNode(button);
|
||||
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import com.sun.javafx.scene.control.skin.ButtonSkin;
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.ScaleTransition;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
@@ -12,8 +14,10 @@ import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
@@ -35,6 +39,10 @@ public class UserController {
|
||||
@FXML
|
||||
private Button signUpButton;
|
||||
|
||||
public void initialize() {
|
||||
loginButton.setSkin(new LoginButtonSkin(loginButton));
|
||||
signUpButton.setSkin(new LoginButtonSkin(signUpButton));
|
||||
}
|
||||
/**
|
||||
* Handles when the user clicks on the login button.
|
||||
* it checks if the username and password fields are filled
|
||||
@@ -65,7 +73,13 @@ public class UserController {
|
||||
System.out.println("Password is " + passwordField.getText());
|
||||
}
|
||||
//log the user in with the userService method
|
||||
userService.loginUser(usernameField.getText(), passwordField.getText());
|
||||
try {
|
||||
userService.loginUser(usernameField.getText(), passwordField.getText());
|
||||
} catch (HttpClientErrorException ex) {
|
||||
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
|
||||
"Your username or password is incorrect!");
|
||||
return;
|
||||
}
|
||||
Stage current = (Stage) owner;
|
||||
//after logging in, close the login window
|
||||
current.close();
|
||||
@@ -129,10 +143,47 @@ public class UserController {
|
||||
Parent registerWindow = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/RegisterWindow.fxml"));
|
||||
Scene registerScene = new Scene(registerWindow);
|
||||
registerScene.getStylesheets().add(this.getClass().getClassLoader()
|
||||
.getResource("stylesheets/registerWindowStyle.css").toExternalForm());
|
||||
Stage registerStage = new Stage();
|
||||
registerStage.setScene(registerScene);
|
||||
registerStage.setTitle("Enter register credentials");
|
||||
registerStage.show();
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class LoginButtonSkin extends ButtonSkin {
|
||||
public LoginButtonSkin(Button button) {
|
||||
super(button);
|
||||
ScaleTransition scaleUp = new ScaleTransition(Duration.millis(140));
|
||||
scaleUp.setToX(1.1);
|
||||
scaleUp.setToY(1.1);
|
||||
scaleUp.setNode(button);
|
||||
button.setOnMouseEntered(e -> scaleUp.playFromStart());
|
||||
|
||||
ScaleTransition scaleMiddleDown = new ScaleTransition(Duration.millis(50));
|
||||
scaleMiddleDown.setFromX(1.1);
|
||||
scaleMiddleDown.setFromY(1.1);
|
||||
scaleMiddleDown.setToX(1.05);
|
||||
scaleMiddleDown.setToY(1.05);
|
||||
scaleMiddleDown.setNode(button);
|
||||
button.setOnMousePressed(e -> scaleMiddleDown.playFromStart());
|
||||
|
||||
ScaleTransition scaleMiddleUp = new ScaleTransition(Duration.millis(50));
|
||||
scaleMiddleUp.setFromX(1.05);
|
||||
scaleMiddleUp.setFromY(1.05);
|
||||
scaleMiddleUp.setToX(1.1);
|
||||
scaleMiddleUp.setToY(1.1);
|
||||
scaleMiddleUp.setNode(button);
|
||||
button.setOnMouseReleased(e -> scaleMiddleUp.playFromStart());
|
||||
|
||||
ScaleTransition scaleDown = new ScaleTransition(Duration.millis(200));
|
||||
scaleDown.setToX(1.0);
|
||||
scaleDown.setToY(1.0);
|
||||
scaleDown.setNode(button);
|
||||
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,13 +109,13 @@ public class UserService {
|
||||
* @param value value of the input
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateExtraInput(String name, String inputName, Boolean value) {
|
||||
public void updateExtraInput(String name, String inputName, String value) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
|
||||
.queryParam("name", name)
|
||||
.queryParam("inputName", inputName)
|
||||
.queryParam("value",value);
|
||||
.queryParam("value", value);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||
@@ -128,15 +128,16 @@ public class UserService {
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Float getFootprint(String name) {
|
||||
public double getFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float result = this.restTemplate.getForObject(builder
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
double result = Math.round(footprint * 10) / 10.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ public class UserService {
|
||||
* @param name name of the user
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
public Float getFirstFootprint(String name) {
|
||||
public double getFirstFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
|
||||
@@ -154,7 +155,8 @@ public class UserService {
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
return footprint;
|
||||
double result = Math.round(footprint * 10) / 10.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,6 +232,24 @@ public class UserService {
|
||||
.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.
|
||||
* @param name the username of the current user.
|
||||
@@ -252,18 +272,52 @@ public class UserService {
|
||||
* @param name the username of the current user.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Map<String, Boolean> getExtraInputs(String name) {
|
||||
public Map<String, String> getExtraInputs(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
|
||||
.queryParam("name", name);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build()
|
||||
Map<String, String> result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), Map.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 results of a user.
|
||||
* @param name name of the user
|
||||
* @return Map with all results
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Map<String, String> getResults(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getResults")
|
||||
.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.
|
||||
*/
|
||||
@@ -278,4 +332,4 @@ public class UserService {
|
||||
.build().encode().toUri(), List.class);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
|
||||
<children>
|
||||
@@ -178,7 +165,7 @@
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<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 size="13.0" />
|
||||
</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" />
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<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 size="13.0" />
|
||||
</font>
|
||||
@@ -197,7 +184,7 @@
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<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 size="13.0" />
|
||||
</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" />
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<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 size="13.0" />
|
||||
</font>
|
||||
@@ -236,7 +223,7 @@
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<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 size="13.0" />
|
||||
</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" />
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<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 size="13.0" />
|
||||
</font>
|
||||
@@ -285,7 +272,7 @@
|
||||
</font></TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||
<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 size="16.0" />
|
||||
</font>
|
||||
@@ -294,7 +281,7 @@
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||
<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 size="16.0" />
|
||||
</font>
|
||||
|
||||
@@ -23,12 +23,7 @@
|
||||
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" />
|
||||
<Button fx:id="signUpButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" />
|
||||
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
|
||||
<Hyperlink alignment="CENTER" layoutX="384.0" layoutY="301.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="#3db25a" textOverrun="LEADING_WORD_ELLIPSIS">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="18.0" />
|
||||
</font>
|
||||
</Hyperlink>
|
||||
<Text fill="#23773d" layoutX="20.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
|
||||
<Text fill="#23773d" layoutX="20.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not a member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
|
||||
<font>
|
||||
<Font name="Californian FB" size="20.0" />
|
||||
</font>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
@@ -24,7 +25,7 @@
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
|
||||
<Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" text="Sign up!" textFill="#c4eec9">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<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 size="13.0" />
|
||||
</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" />
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<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 size="13.0" />
|
||||
</font>
|
||||
@@ -197,7 +197,7 @@
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<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 size="13.0" />
|
||||
</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" />
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<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 size="13.0" />
|
||||
</font>
|
||||
@@ -236,7 +236,7 @@
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<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 size="13.0" />
|
||||
</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" />
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<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 size="13.0" />
|
||||
</font>
|
||||
@@ -285,7 +285,7 @@
|
||||
</font></TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||
<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 size="16.0" />
|
||||
</font>
|
||||
@@ -294,7 +294,7 @@
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||
<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 size="16.0" />
|
||||
</font>
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
<?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.control.Button?>
|
||||
<?import javafx.scene.control.CheckBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?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>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
@@ -44,10 +54,36 @@
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</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="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 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="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>
|
||||
<Line endX="104.0" layoutX="108.0" layoutY="88.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
|
||||
</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">
|
||||
<children>
|
||||
@@ -129,32 +165,32 @@
|
||||
</Label>
|
||||
<Pane layoutX="290.0" layoutY="130.0" prefHeight="342.0" prefWidth="230.0" style="-fx-background-color: #f4fff4;">
|
||||
<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 size="14.0" />
|
||||
</font>
|
||||
</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 size="14.0" />
|
||||
</font>
|
||||
</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 size="14.0" />
|
||||
</font>
|
||||
</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 size="14.0" />
|
||||
</font>
|
||||
</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 size="14.0" />
|
||||
</font>
|
||||
</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 size="14.0" />
|
||||
</font>
|
||||
@@ -205,74 +241,99 @@
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Pane layoutX="545.0" layoutY="130.0" prefHeight="342.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
|
||||
<Pane layoutX="545.0" layoutY="130.0" prefHeight="255.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="26.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="14.0" prefHeight="46.0" prefWidth="115.0" text="Meat fish eggs">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="90.0" prefHeight="46.0" prefWidth="115.0" text="Grains/baked foods" textAlignment="CENTER">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="60.0" prefHeight="46.0" prefWidth="115.0" text="Grains/baked foods" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="154.0" prefHeight="46.0" prefWidth="115.0" text="Dairy">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="106.0" prefHeight="46.0" prefWidth="115.0" text="Dairy">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="218.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="152.0" prefHeight="46.0" prefWidth="115.0" text="Fruits vegetables">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="282.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="198.0" prefHeight="46.0" prefWidth="115.0" text="Snacks drinks">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="meat" layoutX="171.0" layoutY="41.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="grains" layoutX="171.0" layoutY="105.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="dairy" layoutX="171.0" layoutY="169.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="fruits" layoutX="171.0" layoutY="233.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="snacks" layoutX="171.0" layoutY="297.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="meat" layoutX="171.0" layoutY="29.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="grains" layoutX="171.0" layoutY="75.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="dairy" layoutX="171.0" layoutY="121.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="fruits" layoutX="171.0" layoutY="167.0" styleClass="activityField" text="Label" />
|
||||
<Label fx:id="snacks" layoutX="171.0" layoutY="213.0" styleClass="activityField" text="Label" />
|
||||
</children>
|
||||
</Pane>
|
||||
<Label alignment="CENTER" layoutX="545.0" layoutY="488.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222">
|
||||
<Label alignment="CENTER" layoutX="545.0" layoutY="385.0" prefHeight="32.0" prefWidth="255.0" text="Extras!" textAlignment="CENTER" textFill="#107222">
|
||||
<font>
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Pane layoutX="545.0" layoutY="520.0" prefHeight="129.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
|
||||
<Pane layoutX="545.0" layoutY="412.0" prefHeight="238.0" prefWidth="255.0" style="-fx-background-color: #f4fff4;">
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="7.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.0" layoutY="56.0" prefHeight="27.0" prefWidth="183.0" text="Buying local produce">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
|
||||
<Label fx:id="localProduce" layoutX="189.0" layoutY="56.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.0" layoutY="92.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
|
||||
<Label fx:id="bike" layoutX="189.0" layoutY="92.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="164.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
|
||||
<Label fx:id="loweringTemp" layoutX="188.0" layoutY="164.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="200.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="solarPanels" layoutX="188.0" layoutY="200.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="13.0" layoutY="128.0" prefHeight="27.0" prefWidth="183.0" text="Using public transport">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="publicTrans" layoutX="188.0" layoutY="128.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="11.0" layoutY="20.0" prefHeight="27.0" prefWidth="183.0" text="Eating vegetarian meal">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="veganMeal" layoutX="188.0" layoutY="20.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
</children>
|
||||
</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">
|
||||
<children>
|
||||
<Text layoutX="94.0" layoutY="72.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Your Profile" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
||||
@@ -400,14 +461,14 @@
|
||||
</Button>
|
||||
<TableView fx:id="globalLeaderboard" layoutX="56.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="globalUser" prefWidth="75.0" text="User" />
|
||||
<TableColumn fx:id="globalScore" prefWidth="124.0" text="Score" />
|
||||
<TableColumn fx:id="globalUser" prefWidth="121.0" text="User" />
|
||||
<TableColumn fx:id="globalScore" prefWidth="78.0" text="Score" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<TableView fx:id="developmentLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="developmentUser" prefWidth="75.0" text="User" />
|
||||
<TableColumn fx:id="developmentScore" prefWidth="124.0" text="Score" />
|
||||
<TableColumn fx:id="developmentUser" prefWidth="126.0" text="User" />
|
||||
<TableColumn fx:id="developmentScore" prefWidth="73.0" text="Score" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616">
|
||||
@@ -420,6 +481,95 @@
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</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>
|
||||
</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">
|
||||
|
||||
262
src/Client/src/main/resources/fxml/extraActivities.fxml
Normal file
@@ -0,0 +1,262 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?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 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>
|
||||
<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>
|
||||
</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: 26 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 |
@@ -2,4 +2,12 @@
|
||||
-fx-background-color: #005e07;
|
||||
-fx-text-fill: #c4eec9;
|
||||
-fx-font-weight: bold;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
-fx-background-color: #027009;
|
||||
}
|
||||
|
||||
.button:pressed {
|
||||
-fx-background-color: #1ba023;
|
||||
}
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
.slider {
|
||||
-show-value-on-interaction: true;
|
||||
-fx-text-fill: red;
|
||||
}
|
||||
|
||||
.km-yearBox {
|
||||
|
||||
@@ -53,8 +53,15 @@
|
||||
-fx-border-color: #497251;
|
||||
}
|
||||
|
||||
#calculateFootPrintButton:pressed {
|
||||
-fx-border-color: #497251;
|
||||
#logOutButton {
|
||||
-fx-background-color: #5a635c;
|
||||
-fx-text-fill: #e3efe4;
|
||||
}
|
||||
#logOutButton:hover {
|
||||
-fx-background-color: #e08f8f;
|
||||
}
|
||||
#logOutButton:pressed {
|
||||
-fx-background-color: #ba3737;
|
||||
}
|
||||
|
||||
/*friends table*/
|
||||
@@ -85,5 +92,16 @@
|
||||
-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 static org.junit.Assert.assertEquals;
|
||||
|
||||
import greenify.client.Friend;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
44
src/Client/src/test/java/HintsTest.java
Normal file
@@ -0,0 +1,44 @@
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
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 "
|
||||
+ "every day so we can have toilet paper."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomHintTest() {
|
||||
Hints test = new Hints();
|
||||
String random = test.randomHint();
|
||||
assertTrue(test.hints.contains(random));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hintsContainsTestTwo() {
|
||||
Hints test = new Hints();
|
||||
assertTrue(test.hints.contains("Plastic bad, very bad."));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void hintsNotNullTest() {
|
||||
Hints test = new Hints();
|
||||
assertNotNull(test.hints);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import greenify.client.rest.UserService;
|
||||
import greenify.common.UserDto;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -33,7 +35,7 @@ public class UserServiceTest {
|
||||
.thenReturn(testUser);
|
||||
|
||||
UserDto user = userService.registerUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +45,7 @@ public class UserServiceTest {
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDto user = userService.loginUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,8 +54,8 @@ public class UserServiceTest {
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
double result = (5 * 10) / 10.0;
|
||||
assertTrue(result == userService.getFootprint("Eric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,8 +64,8 @@ public class UserServiceTest {
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
double result = (5 * 10) / 10.0;
|
||||
assertTrue(result == userService.getFirstFootprint("Eric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +75,7 @@ public class UserServiceTest {
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +85,7 @@ public class UserServiceTest {
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +96,7 @@ public class UserServiceTest {
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getFriendNames("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +107,7 @@ public class UserServiceTest {
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getAllUsers();
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,18 +118,18 @@ public class UserServiceTest {
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, String> result = userService.getInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraInputsTest() throws Exception {
|
||||
Map<String, Boolean> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", true);
|
||||
Map<String, String> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", "5");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, Boolean> result = userService.getExtraInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
Map<String, String> result = userService.getExtraInputs("Eric");
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,8 +140,8 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void setExtraInputTest() throws Exception {
|
||||
userService.updateExtraInput("Eric", "solar_panels", true);
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
|
||||
userService.updateExtraInput("Eric", "solar_panels", "8");
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", "8");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,6 +149,26 @@ public class UserServiceTest {
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResultsTest() throws Exception {
|
||||
userService.getResults("mika");
|
||||
Mockito.verify(userService).getResults("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.
|
||||
* @return the map of default values
|
||||
*/
|
||||
public static Map<String, Boolean> getExtraValues() {
|
||||
Map<String, Boolean> map = new HashMap<String, Boolean>() { };
|
||||
map.put("local_produce", false);
|
||||
map.put("bike", false);
|
||||
map.put("temperature", false);
|
||||
map.put("solar_panels", false);
|
||||
public static Map<String, String> getExtraValues() {
|
||||
Map<String, String> map = new HashMap<String, String>() { };
|
||||
map.put("vegan", "0");
|
||||
map.put("local_produce", "0");
|
||||
map.put("bike", "0");
|
||||
map.put("public_transport", "0");
|
||||
map.put("temperature", "0");
|
||||
map.put("solar_panels", "0");
|
||||
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;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.server.AllAchievements;
|
||||
import greenify.server.InputValidator;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -45,11 +46,14 @@ public class User {
|
||||
private Map<String, String> footPrintInputs = new HashMap<>();
|
||||
|
||||
@ElementCollection
|
||||
private Map<String, Boolean> extraInputs = new HashMap<>();
|
||||
private Map<String, String> extraInputs = new HashMap<>();
|
||||
|
||||
@ManyToMany
|
||||
private List<User> friends;
|
||||
|
||||
@ElementCollection
|
||||
private Map<String, Boolean> achievements;
|
||||
|
||||
public User() {}
|
||||
|
||||
/**
|
||||
@@ -65,6 +69,7 @@ public class User {
|
||||
this.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||
this.setExtraInputs(InputValidator.getExtraValues());
|
||||
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.
|
||||
* @return extra inputs of the user
|
||||
*/
|
||||
public Map<String, Boolean> getExtraInputs() {
|
||||
public Map<String, String> getExtraInputs() {
|
||||
return extraInputs;
|
||||
}
|
||||
|
||||
@@ -175,7 +180,7 @@ public class User {
|
||||
* This method sets the extra 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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* @return the JSON form of the object.
|
||||
|
||||
@@ -63,7 +63,7 @@ public class UserController {
|
||||
@RequestMapping("/setExtraInput")
|
||||
public void setExtraInput(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "inputName") String inputName,
|
||||
@RequestParam(value = "value") Boolean value) {
|
||||
@RequestParam(value = "value") String value) {
|
||||
userService.setExtraInput(name, inputName, value);
|
||||
}
|
||||
|
||||
@@ -150,18 +150,50 @@ public class UserController {
|
||||
* This method gets the extra inputs map of the user.
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds friend for a user.
|
||||
* This method adds a friend to a user.
|
||||
* @param name name of the user
|
||||
*
|
||||
* @param friend the name of the user you want to add as a friend.
|
||||
*/
|
||||
@RequestMapping("/addFriend")
|
||||
public void addFriend(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "friend") String friend) {
|
||||
@RequestParam(value = "friend") String 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the result for schema.
|
||||
* @param name name of the user
|
||||
* @return map of all results of the user
|
||||
*/
|
||||
@RequestMapping("/getResults")
|
||||
public Map<String, String> getResults(@RequestParam(value = "name") String name) {
|
||||
return userService.getResults(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -72,21 +73,79 @@ public class CalculatorService {
|
||||
* @return the footprint of the user
|
||||
*/
|
||||
public Float calculateFootprint(User user) {
|
||||
Float footprint = invokeExternalService(user.getFootPrintInputs());
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds extra input to the user.
|
||||
* @param user name of the user
|
||||
*/
|
||||
public void addExtras(User user) {
|
||||
if (user.getExtraInputs().get("local_produce")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
} else if (user.getExtraInputs().get("bike")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
} else if (user.getExtraInputs().get("temperature")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
} else if (user.getExtraInputs().get("solar_panels")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
Map<String, String> inputs = user.getFootPrintInputs();
|
||||
Float netPublic = Float.parseFloat(user.getFootPrintInputs()
|
||||
.get("input_footprint_transportation_publictrans"))
|
||||
+ Float.parseFloat(user.getExtraInputs().get("public_transport"));
|
||||
Float netCar = Float.parseFloat(user.getFootPrintInputs()
|
||||
.get("input_footprint_transportation_miles1"))
|
||||
- Float.parseFloat(user.getExtraInputs().get("public_transport"))
|
||||
- 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);
|
||||
}
|
||||
|
||||
public Map<String, String> getResults(Map<String, String> map) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
headers.set("app_id", "a98272e3");
|
||||
headers.set("app_key", "b9167c4918cb2b3143614b595065d83b");
|
||||
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
|
||||
UriComponentsBuilder builder =
|
||||
UriComponentsBuilder.fromHttpUrl("https://apis.berkeley.edu/coolclimate/footprint");
|
||||
for (String inputId : map.keySet()) {
|
||||
builder = builder.queryParam(inputId, map.get(inputId));
|
||||
}
|
||||
ResponseEntity<String> response = restTemplate
|
||||
.exchange(builder.build().encode().toUri(), HttpMethod.GET,
|
||||
entity, String.class);
|
||||
String transport = response.getBody().substring(Objects.requireNonNull(response.getBody())
|
||||
.indexOf("<result_transport_total>")
|
||||
+ 24, response.getBody().indexOf("</result_transport_total>"));
|
||||
String housing = response.getBody().substring(Objects.requireNonNull(response.getBody())
|
||||
.indexOf("<result_housing_total>")
|
||||
+ 22, response.getBody().indexOf("</result_housing_total>"));
|
||||
String food = response.getBody().substring(Objects.requireNonNull(response.getBody())
|
||||
.indexOf("<result_food_total>")
|
||||
+ 19, response.getBody().indexOf("</result_food_total>"));
|
||||
String goods = response.getBody().substring(Objects.requireNonNull(response.getBody())
|
||||
.indexOf("<result_goods_total>")
|
||||
+ 20, response.getBody().indexOf("</result_goods_total>"));
|
||||
String services = response.getBody().substring(Objects.requireNonNull(response.getBody())
|
||||
.indexOf("<result_services_total>")
|
||||
+ 23, response.getBody().indexOf("</result_services_total>"));
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
resultMap.put("transport", transport);
|
||||
resultMap.put("housing", housing);
|
||||
resultMap.put("food", food);
|
||||
resultMap.put("goods", goods);
|
||||
resultMap.put("services", services);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package greenify.server.service;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.common.UserDto;
|
||||
import greenify.server.AllAchievements;
|
||||
import greenify.server.InputValidator;
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
@@ -19,6 +20,9 @@ public class UserService {
|
||||
@Autowired
|
||||
CalculatorService calculatorService;
|
||||
|
||||
@Autowired
|
||||
AchievementService achievementService;
|
||||
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
|
||||
@@ -37,6 +41,7 @@ public class UserService {
|
||||
user.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||
Float footprint = calculatorService.calculateFootprint(user);
|
||||
user.setFootPrint(footprint);
|
||||
user.setAchievements(AllAchievements.getDefaults());
|
||||
userRepository.save(user);
|
||||
} else {
|
||||
throw new ApplicationException("User already exists");
|
||||
@@ -64,21 +69,37 @@ public class UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< HEAD
|
||||
* Adds a friend to the friendlist of the user.
|
||||
* @param name the username of the user
|
||||
* @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) {
|
||||
User user = userRepository.findByName(name);
|
||||
User add = userRepository.findByName(friend);
|
||||
if (user == null || add == null ) {
|
||||
if (add == null ) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
}
|
||||
user.addFriend(add);
|
||||
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.
|
||||
* @param name name of the user
|
||||
@@ -93,6 +114,7 @@ public class UserService {
|
||||
if (InputValidator.isValidItem(inputName)
|
||||
&& InputValidator.isValidItemValue(inputName, value)) {
|
||||
user.getFootPrintInputs().put(inputName, value);
|
||||
achievementService.updateAchievements(user);
|
||||
userRepository.save(user);
|
||||
} else {
|
||||
throw new ApplicationException("Invalid input");
|
||||
@@ -106,12 +128,14 @@ public class UserService {
|
||||
* @param inputName name of the input of the user
|
||||
* @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);
|
||||
if (user == null) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@@ -146,7 +170,7 @@ public class UserService {
|
||||
* @param name of the user
|
||||
* @return extra input map
|
||||
*/
|
||||
public Map<String, Boolean> getExtraInputMap(String name) {
|
||||
public Map<String, String> getExtraInputMap(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
return user.getExtraInputs();
|
||||
}
|
||||
@@ -210,6 +234,63 @@ public class UserService {
|
||||
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 all achievements of a user.
|
||||
* @param name name of the user
|
||||
* @return map with all achievements of a user
|
||||
*/
|
||||
public Map<String, String> getResults(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
Map<String, String> results = calculatorService.getResults(user.getFootPrintInputs());
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the 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_miscservices", "114");
|
||||
put("internal_state_abbreviation", "US");
|
||||
}
|
||||
}
|
||||
};
|
||||
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.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.server.AllAchievements;
|
||||
|
||||
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
|
||||
public void setFriendTest() {
|
||||
List<User> friends = new ArrayList<User>();
|
||||
@@ -134,4 +157,17 @@ public class UserTest {
|
||||
first.setFriends(friends);
|
||||
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 {
|
||||
ArgumentCaptor<String> arg1Captor = 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")
|
||||
.param("name", "ceren")
|
||||
.param("inputName", "input_size")
|
||||
.param("value", "true")
|
||||
.param("value", "5")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
@@ -94,7 +94,7 @@ public class UserControllerTest {
|
||||
.setExtraInput(arg1Captor.capture(), arg2Captor.capture(), arg3Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
assertEquals("input_size", arg2Captor.getValue());
|
||||
assertEquals(true, arg3Captor.getValue());
|
||||
assertEquals("5", arg3Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,6 +113,22 @@ public class UserControllerTest {
|
||||
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
|
||||
public void getInputMapTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
@@ -221,4 +237,29 @@ public class UserControllerTest {
|
||||
verify(userService, times(1)).saveFirstFootprint(arg1Captor.capture());
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResultsTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/getResults")
|
||||
.param("name", "mika")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1)).getResults(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;
|
||||
|
||||
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.Before;
|
||||
import org.junit.Test;
|
||||
@@ -14,16 +7,10 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
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.web.client.ExpectedCount;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -59,62 +46,6 @@ public class CalculatorServiceTest {
|
||||
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
|
||||
public void invokeExternalServiceTest() {
|
||||
CalculatorService service = new CalculatorService();
|
||||
@@ -242,4 +173,138 @@ public class CalculatorServiceTest {
|
||||
Float footPrint = service.invokeExternalService(map);
|
||||
Assert.assertEquals(new Float(11421.537), footPrint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResultsTest() {
|
||||
CalculatorService service = new CalculatorService();
|
||||
service.restTemplate = new RestTemplate();
|
||||
Map<String,String> map = new HashMap<String, String>() {{
|
||||
put("input_location", "Chicago");
|
||||
put("input_location_mode", "1");
|
||||
put("input_size", "1");
|
||||
put("input_income", "40000");
|
||||
put("input_population", "1");
|
||||
put("input_changed", "0");
|
||||
put("input_footprint_household_adults", "1");
|
||||
put("input_footprint_household_children", "0");
|
||||
put("input_footprint_transportation_num_vehicles", "1");
|
||||
put("input_footprint_transportation_miles1", "16100");
|
||||
put("input_footprint_transportation_mpg1", "6");
|
||||
put("input_footprint_transportation_fuel1", "2");
|
||||
put("input_footprint_transportation_miles2", "13200");
|
||||
put("input_footprint_transportation_fuel2", "0");
|
||||
put("input_footprint_transportation_mpg2", "22");
|
||||
put("input_footprint_transportation_miles3", "13200");
|
||||
put("input_footprint_transportation_fuel3", "0");
|
||||
put("input_footprint_transportation_mpg3", "22");
|
||||
put("input_footprint_transportation_miles4", "13200");
|
||||
put("input_footprint_transportation_fuel4", "0");
|
||||
put("input_footprint_transportation_mpg4", "22");
|
||||
put("input_footprint_transportation_miles5", "13200");
|
||||
put("input_footprint_transportation_fuel5", "0");
|
||||
put("input_footprint_transportation_mpg5", "22");
|
||||
put("input_footprint_transportation_miles6", "13200");
|
||||
put("input_footprint_transportation_fuel6", "0");
|
||||
put("input_footprint_transportation_mpg6", "22");
|
||||
put("input_footprint_transportation_miles7", "13200");
|
||||
put("input_footprint_transportation_fuel7", "0");
|
||||
put("input_footprint_transportation_mpg7", "22");
|
||||
put("input_footprint_transportation_miles8", "13200");
|
||||
put("input_footprint_transportation_fuel8", "0");
|
||||
put("input_footprint_transportation_mpg8", "22");
|
||||
put("input_footprint_transportation_miles9", "13200");
|
||||
put("input_footprint_transportation_fuel9", "0");
|
||||
put("input_footprint_transportation_mpg9", "22");
|
||||
put("input_footprint_transportation_miles10", "13200");
|
||||
put("input_footprint_transportation_fuel10", "0");
|
||||
put("input_footprint_transportation_mpg10", "22");
|
||||
put("input_footprint_transportation_groundtype", "436");
|
||||
put("input_footprint_transportation_publictrans", "436");
|
||||
put("input_footprint_transportation_bus", "436");
|
||||
put("input_footprint_transportation_transit", "436");
|
||||
put("input_footprint_transportation_commuter", "436");
|
||||
put("input_footprint_transportation_intercity", "436");
|
||||
put("input_footprint_transportation_airtype", "3900");
|
||||
put("input_footprint_transportation_airtotal", "3900");
|
||||
put("input_footprint_transportation_airshort", "3900");
|
||||
put("input_footprint_transportation_airmedium", "3900");
|
||||
put("input_footprint_transportation_airlong", "3900");
|
||||
put("input_footprint_transportation_airextended", "3900");
|
||||
put("input_footprint_housing_cdd", "40000");
|
||||
put("input_footprint_housing_hdd", "40000");
|
||||
put("input_footprint_housing_electricity_type", "40000");
|
||||
put("input_footprint_housing_electrivity_dollars", "40000");
|
||||
put("input_footprint_housing_electricity_kwh", "12632");
|
||||
put("input_footprint_housing_cleanpercent", "0");
|
||||
put("input_footprint_housing_naturalgas_type", "1");
|
||||
put("input_footprint_housing_naturalgas_dollars", "40000");
|
||||
put("input_footprint_housing_naturalgas_therms", "472");
|
||||
put("input_footprint_housing_naturalgas_cuft", "40000");
|
||||
put("input_footprint_housing_heatingoil_type", "40000");
|
||||
put("input_footprint_housing_heatingoil_dollars", "40000");
|
||||
put("input_footprint_housing_heatingoil_gallons", "73");
|
||||
put("input_footprint_housing_heatingoil_dollars_per_gallon", "40000");
|
||||
put("input_footprint_housing_squarefeet", "1850");
|
||||
put("input_footprint_housing_watersewage", "100");
|
||||
put("input_footprint_housing_gco2_per_kwh", "40000");
|
||||
put("input_footprint_shopping_food_meatfisheggs_default", "40000");
|
||||
put("input_footprint_shopping_food_meat_beefpork_default", "40000");
|
||||
put("input_footprint_shopping_food_meat_poultry_default", "40000");
|
||||
put("input_footprint_shopping_food_meat_fish_default", "40000");
|
||||
put("input_footprint_shopping_food_meat_other_default", "40000");
|
||||
put("input_footprint_shopping_food_fruitvegetables_default", "40000");
|
||||
put("input_footprint_shopping_food_dairy_default", "4.2");
|
||||
put("input_footprint_shopping_food_cereals_default", "40000");
|
||||
put("input_footprint_shopping_food_otherfood_default", "40000");
|
||||
put("input_footprint_shopping_food_meattype", "40000");
|
||||
put("input_footprint_shopping_food_meatfisheggs", "2.4");
|
||||
put("input_footprint_shopping_food_meat_beefpork", "2.4");
|
||||
put("input_footprint_shopping_food_meat_poultry", "2.4");
|
||||
put("input_footprint_shopping_food_meat_fish", "2.4");
|
||||
put("input_footprint_shopping_food_meat_other", "2.4");
|
||||
put("input_footprint_shopping_food_cereals", "4.1");
|
||||
put("input_footprint_shopping_food_dairy", "2.2");
|
||||
put("input_footprint_shopping_food_fruitvegetables", "3.5");
|
||||
put("input_footprint_shopping_food_otherfood", "3.4");
|
||||
put("input_footprint_shopping_goods_default_furnitureappliances", "1310");
|
||||
put("input_footprint_shopping_goods_default_clothing", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_entertainment", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_office", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_personalcare", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_autoparts", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_medical", "1310");
|
||||
put("input_footprint_shopping_goods_type", "1310");
|
||||
put("input_footprint_shopping_goods_total", "1310");
|
||||
put("input_footprint_shopping_goods_furnitureappliances", "1310");
|
||||
put("input_footprint_shopping_goods_clothing", "1310");
|
||||
put("input_footprint_shopping_goods_other_type", "1310");
|
||||
put("input_footprint_shopping_goods_other_total", "1310");
|
||||
put("input_footprint_shopping_goods_other_entertainment", "1310");
|
||||
put("input_footprint_shopping_goods_other_office", "1310");
|
||||
put("input_footprint_shopping_goods_other_personalcare", "1310");
|
||||
put("input_footprint_shopping_goods_other_autoparts", "1310");
|
||||
put("input_footprint_shopping_goods_other_medical", "1310");
|
||||
put("input_footprint_shopping_services_type", "1310");
|
||||
put("input_footprint_shopping_services_total", "1310");
|
||||
put("input_footprint_shopping_services_healthcare", "1310");
|
||||
put("input_footprint_shopping_services_education", "1310");
|
||||
put("input_footprint_shopping_services_communications", "1310");
|
||||
put("input_footprint_shopping_services_vehicleservices", "1310");
|
||||
put("input_footprint_shopping_services_finance", "1310");
|
||||
put("input_footprint_shopping_services_household", "1310");
|
||||
put("input_footprint_shopping_services_charity", "1310");
|
||||
put("input_footprint_shopping_services_miscservices", "1310");
|
||||
put("internal_state_abbreviation", "US");
|
||||
put("input_footprint_shopping_services_total", "2413");
|
||||
}
|
||||
};
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("transport", "10769.855687");
|
||||
result.put("housing", "556.831359");
|
||||
result.put("food", "0.028481");
|
||||
result.put("goods", "55.256948");
|
||||
result.put("services", "39.564835");
|
||||
Map<String, String> footPrint = service.getResults(map);
|
||||
Assert.assertEquals(result, footPrint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.common.UserDto;
|
||||
import greenify.server.AllAchievements;
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
import org.junit.Assert;
|
||||
@@ -43,6 +44,9 @@ public class UserServiceTest {
|
||||
@MockBean
|
||||
private CalculatorService calculatorService;
|
||||
|
||||
@MockBean
|
||||
private AchievementService achievementService;
|
||||
|
||||
/**
|
||||
* setUp method for test.
|
||||
*/
|
||||
@@ -97,8 +101,8 @@ public class UserServiceTest {
|
||||
User alex = new User(1L, "alex", "password");
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
userService.setExtraInput("alex", "solar_panels", true);
|
||||
assertEquals(true, alex.getExtraInputs()
|
||||
userService.setExtraInput("alex", "solar_panels", "5");
|
||||
assertEquals("5", alex.getExtraInputs()
|
||||
.get("solar_panels"));
|
||||
}
|
||||
|
||||
@@ -109,7 +113,8 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void setExtraInputNullTest() {
|
||||
assertThrows(ApplicationException.class, () -> userService.setExtraInput(null, "hello", true));
|
||||
assertThrows(ApplicationException.class, () -> userService
|
||||
.setExtraInput(null, "hello", "6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,7 +171,7 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void getExtraInputMapTest() {
|
||||
Map<String, Boolean> map = new HashMap<>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
User alex = new User(1L, "alex", "password");
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
@@ -265,13 +270,60 @@ public class UserServiceTest {
|
||||
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
|
||||
public void addFriendNullFriendTest() {
|
||||
assertThrows(ApplicationException.class, () -> userService.addFriend("alex", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFriendNullUserTest() {
|
||||
assertThrows(ApplicationException.class, () -> userService.addFriend(null, "password"));
|
||||
public void setAchievementTest() {
|
||||
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"));
|
||||
}
|
||||
}
|
||||