diff --git a/hellofx/app/src/main/java/client/CreateEventController.java b/hellofx/app/src/main/java/client/CreateEventController.java index d78c55b..c2096ec 100644 --- a/hellofx/app/src/main/java/client/CreateEventController.java +++ b/hellofx/app/src/main/java/client/CreateEventController.java @@ -3,10 +3,37 @@ package client; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.DatePicker; +import javafx.scene.control.TextField; import javafx.stage.Stage; +import res.DataController; +import res.Event; + +import java.time.LocalDateTime; +import java.util.ArrayList; public class CreateEventController { + @FXML + public DatePicker datePickerDate; + @FXML + public TextField textName; + @FXML + public TextField textStart; + @FXML + public TextField textEnd; + @FXML + public ComboBox ComboBoxTyp; + @FXML + public ComboBox ComboBoxPriotity; + @FXML + public CheckBox checkBoxIsFullDay; + @FXML + public CheckBox checkBoxIsPrivate; + + public CreateEventController(){} @FXML @@ -14,8 +41,25 @@ public class CreateEventController { @FXML - protected void createBtnClick(ActionEvent event){ - Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + protected void createBtnClick(ActionEvent actionEvent){ + + Event event = new Event( + textName.getText(), + ComboBoxPriotity.getSelectionModel().getSelectedIndex(), + checkBoxIsFullDay.isSelected(), + checkBoxIsPrivate.isSelected(), + textStart.getText(), + textEnd.getText(), + datePickerDate.getValue().atStartOfDay(), + 1 + ); + + System.out.println(event.getAsUrlParam()); + + DataController dataController = new DataController(); + dataController.CreateEvent(event); + + Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stage.close(); } diff --git a/hellofx/app/src/main/java/client/MainController.java b/hellofx/app/src/main/java/client/MainController.java index 13ac105..b49f8ff 100644 --- a/hellofx/app/src/main/java/client/MainController.java +++ b/hellofx/app/src/main/java/client/MainController.java @@ -49,6 +49,14 @@ public class MainController { createWeek(); setDates(); + updateEvents(); + } + + private void updateEvents() { + for(VBox vBox : dayVBoxes){ + vBox.getChildren().clear(); + } + DataController dataController = new DataController(); ArrayList eventList = dataController.getAllVisibleEvents(); @@ -74,6 +82,7 @@ public class MainController { catch (IOException e){ e.printStackTrace(); } + updateEvents(); } private void createWeek(){ diff --git a/hellofx/app/src/main/resources/client/create-event.fxml b/hellofx/app/src/main/resources/client/create-event.fxml index 34e83fc..c9267c5 100644 --- a/hellofx/app/src/main/resources/client/create-event.fxml +++ b/hellofx/app/src/main/resources/client/create-event.fxml @@ -3,6 +3,8 @@ + + @@ -19,25 +21,38 @@ + - - - - + + + + + + - - - - - - + + + + + + + + + + + + + + + + - + diff --git a/hellofx/data/src/main/java/res/DataController.java b/hellofx/data/src/main/java/res/DataController.java index d9a40be..0318fcc 100644 --- a/hellofx/data/src/main/java/res/DataController.java +++ b/hellofx/data/src/main/java/res/DataController.java @@ -16,6 +16,7 @@ public class DataController { private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/vpr/all-events"; private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/vpr/all-users"; + private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/vpr/add-event"; private HttpRequest httpRequest; @@ -23,6 +24,13 @@ public class DataController { httpRequest = new HttpRequest(); } + public void CreateEvent(Event event){ + try { + System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam())); + } catch (Exception e) { + e.printStackTrace(); + } + } public ArrayList getAllVisibleEvents() { ArrayList eventList = new ArrayList<>(); diff --git a/hellofx/data/src/main/java/res/Event.java b/hellofx/data/src/main/java/res/Event.java index 6a6f7e0..33ee93f 100644 --- a/hellofx/data/src/main/java/res/Event.java +++ b/hellofx/data/src/main/java/res/Event.java @@ -12,6 +12,7 @@ public class Event { private String name; private int priority; private boolean isFullDay; + private boolean isPrivate; private String start; private String end; @@ -37,21 +38,39 @@ public class Event { */ public Event(ArrayList arr) { - id = (int)arr.get(0); - name = (String)arr.get(1); - start = (String)arr.get(2); - end = (String)arr.get(3); - priority = (int)arr.get(4); - isFullDay = (Boolean)arr.get(5); //((String)arr.get(5)).equals("true"); + id = (int) arr.get(0); + name = (String) arr.get(1); + start = (String) arr.get(2); + end = (String) arr.get(3); + priority = (int) arr.get(4); + isFullDay = (Boolean) arr.get(5); //((String)arr.get(5)).equals("true"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); date = LocalDateTime.parse(arr.get(6) + " 00:00", formatter); - ownerId = (int)arr.get(7); + ownerId = (int) arr.get(7); ownerName = arr.get(8) + " " + arr.get(9); } + public Event(String name, + int priority, + boolean isFullDay, + boolean isPrivate, + String start, + String end, + LocalDateTime date, + int ownerId + ) { + this.name = name; + this.priority = priority; + this.isFullDay = isFullDay; + this.isPrivate = isPrivate; + this.start = start; + this.end = end; + this.date = date; + this.ownerId = ownerId; + } public int getId() { return id; @@ -85,6 +104,14 @@ public class Event { isFullDay = fullDay; } + public boolean isPrivate() { + return isPrivate; + } + + public void setPrivate(boolean aPrivate) { + isPrivate = aPrivate; + } + public String getStart() { return start; } @@ -133,4 +160,15 @@ public class Event { (isFullDay ? "\nDen ganzen Tag lang" : ""); } + + public String getAsUrlParam() { + return "userId=" + getOwnerId() + + "&date=" + getDate().toLocalDate() + + "&name=" + getName() + + "&start=" + getStart() + + "&end=" + getEnd() + + "&prority=" + getPriority() + + "&isFullDay=" + isFullDay() + + "&isPrivate=" + isPrivate(); + } }