add: create Food with allergies

This commit is contained in:
Johannes Kantz
2023-02-04 20:04:26 +01:00
parent c49d3cb699
commit 47905bc8d0
2 changed files with 24 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
package com.bib.essensbestellungsverwaltung;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
@@ -7,6 +9,7 @@ import javafx.scene.control.RadioButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import org.controlsfx.control.CheckComboBox;
import java.util.ArrayList;
import java.util.List;
@@ -27,9 +30,18 @@ public class CreateFoodController {
@FXML
public RadioButton isFleischRadio;
@FXML
public TextArea allergienTextBox;
@FXML
public Text responseText;
public CheckComboBox allergienComboBox;
@FXML
public void initialize() {
List<String> a = Database.getTable("allergy");
ObservableList<String> allergies = FXCollections.observableArrayList();
for (String allergie : a) {
allergies.add(allergie.split(":")[0] + ": " + allergie.split(":")[1]);
}
allergienComboBox.getItems().addAll(allergies);
}
@FXML
public void onAbbrechen(ActionEvent actionEvent) {
@@ -78,7 +90,12 @@ public class CreateFoodController {
int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3;
FoodType foodType = new FoodType(ft, "Vegan");
List<Allergy> allergies = new ArrayList<>();
// TODO: allergien hinzufügen
allergienComboBox.getCheckModel().getCheckedItems().stream().forEach(a -> {
long id = Integer.parseInt(a.toString().split(":")[0]);
String name = a.toString().split(":")[1].trim();
allergies.add((new Allergy(id, name, "")));
});
System.out.println(allergies.get(0).getName());
long id = FoodMgr.createFood(new Food(gerichtName, beschreibung, isNachtisch, foodType, allergies));
if(id <= 0){
@@ -102,6 +119,6 @@ public class CreateFoodController {
isVeganRadio.setSelected(false);
isVegetarischRadio.setSelected(false);
isFleischRadio.setSelected(false);
allergienTextBox.setText("");
allergienComboBox.getCheckModel().clearChecks();
}
}