Merge branch 'master' into 'Add_Calculator_to_GUI'

# Conflicts:
#   src/Client/src/main/java/greenify/client/controller/DashBoardController.java
#   src/Client/src/main/resources/fxml/dashboard.fxml

the conflicts were only empty lines on the master
This commit is contained in:
Sem van der Hoeven
2019-03-26 14:04:49 +00:00
47 changed files with 638 additions and 529 deletions

View File

@@ -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();
}

View File

@@ -121,11 +121,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);
@@ -157,23 +153,6 @@ public class DashBoardController {
friendsPane.setVisible(true);
}
/**
* 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);

View File

@@ -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()

View File

@@ -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;
}
}

View File

@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.UserController">
<children>
<ImageView fitHeight="600.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
@@ -36,3 +32,4 @@
<TextField fx:id="usernameField" layoutX="319.0" layoutY="154.0" prefHeight="42.0" prefWidth="303.0" promptText="Username" />
</children>
</AnchorPane>

View File

@@ -1,21 +1,14 @@
<?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.control.Button?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
<children>
<Line fx:id="uNamePathLine" endX="100.0" layoutX="2.0" layoutY="109.0" startX="-100.0" />
<Line fx:id="uNamePathLine" endX="100.0" layoutX="2.0" layoutY="109.0" startX="-100.0" />
<ImageView fitHeight="312.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../registerBackground.png" />

View File

@@ -7,17 +7,6 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<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>
@@ -62,7 +51,7 @@
</Text>
<Pane layoutX="20.0" layoutY="93.0" prefHeight="471.0" prefWidth="280.0" style="-fx-background-color: #f4fff4;">
<children>
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="55.0" mnemonicParsing="false" onAction="#addVeganMeal" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Eating a vegetarian meal" textFill="#e0ffe1">
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="55.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Eating a vegetarian meal" textFill="#e0ffe1">
<font>
<Font size="14.0" />
</font>
@@ -260,10 +249,10 @@
</font>
</Text>
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="130.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
<columns>
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
</columns>
<columns>
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
</columns>
</TableView>
</children>
</AnchorPane>

View File

@@ -14,7 +14,6 @@ import org.springframework.web.client.RestTemplate;
@RunWith(MockitoJUnitRunner.class)
public class UserServiceTest {
//logger that logs everything to the console
private static Logger logger = LoggerFactory.getLogger(UserServiceTest.class);
@Mock
@@ -26,8 +25,7 @@ public class UserServiceTest {
@Test
public void userRegisterTest() throws Exception {
//tests if registering works
UserDto testUser = new UserDto(1L, "Eric", 0);
UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=password"),
UserDto.class))
.thenReturn(testUser);
@@ -38,25 +36,13 @@ public class UserServiceTest {
@Test
public void userLoginTest() throws Exception {
//tests if logging in works
UserDto testUser = new UserDto(1L, "Eric", 0);
UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"),
UserDto.class))
.thenReturn(testUser);
UserDto user = userService.loginUser("Eric", "password");
Assert.assertEquals(testUser, user);
}
@Test
public void addVeganMealTest() throws Exception {
//tests if adding a vegetarian meal works
UserDto testUser = new UserDto(1L, "Eric", 0);
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/addVeganMeal?id=1&name=Eric"),
UserDto.class))
.thenReturn(testUser);
UserDto user = userService.addVeganMeal(1L, "Eric");
Assert.assertEquals(testUser, user);
}
}