diff --git a/client/src/main/java/client/Main.java b/client/src/main/java/client/Main.java index 25f7357..6b9db4f 100644 --- a/client/src/main/java/client/Main.java +++ b/client/src/main/java/client/Main.java @@ -17,15 +17,11 @@ package client; import static com.google.inject.Guice.createInjector; -import java.io.IOException; -import java.net.URISyntaxException; - import client.scenes.AddStepsCtrl; import client.scenes.MainCtrl; import client.scenes.AddIngredientCtrl; import client.scenes.AddNameCtrl; import client.scenes.FoodpalApplicationCtrl; -import client.scenes.QuoteOverviewCtrl; import com.google.inject.Injector; import client.utils.ServerUtilsExample; @@ -37,7 +33,7 @@ public class Main extends Application { private static final Injector INJECTOR = createInjector(new MyModule()); private static final MyFXML FXML = new MyFXML(INJECTOR); - public static void main(String[] args) throws URISyntaxException, IOException { + public static void main(String[] args){ launch(); } @@ -51,15 +47,12 @@ public class Main extends Application { return; } - var overview = FXML.load(QuoteOverviewCtrl.class, "client", "scenes", "QuoteOverview.fxml"); var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml"); var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.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); - mainCtrl.initialize(primaryStage, overview, addName, foodpal, addIngredient, addStep); + mainCtrl.initialize(primaryStage, addName, foodpal, addIngredient, addStep); } } \ No newline at end of file diff --git a/client/src/main/java/client/MyModule.java b/client/src/main/java/client/MyModule.java index c842dde..df14aa2 100644 --- a/client/src/main/java/client/MyModule.java +++ b/client/src/main/java/client/MyModule.java @@ -22,7 +22,6 @@ import com.google.inject.Scopes; import client.scenes.AddNameCtrl; import client.scenes.MainCtrl; -import client.scenes.QuoteOverviewCtrl; public class MyModule implements Module { @@ -31,6 +30,5 @@ public class MyModule implements Module { binder.bind(MainCtrl.class).in(Scopes.SINGLETON); binder.bind(AddNameCtrl.class).in(Scopes.SINGLETON); binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON); - binder.bind(QuoteOverviewCtrl.class).in(Scopes.SINGLETON); } } \ No newline at end of file diff --git a/client/src/main/java/client/scenes/MainCtrl.java b/client/src/main/java/client/scenes/MainCtrl.java index 6e24fd1..018eec1 100644 --- a/client/src/main/java/client/scenes/MainCtrl.java +++ b/client/src/main/java/client/scenes/MainCtrl.java @@ -26,9 +26,6 @@ public class MainCtrl { private Stage primaryStage; - private QuoteOverviewCtrl overviewCtrl; - private Scene overview; - private AddNameCtrl addNameCtrl; private Scene addName; @@ -42,7 +39,6 @@ public class MainCtrl { private Scene addStep; public void initialize(Stage primaryStage, - Pair overview, Pair addName, Pair foodpal, Pair addIngredient, @@ -51,9 +47,6 @@ public class MainCtrl { this.primaryStage = primaryStage; - this.overviewCtrl = overview.getKey(); - this.overview = new Scene(overview.getValue()); - this.addNameCtrl = addName.getKey(); this.addName = new Scene(addName.getValue()); @@ -71,11 +64,6 @@ public class MainCtrl { primaryStage.show(); } - public void showOverview() { - primaryStage.setTitle("Quotes: Overview"); - primaryStage.setScene(overview); - overviewCtrl.refresh(); - } public void showAddName() { primaryStage.setTitle("Naming recipes"); diff --git a/client/src/main/java/client/scenes/QuoteOverviewCtrl.java b/client/src/main/java/client/scenes/QuoteOverviewCtrl.java deleted file mode 100644 index 47e241b..0000000 --- a/client/src/main/java/client/scenes/QuoteOverviewCtrl.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 java.net.URL; -import java.util.ResourceBundle; - -import com.google.inject.Inject; - -import client.utils.ServerUtilsExample; -import commons.Quote; -import javafx.beans.property.SimpleStringProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; - -public class QuoteOverviewCtrl implements Initializable { - - private final ServerUtilsExample server; - private final MainCtrl mainCtrl; - - private ObservableList data; - - @FXML - private TableView table; - @FXML - private TableColumn colFirstName; - @FXML - private TableColumn colLastName; - @FXML - private TableColumn colQuote; - - @Inject - public QuoteOverviewCtrl(ServerUtilsExample server, MainCtrl mainCtrl) { - this.server = server; - this.mainCtrl = mainCtrl; - } - - @Override - public void initialize(URL location, ResourceBundle resources) { - colFirstName.setCellValueFactory(q -> new SimpleStringProperty(q.getValue().person.firstName)); - colLastName.setCellValueFactory(q -> new SimpleStringProperty(q.getValue().person.lastName)); - colQuote.setCellValueFactory(q -> new SimpleStringProperty(q.getValue().quote)); - } - - public void addQuote() { - mainCtrl.showAddName(); - } - - public void refresh() { - var quotes = server.getQuotes(); - data = FXCollections.observableList(quotes); - table.setItems(data); - } -} \ No newline at end of file diff --git a/client/src/main/java/client/utils/ServerUtils.java b/client/src/main/java/client/utils/ServerUtils.java index ed52956..7bf5de9 100644 --- a/client/src/main/java/client/utils/ServerUtils.java +++ b/client/src/main/java/client/utils/ServerUtils.java @@ -158,22 +158,22 @@ public class ServerUtils { return true; } - public Recipe addRecipeName(String name) throws IOException, InterruptedException { + public void addRecipeName(String name) throws IOException, InterruptedException { Recipe newRecipe = new Recipe(); newRecipe.setName(name); - return addRecipe(newRecipe); + addRecipe(newRecipe); } - public Recipe addRecipeIngredient(Recipe recipe, String ingredient) throws IOException, InterruptedException { + public void addRecipeIngredient(Recipe recipe, String ingredient) throws IOException, InterruptedException { List ingredients = new ArrayList<>(recipe.getIngredients()); ingredients.add(ingredient); recipe.setIngredients(ingredients); - return updateRecipe(recipe); //updates the recipe instead of creating an whole new recipe + updateRecipe(recipe); } - public Recipe updateRecipe(Recipe recipe) throws IOException, InterruptedException { + public void updateRecipe(Recipe recipe) throws IOException, InterruptedException { String json = objectMapper.writeValueAsString(recipe); HttpRequest request = HttpRequest.newBuilder() @@ -187,14 +187,14 @@ public class ServerUtils { throw new IOException("Failed to update recipe: " + recipe.toDetailedString() + "body: " + response.body()); } - return objectMapper.readValue(response.body(),Recipe.class); + objectMapper.readValue(response.body(), Recipe.class); } - public Recipe addRecipeStep(Recipe recipe, String preparationStep) throws IOException, InterruptedException { + public void addRecipeStep(Recipe recipe, String preparationStep) throws IOException, InterruptedException { List preparationSteps = new ArrayList<>(recipe.getPreparationSteps()); preparationSteps.add(preparationStep); recipe.setPreparationSteps(preparationSteps); - return updateRecipe(recipe); + updateRecipe(recipe); } } \ No newline at end of file