feat/kindErstellen #9

Merged
PBS2H21ASH merged 23 commits from feat/kindErstellen into stable 2023-02-05 20:40:12 +01:00
4 changed files with 196 additions and 102 deletions
Showing only changes of commit b37cd2ad38 - Show all commits

View File

@ -0,0 +1,142 @@
package com.bib.essensbestellungsverwaltung;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import org.controlsfx.control.CheckComboBox;
import java.util.ArrayList;
import java.util.List;
public class ChildController {
public TextField firstName;
public ChoiceBox childChoiceBox;
public TextField lastName;
public Button kindHinzufügenButton;
public CheckComboBox allergienComboBox;
public Button kindLoeschenButton;
private Child currentChild = null;
private long selectedChildId;
@FXML
public void initialize() {
kindLoeschenButton.setDisable(true);
updateChildChoiceBoxItems();
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);
}
public void onSelectChild(ActionEvent mouseEvent) {
selectedChildId = Integer.parseInt(childChoiceBox.getValue().toString().split(":")[0]);
System.out.println("Selected Child: " + selectedChildId);
clearInputs();
if(selectedChildId == 0) {
kindHinzufügenButton.setText("Kind Hinzufügen");
kindLoeschenButton.setDisable(true);
return;
}
// Get selected child and update fields
currentChild = AccountMgr.getChildById(selectedChildId);
firstName.setText(currentChild.getFirstname());
lastName.setText(currentChild.getName());
for (AllergySeverity a : currentChild.getAllergies()){
allergienComboBox.getCheckModel().check((int) a.getAllergy().getId() - 1);
}
kindHinzufügenButton.setText("Kind updaten");
kindLoeschenButton.setDisable(false);
}
public void onKindHinzufügen(ActionEvent actionEvent) {
if(childChoiceBox.getValue() == null){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Ungültige Eingabe");
alert.setHeaderText("Sie müssen ein Kind auswählen");
alert.showAndWait();
return;
}
if(lastName.getText().isBlank() || firstName.getText().isBlank()){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Ungültige Eingabe");
alert.setHeaderText("Es wurden nicht alle Felder ausgefüllt");
alert.showAndWait();
return;
}
Address adress = AccountMgr.currentUser.getAddress();
List<AllergySeverity> allergies = new ArrayList<>();
allergienComboBox.getCheckModel().getCheckedItems().stream().forEach(a -> {
long id = Integer.parseInt(a.toString().split(":")[0]);
String name = a.toString().split(":")[1].trim();
// TODO: Allergy Severity
allergies.add(new AllergySeverity(new Allergy(id, name, ""), 2, null));
});
if(selectedChildId == 0){
// TODO: Create child
long id = AccountMgr.createChild(new Child(lastName.getText(), firstName.getText(), adress, allergies));
System.out.println("Child created: " + id);
if(id <= 0){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Es ist ein fehler beim erstellen des Kinds aufgetreten");
alert.showAndWait();
return;
}
AccountMgr.matchParentChild(String.valueOf(AccountMgr.currentUser.getId()), String.valueOf(id));
childChoiceBox.getItems().add(id + ": " + firstName.getText() + " " + lastName.getText());
childChoiceBox.setValue(childChoiceBox.getItems().get(childChoiceBox.getItems().size() - 1));
clearInputs();
onSelectChild(null);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Kind erstellt");
alert.setHeaderText("Es wurde ein Kind erstellt");
alert.showAndWait();
}else {
long id = AccountMgr.updateChild(new Child(currentChild.getId(), lastName.getText(), firstName.getText(), adress, allergies));
System.out.println("Updated Child: " + id);
}
}
private void clearInputs(){
firstName.setText("");
lastName.setText("");
allergienComboBox.getCheckModel().clearChecks();
}
public void updateChildChoiceBoxItems(){
List<Child> childList = AccountMgr.getAllChildrenFromParentWithId(AccountMgr.currentUser.getId());
ObservableList<Object> childOptions = FXCollections.observableArrayList(childList.stream().map(c -> c.getId() + ": " + c.getFirstname() + " " + c.getName()).toList().toArray(new String[0]));
childOptions.add(0, "0: neues Kind erstellen");
childChoiceBox.setItems(childOptions);
}
public void onKindLoeschen(ActionEvent actionEvent) {
AccountMgr.deleteChildWithId(currentChild.getId());
System.out.println("Deleted Child: " + currentChild.getId());
childChoiceBox.getItems().remove(childChoiceBox.getItems().stream().filter(v -> v.equals(currentChild.getId() + ": " + currentChild.getFirstname() + " " + currentChild.getName())).findFirst().get());
childChoiceBox.setValue(childChoiceBox.getItems().get(1));
onSelectChild(null);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Kind wurde gelöscht");
alert.showAndWait();
}
}

