add: create Food with allergies
This commit is contained in:
parent
c49d3cb699
commit
47905bc8d0
@ -1,5 +1,7 @@
|
|||||||
package com.bib.essensbestellungsverwaltung;
|
package com.bib.essensbestellungsverwaltung;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
@ -7,6 +9,7 @@ import javafx.scene.control.RadioButton;
|
|||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import org.controlsfx.control.CheckComboBox;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -27,9 +30,18 @@ public class CreateFoodController {
|
|||||||
@FXML
|
@FXML
|
||||||
public RadioButton isFleischRadio;
|
public RadioButton isFleischRadio;
|
||||||
@FXML
|
@FXML
|
||||||
public TextArea allergienTextBox;
|
|
||||||
@FXML
|
|
||||||
public Text responseText;
|
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
|
@FXML
|
||||||
public void onAbbrechen(ActionEvent actionEvent) {
|
public void onAbbrechen(ActionEvent actionEvent) {
|
||||||
@ -78,7 +90,12 @@ public class CreateFoodController {
|
|||||||
int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3;
|
int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3;
|
||||||
FoodType foodType = new FoodType(ft, "Vegan");
|
FoodType foodType = new FoodType(ft, "Vegan");
|
||||||
List<Allergy> allergies = new ArrayList<>();
|
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));
|
long id = FoodMgr.createFood(new Food(gerichtName, beschreibung, isNachtisch, foodType, allergies));
|
||||||
if(id <= 0){
|
if(id <= 0){
|
||||||
@ -102,6 +119,6 @@ public class CreateFoodController {
|
|||||||
isVeganRadio.setSelected(false);
|
isVeganRadio.setSelected(false);
|
||||||
isVegetarischRadio.setSelected(false);
|
isVegetarischRadio.setSelected(false);
|
||||||
isFleischRadio.setSelected(false);
|
isFleischRadio.setSelected(false);
|
||||||
allergienTextBox.setText("");
|
allergienComboBox.getCheckModel().clearChecks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.text.*?>
|
<?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">
|
<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>
|
<children>
|
||||||
@ -90,8 +91,8 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox prefHeight="76.0" prefWidth="459.0">
|
<HBox prefHeight="76.0" prefWidth="459.0">
|
||||||
<children>
|
<children>
|
||||||
<Label prefHeight="41.0" prefWidth="171.0" text="Allergien mit Komma getrennt" />
|
<Label prefHeight="25.0" prefWidth="171.0" text="Allergien" />
|
||||||
<TextArea fx:id="allergienTextBox" prefHeight="76.0" prefWidth="246.0" />
|
<CheckComboBox fx:id="allergienComboBox" prefHeight="25.0" prefWidth="200.0" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<Text fx:id="responseText" fill="RED" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="459.13673400878906">
|
<Text fx:id="responseText" fill="RED" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="459.13673400878906">
|
||||||
|
Loading…
Reference in New Issue
Block a user