Adding preparation steps is possible, but no automatically refresh
This commit is contained in:
parent
717684e159
commit
1414393aad
8 changed files with 158 additions and 16 deletions
|
|
@ -50,9 +50,11 @@ public class Main extends Application {
|
||||||
var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml");
|
var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml");
|
||||||
var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.fxml");
|
var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.fxml");
|
||||||
var addIngredient = FXML.load(AddIngredientCtrl.class, "client", "scenes", "AddIngredient.fxml");
|
var addIngredient = FXML.load(AddIngredientCtrl.class, "client", "scenes", "AddIngredient.fxml");
|
||||||
|
var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
|
||||||
mainCtrl.initialize(primaryStage, overview, addName, foodpal, addIngredient);
|
mainCtrl.initialize(primaryStage, overview, addName, foodpal, addIngredient, addStep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,13 +19,13 @@ import client.utils.ServerUtils;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import commons.Recipe;
|
import commons.Recipe;
|
||||||
import jakarta.ws.rs.WebApplicationException;
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AddIngredientCtrl {
|
public class AddIngredientCtrl {
|
||||||
|
|
||||||
|
|
@ -33,7 +33,8 @@ public class AddIngredientCtrl {
|
||||||
private final MainCtrl mainCtrl;
|
private final MainCtrl mainCtrl;
|
||||||
private final FoodpalApplicationCtrl foodpalCtrl;
|
private final FoodpalApplicationCtrl foodpalCtrl;
|
||||||
|
|
||||||
public TextField recipeName;
|
@FXML
|
||||||
|
public TextField ingredient;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -51,7 +52,7 @@ public class AddIngredientCtrl {
|
||||||
public void ok() throws IOException, InterruptedException {
|
public void ok() throws IOException, InterruptedException {
|
||||||
try {
|
try {
|
||||||
Recipe selected = foodpalCtrl.getSelectedRecipe();
|
Recipe selected = foodpalCtrl.getSelectedRecipe();
|
||||||
server.addRecipeIngredient(selected, recipeName.getText());
|
server.addRecipeIngredient(selected, ingredient.getText());
|
||||||
} catch (WebApplicationException e) {
|
} catch (WebApplicationException e) {
|
||||||
|
|
||||||
var alert = new Alert(Alert.AlertType.ERROR);
|
var alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
|
@ -67,7 +68,7 @@ public class AddIngredientCtrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearFields() {
|
private void clearFields() {
|
||||||
recipeName.clear();
|
ingredient.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void keyPressed(KeyEvent e) throws IOException, InterruptedException {
|
public void keyPressed(KeyEvent e) throws IOException, InterruptedException {
|
||||||
|
|
|
||||||
86
client/src/main/java/client/scenes/AddStepsCtrl.java
Normal file
86
client/src/main/java/client/scenes/AddStepsCtrl.java
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2021 Delft University of Technology
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package client.scenes;
|
||||||
|
|
||||||
|
import client.utils.ServerUtils;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import commons.Recipe;
|
||||||
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class AddStepsCtrl {
|
||||||
|
|
||||||
|
private final ServerUtils server;
|
||||||
|
private final MainCtrl mainCtrl;
|
||||||
|
private final FoodpalApplicationCtrl foodpalCtrl;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField preparationStep;
|
||||||
|
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public AddStepsCtrl(ServerUtils server, MainCtrl mainCtrl, FoodpalApplicationCtrl foodpalCtrl) {
|
||||||
|
this.mainCtrl = mainCtrl;
|
||||||
|
this.server = server;
|
||||||
|
this.foodpalCtrl = foodpalCtrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() throws IOException, InterruptedException {
|
||||||
|
clearFields();
|
||||||
|
mainCtrl.showFoodpal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ok() throws IOException, InterruptedException {
|
||||||
|
try {
|
||||||
|
Recipe selected = foodpalCtrl.getSelectedRecipe();
|
||||||
|
server.addRecipeStep(selected, preparationStep.getText());
|
||||||
|
} catch (WebApplicationException e) {
|
||||||
|
|
||||||
|
var alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
alert.setContentText(e.getMessage());
|
||||||
|
alert.showAndWait();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
clearFields();
|
||||||
|
mainCtrl.showFoodpal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearFields() {
|
||||||
|
preparationStep.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e) throws IOException, InterruptedException {
|
||||||
|
switch (e.getCode()) {
|
||||||
|
case ENTER:
|
||||||
|
ok();
|
||||||
|
break;
|
||||||
|
case ESCAPE:
|
||||||
|
cancel();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -168,7 +168,7 @@ public class FoodpalApplicationCtrl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can add ingredients. you get send to a different scene that creates the ingredient
|
* You can add ingredients. you get send to a different scene that creates the ingredient
|
||||||
* It doesn't automaticcaly refresh yet so before you can see the new ingredient you have to first click on a
|
* It doesn't automatically refresh yet so before you can see the new ingredient you have to first click on a
|
||||||
* different recipe and come back after
|
* different recipe and come back after
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
|
|
@ -177,10 +177,16 @@ public class FoodpalApplicationCtrl {
|
||||||
mainCtrl.showAddIngredient();
|
mainCtrl.showAddIngredient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can add steps. you get send to a different scene that creates the Step
|
||||||
|
* It doesn't automatically refresh yet so before you can see the new step you have to first click on a
|
||||||
|
* different recipe and come back after
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void addPreparationStep() {
|
private void addPreparationStep() {
|
||||||
// TODO: make it possible to add step to current recipe
|
|
||||||
System.out.println("Add preparation step clicked");
|
System.out.println("Add preparation step clicked");
|
||||||
|
mainCtrl.showAddSteps();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Language buttons
|
// Language buttons
|
||||||
|
|
@ -200,11 +206,16 @@ public class FoodpalApplicationCtrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//without caused errors
|
||||||
@FXML
|
@FXML
|
||||||
private void MakePrintable() {
|
private void MakePrintable() {
|
||||||
System.out.println("Recipe printed");
|
System.out.println("Recipe printed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the recipe that was selected
|
||||||
|
* @return the selected recipe
|
||||||
|
*/
|
||||||
public Recipe getSelectedRecipe() {
|
public Recipe getSelectedRecipe() {
|
||||||
return recipeList.getSelectionModel().getSelectedItem();
|
return recipeList.getSelectionModel().getSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package client.scenes;
|
package client.scenes;
|
||||||
|
|
||||||
import commons.Recipe;
|
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
@ -36,14 +35,18 @@ public class MainCtrl {
|
||||||
private FoodpalApplicationCtrl foodpalCtrl;
|
private FoodpalApplicationCtrl foodpalCtrl;
|
||||||
private Scene foodpal;
|
private Scene foodpal;
|
||||||
|
|
||||||
private AddIngredientCtrl AddIngredientCtrl;
|
private AddIngredientCtrl addIngredientCtrl;
|
||||||
private Scene addIngredient;
|
private Scene addIngredient;
|
||||||
|
|
||||||
|
private AddStepsCtrl addStepsCtrl;
|
||||||
|
private Scene addStep;
|
||||||
|
|
||||||
public void initialize(Stage primaryStage,
|
public void initialize(Stage primaryStage,
|
||||||
Pair<QuoteOverviewCtrl, Parent> overview,
|
Pair<QuoteOverviewCtrl, Parent> overview,
|
||||||
Pair<AddNameCtrl, Parent> addName,
|
Pair<AddNameCtrl, Parent> addName,
|
||||||
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
||||||
Pair<AddIngredientCtrl, Parent> addIngredient
|
Pair<AddIngredientCtrl, Parent> addIngredient,
|
||||||
|
Pair<AddStepsCtrl, Parent> addStep
|
||||||
) throws IOException, InterruptedException {
|
) throws IOException, InterruptedException {
|
||||||
|
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
|
|
@ -57,9 +60,12 @@ public class MainCtrl {
|
||||||
this.foodpalCtrl = foodpal.getKey();
|
this.foodpalCtrl = foodpal.getKey();
|
||||||
this.foodpal = new Scene(foodpal.getValue());
|
this.foodpal = new Scene(foodpal.getValue());
|
||||||
|
|
||||||
this.AddIngredientCtrl = addIngredient.getKey();
|
this.addIngredientCtrl = addIngredient.getKey();
|
||||||
this.addIngredient = new Scene(addIngredient.getValue());
|
this.addIngredient = new Scene(addIngredient.getValue());
|
||||||
|
|
||||||
|
this.addStepsCtrl = addStep.getKey();
|
||||||
|
this.addStep = new Scene(addStep.getValue());
|
||||||
|
|
||||||
|
|
||||||
showFoodpal();
|
showFoodpal();
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
@ -90,11 +96,24 @@ public class MainCtrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAddIngredient() {
|
public void showAddIngredient() {
|
||||||
primaryStage.setTitle("adding ingredients");
|
primaryStage.setTitle("To add ingredients");
|
||||||
primaryStage.setScene(addIngredient);
|
primaryStage.setScene(addIngredient);
|
||||||
addName.setOnKeyPressed(e -> {
|
addIngredient.setOnKeyPressed(e -> {
|
||||||
try {
|
try {
|
||||||
AddIngredientCtrl.keyPressed(e);
|
addIngredientCtrl.keyPressed(e);
|
||||||
|
} catch (IOException | InterruptedException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showAddSteps() {
|
||||||
|
primaryStage.setTitle("To add preparation steps");
|
||||||
|
primaryStage.setScene(addStep);
|
||||||
|
addStep.setOnKeyPressed(e -> {
|
||||||
|
try {
|
||||||
|
addStepsCtrl.keyPressed(e);
|
||||||
} catch (IOException | InterruptedException ex) {
|
} catch (IOException | InterruptedException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,4 +191,12 @@ public class ServerUtils {
|
||||||
|
|
||||||
return objectMapper.readValue(response.body(),Recipe.class);
|
return objectMapper.readValue(response.body(),Recipe.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Recipe addRecipeStep(Recipe recipe, String preparationStep) throws IOException, InterruptedException {
|
||||||
|
List<String> preparationSteps = new ArrayList<>(recipe.getPreparationSteps());
|
||||||
|
preparationSteps.add(preparationStep);
|
||||||
|
recipe.setPreparationSteps(preparationSteps);
|
||||||
|
|
||||||
|
return updateRecipe(recipe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<children>
|
<children>
|
||||||
<Button layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
|
<Button layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
|
||||||
<Button layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
|
<Button layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
|
||||||
<TextField fx:id="recipeName" layoutX="109.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" />
|
<TextField fx:id="ingredient" layoutX="120.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" />
|
||||||
<Label layoutX="28.0" layoutY="29.0" text="Recipe Name" />
|
<Label layoutX="28.0" layoutY="29.0" text="Ingredient Name" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
|
||||||
15
client/src/main/resources/client/scenes/AddSteps.fxml
Normal file
15
client/src/main/resources/client/scenes/AddSteps.fxml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
|
||||||
|
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="94.0" prefWidth="470.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="client.scenes.AddStepsCtrl">
|
||||||
|
<children>
|
||||||
|
<Button layoutX="417.0" layoutY="54.0" mnemonicParsing="false" onAction="#ok" text="Ok" />
|
||||||
|
<Button layoutX="349.0" layoutY="54.0" mnemonicParsing="false" onAction="#cancel" text="Cancel" />
|
||||||
|
<TextField fx:id="preparationStep" layoutX="120.0" layoutY="24.0" prefHeight="18.0" prefWidth="292.0" />
|
||||||
|
<Label layoutX="28.0" layoutY="29.0" text="Preparation step" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue