Skip to content
Snippets Groups Projects
Commit 29f1d2e0 authored by Blersch Lara's avatar Blersch Lara
Browse files

started implementing mealPlan

parent a33cd872
No related branches found
No related tags found
No related merge requests found
package mi.hdm.controllers; package mi.hdm.controllers;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import mi.hdm.mealPlan.MealPlan; import mi.hdm.mealPlan.MealPlan;
import mi.hdm.recipes.Recipe;
import mi.hdm.recipes.RecipeManager;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class MealPlanController extends BaseController { public class MealPlanController extends BaseController {
private final MealPlan mealPlan; private final MealPlan mealPlan;
private final RecipeManager recipeManager;
private final static Logger log = LogManager.getLogger(MealPlanController.class); private final static Logger log = LogManager.getLogger(MealPlanController.class);
//TODO: this page does nothing //TODO: finish this page
@FXML @FXML
private AnchorPane parent; private AnchorPane parent;
@FXML
private GridPane mealPlanGrid;
public MealPlanController(MealPlan mealPlan) { public MealPlanController(MealPlan mealPlan, RecipeManager recipeManager) {
this.mealPlan = mealPlan; this.mealPlan = mealPlan;
this.recipeManager = recipeManager;
} }
@FXML @FXML
public void initialize() { public void initialize() {
loadHeader(parent); loadHeader(parent);
displayMealPlan();
}
private void displayMealPlan() {
LocalDate today = LocalDate.now();
for(int j=1; j<7; j++) {
Label date = new Label(today.plusDays(j).format(DateTimeFormatter.ofPattern("dd.MM.")));
Font font = Font.font("System", FontWeight.BOLD, 17);
date.setFont(font);
mealPlanGrid.add(date, j, 0);
}
for (int j=0; j<7; j++) {
final int J = j;
mealPlan.getRecipeCodeForDay(LocalDate.now().plusDays(j)).ifPresent(code -> {
Recipe r = recipeManager.getRecipeByCode(code);
Label name = new Label(r.getName());
mealPlanGrid.add(name, J, 1);
});
mealPlan.getRecipeCodeForDay(LocalDate.now().plusDays(j)).ifPresentOrElse(code -> {
Recipe r = recipeManager.getRecipeByCode(code);
Label name = new Label(r.getName());
mealPlanGrid.add(name, J, 1);
}, () -> {
Button addRecipeButton = new Button("add recipe");
mealPlanGrid.add(addRecipeButton, J, 1);
//TODO: add listener and search to add a recipe
});
}
} }
} }
...@@ -60,7 +60,6 @@ public class RecipeViewController extends BaseController { ...@@ -60,7 +60,6 @@ public class RecipeViewController extends BaseController {
recipeDescription.setText(recipe.getDescription()); recipeDescription.setText(recipe.getDescription());
recipePreparation.setText(String.join("\n", recipe.getPreparation())); recipePreparation.setText(String.join("\n", recipe.getPreparation()));
//TODO: amount and measurement are not displayed, but without the name they are
recipe.getIngredients().forEach((code, amount) -> { recipe.getIngredients().forEach((code, amount) -> {
Ingredient i = ingredientManager.getIngredient(code).orElseThrow(); Ingredient i = ingredientManager.getIngredient(code).orElseThrow();
IngredientLabel ingredientLabel = new IngredientLabel(amount, i); IngredientLabel ingredientLabel = new IngredientLabel(amount, i);
......
...@@ -127,7 +127,8 @@ public class ShoppingListViewController extends BaseController { ...@@ -127,7 +127,8 @@ public class ShoppingListViewController extends BaseController {
/** /**
* This method reloads the ingredients in the shopping list view * This method reloads the ingredients in the shopping list view
* by clearing it and then refill it with all ingredients from the current shoppingList * by clearing it and then refill it with all ingredients from the current shoppingList.
* If an ingredient is marked as done, it is loaded with a ticked checkbox.
*/ */
private void displayShoppingList() { private void displayShoppingList() {
selectedIngredientsVbox.getChildren().clear(); selectedIngredientsVbox.getChildren().clear();
......
...@@ -55,7 +55,7 @@ public enum View { ...@@ -55,7 +55,7 @@ public enum View {
); );
case MEALPLAN_VIEW -> loader.setControllerFactory((callback) -> case MEALPLAN_VIEW -> loader.setControllerFactory((callback) ->
new MealPlanController(model.getMealPlan()) new MealPlanController(model.getMealPlan(), model.getRecipeManager())
); );
case RECIPE_CREATOR -> loader.setControllerFactory((callback) -> case RECIPE_CREATOR -> loader.setControllerFactory((callback) ->
......
...@@ -4,31 +4,24 @@ ...@@ -4,31 +4,24 @@
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<AnchorPane fx:id="parent" prefHeight="540.0" prefWidth="872.0" xmlns="http://javafx.com/javafx/14"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="mi.hdm.controllers.MealPlanController"> <AnchorPane fx:id="parent" prefHeight="540.0" prefWidth="872.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mi.hdm.controllers.MealPlanController">
<children> <children>
<VBox layoutY="69.0" prefHeight="445.0" prefWidth="872.0" AnchorPane.bottomAnchor="0.0" <VBox layoutY="69.0" prefHeight="445.0" prefWidth="872.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<GridPane hgap="8.0" prefHeight="197.0" prefWidth="190.0" vgap="8.0"> <GridPane hgap="8.0" prefHeight="57.0" prefWidth="842.0" vgap="8.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="78.0"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="78.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="473.0"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="473.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="49.999996185302734" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="49.999996185302734" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="140.00000381469727" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<VBox.margin> <VBox.margin>
<Insets left="15.0" right="15.0" /> <Insets left="15.0" right="15.0" />
</VBox.margin> </VBox.margin>
<children> <children>
<Text fill="#1e1e1e" strokeType="OUTSIDE" strokeWidth="0.0" text="Nutrition" GridPane.rowIndex="1" GridPane.valignment="BOTTOM">
<font>
<Font name="Arial Bold" size="25.0" />
</font>
</Text>
<Label alignment="TOP_CENTER" text="Meal Plan" textFill="#d91c1c" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="TOP"> <Label alignment="TOP_CENTER" text="Meal Plan" textFill="#d91c1c" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="TOP">
<font> <font>
<Font name="Arial" size="34.0" /> <Font name="Arial" size="34.0" />
...@@ -36,8 +29,38 @@ ...@@ -36,8 +29,38 @@
</Label> </Label>
</children> </children>
</GridPane> </GridPane>
<GridPane fx:id="mealPlanGrid" prefHeight="214.0" prefWidth="812.0" GridPane.columnIndex="1" GridPane.rowIndex="0" gridLinesVisible="true">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="110.0" minHeight="10.0" prefHeight="32.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="204.0" minHeight="10.0" prefHeight="182.0" vgrow="SOMETIMES" />
</rowConstraints>
<VBox.margin>
<Insets bottom="30.0" left="30.0" right="30.0" top="30.0" />
</VBox.margin>
<children>
<Label prefHeight="32.0" prefWidth="116.0" text="Today">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children>
</GridPane>
<VBox prefHeight="200.0" prefWidth="522.0"> <VBox prefHeight="200.0" prefWidth="522.0">
<children> <children>
<Text fill="#1e1e1e" strokeType="OUTSIDE" strokeWidth="0.0" text="Nutrition">
<font>
<Font name="Arial Bold" size="25.0" />
</font>
</Text>
<HBox alignment="CENTER_LEFT" prefHeight="57.0" prefWidth="872.0"> <HBox alignment="CENTER_LEFT" prefHeight="57.0" prefWidth="872.0">
<children> <children>
<Text fill="#1e1e1e" strokeType="OUTSIDE" strokeWidth="0.0" text="Fat" wrappingWidth="83.47006416320801"> <Text fill="#1e1e1e" strokeType="OUTSIDE" strokeWidth="0.0" text="Fat" wrappingWidth="83.47006416320801">
......
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