View File

@ -12,7 +12,6 @@ import java.io.IOException;
public class WorkerMenuController {
@FXML
public BorderPane contentView;
@FXML
Button tagesbestellungButton;
@FXML

View File

@ -1,48 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import org.controlsfx.control.*?>
<AnchorPane prefHeight="700.0" prefWidth="950.0" stylesheets="@child.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.ParentController">
<AnchorPane prefHeight="700.0" prefWidth="950.0" stylesheets="@child.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.ChildController">
<children>
<Text layoutX="51.0" layoutY="90.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Kinder">
<font>
<Font size="58.0" />
</font>
</Text>
<HBox id="contentContainer" alignment="CENTER" layoutX="8.0" layoutY="165.0" prefHeight="331.0" prefWidth="937.0">
<HBox id="contentContainer" alignment="CENTER" layoutX="8.0" layoutY="165.0" prefHeight="127.0" prefWidth="937.0">
<children>
<VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Name">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Vorname">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<TextField prefWidth="97.0">
<TextField fx:id="firstName" prefWidth="97.0">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</TextField>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Geburtsdatum">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<DatePicker prefHeight="26.0" prefWidth="226.0">
<VBox.margin>
<Insets top="13.0" />
</VBox.margin>
</DatePicker>
</children>
<HBox.margin>
<Insets left="15.0" right="15.0" />
@ -50,44 +34,16 @@
</VBox>
<VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Alter">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Nachname">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<TextField prefWidth="97.0">
<TextField fx:id="lastName" prefWidth="97.0">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</TextField>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Gruppe">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<ComboBox prefHeight="26.0" prefWidth="230.0">
<VBox.margin>
<Insets top="13.0" />
</VBox.margin>
</ComboBox>
</children>
<HBox.margin>
<Insets left="15.0" right="15.0" />
</HBox.margin>
</VBox>
<VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Allergien">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<ListView prefHeight="101.0" prefWidth="227.0" />
<TextField id="tfAddAllergy" promptText="Allergie hinzufügen">
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</TextField>
</children>
<HBox.margin>
<Insets left="15.0" right="15.0" />
@ -95,6 +51,19 @@
</VBox>
</children>
</HBox>
<Button id="btAddChild" layoutX="419.0" layoutY="502.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="125.0" text="Kind hinzufügen" />
<Button id="btAddChild" fx:id="kindHinzufügenButton" layoutX="779.0" layoutY="646.0" mnemonicParsing="false" onAction="#onKindHinzufügen" prefHeight="26.0" prefWidth="125.0" text="Kind hinzufügen" />
<ChoiceBox fx:id="childChoiceBox" layoutX="704.0" layoutY="62.0" onAction="#onSelectChild" prefWidth="150.0" />
<Label layoutX="704.0" layoutY="44.0" text="Kind" />
<VBox id="contentContainer" layoutX="493.0" layoutY="330.0" prefHeight="250.0" prefWidth="256.0" spacing="20.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Allergien">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<CheckComboBox fx:id="allergienComboBox" prefHeight="25.0" prefWidth="200.0" />
</children>
</VBox>
<Button id="btAddChild" fx:id="kindLoeschenButton" layoutX="621.0" layoutY="646.0" mnemonicParsing="false" onAction="#onKindLoeschen" prefHeight="26.0" prefWidth="125.0" text="Kind löschen" />
</children>
</AnchorPane>

View File

@ -1,20 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<BorderPane fx:id="contentView" prefHeight="750.0" prefWidth="1200.0" stylesheets="@menue.css"
xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.bib.essensbestellungsverwaltung.WorkerMenuController">
<BorderPane fx:id="contentView" prefHeight="750.0" prefWidth="1200.0" stylesheets="@menue.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.WorkerMenuController">
<left>
<VBox alignment="TOP_CENTER" prefHeight="750.0" prefWidth="350.0" spacing="10.0"
style="-fx-background-color: #69b6ff; -fx-padding: 20;" BorderPane.alignment="CENTER">
<VBox alignment="TOP_CENTER" prefHeight="750.0" prefWidth="350.0" spacing="10.0" style="-fx-background-color: #69b6ff; -fx-padding: 20;" BorderPane.alignment="CENTER">
<children>
<Button fx:id="tagesbestellungButton" alignment="CENTER_LEFT" mnemonicParsing="false"
onMouseClicked="#onTagesbestellungenClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Tagesbestellung">
<Button fx:id="tagesbestellungButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onTagesbestellungenClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Tagesbestellung">
<font>
<Font size="20.0" />
</font>
@ -26,9 +22,7 @@
</ImageView>
</graphic>
</Button>
<Button fx:id="monatsabrechnungButton" alignment="CENTER_LEFT" mnemonicParsing="false"
onMouseClicked="#onMonatsabrechnungClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Monatsabrechnung">
<Button fx:id="monatsabrechnungButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onMonatsabrechnungClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Monatsabrechnung">
<font>
<Font size="20.0" />
</font>
@ -40,9 +34,7 @@
</ImageView>
</graphic>
</Button>
<Button fx:id="wochenplanButton" alignment="CENTER_LEFT" mnemonicParsing="false"
onMouseClicked="#onWochenplanClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Wochenplan">
<Button fx:id="wochenplanButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onWochenplanClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Wochenplan">
<font>
<Font size="20.0" />
</font>
@ -54,9 +46,7 @@
</ImageView>
</graphic>
</Button>
<Button fx:id="mahlzeitButton" alignment="CENTER_LEFT" mnemonicParsing="false"
onMouseClicked="#onMahlzeitClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Mahlzeit">
<Button fx:id="mahlzeitButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onMahlzeitClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Mahlzeit">
<font>
<Font size="20.0" />
</font>
@ -68,9 +58,7 @@
</ImageView>
</graphic>
</Button>
<Button fx:id="mitarbeiterButton" alignment="CENTER_LEFT" mnemonicParsing="false"
onMouseClicked="#onMitarbeiterClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Mitarbeiter">
<Button fx:id="mitarbeiterButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onMitarbeiterClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Mitarbeiter">
<font>
<Font size="20.0" />
</font>
@ -87,9 +75,7 @@
<Insets />
</opaqueInsets>
</Region>
<Button fx:id="einstellungenButton" alignment="CENTER_LEFT" layoutX="10.0" layoutY="130.0"
mnemonicParsing="false" onMouseClicked="#onEinstellungenClick" prefHeight="60.0"
prefWidth="250.0" styleClass="sidebar-nav_button" text="Einstellungen">
<Button fx:id="einstellungenButton" alignment="CENTER_LEFT" layoutX="10.0" layoutY="130.0" mnemonicParsing="false" onMouseClicked="#onEinstellungenClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Einstellungen">
<font>
<Font size="20.0" />
</font>
@ -108,11 +94,9 @@
</VBox>
</left>
<top>
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="1200.0" style="-fx-background-color: #69b6ff;"
BorderPane.alignment="CENTER">
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="1200.0" style="-fx-background-color: #69b6ff;" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" onMouseClicked="#onAusloggenClick" styleClass="sidebar-nav_button"
text="Ausloggen">
<Button mnemonicParsing="false" onMouseClicked="#onAusloggenClick" styleClass="sidebar-nav_button" text="Ausloggen">
<opaqueInsets>
<Insets />
</opaqueInsets>