diff --git a/src/Client/src/main/java/greenify/client/Application.java b/src/Client/src/main/java/greenify/client/Application.java index 78a93d0..d9d8694 100644 --- a/src/Client/src/main/java/greenify/client/Application.java +++ b/src/Client/src/main/java/greenify/client/Application.java @@ -54,7 +54,8 @@ public class Application extends javafx.application.Application { .getResource("fxml/LoginWindow.fxml")); primaryStage.setTitle("Greenify"); Scene scene = new Scene(rootNode); - scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/LoginWindowStyle.css").toExternalForm()); + scene.getStylesheets().add(getClass().getClassLoader().getResource( + "stylesheets/LoginWindowStyle.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); } diff --git a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java index f9dad10..4fd4439 100644 --- a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java +++ b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java @@ -268,11 +268,28 @@ public class CalculatorController { shoppingPane.setVisible(true); } - - - - - - - + /** + * The method saves the calculation. + * @param event user clicks to button + */ + public void saveCalculation(ActionEvent event) { + getStartedPane.setVisible(false); + travelPane.setVisible(false); + homePane.setVisible(false); + foodPane.setVisible(false); + shoppingPane.setVisible(false); + if (!annualIncomeLabel.getText().equals(null)) { + userService.updateInput(userService.currentUser.getName(), "input_income", + annualIncomeLabel.getText()); + } + if (!peopleInHouseHoldLabel.getText().equals(null)) { + userService.updateInput(userService.currentUser.getName(), "input_population", + peopleInHouseHoldLabel.getText()); + } + userService.updateInput(userService.currentUser.getName(), + "input_footprint_housing_naturalgas_cuft", "0"); + userService.updateInput(userService.currentUser.getName(), + "input_footprint_transportation_miles1", "0"); + } } + diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 696cdd8..b697ff3 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -31,7 +31,6 @@ public class DashBoardController { UserService userService; private FadeTransition fadeTrans; //transition for switching between the different panels - private int net; @FXML private AnchorPane dashboardPane; @@ -42,8 +41,6 @@ public class DashBoardController { @FXML private AnchorPane friendsPane; @FXML - private Label totalVeganMealCounter; - @FXML private Label welcomebacktext; @FXML private Button dashboardButton; @@ -62,7 +59,7 @@ public class DashBoardController { @FXML private Button calculateFootPrintButton; @FXML - private Label footPrintLabel; + private Label footprintLabel; /** * Loads the the necessary things before anything else. @@ -81,10 +78,6 @@ public class DashBoardController { } - public UserService getUserService() { - return userService; - } - /** * Adds a fade transition for switching between the different panes. * @param node the node on which the transition needs to act @@ -118,7 +111,6 @@ public class DashBoardController { */ public void displayActivities(ActionEvent event) { addFadeTransition(activitiesPane); - totalVeganMealCounter.setText("" + net); System.out.println("display activities"); dashboardPane.setVisible(false); userPane.setVisible(false); @@ -131,6 +123,9 @@ public class DashBoardController { * @param event the event (clicking the button) */ public void displayUser(ActionEvent event) { + System.out.println(userService.currentUser.getName()); + System.out.println(userService.getFootprint(userService.currentUser.getName())); + footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName())); addFadeTransition(userPane); System.out.println("display user"); dashboardPane.setVisible(false); diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index 9c3e238..a67fcf9 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -28,13 +28,10 @@ public class UserController { @FXML private TextField usernameField; - @FXML private PasswordField passwordField; - @FXML private Button loginButton; - @FXML private Button signUpButton; diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index d3c5123..cd2d035 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -83,10 +84,9 @@ public class UserService { * @param name name of the user * @param inputName name of the input * @param value value of the input - * @return returns the result */ @SuppressWarnings("Duplicates") - public String updateInput(String name, String inputName, String value) { + public void updateInput(String name, String inputName, String value) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput") @@ -95,18 +95,35 @@ public class UserService { .queryParam("value",value); new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); - return this.restTemplate.getForObject(builder.build() + ResponseEntity authenticateResponse = this.restTemplate.getForEntity(builder.build() .encode().toUri(), String.class); } + /** + * Gets the footprint of the user. + * @param name name of the user + * @return returns the footprint score + */ + @SuppressWarnings("Duplicates") + public Float 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 + .build().encode().toUri(), Float.class); + return result; + } + /** * Adds a friend to the user. * @param name the username of the current user. * @param friend the username of the friend you want to add. - * @return a userDTO */ @SuppressWarnings("Duplicates") - public String addFriend(String name, String friend) { + public void addFriend(String name, String friend) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend") @@ -114,8 +131,7 @@ public class UserService { .queryParam("friend",friend); HttpEntity entity = new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); - String result = this.restTemplate.getForObject(builder.build() + ResponseEntity authenticateResponse = this.restTemplate.getForEntity(builder.build() .encode().toUri(), String.class); - return result; } } diff --git a/src/Client/src/main/resources/fxml/calculator.fxml b/src/Client/src/main/resources/fxml/calculator.fxml index d4c8106..b1709c2 100644 --- a/src/Client/src/main/resources/fxml/calculator.fxml +++ b/src/Client/src/main/resources/fxml/calculator.fxml @@ -31,10 +31,10 @@ - - - + + + @@ -47,11 +47,11 @@ - + @@ -64,11 +64,11 @@ - + @@ -81,11 +81,11 @@ - + @@ -98,16 +98,16 @@ - + - @@ -581,3 +581,4 @@ + diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml index 94df4c4..535f498 100644 --- a/src/Client/src/main/resources/fxml/dashboard.fxml +++ b/src/Client/src/main/resources/fxml/dashboard.fxml @@ -190,7 +190,7 @@ -