feat: init ui definition nutrition view
This commit is contained in:
parent
f9d4901b6c
commit
3301c75354
5 changed files with 158 additions and 1 deletions
|
|
@ -56,7 +56,7 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
public Label recipesLabel;
|
public Label recipesLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<Recipe> recipeList;
|
public ListView<Recipe> recipeList;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button addRecipeButton;
|
private Button addRecipeButton;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package client.scenes.nutrition;
|
||||||
|
|
||||||
|
import client.utils.LocaleAware;
|
||||||
|
import client.utils.LocaleManager;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class NutritionDetailsCtrl implements LocaleAware {
|
||||||
|
private final LocaleManager manager;
|
||||||
|
|
||||||
|
public Label ingredientName;
|
||||||
|
public Label fatInputLabel;
|
||||||
|
public Label proteinInputLabel;
|
||||||
|
public Label carbInputLabel;
|
||||||
|
public Label estimatedKcalLabel;
|
||||||
|
public Label usageLabel;
|
||||||
|
|
||||||
|
public TextField fatInputElement;
|
||||||
|
public TextField proteinInputElement;
|
||||||
|
public TextField carbInputElement;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public NutritionDetailsCtrl(
|
||||||
|
LocaleManager manager
|
||||||
|
) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void updateText() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocaleManager getLocaleManager() {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package client.scenes.nutrition;
|
||||||
|
|
||||||
|
import client.scenes.FoodpalApplicationCtrl;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import commons.Recipe;
|
||||||
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class NutritionViewCtrl {
|
||||||
|
private ObservableList<Recipe> recipes;
|
||||||
|
private HashMap<String, Integer> ingredientStats;
|
||||||
|
public ListView<String> nutritionIngredientsView;
|
||||||
|
private final NutritionDetailsCtrl nutritionDetailsCtrl;
|
||||||
|
|
||||||
|
// TODO into Ingredient class definition
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comedically verbose function to count unique appearances of an ingredient by name in each recipe.
|
||||||
|
* For each recipe:
|
||||||
|
* 1. Collect unique ingredients that appeared in that recipe.
|
||||||
|
* 2. For each unique ingredient in said recipe:
|
||||||
|
* 1. Initialize the appearance for that ingredient to 0.
|
||||||
|
* 2. For each recipe in list:
|
||||||
|
* 1. If the name of the ingredient exists in the recipe list, increment the statistic by 1.
|
||||||
|
* 2. Else maintain the same value for that statistic.
|
||||||
|
* @param recipeList
|
||||||
|
*/
|
||||||
|
private void updateIngredientStats(
|
||||||
|
List<Recipe> recipeList
|
||||||
|
) {
|
||||||
|
recipeList.forEach(recipe -> {
|
||||||
|
Set<String> uniqueIngredients = new HashSet<>(recipe.getIngredients());
|
||||||
|
nutritionIngredientsView.getItems().setAll(uniqueIngredients);
|
||||||
|
uniqueIngredients.forEach(ingredient -> {
|
||||||
|
ingredientStats.put(ingredient, 0);
|
||||||
|
recipeList.forEach(r ->
|
||||||
|
ingredientStats.put(
|
||||||
|
ingredient,
|
||||||
|
ingredientStats.get(ingredient) + (
|
||||||
|
(r.getIngredients().contains(ingredient))
|
||||||
|
? 1 : 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@Inject
|
||||||
|
public NutritionViewCtrl(
|
||||||
|
FoodpalApplicationCtrl foodpalApplicationCtrl,
|
||||||
|
NutritionDetailsCtrl nutritionDetailsCtrl
|
||||||
|
) {
|
||||||
|
this.recipes = foodpalApplicationCtrl.recipeList.getItems();
|
||||||
|
this.recipes.addListener((ListChangeListener<? super Recipe>) _ -> {
|
||||||
|
updateIngredientStats(this.recipes);
|
||||||
|
});
|
||||||
|
this.nutritionDetailsCtrl = nutritionDetailsCtrl;
|
||||||
|
this.nutritionIngredientsView.selectionModelProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<?import javafx.scene.shape.Line?>
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="client.scenes.nutrition.NutritionDetailsCtrl"
|
||||||
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
|
<VBox visible="false">
|
||||||
|
<Label fx:id="ingredientName" />
|
||||||
|
<HBox>
|
||||||
|
<Label fx:id="fatInputLabel">Fat: </Label>
|
||||||
|
<TextField fx:id="fatInputElement" />
|
||||||
|
</HBox>
|
||||||
|
<HBox>
|
||||||
|
<Label fx:id="proteinInputLabel">Protein: </Label>
|
||||||
|
<TextField fx:id="proteinInputElement" />
|
||||||
|
</HBox>
|
||||||
|
<HBox>
|
||||||
|
<Label fx:id="carbInputLabel">Carbohydrates: </Label>
|
||||||
|
<TextField fx:id="carbInputElement" />
|
||||||
|
</HBox>
|
||||||
|
<Label fx:id="estimatedKcalLabel">Estimated: 0kcal</Label>
|
||||||
|
<Label fx:id="usageLabel">Not used in any recipes</Label>
|
||||||
|
</VBox>
|
||||||
|
|
||||||
|
</AnchorPane>
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.util.*?>
|
||||||
|
<?import javafx.scene.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="client.scenes.nutrition.NutritionViewCtrl"
|
||||||
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
|
<SplitPane>
|
||||||
|
<ListView fx:id="nutritionIngredientsView" />
|
||||||
|
<AnchorPane>
|
||||||
|
<fx:include source="NutritionDetails.fxml" />
|
||||||
|
</AnchorPane>
|
||||||
|
</SplitPane>
|
||||||
|
</AnchorPane>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue