From 34e010f62d0f11dade58948578d734cec9e9bbee Mon Sep 17 00:00:00 2001 From: cugurlu Date: Mon, 25 Mar 2019 13:18:48 +0100 Subject: [PATCH] Fix client errors --- .../java/greenify/client/Application.java | 16 +---------- .../controller/DashBoardController.java | 28 ++----------------- .../client/controller/UserController.java | 2 +- .../greenify/client/rest/UserService.java | 25 ++++++----------- .../fxml/{sample.fxml => LoginWindow.fxml} | 5 +--- .../main/resources/fxml/RegisterWindow.fxml | 9 +----- .../src/main/resources/fxml/dashboard.fxml | 20 +++---------- 7 files changed, 18 insertions(+), 87 deletions(-) rename src/Client/src/main/resources/fxml/{sample.fxml => LoginWindow.fxml} (96%) diff --git a/src/Client/src/main/java/greenify/client/Application.java b/src/Client/src/main/java/greenify/client/Application.java index a8e7d4f..29afbe3 100644 --- a/src/Client/src/main/java/greenify/client/Application.java +++ b/src/Client/src/main/java/greenify/client/Application.java @@ -12,15 +12,11 @@ import org.springframework.context.ConfigurableApplicationContext; import java.io.IOException; -//springbootApplication is so Spring knows that this is a Spring application @SpringBootApplication public class Application extends javafx.application.Application { - //configurable application is for spring so it knows that it can use it private static ConfigurableApplicationContext springContext; - //logger to log all the things that happen to the console private static final Logger log = LoggerFactory.getLogger(Application.class); - //launch is to launch the GUI things public static void main(String[] args) { launch(args); } @@ -29,10 +25,8 @@ public class Application extends javafx.application.Application { * This method takes an url and return a parent. * @param url which is being loaded. * @return parent object. - * @throws IOException if it can't find an FXML file */ public static Parent load(java.net.URL url) throws IOException { - //loader to load the FXML file FXMLLoader loader = new FXMLLoader(); loader.setControllerFactory(springContext::getBean); loader.setLocation(url); @@ -41,22 +35,14 @@ public class Application extends javafx.application.Application { @Override public void init() throws Exception { - //run the application springContext = SpringApplication.run(Application.class); } @Override public void start(Stage primaryStage) throws Exception { - //load the fxml file - Parent rootNode = load(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); - //set the title for the window + Parent rootNode = load(this.getClass().getClassLoader().getResource("fxml/LoginWindow.fxml")); primaryStage.setTitle("Greenify"); - //set the scene Scene scene = new Scene(rootNode); - //add the stylesheet - 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/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index c9429e5..cbba022 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -1,6 +1,5 @@ package greenify.client.controller; -import com.sun.javafx.scene.control.skin.ButtonSkin; import greenify.client.rest.UserService; import javafx.animation.FadeTransition; import javafx.animation.PathTransition; @@ -10,6 +9,7 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.skin.ButtonSkin; import javafx.scene.layout.AnchorPane; import javafx.scene.shape.Line; import javafx.util.Duration; @@ -72,9 +72,6 @@ public class DashBoardController { activitiesButton.setSkin(new MyButtonSkin(activitiesButton)); userButton.setSkin(new MyButtonSkin(userButton)); friendsButton.setSkin(new MyButtonSkin(friendsButton)); - - - } /** @@ -109,11 +106,7 @@ public class DashBoardController { * @param event the event (clicking the button) */ public void displayActivities(ActionEvent event) { - - addFadeTransition(activitiesPane); - - net = userService.currentUser.getVeganMeal() + count; totalVeganMealCounter.setText("" + net); System.out.println("display activities"); dashboardPane.setVisible(false); @@ -146,23 +139,6 @@ public class DashBoardController { } - - /** - * adds a vegetarian meal. - * @param event the event (clicking the button) - */ - public void addVeganMeal(ActionEvent event) { - - count++; - net = userService.currentUser.getVeganMeal() + count; - totalVeganMealCounter.setText("" + net); - veganMealCounter.setText("" + count); - System.out.println(userService); - userService.addVeganMeal(userService.currentUser.getId(), - userService.currentUser.getName()); - System.out.println("Vegetarian meal is added"); - } - //sets the slide in transition for startup public void addSlideTransition(Node node, Line path1) { PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node); @@ -194,4 +170,4 @@ public class DashBoardController { button.setOnMouseExited(e -> scaleDown.playFromStart()); } } -} \ No newline at end of file +} 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 abb387d..fc0f097 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -82,7 +82,7 @@ public class UserController { public void openDashboard() throws IOException { //load the fxml file Parent dash = Application.load(this.getClass().getClassLoader() - .getResource("fxml/dashboard.fxml")); + .getResource("fxml/dashboard.fxml")); Scene scene = new Scene(dash); //add the stylesheet for the CSS scene.getStylesheets().add(getClass().getClassLoader() 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 ced0ec2..c993e2d 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -80,27 +80,18 @@ public class UserService { return result; } - /** - * a user adds vegan meal. - * @param id the id of the user - * @param name the username of the user - * @return a userDTO - */ @SuppressWarnings("Duplicates") - public UserDto addVeganMeal(Long id, String name) { - //this method is almost the same as the registerUser one, but with a different link + public String 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/addVeganMeal") - .queryParam("id", id) - .queryParam("name", name); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput") + .queryParam("name", name) + .queryParam("inputName", inputName) + .queryParam("value",value); HttpEntity entity = new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); - return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class); - } - - @RequestMapping("/userData") - public int getVeganData(@RequestParam(value = "veganMeal") int veganMeal) { - return veganMeal; + String result = this.restTemplate.getForObject(builder.build() + .encode().toUri(), String.class); + return result; } } diff --git a/src/Client/src/main/resources/fxml/sample.fxml b/src/Client/src/main/resources/fxml/LoginWindow.fxml similarity index 96% rename from src/Client/src/main/resources/fxml/sample.fxml rename to src/Client/src/main/resources/fxml/LoginWindow.fxml index 96027de..03a3902 100644 --- a/src/Client/src/main/resources/fxml/sample.fxml +++ b/src/Client/src/main/resources/fxml/LoginWindow.fxml @@ -1,14 +1,10 @@ - - - - @@ -36,3 +32,4 @@ + diff --git a/src/Client/src/main/resources/fxml/RegisterWindow.fxml b/src/Client/src/main/resources/fxml/RegisterWindow.fxml index 35bff80..9daeb7f 100644 --- a/src/Client/src/main/resources/fxml/RegisterWindow.fxml +++ b/src/Client/src/main/resources/fxml/RegisterWindow.fxml @@ -1,21 +1,14 @@ - - - - - - - - + diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml index 2f240b5..9b788d0 100644 --- a/src/Client/src/main/resources/fxml/dashboard.fxml +++ b/src/Client/src/main/resources/fxml/dashboard.fxml @@ -1,22 +1,10 @@ - - - - - - - - - - - - @@ -229,10 +217,10 @@ - - - - + + + +