Skip to content
Snippets Groups Projects
Commit f04f5058 authored by HSoreide's avatar HSoreide
Browse files

Skeleton of view of all recipes in a scrollable list

parent 6041aed0
No related branches found
No related tags found
2 merge requests!42Hs frontend recipes,!41Hs frontend recipes
Pipeline #216184 passed
Showing
with 183 additions and 118 deletions
......@@ -20,17 +20,6 @@ import no.ntnu.idatt1002.demo.data.recipes.IngredientsAtHand;
public class AddIngredientController implements Initializable {
/* ArrayList<String> testIngredients = new ArrayList<>(
Arrays.asList("Tester words", "Another tester word", "tomatoes that are canned", "minced meat", "blueberries")
*//*Arrays.asList(FoodItem.values().toString())*//*
);*/
/*List<String> testIngredients = Arrays.asList("Tester words", "Another tester word", "tomatoes that are canned", "minced meat", "blueberries");*/
/*
String[] testIngredients = {"Tester words", "Another tester word", "tomatoes that are canned", "minced meat", "blueberries"};
*/
private ObservableList<String> ingredients;
private String[] ingredientsList;
private IngredientsAtHand ingredientsAtHand;
......@@ -50,28 +39,13 @@ public class AddIngredientController implements Initializable {
@FXML
void addToFridge(ActionEvent event) throws IOException {
System.out.printf("Add ingredient to fridge");
String item = listView.getSelectionModel().getSelectedItem();
System.out.printf("The item was: %s", item);
ingredientsAtHand.addIngredient(FoodItem.valueOf(item.replace(" ", "_").toUpperCase()));
FileHandler.writeIngredientsAtHand(ingredientsAtHand, "Fridge");
/* FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/SuggestRecipesController.fxml"));
loader.load();
// Location is not set.
SuggestRecipesController suggestRecipesController = loader.getController();
suggestRecipesController.addToFridge(item);*/
// Add to existing at hand and write to file. if not null/blank
}
@FXML
void search(ActionEvent event) {
System.out.printf("Searching for ingredient to fridge");
listView.getItems().clear();
listView.getItems().addAll(searchList(searchBar.getText(), ingredientsList));
......@@ -82,15 +56,10 @@ public class AddIngredientController implements Initializable {
ingredientsAtHand = FileHandler.readIngredientsAtHand("Fridge");
/* ObservableList ingredients = FXCollections.observableArrayList(testIngredients);*/
/* ObservableList<FoodItem> ingredients = FXCollections.observableArrayList(
FoodItem.values());*/
//TODO: Move into initializer? - Tidy up!
List<String> stringIngredients = Arrays.stream(FoodItem.values()).toList().stream().map(value -> value.label).toList();
int noLengthOfList = stringIngredients.size();
ingredientsList = stringIngredients.stream().toArray(String[] ::new);
//private String[] arrayIngredients
ingredients = FXCollections.observableArrayList(stringIngredients);
// Fill list with ingredients
listView.setItems(ingredients);
......
package no.ntnu.idatt1002.demo.controller;
public class AllRecipesController {
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.recipes.FileHandler;
import no.ntnu.idatt1002.demo.data.recipes.IngredientsAtHand;
import no.ntnu.idatt1002.demo.data.recipes.Recipe;
import no.ntnu.idatt1002.demo.data.recipes.RecipeRegister;
import javax.swing.text.html.ListView;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
public class AllRecipesController implements Initializable {
IngredientsAtHand ingredientsAtHand;
RecipeRegister recipeRegister;
@FXML
private Button goBackBtn;
@FXML
// private ListView<String> recipeList;
private ObservableList<Recipe> recipes;
@FXML
private void goBack(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/SuggestRecipes.fxml"));
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
ingredientsAtHand = FileHandler.readIngredientsAtHand("Fridge");
recipeRegister = FileHandler.readRecipeRegister("Recipes");
int numberOfRecipes = recipeRegister.getRecipes().size();
ArrayList<Recipe> recipesList = recipeRegister.pickBestFits(numberOfRecipes, ingredientsAtHand);
/* recipes = FXCollections.observableArrayList(recipesList.stream().);
recipeList.setItems(recipes);*/
}
}
......@@ -23,7 +23,6 @@ public class IngredientTileController implements Initializable {
sb.append("# ").append(ingredient.getFoodType().label.substring(0,1).toUpperCase())
.append(ingredient.getFoodType().label.substring(1));
sb.append(" ").append(ingredient.getAmount()).append(" ").append(ingredient.getUnit().label);
System.out.println(sb);
text.setText(String.valueOf(sb));
}
......
......@@ -69,7 +69,6 @@ public class RecipeController implements Initializable {
ingredientList.getChildren().add(pane);
} catch (IOException e) {
throw new RuntimeException(e);
}
......@@ -93,6 +92,5 @@ public class RecipeController implements Initializable {
public void initialize(URL url, ResourceBundle resourceBundle) {
// ingredients = FXCollections.observableArrayList(recipe.getIngredientList());
}
}
......@@ -54,63 +54,14 @@ public class RecipeTileController implements Initializable {
stage.show();
}
/*
@FXML
private void showMissing(MouseEvent event) throws IOException {
missingIngredientDisplay(true, event);
}*/
/* private void missingIngredientDisplay(boolean show, MouseEvent event) throws IOException {
System.out.println(show);
FXMLLoader loader = new FXMLLoader();
//System.out.println("Time show missing ingredients!");
loader.setLocation(getClass().getResource("/view/SuggestRecipes.fxml"));
String recipeName = this.nameTag.getText();
System.out.println(recipeName);
Parent root = loader.load();
SuggestRecipesController suggestRecipesController = loader.getController();
if(show) {
suggestRecipesController.showMissingIngredients(recipeName);
} else {
suggestRecipesController.showMissingIngredients("");
}
//TODO: stage is null
Stage stage = (Stage) nameTag.getScene().getWindow();
// Stage stage = suggestRecipesController.
//Stage thisStage = (Stage) projectNameTextField.getScene().getWindow();
//Stage stage = getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}*/
public void setData(Recipe recipe) {
nameTag.setText(recipe.getName());
missingTag.setText(Integer.toString(recipe.getMissingIngredients()));
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
recipeRegister = FileHandler.readRecipeRegister("Recipes");
nameTag.setWrapText(true);
}
}
......@@ -18,7 +18,6 @@ import no.ntnu.idatt1002.demo.data.recipes.*;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
......@@ -34,6 +33,9 @@ public class SuggestRecipesController implements Initializable {
@FXML
private Button removeBtn;
@FXML
private Button showAllBtn;
@FXML
private Button goBackBtn;
......@@ -62,7 +64,6 @@ public class SuggestRecipesController implements Initializable {
@FXML
private void addIngredient(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
System.out.println("Time to pop up the pop-up!");
loader.setLocation(getClass().getResource("/view/AddIngredient.fxml"));
DialogPane addIngredientPane = loader.load();
......@@ -81,16 +82,13 @@ public class SuggestRecipesController implements Initializable {
fridgeList.setItems(fridge);
setRecipeTiles();
System.out.println("Clickecked OK!");
}else if(clickedButton.get() == ButtonType.CANCEL) {
System.out.println("Close the dialog");
}
}
@FXML
private void removeFromFridge(ActionEvent event) throws IOException {
System.out.println("Remove the selected from fridge!");
String toRemove = fridgeList.getSelectionModel().getSelectedItem();
//TODO: If anything selected!
ingredientsAtHand.removeIngredient(FoodItem.valueOf(toRemove.replace(" ", "_").toUpperCase()));
......@@ -103,17 +101,6 @@ public class SuggestRecipesController implements Initializable {
}
@FXML
private void goBack(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
private void setRecipeTiles() {
// Ingredeints at hand and recipesRegister
......@@ -169,6 +156,29 @@ public class SuggestRecipesController implements Initializable {
}
@FXML
private void goBack(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@FXML
private void showAllRecipes(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/AllRecipes.fxml"));
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
......@@ -176,7 +186,7 @@ public class SuggestRecipesController implements Initializable {
// If no ingredients at hand file exsists, add one and let it be empty. //TODO
ingredientsAtHand = FileHandler.readIngredientsAtHand("Fridge");
fridge = FXCollections.observableArrayList(ingredientsAtHand.getIngredientsAtHand().stream().map(foodItem -> foodItem.label).toList());
List<String> fridgeLabels = fridge;
//List<String> fridgeLabels = fridge;
fridgeList.setItems(fridge);
recipeRegister = FileHandler.readRecipeRegister("Recipes");
......
......@@ -11,8 +11,21 @@ public enum FoodItem {
TOMATO("tomato"),
ORANGE("orange"),
LEMON("lemon"),
SALSA_SAUCE("salsa sauce")
;
SALSA_SAUCE("salsa sauce"),
CUCUMBER("cucumber"),
SALAD("salad"),
SPINACH("spinach"),
SPRING_ROLL("spring roll"),
BELL_PEPPER("bell pepper"),
CHICKPEAS("chickpeas"),
SPAGHETTI("spaghetti"),
PASTA("pasta"),
CREAM("cream"),
HONEY("honey"),
VINEGAR("vinegar"),
TOMATO_PASTE("tomato paste"),
CHILLI("chilli"),
EGG("egg");
public final String label;
......
......@@ -8,7 +8,8 @@ public enum MeasuringUnit {
TBS("tbs."),
GR("gr."),
KG("kg."),
PC("pieces");
PC("pieces"),
CAN("can");
public final String label;
......
......@@ -97,6 +97,7 @@ public class Recipe {
throw new IllegalArgumentException("The collection of ingredients at hand is empty.");
} else {
missingIngredients = 0;
missingList = new ArrayList<>();
int notMissing = (int) ingredientList.stream().filter((inRecipe) -> ingredientsAtHand.atHand(inRecipe.getFoodType())).count();
ingredientList.forEach((inRecipe) -> {
inRecipe.setAtHand(ingredientsAtHand.atHand(inRecipe.getFoodType()));
......
......@@ -2,5 +2,13 @@ TOMATO
ORANGE
WHEAT_FLOUR
ONION
POTATO
LEMON
EGG
VINEGAR
SPAGHETTI
PASTA
CREAM
TOMATO_PASTE
CHICKPEAS
SPRING_ROLL
YELLOW_CHEESE
MILK
......@@ -17,6 +17,7 @@ Instructions
- ONION | 5.0 | PC
- LEMON | 750.0 | GR
- POTATO | 10.0 | PC
- HONEY | 2.0 | TBS
Instructions for another dish.
......
......@@ -24,7 +24,7 @@
<Insets />
</HBox.margin>
</TextField>
<Button id="button-style" fx:id="searchBtn" alignment="CENTER" contentDisplay="CENTER" mnemonicParsing="false" onAction="#search" styleClass="button-style" stylesheets="@../style.css" text="Search" textAlignment="CENTER">
<Button id="button-style" fx:id="searchBtn" alignment="CENTER" contentDisplay="CENTER" defaultButton="true" mnemonicParsing="false" onAction="#search" styleClass="button-style" stylesheets="@../style.css" text="Search" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
......
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="view.AllRecipes"
prefHeight="400.0" prefWidth="600.0">
<AnchorPane prefHeight="695.0" prefWidth="1130.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.AllRecipesController">
<children>
<ImageView fitHeight="695.0" fitWidth="1130.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../Images/backgroundMini.jpg" />
</image>
</ImageView>
<BorderPane prefHeight="695.0" prefWidth="1130.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>
<HBox prefHeight="125.0" prefWidth="1130.0" BorderPane.alignment="CENTER">
<children>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<Button layoutX="60.0" layoutY="38.0" mnemonicParsing="false" onAction="#goBack" styleClass="button-style" stylesheets="@../style.css" text="GoBack" />
</children>
</Pane>
<Pane prefHeight="100.0" prefWidth="623.0">
<children>
<Label layoutX="195.0" layoutY="21.0" text="All recipes">
<font>
<Font size="48.0" />
</font>
</Label>
</children></Pane>
<Pane prefHeight="200.0" prefWidth="200.0" />
</children></HBox>
</top>
<center>
<ScrollPane prefHeight="514.0" prefWidth="830.0" BorderPane.alignment="CENTER">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="526.0" prefWidth="819.0">
<children>
<ListView fx:id="recipeList" prefHeight="526.0" prefWidth="819.0" styleClass="list-cell" stylesheets="@../style.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</ScrollPane>
</center>
<left>
<Pane prefHeight="595.0" prefWidth="148.0" BorderPane.alignment="CENTER" />
</left>
<right>
<Pane prefHeight="557.0" prefWidth="152.0" BorderPane.alignment="CENTER" />
</right>
<bottom>
<Pane prefHeight="38.0" prefWidth="1130.0" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane>
</children>
</AnchorPane>
......@@ -40,7 +40,7 @@
<Font size="14.0" />
</font>
</Button>
<Button id="button-style" fx:id="removeBtn" layoutX="31.0" layoutY="11.0" mnemonicParsing="false" onAction="#removeFromFridge" styleClass="button-style" stylesheets="@../style.css" text="Remove">
<Button id="button-style" fx:id="removeBtn" layoutX="33.0" layoutY="8.0" mnemonicParsing="false" onAction="#removeFromFridge" styleClass="button-style" stylesheets="@../style.css" text="Remove">
<font>
<Font size="14.0" />
</font>
......@@ -86,7 +86,14 @@
</Label>
</center>
<right>
<VBox alignment="CENTER_LEFT" prefHeight="400.0" prefWidth="405.0" BorderPane.alignment="CENTER" />
<VBox alignment="CENTER_LEFT" prefHeight="400.0" prefWidth="405.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="showAllBtn" mnemonicParsing="false" onAction="#showAllRecipes" styleClass="button-style" stylesheets="@../style.css" text="Or show all recipes" textAlignment="CENTER">
<VBox.margin>
<Insets left="80.0" />
</VBox.margin>
</Button>
</children></VBox>
</right>
</BorderPane>
</top>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment