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();
}
}

View File

@ -4,6 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import org.controlsfx.control.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="731.0" stylesheets="@createFood.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.CreateFoodController">
<children>
@ -90,8 +91,8 @@
</HBox>
<HBox prefHeight="76.0" prefWidth="459.0">
<children>
<Label prefHeight="41.0" prefWidth="171.0" text="Allergien mit Komma getrennt" />
<TextArea fx:id="allergienTextBox" prefHeight="76.0" prefWidth="246.0" />
<Label prefHeight="25.0" prefWidth="171.0" text="Allergien" />
<CheckComboBox fx:id="allergienComboBox" prefHeight="25.0" prefWidth="200.0" />
</children>
</HBox>
<Text fx:id="responseText" fill="RED" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="459.13673400878906">