Resolved the conflicts. We should check if the JavaDoc is still in the right place, because it looked a little weird while resolving the conflicts
Merge branch 'master' into 'fix/checkstyleAndComments' # Conflicts: # src/Client/src/main/java/greenify/client/controller/DashBoardController.java # src/Server/src/main/java/greenify/server/data/model/User.java # src/Server/src/main/java/greenify/server/service/UserService.java # src/Server/src/test/java/greenify/server/data/model/UserTest.java # src/Server/src/test/java/greenify/server/service/UserServiceTest.java
20
README.md
@@ -6,26 +6,6 @@ Run `maven install` ([Intellij](https://www.jetbrains.com/help/idea/2016.3/getti
|
||||
**Checkstyle**:
|
||||
Run `maven site`
|
||||
|
||||
# Daan Sneep (4849515, dsneep)
|
||||
|
||||

|
||||
|
||||
## Personal Development Plan
|
||||
|
||||
My Core Quadrant is visible 
|
||||
|
||||
### G – Goal
|
||||
After completing this project, I want to be able to work on a programming project efficiently with other people. I have never attempted anything of this scale and find that it is a core requirement of becoming a good programmer, as in most companies programming is done within teams, not alone.
|
||||
|
||||
### R – Reality
|
||||
With this project I hope to work towards this goal. I have never programmed as a team on this scale, so this project will be the first step towards my goal.
|
||||
|
||||
### O – Options
|
||||
During this quarter the project will be my only option towards achieving this goal. If I am unhappy with my progress towards my goal by the end of this quarter, I must try to implement the same structure of teamwork in my next projects, and try to learn from the mistakes I made when working as a team in this project.
|
||||
|
||||
### W – Will
|
||||
I will try to make sure to adhere to the structure we establish as a group which describes how we will work together. This way, we all do the work we are supposed to do, and none of us will be overloaded with work. I will also try to make use of all the tools available to us which can improve the quality of programming together (scrum, git, GitLab etc.).
|
||||
|
||||
# Merel Steenbergen (masteenbergen)
|
||||

|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 861 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 26 KiB |
BIN
doc/meetings/week7/20190325_notes.pdf
Normal file
@@ -0,0 +1,154 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class CalculatorController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@FXML
|
||||
private Button calculatorGetStartedButton;
|
||||
@FXML
|
||||
private Button calculatorTravelButton;
|
||||
@FXML
|
||||
private Button calculatorHomeButton;
|
||||
@FXML
|
||||
private Button calculatorFoodButton;
|
||||
@FXML
|
||||
private Button calculatorShoppingButton;
|
||||
@FXML
|
||||
private AnchorPane getStartedPane;
|
||||
@FXML
|
||||
private ScrollPane travelPane;
|
||||
@FXML
|
||||
private AnchorPane homePane;
|
||||
@FXML
|
||||
private AnchorPane foodPane;
|
||||
@FXML
|
||||
private AnchorPane shoppingPane;
|
||||
@FXML
|
||||
private Slider peopleInHouseholdSLider;
|
||||
@FXML
|
||||
private Label peopleInHouseHoldLabel;
|
||||
@FXML
|
||||
private Slider annualIncomeSlider;
|
||||
@FXML
|
||||
private Label annualIncomeLabel;
|
||||
@FXML
|
||||
private Button saveButton;
|
||||
@FXML
|
||||
private Button getStartedNextButton;
|
||||
|
||||
/**
|
||||
* 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 next to them
|
||||
*/
|
||||
public void initialize() {
|
||||
peopleInHouseholdSLider.setSnapToTicks(true);
|
||||
annualIncomeSlider.setSnapToTicks(true);
|
||||
//add listener to slider for amount of people in household
|
||||
peopleInHouseholdSLider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
peopleInHouseHoldLabel.setText("" + newValue.intValue());
|
||||
}
|
||||
});
|
||||
|
||||
//add listener to slider for annual income
|
||||
annualIncomeSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
annualIncomeLabel.setText("" + (newValue.intValue() * 1000));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'get started' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
public void displayGetStarted(ActionEvent event) {
|
||||
getStartedPane.setVisible(true);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'travel' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
public void displayTravel(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(true);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'home' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
public void displayHome(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(true);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'food' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
public void displayFood(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(true);
|
||||
shoppingPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'shopping' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
public void displayShopping(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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.PathTransition;
|
||||
@@ -8,10 +9,13 @@ import javafx.animation.ScaleTransition;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -55,6 +59,9 @@ public class DashBoardController {
|
||||
private AnchorPane menuBar;
|
||||
@FXML
|
||||
private Button addNewActivityButton;
|
||||
@FXML
|
||||
private Button calculateFootPrintButton;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +78,12 @@ public class DashBoardController {
|
||||
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
|
||||
userButton.setSkin(new MyButtonSkin(userButton));
|
||||
friendsButton.setSkin(new MyButtonSkin(friendsButton));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +152,6 @@ public class DashBoardController {
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
friendsPane.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
//sets the slide in transition for startup
|
||||
@@ -148,6 +160,18 @@ public class DashBoardController {
|
||||
pathTrans.play();
|
||||
}
|
||||
|
||||
public void openCalculator() throws IOException {
|
||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/calculator.fxml"));
|
||||
Scene scene = new Scene(calc);
|
||||
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/calculatorStyle.css").toExternalForm());
|
||||
Stage calcStage = new Stage();
|
||||
|
||||
calcStage.setScene(scene);
|
||||
calcStage.setTitle("Calculate CO2 footprint - " + userService.currentUser.getName());
|
||||
calcStage.show();
|
||||
}
|
||||
|
||||
//class for the animations on the navigation buttons
|
||||
public class MyButtonSkin extends ButtonSkin {
|
||||
/**
|
||||
@@ -172,5 +196,6 @@ public class DashBoardController {
|
||||
scaleDown.setToX(1.0);
|
||||
button.setOnMouseExited(e -> scaleDown.playFromStart());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,4 +98,18 @@ public class UserService {
|
||||
return this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), String.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public String addFriend(String name, String friend) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend")
|
||||
.queryParam("name", name)
|
||||
.queryParam("friend",friend);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
String result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), String.class);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
145
src/Client/src/main/resources/fxml/calculator.fxml
Normal file
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import com.jfoenix.controls.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.CalculatorController">
|
||||
<children>
|
||||
<AnchorPane fx:id="calculatorTabs" prefHeight="85.0" prefWidth="820.0" style="-fx-background-color: #677069;">
|
||||
<children>
|
||||
<Button fx:id="calculatorGetStartedButton" contentDisplay="TOP" layoutX="188.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayGetStarted" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Get started" textFill="#d4ddd6" AnchorPane.leftAnchor="188.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/cloud.png" />
|
||||
<!--image credits:-->
|
||||
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
|
||||
<!--from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorTravelButton" contentDisplay="TOP" layoutX="273.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayTravel" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Travel" textFill="#d4ddd6" AnchorPane.leftAnchor="273.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/world.png" />
|
||||
<!--image credits:
|
||||
made by prettycons https://www.flaticon.com/authors/prettycons
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorHomeButton" contentDisplay="TOP" layoutX="358.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayHome" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Home" textFill="#d4ddd6" AnchorPane.leftAnchor="358.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/home.png" />
|
||||
<!--image credits:
|
||||
made by Smashicons https://www.flaticon.com/authors/smashicons
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorFoodButton" contentDisplay="TOP" layoutX="443.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayFood" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Food" textFill="#d4ddd6" AnchorPane.leftAnchor="443.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/coffee-cup.png" />
|
||||
<!--image credits:
|
||||
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorShoppingButton" contentDisplay="TOP" layoutX="528.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayShopping" prefHeight="81.0" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Shopping" textFill="#d4ddd6" AnchorPane.leftAnchor="528.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/shopping-cart.png" />
|
||||
<!--image credits:
|
||||
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" text="Save">
|
||||
<font>
|
||||
<Font size="17.0" />
|
||||
</font></Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="getStartedPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" AnchorPane.leftAnchor="0.0">
|
||||
<children>
|
||||
<Text layoutX="224.0" layoutY="96.0" strokeType="OUTSIDE" strokeWidth="0.0" text="1. How many people live in your household?">
|
||||
<font>
|
||||
<Font size="19.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Slider fx:id="peopleInHouseholdSLider" blockIncrement="1.0" layoutX="260.0" layoutY="147.0" majorTickUnit="1.0" max="6.0" min="1.0" minorTickCount="0" prefHeight="38.0" prefWidth="300.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" />
|
||||
<Label fx:id="peopleInHouseHoldLabel" alignment="CENTER" contentDisplay="CENTER" layoutX="612.0" layoutY="70.0" prefHeight="38.0" prefWidth="44.0" text="0">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font></Label>
|
||||
<Text layoutX="207.0" layoutY="254.0" strokeType="OUTSIDE" strokeWidth="0.0" text="2. What is your gross annual household income?">
|
||||
<font>
|
||||
<Font size="19.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Slider fx:id="annualIncomeSlider" layoutX="224.0" layoutY="302.0" majorTickUnit="10.0" minorTickCount="0" prefHeight="38.0" prefWidth="388.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Text fill="#757575" layoutX="373.0" layoutY="277.0" strokeType="OUTSIDE" strokeWidth="0.0" text="in 1000 euros">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="annualIncomeLabel" layoutX="634.0" layoutY="232.0" prefHeight="30.0" prefWidth="150.0" text="0">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
</Label>
|
||||
<Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" />
|
||||
</children></AnchorPane>
|
||||
<ScrollPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
|
||||
<AnchorPane fx:id="homePane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
|
||||
<AnchorPane fx:id="foodPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
|
||||
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -1,14 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?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="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutY="-2.0" prefHeight="90.0" prefWidth="216.0" text="Greenify" textAlignment="CENTER" textFill="#71bc84">
|
||||
<font>
|
||||
@@ -37,10 +39,10 @@
|
||||
</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 fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="5.0" layoutY="273.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
|
||||
<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" />
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="720.0" visible="false">
|
||||
<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>
|
||||
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
||||
<font>
|
||||
@@ -160,7 +162,7 @@
|
||||
</children>
|
||||
</Pane>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<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">
|
||||
<font>
|
||||
@@ -181,8 +183,22 @@
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" layoutX="517.0" layoutY="121.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
|
||||
<children>
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="scoreField1" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="703.0" prefWidth="820.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.0" />
|
||||
<Label fx:id="welcomebacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
||||
@@ -190,14 +206,14 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="addNewActivityButton" contentDisplay="RIGHT" layoutX="496.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add a new activity" textFill="#29721a">
|
||||
<Button fx:id="addNewActivityButton" contentDisplay="RIGHT" layoutX="577.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add a new activity" textFill="#29721a">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="81.0" fitWidth="74.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../addActivity1.png" />
|
||||
<Image url="@../icons/addActivity1.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
@@ -207,9 +223,25 @@
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="calculateFootPrintButton" contentDisplay="RIGHT" layoutX="572.0" layoutY="124.0" mnemonicParsing="false" onAction="#openCalculator" prefHeight="74.0" prefWidth="205.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Calculate your CO2 footprint" textFill="#29721a">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="81.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/co2_2.png" />
|
||||
<!--image credits:-->
|
||||
<!--https://www.flaticon.com/authors/vectors-market-->
|
||||
<!--https://www.flaticon.com-->
|
||||
<!--http://creativecommons.org/licenses/by/3.0/-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="friendsPane" layoutX="214.0" prefHeight="603.0" prefWidth="720.0">
|
||||
<AnchorPane fx:id="friendsPane" layoutX="216.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<Text layoutX="94.0" layoutY="72.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Your Friends" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
||||
<font>
|
||||
|
||||
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
BIN
src/Client/src/main/resources/icons/cloud.png
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
BIN
src/Client/src/main/resources/icons/co2.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
src/Client/src/main/resources/icons/co2_2.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
src/Client/src/main/resources/icons/coffee-cup.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
src/Client/src/main/resources/icons/home.png
Normal file
|
After Width: | Height: | Size: 9.2 KiB |
BIN
src/Client/src/main/resources/icons/shopping-cart.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
src/Client/src/main/resources/icons/world.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
@@ -0,0 +1,35 @@
|
||||
|
||||
#calculatorTabs .navButton {
|
||||
-fx-background-color: transparent;
|
||||
-fx-font-size: 16px;
|
||||
}
|
||||
#calculatorTabs .navButton:pressed {
|
||||
-fx-border-color: #677069;
|
||||
}
|
||||
#calculatorTabs .navButton:hover {
|
||||
-fx-background-color: #707a72;
|
||||
}
|
||||
#calculatorTabs #saveButton {
|
||||
-fx-background-color: #89a888;
|
||||
-fx-font-size: 16px;
|
||||
-fx-font-weight: regular;
|
||||
}
|
||||
|
||||
.nextButton {
|
||||
-fx-background-color: #89a888;
|
||||
-fx-font-size: 16px;
|
||||
-fx-font-family: Corbel;
|
||||
}
|
||||
.nextButton:hover {
|
||||
-fx-background-color: #9ec19c;
|
||||
}
|
||||
|
||||
.slider {
|
||||
-show-value-on-interaction: true;
|
||||
-fx-text-fill: red;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -48,10 +48,15 @@
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
|
||||
#addNewActivityButton:pressed {
|
||||
-fx-border-color: #497251;
|
||||
}
|
||||
|
||||
#calculateFootPrintButton:pressed {
|
||||
-fx-border-color: #497251;
|
||||
}
|
||||
|
||||
/*friends table*/
|
||||
#friendsTable .column-header {
|
||||
/*-fx-background-color: linear-gradient(#4b7a3d, #588c58);*/
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package greenify.server.data.model;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import greenify.server.InputValidator;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@@ -21,6 +20,7 @@ import javax.validation.constraints.NotNull;
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@NotNull
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@@ -36,7 +36,11 @@ public class User {
|
||||
@ElementCollection
|
||||
private Map<String, String> footPrintInputs = new HashMap<>();
|
||||
|
||||
User() { }
|
||||
@ManyToMany
|
||||
@JoinColumn
|
||||
private Collection<User> friends;
|
||||
|
||||
public User() {}
|
||||
|
||||
/**
|
||||
* This method makes a user object.
|
||||
@@ -49,6 +53,7 @@ public class User {
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||
this.friends = new ArrayList<User>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,6 +136,29 @@ public class User {
|
||||
this.footPrintInputs = footPrintInputs;
|
||||
}
|
||||
|
||||
public ArrayList<User> getFriends() {
|
||||
return (ArrayList<User>)this.friends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a friend to the friendslist of the user.
|
||||
* @param user the friend you want to add.
|
||||
*/
|
||||
public void addFriend(User user) {
|
||||
if (user.equals(this)) {
|
||||
throw new ApplicationException("Cannot add yourself as a friend");
|
||||
}
|
||||
else {
|
||||
friends.add(user);
|
||||
System.out.print("Friend added!");
|
||||
}
|
||||
}
|
||||
|
||||
public void setFootPrint(Float footPrint) {
|
||||
this.footPrint = footPrint;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets a human readable (JSON) object.
|
||||
* @return the JSON form of the object.
|
||||
@@ -142,10 +170,20 @@ public class User {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks whether two users are equal or not.
|
||||
* @param other an other user
|
||||
* @return users are (not) equal
|
||||
* Returns the name and score of the friends in JSON. Needed for the leaderboard.
|
||||
* @return a JSON object of the friendlist with only names and scores.
|
||||
*/
|
||||
public String friendsToString(){
|
||||
String result = "friends=[";
|
||||
for (User u : friends) {
|
||||
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
|
||||
}
|
||||
if (result.endsWith(", ")) {
|
||||
return result.substring(0, result.lastIndexOf(",")) + "]";
|
||||
}
|
||||
return result + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof User) {
|
||||
|
||||
@@ -60,10 +60,35 @@ public class UserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets input for a user.
|
||||
* @param name name of the user
|
||||
* @param inputName name of the input of the user
|
||||
* @param value value of the input
|
||||
* 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.
|
||||
* @return a userDTO of the logged in user
|
||||
*/
|
||||
public void addFriend(String name, String friend) {
|
||||
User user = userRepository.findByName(name);
|
||||
User add = userRepository.findByName(friend);
|
||||
if (add == null) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
}
|
||||
user.addFriend(add);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the friendlist of the user in JSON.
|
||||
* @param name the username of the user
|
||||
* @return a userDTO of the logged in user
|
||||
*/
|
||||
public String getLeaderboard(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
return user.friendsToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The method sets input value.
|
||||
* @param name of the user
|
||||
* @param inputName is the name of the setting input
|
||||
* @param value of the input
|
||||
*/
|
||||
public void setInput(String name, String inputName, String value) {
|
||||
User user = userRepository.findByName(name);
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package greenify.server.data.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import greenify.common.ApplicationException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UserTest {
|
||||
|
||||
@Test
|
||||
@@ -79,4 +84,42 @@ public class UserTest {
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFriendEmpty() {
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "merel", "password");
|
||||
assertEquals(first.getFriends(), second.getFriends());
|
||||
assertEquals(first.getFriends(), new ArrayList<User>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFriendTest() {
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "merel", "password");
|
||||
assertEquals(first.getFriends(), second.getFriends());
|
||||
first.addFriend(second);
|
||||
ArrayList<User> test = new ArrayList<User>();
|
||||
test.add(second);
|
||||
assertEquals(first.getFriends(), test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addYourselfTest() {
|
||||
User test = new User(1L, "greenify", "password");
|
||||
assertEquals(test.getFriends(), new ArrayList<User>());
|
||||
assertThrows(ApplicationException.class, () -> {
|
||||
test.addFriend(test);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void friendsToStringTest() {
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "merel", "password");
|
||||
first.addFriend(second);
|
||||
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class UserServiceTest {
|
||||
@TestConfiguration
|
||||
@@ -44,6 +46,9 @@ public class UserServiceTest {
|
||||
User alex = new User(1L, "alex", "password");
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
User lola = new User(2L, "lola", "password");
|
||||
when(userRepository.findByName(lola.getName()))
|
||||
.thenReturn(lola);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,4 +149,24 @@ public class UserServiceTest {
|
||||
assertThrows(ApplicationException.class, () -> userService.loginUser(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFriendTest() {
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leaderboardTest() {
|
||||
User alex = userRepository.findByName("alex");
|
||||
User lola = userRepository.findByName("lola");
|
||||
userService.addFriend("alex", "lola");
|
||||
assertEquals(userService.getLeaderboard("alex"), "friends=[{name=lola, footprint=0.0}]");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||