From 097cce14e88d7f322a31aa491c44a71e8a9f4aab Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Thu, 13 Jan 2022 17:35:16 +0100 Subject: [PATCH 01/43] Save toke on login --- client/data/src/main/java/res/DataController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 1ac15b5..f4713ed 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -15,6 +15,7 @@ import java.util.*; public class DataController { public static long USER_ID = -1; + public static String TOKEN = ""; private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/event/all"; private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/event/add"; @@ -31,12 +32,15 @@ public class DataController { public boolean login(String username, String password) { try { - USER_ID = Long.parseLong(httpRequest.sendPostRequest( + String response = httpRequest.sendPostRequest( LOGIN_ENDPOINT, "login=" + username + "&password=" + password, false - )); + ); + + USER_ID = Long.parseLong(response.split("\\s+")[1]); + TOKEN = response.split("\\s+")[0]; } catch (Exception e) { e.printStackTrace(); return false; From b12de1cd2ec1616fc46d85df2d73fceb76691e83 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Thu, 13 Jan 2022 23:14:36 +0100 Subject: [PATCH 02/43] Use Tuple as response --- client/data/src/main/java/helper/Tuple.java | 27 ++++++++++++++ .../src/main/java/res/DataController.java | 23 ++++++++---- .../data/src/main/java/res/HttpRequest.java | 36 +++++++++++-------- 3 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 client/data/src/main/java/helper/Tuple.java diff --git a/client/data/src/main/java/helper/Tuple.java b/client/data/src/main/java/helper/Tuple.java new file mode 100644 index 0000000..e342ad6 --- /dev/null +++ b/client/data/src/main/java/helper/Tuple.java @@ -0,0 +1,27 @@ +package helper; + +public class Tuple { + public final X key; + public final Y value; + + public Tuple(X key, Y value) { + this.key = key; + this.value = value; + } + + public X getKey() { + return key; + } + + public Y getValue() { + return value; + } + + @Override + public String toString() { + return "Tuple{" + + "key=" + key + + ", value=" + value + + '}'; + } +} diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index f4713ed..01e58bf 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -2,6 +2,7 @@ package res; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import helper.Tuple; import java.io.BufferedReader; import java.io.DataOutputStream; @@ -15,7 +16,6 @@ import java.util.*; public class DataController { public static long USER_ID = -1; - public static String TOKEN = ""; private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/event/all"; private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/event/add"; @@ -23,6 +23,7 @@ public class DataController { private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login"; private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/user/all"; + private static final String HEADER_TEST_ENDPOINT = "http://localhost:8080/vpr/header-test"; private final HttpRequest httpRequest; @@ -32,19 +33,28 @@ public class DataController { public boolean login(String username, String password) { try { - String response = httpRequest.sendPostRequest( + Tuple response = httpRequest.sendPostRequest( LOGIN_ENDPOINT, "login=" + username + "&password=" + password, false ); + String[] data = response.getValue().split("\\s+"); - USER_ID = Long.parseLong(response.split("\\s+")[1]); - TOKEN = response.split("\\s+")[0]; + USER_ID = Long.parseLong(data[1]); + HttpRequest.TOKEN = data[1]; + + Tuple auth = httpRequest.sendPostRequest( + HEADER_TEST_ENDPOINT, + "", + true + ); + System.out.println("auth " + auth); } catch (Exception e) { e.printStackTrace(); return false; } + return USER_ID >= 0; } @@ -68,11 +78,11 @@ public class DataController { ArrayList eventList = new ArrayList<>(); try { - String jsonResponse = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true); + Tuple response = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true); + String jsonResponse = response.getValue(); System.out.println(jsonResponse); ObjectMapper objectMapper = new ObjectMapper(); - //String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }"; for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) { ArrayList list = new ArrayList<>(); @@ -112,7 +122,6 @@ public class DataController { // Parse JSON ObjectMapper objectMapper = new ObjectMapper(); - //String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }"; return objectMapper.readValue(jsonString, Event[].class); } diff --git a/client/data/src/main/java/res/HttpRequest.java b/client/data/src/main/java/res/HttpRequest.java index 398f157..311fad4 100644 --- a/client/data/src/main/java/res/HttpRequest.java +++ b/client/data/src/main/java/res/HttpRequest.java @@ -1,5 +1,7 @@ package res; +import helper.Tuple; + import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStreamReader; @@ -9,7 +11,9 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; public class HttpRequest { - public String sendPostRequest(String urlString, String urlParameters, boolean sendAuth) throws Exception { + public static String TOKEN = ""; + + public Tuple sendPostRequest(String urlString, String urlParameters, boolean sendAuth) throws Exception { byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); int postDataLength = postData.length; @@ -39,7 +43,7 @@ public class HttpRequest { if(sendAuth){ con.setRequestProperty("Accept", "application/json"); - con.setRequestProperty("Authorization", "Bearer {token}"); + con.setRequestProperty("Authorization", "Bearer " + TOKEN); } try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) { @@ -47,22 +51,24 @@ public class HttpRequest { } int status = con.getResponseCode(); - if (status == 200) { - BufferedReader in = new BufferedReader( - new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuilder content = new StringBuilder(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } - in.close(); + String inputLine; + StringBuilder content = new StringBuilder(); + BufferedReader in; - con.disconnect(); - return content.toString(); + if (status == 200) { + in = new BufferedReader(new InputStreamReader(con.getInputStream())); } else { - con.disconnect(); - throw new Exception("Status: " + status); + in = new BufferedReader(new InputStreamReader(con.getErrorStream())); } + + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + con.disconnect(); + + return new Tuple<>(status, content.toString()); } public String sendGetRequest(String urlString) throws Exception { From 947f31f20e47e0d074240330d13035a65534a01d Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Fri, 14 Jan 2022 19:37:06 +0100 Subject: [PATCH 03/43] Fixed login token --- client/data/src/main/java/res/DataController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 01e58bf..8d3444b 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -42,7 +42,7 @@ public class DataController { String[] data = response.getValue().split("\\s+"); USER_ID = Long.parseLong(data[1]); - HttpRequest.TOKEN = data[1]; + HttpRequest.TOKEN = data[0]; Tuple auth = httpRequest.sendPostRequest( HEADER_TEST_ENDPOINT, From 0132077c62b93864c67547358efa07e482ba8f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Tue, 18 Jan 2022 12:37:58 +0100 Subject: [PATCH 04/43] Added edit and delete event svgs --- .../src/main/java/main/MainController.java | 49 ++++++++++++++++++- .../app/src/main/resources/main/main-view.css | 26 ++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 983b955..0546e5e 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -1,15 +1,24 @@ package main; +import com.jfoenix.svg.SVGGlyph; +import com.jfoenix.svg.SVGGlyphLoader; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.geometry.Bounds; import javafx.geometry.Pos; +import javafx.scene.Group; import javafx.scene.Scene; import customUI.Button; import customUI.Label; +import javafx.scene.control.ContentDisplay; import javafx.scene.control.ScrollPane; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.shape.SVGPath; import javafx.stage.Modality; import javafx.stage.Stage; import res.DataController; @@ -139,15 +148,43 @@ public class MainController { HBox btnHBox = new HBox(); btnHBox.setAlignment(Pos.BOTTOM_RIGHT); + Button deleteBtn = new Button(); - deleteBtn.setTextValue(" X "); + Group svgDel = new Group( + createPath("M0 0h24v24H0z", "transparent", "transparent"), + createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", + "white", "lightgray") + ); + Bounds boundsDel = svgDel.getBoundsInParent(); + double scaleDel = Math.min(20/boundsDel.getWidth(), 20 / boundsDel.getHeight()); + svgDel.setScaleX(scaleDel); + svgDel.setScaleY(scaleDel); + deleteBtn.setGraphic(svgDel); + deleteBtn.setMaxSize(24, 24); + deleteBtn.setMinSize(24, 24); + deleteBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); + deleteBtn.getStyleClass().add("deleteEventBtn"); deleteBtn.setOnAction(e -> { DataController dataController = new DataController(); dataController.deleteEvent(event.getId()); updateEvents(); }); + Button editBtn = new Button(); - editBtn.setTextValue("edit"); + Group svgEdit = new Group( + createPath("M0 0h24v24H0z", "transparent", "transparent"), + createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", + "white", "lightgray") + ); + Bounds boundsEdit = svgEdit.getBoundsInParent(); + double scaleEdit = Math.min(20/boundsEdit.getWidth(), 20 / boundsEdit.getHeight()); + svgEdit.setScaleX(scaleEdit); + svgEdit.setScaleY(scaleEdit); + editBtn.setGraphic(svgEdit); + editBtn.setMaxSize(24, 24); + editBtn.setMinSize(24, 24); + editBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); + editBtn.getStyleClass().add("editEventBtn"); editBtn.setOnAction(event1 -> { try { FXMLLoader fxmlLoader = new FXMLLoader( @@ -226,4 +263,12 @@ public class MainController { LabelMonth.setText(dateFormatter.format(weekStartDateTime)); } + + private static SVGPath createPath(String d, String fill, String hoverFill) { + SVGPath path = new SVGPath(); + path.getStyleClass().add("svg"); + path.setContent(d); + path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';'); + return path; + } } \ No newline at end of file diff --git a/client/app/src/main/resources/main/main-view.css b/client/app/src/main/resources/main/main-view.css index 684f7b7..0821874 100644 --- a/client/app/src/main/resources/main/main-view.css +++ b/client/app/src/main/resources/main/main-view.css @@ -76,3 +76,29 @@ Label{ -fx-background-color: white; } +.editEventBtn{ + -fx-background-color: transparent; + -fx-border-color: transparent; +} + +.editEventBtn .svg { + -fx-fill: -fill; +} + +.editEventBtn:hover .svg { + -fx-fill: -hover-fill; +} + +.deleteEventBtn{ + -fx-background-color: transparent; + -fx-border-color: transparent; +} + +.deleteEventBtn .svg { + -fx-fill: -fill; +} + +.deleteEventBtn:hover .svg { + -fx-fill: -hover-fill; +} + From 78505097dbcedb6b74d0ce90c43e3f94b9030979 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Wed, 19 Jan 2022 00:16:23 +0100 Subject: [PATCH 05/43] Fixed event/all and event/del endpoints --- .../src/main/java/main/MainApplication.java | 24 +++++++----- .../src/main/java/main/MainController.java | 4 +- client/data/build.gradle.kts | 1 + .../src/main/java/res/DataController.java | 31 +++++++++------- client/data/src/main/java/res/Event.java | 37 ++++++++++++++++++- 5 files changed, 70 insertions(+), 27 deletions(-) diff --git a/client/app/src/main/java/main/MainApplication.java b/client/app/src/main/java/main/MainApplication.java index e0cbbdd..6108243 100644 --- a/client/app/src/main/java/main/MainApplication.java +++ b/client/app/src/main/java/main/MainApplication.java @@ -13,26 +13,32 @@ public class MainApplication extends Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); - - Scene scene = new Scene(fxmlLoader.load(), 1200, 700); - scene.getStylesheets().add(Objects.requireNonNull( - - MainApplication.class.getResource("main-view.css")).toExternalForm()); - stage.setTitle("SharePlaner"); - stage.setScene(scene); + System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170"); + // Load login-scene FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml")); Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500); sceneLogin.getStylesheets().add(Objects.requireNonNull( - MainApplication.class.getResource("../users/login.css")).toExternalForm()); + MainApplication.class.getResource("../users/login.css")).toExternalForm() + ); Stage stageLogin = new Stage(); stageLogin.setTitle("Anmelden"); stageLogin.setScene(sceneLogin); stageLogin.showAndWait(); if (DataController.USER_ID >= 0) { + // Load main-scene + FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); + + Scene scene = new Scene(fxmlLoader.load(), 1200, 700); + scene.getStylesheets().add(Objects.requireNonNull( + MainApplication.class.getResource("main-view.css")).toExternalForm() + ); + stage.setTitle("SharePlaner"); + stage.setScene(scene); stage.show(); + + System.out.println("Logged in..."); } } diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 983b955..dbdcce6 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -56,7 +56,7 @@ public class MainController { } DataController dataController = new DataController(); - ArrayList eventList = dataController.getAllVisibleEvents(); + ArrayList eventList = dataController.getAllVisibleEvents(weekStartDateTime, weekStartDateTime.plusDays(7)); for (Event event : eventList) { addEvent(event); @@ -143,7 +143,7 @@ public class MainController { deleteBtn.setTextValue(" X "); deleteBtn.setOnAction(e -> { DataController dataController = new DataController(); - dataController.deleteEvent(event.getId()); + dataController.deleteEvent(event.getOwnerId(), event.getId(), event.getDate()); updateEvents(); }); Button editBtn = new Button(); diff --git a/client/data/build.gradle.kts b/client/data/build.gradle.kts index 5b07f24..147ec02 100644 --- a/client/data/build.gradle.kts +++ b/client/data/build.gradle.kts @@ -7,4 +7,5 @@ dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion") } diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 8d3444b..2937b9b 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -1,6 +1,7 @@ package res; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import helper.Tuple; @@ -11,6 +12,7 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; import java.util.*; public class DataController { @@ -66,34 +68,35 @@ public class DataController { } } - public void deleteEvent(int eventId) { + public void deleteEvent(int userId, int eventId, LocalDateTime date) { try { - System.out.println(httpRequest.sendPostRequest(DELETE_EVENT_ENDPOINT, "eventId=" + eventId, true)); + System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate()); + System.out.println(httpRequest.sendPostRequest( + DELETE_EVENT_ENDPOINT, + "userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(), + true + )); } catch (Exception e) { e.printStackTrace(); } } - public ArrayList getAllVisibleEvents() { + public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) { ArrayList eventList = new ArrayList<>(); - try { - Tuple response = httpRequest.sendPostRequest(ALL_EVENTS_ENDPOINT, "userId=" + USER_ID, true); + Tuple response = httpRequest.sendPostRequest( + ALL_EVENTS_ENDPOINT, + "userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(), + true + ); String jsonResponse = response.getValue(); System.out.println(jsonResponse); ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>(){}); - for (Object obj : objectMapper.readValue(jsonResponse, Object[].class)) { - ArrayList list = new ArrayList<>(); - if (obj.getClass().isArray()) { - list = (ArrayList) Arrays.asList((Object[]) obj); - } else if (obj instanceof Collection) { - list = new ArrayList<>((Collection) obj); - } - eventList.add(new Event(list)); - } } catch (Exception e) { e.printStackTrace(); } diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index 90e9d41..5a51d2a 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -2,6 +2,7 @@ package res; import com.sun.jdi.event.StepEvent; +import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.LocalDate; @@ -43,6 +44,10 @@ public class Event { u.name AS uname */ + public Event() { + + } + public Event(ArrayList arr) { id = (int) arr.get(0); name = (String) arr.get(1); @@ -59,6 +64,33 @@ public class Event { ownerName = arr.get(8) + " " + arr.get(9); } + public Event( + int id, + String name, + int priority, + boolean isFullDay, + boolean isPrivate, + String start, + String end, + String date, + int ownerId, + String ownerName + ) { + this.ownerId = ownerId; + this.ownerName = ownerName; + this.id = id; + this.name = name; + this.start = start; + this.end = end; + this.priority = priority; + this.isFullDay = isFullDay; + + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + this.date = LocalDateTime.parse(date + " 00:00", formatter); + + } + public Event(String name, int priority, boolean isFullDay, @@ -174,8 +206,9 @@ public class Event { return date; } - public void setDate(LocalDateTime date) { - this.date = date; + public void setDate(String date) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + this.date = LocalDateTime.parse(date + " 00:00", formatter); } public int getOwnerId() { From 2269f05f5231260f241186f8afade83ec816eec2 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Wed, 19 Jan 2022 00:30:13 +0100 Subject: [PATCH 06/43] Fixed event/add endpoint --- .../main/java/main/CreateEventController.java | 5 +-- client/data/src/main/java/res/Event.java | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index 1c61cbf..c67fdca 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -12,6 +12,7 @@ import javafx.util.converter.LocalTimeStringConverter; import res.DataController; import res.Event; +import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.FormatStyle; import java.util.Locale; @@ -65,8 +66,8 @@ public class CreateEventController { ComboBoxPriotity.getSelectionModel().getSelectedIndex(), toggleBtnIsFullDay.isSelected(), toggleBtnIsPrivate.isSelected(), - timeStart.getValue().toString(), - timeEnd.getValue().toString(), + timeStart.getValue(), + timeEnd.getValue(), datePickerDate.getValue().atStartOfDay(), (int) DataController.USER_ID ); diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index 5a51d2a..022aeea 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -4,9 +4,11 @@ import com.sun.jdi.event.StepEvent; import java.io.Serializable; import java.nio.charset.StandardCharsets; +import java.sql.SQLOutput; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.regex.Matcher; @@ -95,17 +97,19 @@ public class Event { int priority, boolean isFullDay, boolean isPrivate, - String start, - String end, + LocalTime start, + LocalTime end, LocalDateTime date, int ownerId - ) throws IllegalArgumentException{ - if(name.length() < 3){ + ) throws IllegalArgumentException { + + System.out.println("Create Event"); + if (name.length() < 3) { throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben."); } Pattern pattern = Pattern.compile("[A-Za-z\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-9 =!?+*/$.:,;_<>()-]*"); Matcher matcher = pattern.matcher(name); - if(!matcher.matches()){ + if (!matcher.matches()) { System.out.println(name); byte[] bytes = name.getBytes(StandardCharsets.UTF_16); @@ -114,25 +118,25 @@ public class Event { System.out.println(utf8EncodedString); for (char c : (name).toCharArray()) { - System.out.print(c + " " + (int)c + ", "); + System.out.print(c + " " + (int) c + ", "); } System.out.println(); for (char c : (name).toCharArray()) { - System.out.print(c + " " + (int)c + ", "); + System.out.print(c + " " + (int) c + ", "); } System.out.println(); for (char c : ("TäöüÄÖÜ").toCharArray()) { - System.out.print(c + " " + (int)c + ", "); + System.out.print(c + " " + (int) c + ", "); } System.out.println(); throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$.:,;_ <>()-"); } - if(priority < 0){ + if (priority < 0) { throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen."); } LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay(); - if(Duration.between(today, date).isNegative()){ + if (Duration.between(today, date).isNegative()) { throw new IllegalArgumentException("Das Datum muss in der Zukunft liegen."); } @@ -140,8 +144,8 @@ public class Event { this.priority = priority; this.isFullDay = isFullDay; this.isPrivate = isPrivate; - this.start = start; - this.end = end; + if (start != null) this.start = start.toString(); + if (start != null) this.end = end.toString(); this.date = date; this.ownerId = ownerId; } @@ -242,12 +246,12 @@ public class Event { "&name=" + getName() + "&start=" + getStart() + "&end=" + getEnd() + - "&prority=" + getPriority() + + "&priority=" + getPriority() + "&isFullDay=" + isFullDay() + "&isPrivate=" + isPrivate(); } - private String convertToASCII(String s){ + private String convertToASCII(String s) { byte[] germanBytes = s.getBytes(); return new String(germanBytes, StandardCharsets.US_ASCII); } From 2f0c4b2a4c33de9f8cacd8ebd50a76c3f2ca9b50 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Thu, 20 Jan 2022 13:33:49 +0100 Subject: [PATCH 07/43] Added edit-function --- .../main/java/main/CreateEventController.java | 11 ++- .../main/java/main/EditEventController.java | 25 ++++++ .../src/main/java/main/MainController.java | 22 +++++- .../src/main/resources/main/edit-event.fxml | 2 +- .../java/helper/HttpRequestException.java | 23 ++++++ .../src/main/java/res/DataController.java | 76 ++++++++++--------- 6 files changed, 117 insertions(+), 42 deletions(-) create mode 100644 client/app/src/main/java/main/EditEventController.java create mode 100644 client/data/src/main/java/helper/HttpRequestException.java diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index c67fdca..47f69c6 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -1,6 +1,7 @@ package main; import com.jfoenix.controls.*; +import helper.HttpRequestException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; @@ -74,16 +75,20 @@ public class CreateEventController { System.out.println(event.getAsUrlParam()); - DataController dataController = new DataController(); - dataController.createEvent(event); + sendHttpRequest(event); Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stage.close(); - } catch (RuntimeException e) { + } catch (HttpRequestException e) { labelError.setText(e.getMessage()); } } + protected void sendHttpRequest(Event event) throws HttpRequestException { + DataController dataController = new DataController(); + dataController.createEvent(event); + } + @FXML protected void abortBtnClick(ActionEvent event) { Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java new file mode 100644 index 0000000..3e34d04 --- /dev/null +++ b/client/app/src/main/java/main/EditEventController.java @@ -0,0 +1,25 @@ +package main; + +import helper.HttpRequestException; +import res.DataController; +import res.Event; + +public class EditEventController extends CreateEventController{ + + private Event currentEvent; + + public Event getCurrentEvent() { + return currentEvent; + } + + public void setCurrentEvent(Event currentEvent) { + this.currentEvent = currentEvent; + } + + @Override + protected void sendHttpRequest(Event event) throws HttpRequestException { + DataController dataController = new DataController(); + dataController.deleteEvent(currentEvent.getOwnerId(), currentEvent.getId(), currentEvent.getDate()); + dataController.createEvent(event); + } +} diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index dbdcce6..f16a2c0 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -1,5 +1,6 @@ package main; +import helper.HttpRequestException; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.geometry.Pos; @@ -56,11 +57,17 @@ public class MainController { } DataController dataController = new DataController(); - ArrayList eventList = dataController.getAllVisibleEvents(weekStartDateTime, weekStartDateTime.plusDays(7)); + try { + ArrayList eventList = dataController.getAllVisibleEvents(weekStartDateTime, weekStartDateTime.plusDays(7)); - for (Event event : eventList) { - addEvent(event); + for (Event event : eventList) { + addEvent(event); + } + } catch (HttpRequestException e) { + e.printStackTrace(); } + + } @FXML @@ -143,7 +150,11 @@ public class MainController { deleteBtn.setTextValue(" X "); deleteBtn.setOnAction(e -> { DataController dataController = new DataController(); - dataController.deleteEvent(event.getOwnerId(), event.getId(), event.getDate()); + try { + dataController.deleteEvent(event.getOwnerId(), event.getId(), event.getDate()); + } catch (HttpRequestException ex) { + ex.printStackTrace(); + } updateEvents(); }); Button editBtn = new Button(); @@ -160,7 +171,10 @@ public class MainController { stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); + EditEventController editEventController = fxmlLoader.getController(); + editEventController.setCurrentEvent(event); stage.showAndWait(); + updateEvents(); } catch (IOException e) { e.printStackTrace(); } diff --git a/client/app/src/main/resources/main/edit-event.fxml b/client/app/src/main/resources/main/edit-event.fxml index 9180344..939dddb 100644 --- a/client/app/src/main/resources/main/edit-event.fxml +++ b/client/app/src/main/resources/main/edit-event.fxml @@ -8,7 +8,7 @@ + fx:controller="main.EditEventController"> diff --git a/client/data/src/main/java/helper/HttpRequestException.java b/client/data/src/main/java/helper/HttpRequestException.java new file mode 100644 index 0000000..972dd3f --- /dev/null +++ b/client/data/src/main/java/helper/HttpRequestException.java @@ -0,0 +1,23 @@ +package helper; + +public class HttpRequestException extends Exception{ + private int status; + + public HttpRequestException(String message, int status) { + super(message); + this.status = status; + } + + public HttpRequestException(Tuple response) { + super(response.getValue()); + this.status = response.getKey(); + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 2937b9b..279688a 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -3,6 +3,7 @@ package res; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import helper.HttpRequestException; import helper.Tuple; import java.io.BufferedReader; @@ -24,6 +25,7 @@ public class DataController { private static final String DELETE_EVENT_ENDPOINT = "http://localhost:8080/event/del"; private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login"; + private static final String LOGIN_WITH_TOKEN_ENDPOINT = "http://localhost:8080/user/login-with-token"; private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/user/all"; private static final String HEADER_TEST_ENDPOINT = "http://localhost:8080/vpr/header-test"; @@ -60,28 +62,52 @@ public class DataController { return USER_ID >= 0; } - public void createEvent(Event event) { + public boolean loginWIthToken(String username, String password) { try { - System.out.println(httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam(), true)); + Tuple response = httpRequest.sendPostRequest( + LOGIN_WITH_TOKEN_ENDPOINT, + "userId=" + USER_ID, + true + ); } catch (Exception e) { - throw new RuntimeException("Es konnte keine Verbindung mit dem Server hergestellt werden."); + e.printStackTrace(); + return false; + } + return USER_ID >= 0; + } + + public void createEvent(Event event) throws HttpRequestException { + try { + Tuple response = httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam(), true); + if(response.getKey() != 200){ + throw new HttpRequestException(response); + } + }catch (HttpRequestException e){ + throw e; + }catch (Exception e) { + throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); } } - public void deleteEvent(int userId, int eventId, LocalDateTime date) { + public void deleteEvent(int userId, int eventId, LocalDateTime date) throws HttpRequestException { try { System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate()); - System.out.println(httpRequest.sendPostRequest( + Tuple response = httpRequest.sendPostRequest( DELETE_EVENT_ENDPOINT, "userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(), true - )); - } catch (Exception e) { - e.printStackTrace(); + ); + if(response.getKey() != 200){ + throw new HttpRequestException(response); + } + }catch (HttpRequestException e){ + throw e; + }catch (Exception e) { + throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); } } - public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) { + public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException { ArrayList eventList = new ArrayList<>(); try { Tuple response = httpRequest.sendPostRequest( @@ -89,6 +115,9 @@ public class DataController { "userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(), true ); + if(response.getKey() != 200){ + throw new HttpRequestException(response); + } String jsonResponse = response.getValue(); System.out.println(jsonResponse); @@ -97,35 +126,14 @@ public class DataController { eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>(){}); - } catch (Exception e) { - e.printStackTrace(); + }catch (HttpRequestException e){ + throw e; + }catch (Exception e) { + throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); } return eventList; } - public Event[] getAllEvents() { - Event[] eventList = null; - try { - String jsonResponse = httpRequest.sendGetRequest("http://localhost:8080/vpr/all-events-test"); - eventList = parseJsonToEventList(jsonResponse); - for (Event e : eventList) { - System.out.println(e); - } - } catch (Exception e) { - e.printStackTrace(); - } - - return eventList; - } - - private Event[] parseJsonToEventList(String jsonString) throws JsonProcessingException { - ArrayList eventList; - - // Parse JSON - ObjectMapper objectMapper = new ObjectMapper(); - - return objectMapper.readValue(jsonString, Event[].class); - } } \ No newline at end of file From 0d626bb6dc56d67326135ce3721c4dab774122c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Thu, 20 Jan 2022 13:49:07 +0100 Subject: [PATCH 08/43] Refactored create svg Buttons --- .../main/java/main/CreateEventController.java | 1 - .../src/main/java/main/MainController.java | 39 +++++-------------- .../app/src/main/java/main/SvgBtnCreator.java | 34 ++++++++++++++++ 3 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 client/app/src/main/java/main/SvgBtnCreator.java diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index c67fdca..b0b8992 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -12,7 +12,6 @@ import javafx.util.converter.LocalTimeStringConverter; import res.DataController; import res.Event; -import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.FormatStyle; import java.util.Locale; diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 5d90bd3..c7e5b4e 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -1,23 +1,18 @@ package main; -import com.jfoenix.svg.SVGGlyph; -import com.jfoenix.svg.SVGGlyphLoader; +import customUI.Button; +import customUI.Label; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.geometry.Bounds; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; -import customUI.Button; -import customUI.Label; import javafx.scene.control.ContentDisplay; import javafx.scene.control.ScrollPane; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javafx.scene.paint.Color; import javafx.scene.shape.SVGPath; import javafx.stage.Modality; import javafx.stage.Stage; @@ -149,20 +144,13 @@ public class MainController { HBox btnHBox = new HBox(); btnHBox.setAlignment(Pos.BOTTOM_RIGHT); - Button deleteBtn = new Button(); Group svgDel = new Group( - createPath("M0 0h24v24H0z", "transparent", "transparent"), - createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", "white", "lightgray") ); - Bounds boundsDel = svgDel.getBoundsInParent(); - double scaleDel = Math.min(20/boundsDel.getWidth(), 20 / boundsDel.getHeight()); - svgDel.setScaleX(scaleDel); - svgDel.setScaleY(scaleDel); - deleteBtn.setGraphic(svgDel); - deleteBtn.setMaxSize(24, 24); - deleteBtn.setMinSize(24, 24); - deleteBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); + Button deleteBtn = SvgBtnCreator.cretaeBtn(svgDel); + deleteBtn.getStyleClass().add("deleteEventBtn"); deleteBtn.setOnAction(e -> { DataController dataController = new DataController(); @@ -170,20 +158,12 @@ public class MainController { updateEvents(); }); - Button editBtn = new Button(); Group svgEdit = new Group( - createPath("M0 0h24v24H0z", "transparent", "transparent"), - createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", "white", "lightgray") ); - Bounds boundsEdit = svgEdit.getBoundsInParent(); - double scaleEdit = Math.min(20/boundsEdit.getWidth(), 20 / boundsEdit.getHeight()); - svgEdit.setScaleX(scaleEdit); - svgEdit.setScaleY(scaleEdit); - editBtn.setGraphic(svgEdit); - editBtn.setMaxSize(24, 24); - editBtn.setMinSize(24, 24); - editBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); + Button editBtn = SvgBtnCreator.cretaeBtn(svgEdit); editBtn.getStyleClass().add("editEventBtn"); editBtn.setOnAction(event1 -> { try { @@ -271,4 +251,5 @@ public class MainController { path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';'); return path; } + } \ No newline at end of file diff --git a/client/app/src/main/java/main/SvgBtnCreator.java b/client/app/src/main/java/main/SvgBtnCreator.java new file mode 100644 index 0000000..1a6d5fa --- /dev/null +++ b/client/app/src/main/java/main/SvgBtnCreator.java @@ -0,0 +1,34 @@ +package main; + +import javafx.geometry.Bounds; +import javafx.scene.Group; +import customUI.Button; +import javafx.scene.control.ContentDisplay; +import javafx.scene.shape.SVGPath; + +public class SvgBtnCreator { + + public static Button cretaeBtn(Group group) { + Button btn = new Button(); + + Bounds boundsDel = group.getBoundsInParent(); + double scaleDel = Math.min(20 / boundsDel.getWidth(), 20 / boundsDel.getHeight()); + group.setScaleX(scaleDel); + group.setScaleY(scaleDel); + btn.setGraphic(group); + btn.setMaxSize(24, 24); + btn.setMinSize(24, 24); + btn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); + + return btn; + } + + public static SVGPath createPath(String d, String fill, String hoverFill) { + SVGPath path = new SVGPath(); + path.getStyleClass().add("svg"); + path.setContent(d); + path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';'); + return path; + } + +} From 83c1ae68147dc178fbce2c7d7373fe35d789b04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Thu, 20 Jan 2022 13:50:59 +0100 Subject: [PATCH 09/43] Made svg size to const --- client/app/src/main/java/main/SvgBtnCreator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/app/src/main/java/main/SvgBtnCreator.java b/client/app/src/main/java/main/SvgBtnCreator.java index 1a6d5fa..cd1321e 100644 --- a/client/app/src/main/java/main/SvgBtnCreator.java +++ b/client/app/src/main/java/main/SvgBtnCreator.java @@ -8,6 +8,8 @@ import javafx.scene.shape.SVGPath; public class SvgBtnCreator { + private static final int SVG_SIZE = 24; + public static Button cretaeBtn(Group group) { Button btn = new Button(); @@ -16,8 +18,8 @@ public class SvgBtnCreator { group.setScaleX(scaleDel); group.setScaleY(scaleDel); btn.setGraphic(group); - btn.setMaxSize(24, 24); - btn.setMinSize(24, 24); + btn.setMaxSize(SVG_SIZE, SVG_SIZE); + btn.setMinSize(SVG_SIZE, SVG_SIZE); btn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); return btn; From 45c58ea37faeda4546ca957a73960a4c5bd125a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Thu, 20 Jan 2022 13:52:35 +0100 Subject: [PATCH 10/43] Made changeable size of svg --- client/app/src/main/java/main/MainController.java | 4 ++-- client/app/src/main/java/main/SvgBtnCreator.java | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index c7e5b4e..cead76a 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -149,7 +149,7 @@ public class MainController { SvgBtnCreator.createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", "white", "lightgray") ); - Button deleteBtn = SvgBtnCreator.cretaeBtn(svgDel); + Button deleteBtn = SvgBtnCreator.cretaeBtn(svgDel, 24); deleteBtn.getStyleClass().add("deleteEventBtn"); deleteBtn.setOnAction(e -> { @@ -163,7 +163,7 @@ public class MainController { SvgBtnCreator.createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", "white", "lightgray") ); - Button editBtn = SvgBtnCreator.cretaeBtn(svgEdit); + Button editBtn = SvgBtnCreator.cretaeBtn(svgEdit, 24); editBtn.getStyleClass().add("editEventBtn"); editBtn.setOnAction(event1 -> { try { diff --git a/client/app/src/main/java/main/SvgBtnCreator.java b/client/app/src/main/java/main/SvgBtnCreator.java index cd1321e..0703d5d 100644 --- a/client/app/src/main/java/main/SvgBtnCreator.java +++ b/client/app/src/main/java/main/SvgBtnCreator.java @@ -8,9 +8,7 @@ import javafx.scene.shape.SVGPath; public class SvgBtnCreator { - private static final int SVG_SIZE = 24; - - public static Button cretaeBtn(Group group) { + public static Button cretaeBtn(Group group, int svgSize) { Button btn = new Button(); Bounds boundsDel = group.getBoundsInParent(); @@ -18,8 +16,8 @@ public class SvgBtnCreator { group.setScaleX(scaleDel); group.setScaleY(scaleDel); btn.setGraphic(group); - btn.setMaxSize(SVG_SIZE, SVG_SIZE); - btn.setMinSize(SVG_SIZE, SVG_SIZE); + btn.setMaxSize(svgSize, svgSize); + btn.setMinSize(svgSize, svgSize); btn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); return btn; From 9345dbc8689914e41355f62dc8ab951ee3fd91bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Thu, 20 Jan 2022 14:40:50 +0100 Subject: [PATCH 11/43] Moved SvgBtnCreator to helper package --- client/app/src/main/java/{main => helper}/SvgBtnCreator.java | 2 +- client/app/src/main/java/main/MainController.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename client/app/src/main/java/{main => helper}/SvgBtnCreator.java (98%) diff --git a/client/app/src/main/java/main/SvgBtnCreator.java b/client/app/src/main/java/helper/SvgBtnCreator.java similarity index 98% rename from client/app/src/main/java/main/SvgBtnCreator.java rename to client/app/src/main/java/helper/SvgBtnCreator.java index 0703d5d..a978be3 100644 --- a/client/app/src/main/java/main/SvgBtnCreator.java +++ b/client/app/src/main/java/helper/SvgBtnCreator.java @@ -1,4 +1,4 @@ -package main; +package helper; import javafx.geometry.Bounds; import javafx.scene.Group; diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index cead76a..4968a18 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -2,13 +2,12 @@ package main; import customUI.Button; import customUI.Label; +import helper.SvgBtnCreator; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; -import javafx.geometry.Bounds; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; -import javafx.scene.control.ContentDisplay; import javafx.scene.control.ScrollPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; From 14910083f4a80bccda87ee25a1f21de30684ebfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Thu, 20 Jan 2022 15:08:58 +0100 Subject: [PATCH 12/43] Added svgButtons to the left navigation --- .../src/main/java/helper/SvgBtnCreator.java | 2 +- .../src/main/java/main/MainController.java | 43 ++++++++++++++++++- .../app/src/main/resources/main/main-view.css | 17 +++++--- .../src/main/resources/main/main-view.fxml | 11 +---- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/client/app/src/main/java/helper/SvgBtnCreator.java b/client/app/src/main/java/helper/SvgBtnCreator.java index a978be3..b23e366 100644 --- a/client/app/src/main/java/helper/SvgBtnCreator.java +++ b/client/app/src/main/java/helper/SvgBtnCreator.java @@ -12,7 +12,7 @@ public class SvgBtnCreator { Button btn = new Button(); Bounds boundsDel = group.getBoundsInParent(); - double scaleDel = Math.min(20 / boundsDel.getWidth(), 20 / boundsDel.getHeight()); + double scaleDel = Math.min(svgSize / boundsDel.getWidth(), svgSize / boundsDel.getHeight()); group.setScaleX(scaleDel); group.setScaleY(scaleDel); btn.setGraphic(group); diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 4968a18..937d4c2 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -27,6 +27,8 @@ import java.util.Objects; public class MainController { + @FXML + public VBox leftNav; @FXML private GridPane calendarGrid; @@ -49,8 +51,39 @@ public class MainController { public void initialize() { createWeek(); setDates(); - updateEvents(); + + leftNav.setSpacing(40); + + Group svgAdd = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z", + "white", "lightgray") + ); + Button addBtn = SvgBtnCreator.cretaeBtn(svgAdd, 40); + addBtn.setOnAction(e -> onAddBtnClick()); + addBtn.getStyleClass().add("main-btn"); + leftNav.getChildren().add(addBtn); + + Group svgSettings = new Group( + SvgBtnCreator.createPath("M0,0h24v24H0V0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z", + "white", "lightgray") + ); + Button settingsBtn = SvgBtnCreator.cretaeBtn(svgSettings, 40); + settingsBtn.setOnAction(e -> onSettingBtnClick()); + settingsBtn.getStyleClass().add("main-btn"); + leftNav.getChildren().add(settingsBtn); + + Group svgLogout = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z", + "white", "lightgray") + ); + Button logoutBtn = SvgBtnCreator.cretaeBtn(svgLogout, 40); + logoutBtn.setOnAction(e -> onLogoutBtnClick()); + logoutBtn.getStyleClass().add("main-btn"); + leftNav.getChildren().add(logoutBtn); } private void updateEvents() { @@ -108,6 +141,14 @@ public class MainController { updateEvents(); } + protected void onSettingBtnClick(){ + + } + + protected void onLogoutBtnClick(){ + + } + private void createWeek() { for (int i = 0; i < 7; i++) { Label label = new Label(); diff --git a/client/app/src/main/resources/main/main-view.css b/client/app/src/main/resources/main/main-view.css index 0821874..657cac8 100644 --- a/client/app/src/main/resources/main/main-view.css +++ b/client/app/src/main/resources/main/main-view.css @@ -63,13 +63,16 @@ Label{ } .main-btn{ - -fx-background-color: #ffffff; - -fx-text-fill: -fx-main-text-color; - -fx-background-radius: 5em; - -fx-min-width: 40px; - -fx-min-height: 40px; - -fx-max-width: 40px; - -fx-max-height: 40px; + -fx-background-color: transparent; + -fx-border-color: transparent; +} + +.main-btn .svg { + -fx-fill: -fill; +} + +.main-btn:hover .svg { + -fx-fill: -hover-fill; } .navBtn{ diff --git a/client/app/src/main/resources/main/main-view.fxml b/client/app/src/main/resources/main/main-view.fxml index 758226a..825fb73 100644 --- a/client/app/src/main/resources/main/main-view.fxml +++ b/client/app/src/main/resources/main/main-view.fxml @@ -15,20 +15,11 @@ - - - ADD - - - ADD - - - ADD - From 1439a67e7c212c0ca12b24429283917ccd417a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Thu, 20 Jan 2022 18:27:02 +0100 Subject: [PATCH 13/43] Added svgButton to calender navigation (TODO: Fix bg.color) --- .../src/main/java/helper/SvgBtnCreator.java | 2 +- .../src/main/java/main/MainController.java | 55 ++++++++++++++----- .../app/src/main/resources/main/main-view.css | 11 +++- .../src/main/resources/main/main-view.fxml | 6 +- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/client/app/src/main/java/helper/SvgBtnCreator.java b/client/app/src/main/java/helper/SvgBtnCreator.java index b23e366..5f0e3ff 100644 --- a/client/app/src/main/java/helper/SvgBtnCreator.java +++ b/client/app/src/main/java/helper/SvgBtnCreator.java @@ -8,7 +8,7 @@ import javafx.scene.shape.SVGPath; public class SvgBtnCreator { - public static Button cretaeBtn(Group group, int svgSize) { + public static Button createBtn(Group group, int svgSize) { Button btn = new Button(); Bounds boundsDel = group.getBoundsInParent(); diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 937d4c2..446021f 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -12,7 +12,6 @@ import javafx.scene.control.ScrollPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javafx.scene.shape.SVGPath; import javafx.stage.Modality; import javafx.stage.Stage; import res.DataController; @@ -30,6 +29,8 @@ public class MainController { @FXML public VBox leftNav; @FXML + public GridPane mainGridPane; + @FXML private GridPane calendarGrid; @FXML @@ -60,17 +61,17 @@ public class MainController { SvgBtnCreator.createPath("M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z", "white", "lightgray") ); - Button addBtn = SvgBtnCreator.cretaeBtn(svgAdd, 40); + Button addBtn = SvgBtnCreator.createBtn(svgAdd, 40); addBtn.setOnAction(e -> onAddBtnClick()); addBtn.getStyleClass().add("main-btn"); leftNav.getChildren().add(addBtn); Group svgSettings = new Group( - SvgBtnCreator.createPath("M0,0h24v24H0V0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M0 0h24v24H0V0z", "transparent", "transparent"), SvgBtnCreator.createPath("M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z", "white", "lightgray") ); - Button settingsBtn = SvgBtnCreator.cretaeBtn(svgSettings, 40); + Button settingsBtn = SvgBtnCreator.createBtn(svgSettings, 40); settingsBtn.setOnAction(e -> onSettingBtnClick()); settingsBtn.getStyleClass().add("main-btn"); leftNav.getChildren().add(settingsBtn); @@ -80,10 +81,43 @@ public class MainController { SvgBtnCreator.createPath("M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z", "white", "lightgray") ); - Button logoutBtn = SvgBtnCreator.cretaeBtn(svgLogout, 40); + Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40); logoutBtn.setOnAction(e -> onLogoutBtnClick()); logoutBtn.getStyleClass().add("main-btn"); leftNav.getChildren().add(logoutBtn); + + Group svgBack = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z", + "white", "lightgray") + ); + Button backBtn = SvgBtnCreator.createBtn(svgBack, 40); + backBtn.setOnAction(e -> onBackClick()); + backBtn.getStyleClass().add("navBtn"); + GridPane.setColumnIndex(backBtn, 1); + mainGridPane.getChildren().add(backBtn); + + Group svgToday = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M20 3h-1V1h-2v2H7V1H5v2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 18H4V8h16v13z", + "white", "lightgray") + ); + Button todayBtn = SvgBtnCreator.createBtn(svgToday, 40); + todayBtn.setOnAction(e -> onTodayClick()); + todayBtn.getStyleClass().add("navBtn"); + GridPane.setColumnIndex(todayBtn, 2); + mainGridPane.getChildren().add(todayBtn); + + Group svgNext = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z", + "white", "lightgray") + ); + Button nextBtn = SvgBtnCreator.createBtn(svgNext, 40); + nextBtn.setOnAction(e -> onNextClick()); + nextBtn.getStyleClass().add("navBtn"); + GridPane.setColumnIndex(nextBtn, 3); + mainGridPane.getChildren().add(nextBtn); } private void updateEvents() { @@ -189,7 +223,7 @@ public class MainController { SvgBtnCreator.createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", "white", "lightgray") ); - Button deleteBtn = SvgBtnCreator.cretaeBtn(svgDel, 24); + Button deleteBtn = SvgBtnCreator.createBtn(svgDel, 24); deleteBtn.getStyleClass().add("deleteEventBtn"); deleteBtn.setOnAction(e -> { @@ -203,7 +237,7 @@ public class MainController { SvgBtnCreator.createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", "white", "lightgray") ); - Button editBtn = SvgBtnCreator.cretaeBtn(svgEdit, 24); + Button editBtn = SvgBtnCreator.createBtn(svgEdit, 24); editBtn.getStyleClass().add("editEventBtn"); editBtn.setOnAction(event1 -> { try { @@ -284,12 +318,5 @@ public class MainController { } - private static SVGPath createPath(String d, String fill, String hoverFill) { - SVGPath path = new SVGPath(); - path.getStyleClass().add("svg"); - path.setContent(d); - path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';'); - return path; - } } \ No newline at end of file diff --git a/client/app/src/main/resources/main/main-view.css b/client/app/src/main/resources/main/main-view.css index 657cac8..b32e122 100644 --- a/client/app/src/main/resources/main/main-view.css +++ b/client/app/src/main/resources/main/main-view.css @@ -76,7 +76,16 @@ Label{ } .navBtn{ - -fx-background-color: white; + -fx-background-color: transparent; + -fx-border-color: transparent; +} + +.navBtn .svg { + -fx-fill: -fill; +} + +.navBtn:hover .svg { + -fx-fill: -hover-fill; } .editEventBtn{ diff --git a/client/app/src/main/resources/main/main-view.fxml b/client/app/src/main/resources/main/main-view.fxml index 825fb73..3c45b3e 100644 --- a/client/app/src/main/resources/main/main-view.fxml +++ b/client/app/src/main/resources/main/main-view.fxml @@ -4,7 +4,6 @@ - @@ -21,7 +20,7 @@ - + @@ -40,9 +39,6 @@ - zurück - heute - weiter From ea3288a3455092a622b388ea1e85e6662155833f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Fri, 21 Jan 2022 07:58:27 +0100 Subject: [PATCH 14/43] Fixed bg-color --- .../src/main/java/main/MainController.java | 20 ++++++++++--------- .../app/src/main/resources/main/main-view.css | 4 ++++ .../src/main/resources/main/main-view.fxml | 2 ++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 446021f..292598e 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -9,6 +9,7 @@ import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; +import javafx.scene.control.Tooltip; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -31,6 +32,8 @@ public class MainController { @FXML public GridPane mainGridPane; @FXML + public HBox buttonBox; + @FXML private GridPane calendarGrid; @FXML @@ -59,7 +62,7 @@ public class MainController { Group svgAdd = new Group( SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), SvgBtnCreator.createPath("M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z", - "white", "lightgray") + "white", "gray") ); Button addBtn = SvgBtnCreator.createBtn(svgAdd, 40); addBtn.setOnAction(e -> onAddBtnClick()); @@ -69,7 +72,7 @@ public class MainController { Group svgSettings = new Group( SvgBtnCreator.createPath("M0 0h24v24H0V0z", "transparent", "transparent"), SvgBtnCreator.createPath("M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z", - "white", "lightgray") + "white", "gray") ); Button settingsBtn = SvgBtnCreator.createBtn(svgSettings, 40); settingsBtn.setOnAction(e -> onSettingBtnClick()); @@ -79,7 +82,7 @@ public class MainController { Group svgLogout = new Group( SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), SvgBtnCreator.createPath("M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z", - "white", "lightgray") + "white", "gray") ); Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40); logoutBtn.setOnAction(e -> onLogoutBtnClick()); @@ -95,7 +98,7 @@ public class MainController { backBtn.setOnAction(e -> onBackClick()); backBtn.getStyleClass().add("navBtn"); GridPane.setColumnIndex(backBtn, 1); - mainGridPane.getChildren().add(backBtn); + buttonBox.getChildren().add(backBtn); Group svgToday = new Group( SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), @@ -106,7 +109,7 @@ public class MainController { todayBtn.setOnAction(e -> onTodayClick()); todayBtn.getStyleClass().add("navBtn"); GridPane.setColumnIndex(todayBtn, 2); - mainGridPane.getChildren().add(todayBtn); + buttonBox.getChildren().add(todayBtn); Group svgNext = new Group( SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), @@ -117,7 +120,7 @@ public class MainController { nextBtn.setOnAction(e -> onNextClick()); nextBtn.getStyleClass().add("navBtn"); GridPane.setColumnIndex(nextBtn, 3); - mainGridPane.getChildren().add(nextBtn); + buttonBox.getChildren().add(nextBtn); } private void updateEvents() { @@ -167,7 +170,6 @@ public class MainController { stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); - //stage.initStyle(StageStyle.UNDECORATED); stage.showAndWait(); } catch (IOException e) { e.printStackTrace(); @@ -221,7 +223,7 @@ public class MainController { Group svgDel = new Group( SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), SvgBtnCreator.createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", - "white", "lightgray") + "white", "gray") ); Button deleteBtn = SvgBtnCreator.createBtn(svgDel, 24); @@ -235,7 +237,7 @@ public class MainController { Group svgEdit = new Group( SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), SvgBtnCreator.createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", - "white", "lightgray") + "white", "gray") ); Button editBtn = SvgBtnCreator.createBtn(svgEdit, 24); editBtn.getStyleClass().add("editEventBtn"); diff --git a/client/app/src/main/resources/main/main-view.css b/client/app/src/main/resources/main/main-view.css index b32e122..56d1402 100644 --- a/client/app/src/main/resources/main/main-view.css +++ b/client/app/src/main/resources/main/main-view.css @@ -75,6 +75,10 @@ Label{ -fx-fill: -hover-fill; } +.buttonBox{ + -fx-background-color: #77859E; +} + .navBtn{ -fx-background-color: transparent; -fx-border-color: transparent; diff --git a/client/app/src/main/resources/main/main-view.fxml b/client/app/src/main/resources/main/main-view.fxml index 3c45b3e..8f2d3f8 100644 --- a/client/app/src/main/resources/main/main-view.fxml +++ b/client/app/src/main/resources/main/main-view.fxml @@ -40,6 +40,8 @@ + + From 0840ee1d12776cf4e52fe377c6aee35da95d9e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Fri, 21 Jan 2022 11:13:44 +0100 Subject: [PATCH 15/43] Refactored code and added tooltips to the buttons --- .../app/src/main/java/customUI/Tooltip.java | 9 ++ .../src/main/java/helper/SvgBtnCreator.java | 34 +++++ .../src/main/java/main/MainController.java | 135 +++++++++--------- 3 files changed, 111 insertions(+), 67 deletions(-) create mode 100644 client/app/src/main/java/customUI/Tooltip.java diff --git a/client/app/src/main/java/customUI/Tooltip.java b/client/app/src/main/java/customUI/Tooltip.java new file mode 100644 index 0000000..7407500 --- /dev/null +++ b/client/app/src/main/java/customUI/Tooltip.java @@ -0,0 +1,9 @@ +package customUI; + +public class Tooltip extends javafx.scene.control.Tooltip { + + public Tooltip(String tollTipText){ + super(Converter.CONVERT_STR(tollTipText)); + } + +} diff --git a/client/app/src/main/java/helper/SvgBtnCreator.java b/client/app/src/main/java/helper/SvgBtnCreator.java index 5f0e3ff..c9546fe 100644 --- a/client/app/src/main/java/helper/SvgBtnCreator.java +++ b/client/app/src/main/java/helper/SvgBtnCreator.java @@ -4,6 +4,7 @@ import javafx.geometry.Bounds; import javafx.scene.Group; import customUI.Button; import javafx.scene.control.ContentDisplay; +import customUI.Tooltip; import javafx.scene.shape.SVGPath; public class SvgBtnCreator { @@ -23,6 +24,39 @@ public class SvgBtnCreator { return btn; } + public static Button createBtn(Group group, int svgSize, String styleClass) { + Button btn = new Button(); + + Bounds boundsDel = group.getBoundsInParent(); + double scaleDel = Math.min(svgSize / boundsDel.getWidth(), svgSize / boundsDel.getHeight()); + group.setScaleX(scaleDel); + group.setScaleY(scaleDel); + btn.setGraphic(group); + btn.setMaxSize(svgSize, svgSize); + btn.setMinSize(svgSize, svgSize); + btn.getStyleClass().add(styleClass); + + return btn; + } + + public static Button createBtn(Group group, int svgSize, String styleClass, String toolTip) { + Button btn = new Button(); + + Bounds boundsDel = group.getBoundsInParent(); + double scaleDel = Math.min(svgSize / boundsDel.getWidth(), svgSize / boundsDel.getHeight()); + group.setScaleX(scaleDel); + group.setScaleY(scaleDel); + btn.setGraphic(group); + btn.setMaxSize(svgSize, svgSize); + btn.setMinSize(svgSize, svgSize); + btn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); + btn.getStyleClass().add(styleClass); + Tooltip tooltip = new Tooltip(toolTip); + btn.setTooltip(tooltip); + + return btn; + } + public static SVGPath createPath(String d, String fill, String hoverFill) { SVGPath path = new SVGPath(); path.getStyleClass().add("svg"); diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 292598e..098fd12 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -9,7 +9,6 @@ import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; -import javafx.scene.control.Tooltip; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -56,71 +55,8 @@ public class MainController { createWeek(); setDates(); updateEvents(); - + createBtns(); leftNav.setSpacing(40); - - Group svgAdd = new Group( - SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), - SvgBtnCreator.createPath("M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z", - "white", "gray") - ); - Button addBtn = SvgBtnCreator.createBtn(svgAdd, 40); - addBtn.setOnAction(e -> onAddBtnClick()); - addBtn.getStyleClass().add("main-btn"); - leftNav.getChildren().add(addBtn); - - Group svgSettings = new Group( - SvgBtnCreator.createPath("M0 0h24v24H0V0z", "transparent", "transparent"), - SvgBtnCreator.createPath("M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z", - "white", "gray") - ); - Button settingsBtn = SvgBtnCreator.createBtn(svgSettings, 40); - settingsBtn.setOnAction(e -> onSettingBtnClick()); - settingsBtn.getStyleClass().add("main-btn"); - leftNav.getChildren().add(settingsBtn); - - Group svgLogout = new Group( - SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), - SvgBtnCreator.createPath("M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z", - "white", "gray") - ); - Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40); - logoutBtn.setOnAction(e -> onLogoutBtnClick()); - logoutBtn.getStyleClass().add("main-btn"); - leftNav.getChildren().add(logoutBtn); - - Group svgBack = new Group( - SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), - SvgBtnCreator.createPath("M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z", - "white", "lightgray") - ); - Button backBtn = SvgBtnCreator.createBtn(svgBack, 40); - backBtn.setOnAction(e -> onBackClick()); - backBtn.getStyleClass().add("navBtn"); - GridPane.setColumnIndex(backBtn, 1); - buttonBox.getChildren().add(backBtn); - - Group svgToday = new Group( - SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), - SvgBtnCreator.createPath("M20 3h-1V1h-2v2H7V1H5v2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 18H4V8h16v13z", - "white", "lightgray") - ); - Button todayBtn = SvgBtnCreator.createBtn(svgToday, 40); - todayBtn.setOnAction(e -> onTodayClick()); - todayBtn.getStyleClass().add("navBtn"); - GridPane.setColumnIndex(todayBtn, 2); - buttonBox.getChildren().add(todayBtn); - - Group svgNext = new Group( - SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), - SvgBtnCreator.createPath("M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z", - "white", "lightgray") - ); - Button nextBtn = SvgBtnCreator.createBtn(svgNext, 40); - nextBtn.setOnAction(e -> onNextClick()); - nextBtn.getStyleClass().add("navBtn"); - GridPane.setColumnIndex(nextBtn, 3); - buttonBox.getChildren().add(nextBtn); } private void updateEvents() { @@ -225,7 +161,7 @@ public class MainController { SvgBtnCreator.createPath("M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z", "white", "gray") ); - Button deleteBtn = SvgBtnCreator.createBtn(svgDel, 24); + Button deleteBtn = SvgBtnCreator.createBtn(svgDel, 24, "", "Löschen des Termins"); deleteBtn.getStyleClass().add("deleteEventBtn"); deleteBtn.setOnAction(e -> { @@ -239,7 +175,7 @@ public class MainController { SvgBtnCreator.createPath("M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z", "white", "gray") ); - Button editBtn = SvgBtnCreator.createBtn(svgEdit, 24); + Button editBtn = SvgBtnCreator.createBtn(svgEdit, 24, "", "Bearbeiten des Termins"); editBtn.getStyleClass().add("editEventBtn"); editBtn.setOnAction(event1 -> { try { @@ -320,5 +256,70 @@ public class MainController { } + private void createBtns(){ + Group svgAdd = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z", + "white", "gray") + ); + Button addBtn = SvgBtnCreator.createBtn(svgAdd, 40, "main-btn", "Erstellt einen neuen Termin"); + addBtn.setOnAction(e -> onAddBtnClick()); + addBtn.getStyleClass().add("main-btn"); + leftNav.getChildren().add(addBtn); + + Group svgSettings = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0V0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z", + "white", "gray") + ); + Button settingsBtn = SvgBtnCreator.createBtn(svgSettings, 40, "main-btn", "Öffnet die Einstellungen"); + settingsBtn.setOnAction(e -> onSettingBtnClick()); + settingsBtn.getStyleClass().add("main-btn"); + leftNav.getChildren().add(settingsBtn); + + Group svgLogout = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z", + "white", "gray") + ); + Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40, "main-btn", "Abmelden"); + logoutBtn.setOnAction(e -> onLogoutBtnClick()); + logoutBtn.getStyleClass().add("main-btn"); + leftNav.getChildren().add(logoutBtn); + + Group svgBack = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z", + "white", "lightgray") + ); + Button backBtn = SvgBtnCreator.createBtn(svgBack, 40, "navBtn", "Zeigt die vorherige Woche"); + backBtn.setOnAction(e -> onBackClick()); + backBtn.getStyleClass().add("navBtn"); + GridPane.setColumnIndex(backBtn, 1); + buttonBox.getChildren().add(backBtn); + + Group svgToday = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M20 3h-1V1h-2v2H7V1H5v2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 18H4V8h16v13z", + "white", "lightgray") + ); + Button todayBtn = SvgBtnCreator.createBtn(svgToday, 40, "navBtn", "Zeigt die aktuelle Woche"); + todayBtn.setOnAction(e -> onTodayClick()); + todayBtn.getStyleClass().add("navBtn"); + GridPane.setColumnIndex(todayBtn, 2); + buttonBox.getChildren().add(todayBtn); + + Group svgNext = new Group( + SvgBtnCreator.createPath("M0 0h24v24H0z", "transparent", "transparent"), + SvgBtnCreator.createPath("M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z", + "white", "lightgray") + ); + Button nextBtn = SvgBtnCreator.createBtn(svgNext, 40, "navBtn", "Zeigt die nächste Woche"); + nextBtn.setOnAction(e -> onNextClick()); + nextBtn.getStyleClass().add("navBtn"); + GridPane.setColumnIndex(nextBtn, 3); + buttonBox.getChildren().add(nextBtn); + } + } \ No newline at end of file From c040e54fb8a97a315df860700fa67f95daa50f51 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sun, 23 Jan 2022 17:40:49 +0100 Subject: [PATCH 16/43] Added Config --- .../src/main/java/main/MainApplication.java | 56 +++++++++++++------ client/data/src/main/java/config/Config.java | 41 ++++++++++++++ .../src/main/java/config/ConfigLoader.java | 38 +++++++++++++ 3 files changed, 119 insertions(+), 16 deletions(-) create mode 100644 client/data/src/main/java/config/Config.java create mode 100644 client/data/src/main/java/config/ConfigLoader.java diff --git a/client/app/src/main/java/main/MainApplication.java b/client/app/src/main/java/main/MainApplication.java index 6108243..f6987aa 100644 --- a/client/app/src/main/java/main/MainApplication.java +++ b/client/app/src/main/java/main/MainApplication.java @@ -1,10 +1,13 @@ package main; +import config.Config; +import config.ConfigLoader; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; import res.DataController; +import res.HttpRequest; import java.io.IOException; import java.util.Objects; @@ -12,10 +15,46 @@ import java.util.Objects; public class MainApplication extends Application { @Override public void start(Stage stage) throws IOException { + Config config = ConfigLoader.load(); + if(config == null){ + config = new Config(false, -1, ""); + } System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170"); - // Load login-scene + if( + !config.isLoginSaved() + || new DataController().loginWithToken(config.getId(), config.getToken()) + ){ + // Load login-scene + loadLoginScene(); + } + + if (DataController.USER_ID >= 0) { + if(config.isLoginSaved()){ + config.setId(DataController.USER_ID); + config.setToken(HttpRequest.TOKEN); + } + // Load main-scene + loadMainScene(stage); + + System.out.println("Logged in..."); + } + } + + private void loadMainScene(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); + + Scene scene = new Scene(fxmlLoader.load(), 1200, 700); + scene.getStylesheets().add(Objects.requireNonNull( + MainApplication.class.getResource("main-view.css")).toExternalForm() + ); + stage.setTitle("SharePlaner"); + stage.setScene(scene); + stage.show(); + } + + private void loadLoginScene() throws IOException { FXMLLoader fxmlLoaderLogin = new FXMLLoader(MainApplication.class.getResource("../users/login.fxml")); Scene sceneLogin = new Scene(fxmlLoaderLogin.load(), 650, 500); sceneLogin.getStylesheets().add(Objects.requireNonNull( @@ -25,21 +64,6 @@ public class MainApplication extends Application { stageLogin.setTitle("Anmelden"); stageLogin.setScene(sceneLogin); stageLogin.showAndWait(); - - if (DataController.USER_ID >= 0) { - // Load main-scene - FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); - - Scene scene = new Scene(fxmlLoader.load(), 1200, 700); - scene.getStylesheets().add(Objects.requireNonNull( - MainApplication.class.getResource("main-view.css")).toExternalForm() - ); - stage.setTitle("SharePlaner"); - stage.setScene(scene); - stage.show(); - - System.out.println("Logged in..."); - } } public static void main(String[] args) { diff --git a/client/data/src/main/java/config/Config.java b/client/data/src/main/java/config/Config.java new file mode 100644 index 0000000..98401a0 --- /dev/null +++ b/client/data/src/main/java/config/Config.java @@ -0,0 +1,41 @@ +package config; + +public class Config { + private boolean saveLogin; + private long id; + private String token; + + public Config(){ + + } + + public Config(boolean saveLogin, long id, String token) { + this.saveLogin = saveLogin; + this.id = id; + this.token = token; + } + + public boolean isLoginSaved() { + return saveLogin; + } + + public void setSaveLogin(boolean saveLogin) { + this.saveLogin = saveLogin; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } +} diff --git a/client/data/src/main/java/config/ConfigLoader.java b/client/data/src/main/java/config/ConfigLoader.java new file mode 100644 index 0000000..56e195e --- /dev/null +++ b/client/data/src/main/java/config/ConfigLoader.java @@ -0,0 +1,38 @@ +package config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import res.DataController; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class ConfigLoader { + + public static Config load(){ + try { + String jsonString = Files.readString(Paths.get("config.json")); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + return objectMapper.readValue(jsonString, Config.class); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static void save(Config config){ + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + + try { + Files.writeString(Paths.get( + "config.json"), + objectMapper.writeValueAsString(config) + ); + } catch (IOException e) { + e.printStackTrace(); + } + } +} From e021809fd75fd76e616ebed66c93c35d8df5f636 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sun, 23 Jan 2022 17:41:40 +0100 Subject: [PATCH 17/43] use camelCase for static methods --- client/app/src/main/java/customUI/Button.java | 2 +- client/app/src/main/java/customUI/Converter.java | 2 +- client/app/src/main/java/customUI/Label.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/app/src/main/java/customUI/Button.java b/client/app/src/main/java/customUI/Button.java index 3d4d4bf..61df976 100644 --- a/client/app/src/main/java/customUI/Button.java +++ b/client/app/src/main/java/customUI/Button.java @@ -3,6 +3,6 @@ package customUI; public class Button extends javafx.scene.control.Button { public void setTextValue(String text){ - super.setText(Converter.CONVERT_STR(text)); + super.setText(Converter.convertString(text)); } } diff --git a/client/app/src/main/java/customUI/Converter.java b/client/app/src/main/java/customUI/Converter.java index bf0c895..dc737af 100644 --- a/client/app/src/main/java/customUI/Converter.java +++ b/client/app/src/main/java/customUI/Converter.java @@ -8,7 +8,7 @@ public class Converter { ß \u00df */ @SuppressWarnings("all") - public static String CONVERT_STR(String str){ + public static String convertString(String str){ return str .replace("ä", "\u00e4") .replace("Ä", "\u00c4") diff --git a/client/app/src/main/java/customUI/Label.java b/client/app/src/main/java/customUI/Label.java index 8ba0ce2..ad5321e 100644 --- a/client/app/src/main/java/customUI/Label.java +++ b/client/app/src/main/java/customUI/Label.java @@ -2,7 +2,7 @@ package customUI; public class Label extends javafx.scene.control.Label { public Label(String content){ - super(Converter.CONVERT_STR(content)); + super(Converter.convertString(content)); } public Label(){ @@ -10,6 +10,6 @@ public class Label extends javafx.scene.control.Label { } public void setTextValue(String text){ - super.setText(Converter.CONVERT_STR(text)); + super.setText(Converter.convertString(text)); } } From 2c3d646c4708dba59345dda0a9a6d5390f30ee91 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sun, 23 Jan 2022 21:21:16 +0100 Subject: [PATCH 18/43] Added save login --- .../src/main/java/main/MainApplication.java | 7 ++--- .../app/src/main/resources/main/main-view.css | 26 +++++++++++++++++++ client/data/src/main/java/config/Config.java | 2 +- .../src/main/java/res/DataController.java | 11 ++++++-- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/client/app/src/main/java/main/MainApplication.java b/client/app/src/main/java/main/MainApplication.java index f6987aa..09274f4 100644 --- a/client/app/src/main/java/main/MainApplication.java +++ b/client/app/src/main/java/main/MainApplication.java @@ -23,17 +23,18 @@ public class MainApplication extends Application { System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170"); if( - !config.isLoginSaved() - || new DataController().loginWithToken(config.getId(), config.getToken()) + !config.isSaveLogin() + || !new DataController().loginWithToken(config.getId(), config.getToken()) ){ // Load login-scene loadLoginScene(); } if (DataController.USER_ID >= 0) { - if(config.isLoginSaved()){ + if(config.isSaveLogin()){ config.setId(DataController.USER_ID); config.setToken(HttpRequest.TOKEN); + ConfigLoader.save(config); } // Load main-scene loadMainScene(stage); diff --git a/client/app/src/main/resources/main/main-view.css b/client/app/src/main/resources/main/main-view.css index 684f7b7..0821874 100644 --- a/client/app/src/main/resources/main/main-view.css +++ b/client/app/src/main/resources/main/main-view.css @@ -76,3 +76,29 @@ Label{ -fx-background-color: white; } +.editEventBtn{ + -fx-background-color: transparent; + -fx-border-color: transparent; +} + +.editEventBtn .svg { + -fx-fill: -fill; +} + +.editEventBtn:hover .svg { + -fx-fill: -hover-fill; +} + +.deleteEventBtn{ + -fx-background-color: transparent; + -fx-border-color: transparent; +} + +.deleteEventBtn .svg { + -fx-fill: -fill; +} + +.deleteEventBtn:hover .svg { + -fx-fill: -hover-fill; +} + diff --git a/client/data/src/main/java/config/Config.java b/client/data/src/main/java/config/Config.java index 98401a0..07e8b2f 100644 --- a/client/data/src/main/java/config/Config.java +++ b/client/data/src/main/java/config/Config.java @@ -15,7 +15,7 @@ public class Config { this.token = token; } - public boolean isLoginSaved() { + public boolean isSaveLogin() { return saveLogin; } diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 279688a..f920bac 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -62,17 +62,24 @@ public class DataController { return USER_ID >= 0; } - public boolean loginWIthToken(String username, String password) { + public boolean loginWithToken(long userId, String token) { try { + HttpRequest.TOKEN = token; Tuple response = httpRequest.sendPostRequest( LOGIN_WITH_TOKEN_ENDPOINT, - "userId=" + USER_ID, + "userId=" + userId, true ); + + System.out.println(response.getKey() + " " + response.getValue()); + + if(response.getKey() != 200) return false; } catch (Exception e) { e.printStackTrace(); return false; } + USER_ID = userId; + HttpRequest.TOKEN = token; return USER_ID >= 0; } From 4ce4445d50c8b10561d7ca446b65db86393d02fd Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sun, 23 Jan 2022 22:05:23 +0100 Subject: [PATCH 19/43] Merged --- client/app/src/main/java/customUI/Tooltip.java | 2 +- client/app/src/main/java/main/CreateEventController.java | 4 +++- client/app/src/main/java/main/MainController.java | 3 +-- client/config.json | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 client/config.json diff --git a/client/app/src/main/java/customUI/Tooltip.java b/client/app/src/main/java/customUI/Tooltip.java index 7407500..2a5324a 100644 --- a/client/app/src/main/java/customUI/Tooltip.java +++ b/client/app/src/main/java/customUI/Tooltip.java @@ -3,7 +3,7 @@ package customUI; public class Tooltip extends javafx.scene.control.Tooltip { public Tooltip(String tollTipText){ - super(Converter.CONVERT_STR(tollTipText)); + super(Converter.convertString(tollTipText)); } } diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index 0511b96..e36cd4a 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -61,6 +61,8 @@ public class CreateEventController { throw new IllegalArgumentException("Bitte w\u00e4hle ein Datum aus"); } + System.out.println(datePickerDate.getValue()); + Event event = new Event( textName.getText(), ComboBoxPriotity.getSelectionModel().getSelectedIndex(), @@ -78,7 +80,7 @@ public class CreateEventController { Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stage.close(); - } catch (HttpRequestException e) { + } catch (Exception e) { labelError.setText(e.getMessage()); } } diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 150c4b8..2fb1398 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -7,9 +7,8 @@ import helper.HttpRequestException; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.geometry.Pos; +import javafx.scene.Group; import javafx.scene.Scene; -import customUI.Button; -import customUI.Label; import javafx.scene.control.ScrollPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; diff --git a/client/config.json b/client/config.json new file mode 100644 index 0000000..e80bf9d --- /dev/null +++ b/client/config.json @@ -0,0 +1 @@ +{"saveLogin":true,"id":1,"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtYXJjIn0.NdOMxKKgH4ZNZ84uA81L57vJtR9OhTVyKwtNsOuZhFQ"} \ No newline at end of file From c79e9a4581d781d71d93176cc7856263d712ed1e Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Mon, 24 Jan 2022 12:45:08 +0100 Subject: [PATCH 20/43] Fixed special Chars --- .../main/java/main/EditEventController.java | 17 +++ .../java/main/MainApplication_structure.puml | 109 ++++++++++++++++++ client/config.json | 2 +- client/data/src/main/java/res/Event.java | 29 +---- 4 files changed, 130 insertions(+), 27 deletions(-) create mode 100644 client/app/src/main/java/main/MainApplication_structure.puml diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index 3e34d04..58d1ea6 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -1,9 +1,17 @@ package main; +import customUI.Converter; import helper.HttpRequestException; +import javafx.fxml.FXML; +import javafx.util.StringConverter; +import javafx.util.converter.LocalTimeStringConverter; import res.DataController; import res.Event; +import java.time.LocalTime; +import java.time.format.FormatStyle; +import java.util.Locale; + public class EditEventController extends CreateEventController{ private Event currentEvent; @@ -14,8 +22,17 @@ public class EditEventController extends CreateEventController{ public void setCurrentEvent(Event currentEvent) { this.currentEvent = currentEvent; + + textName.setText(Converter.convertString(currentEvent.getName())); + datePickerDate.setValue(currentEvent.getDate().toLocalDate()); + ComboBoxPriotity.getSelectionModel().select(currentEvent.getPriority()); + + //timeEnd.setValue(currentEvent.getEnd()); } + + + @Override protected void sendHttpRequest(Event event) throws HttpRequestException { DataController dataController = new DataController(); diff --git a/client/app/src/main/java/main/MainApplication_structure.puml b/client/app/src/main/java/main/MainApplication_structure.puml new file mode 100644 index 0000000..65371cd --- /dev/null +++ b/client/app/src/main/java/main/MainApplication_structure.puml @@ -0,0 +1,109 @@ +@startuml + +/' diagram meta data start +config=StructureConfiguration; +{ + "projectClassification": { + "searchMode": "OpenProject", // OpenProject, AllProjects + "includedProjects": "", + "pathEndKeywords": "*.impl", + "isClientPath": "", + "isClientName": "", + "isTestPath": "", + "isTestName": "", + "isMappingPath": "", + "isMappingName": "", + "isDataAccessPath": "", + "isDataAccessName": "", + "isDataStructurePath": "", + "isDataStructureName": "", + "isInterfaceStructuresPath": "", + "isInterfaceStructuresName": "", + "isEntryPointPath": "", + "isEntryPointName": "" + }, + "graphRestriction": { + "classPackageExcludeFilter": "", + "classPackageIncludeFilter": "", + "classNameExcludeFilter": "", + "classNameIncludeFilter": "", + "methodNameExcludeFilter": "", + "methodNameIncludeFilter": "", + "removeByInheritance": "", // inheritance/annotation based filtering is done in a second step + "removeByAnnotation": "", + "removeByClassPackage": "", // cleanup the graph after inheritance/annotation based filtering is done + "removeByClassName": "", + "cutMappings": false, + "cutEnum": true, + "cutTests": true, + "cutClient": true, + "cutDataAccess": false, + "cutInterfaceStructures": false, + "cutDataStructures": false, + "cutGetterAndSetter": true, + "cutConstructors": true + }, + "graphTraversal": { + "forwardDepth": 3, + "backwardDepth": 3, + "classPackageExcludeFilter": "", + "classPackageIncludeFilter": "", + "classNameExcludeFilter": "", + "classNameIncludeFilter": "", + "methodNameExcludeFilter": "", + "methodNameIncludeFilter": "", + "hideMappings": false, + "hideDataStructures": false, + "hidePrivateMethods": true, + "hideInterfaceCalls": true, // indirection: implementation -> interface (is hidden) -> implementation + "onlyShowApplicationEntryPoints": false // root node is included + }, + "details": { + "aggregation": "GroupByClass", // ByClass, GroupByClass, None + "showClassGenericTypes": true, + "showMethods": true, + "showMethodParameterNames": true, + "showMethodParameterTypes": true, + "showMethodReturnType": true, + "showPackageLevels": 2, + "showDetailedClassStructure": true + }, + "rootClass": "main.MainApplication" +} +diagram meta data end '/ + + + +digraph g { + rankdir="TB" + splines=polyline + + +'nodes +subgraph cluster_3343801 { + label=main + labeljust=l + fillcolor="#ececec" + style=filled + + MainApplication3343801[ + label=< + +
+ + + + +
(C)MainApplication
- loadLoginScene()
- loadMainScene(stage: Stage)
+ main(args: String[])
+ start(stage: Stage)
> + style=filled + margin=0 + shape=plaintext + fillcolor="#FFFFFF" +]; +} + +'edges + + +} +@enduml \ No newline at end of file diff --git a/client/config.json b/client/config.json index e80bf9d..65c46cc 100644 --- a/client/config.json +++ b/client/config.json @@ -1 +1 @@ -{"saveLogin":true,"id":1,"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtYXJjIn0.NdOMxKKgH4ZNZ84uA81L57vJtR9OhTVyKwtNsOuZhFQ"} \ No newline at end of file +{"saveLogin":true,"id":1,"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtYXJjIn0.c7OHtcVGdTTVI2VmuY3qSlSscAM2t-aP2piRvf4R9jo"} \ No newline at end of file diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index 022aeea..efabe57 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -110,26 +110,6 @@ public class Event { Pattern pattern = Pattern.compile("[A-Za-z\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-9 =!?+*/$.:,;_<>()-]*"); Matcher matcher = pattern.matcher(name); if (!matcher.matches()) { - System.out.println(name); - - byte[] bytes = name.getBytes(StandardCharsets.UTF_16); - - String utf8EncodedString = new String(bytes, StandardCharsets.UTF_16); - System.out.println(utf8EncodedString); - - for (char c : (name).toCharArray()) { - System.out.print(c + " " + (int) c + ", "); - } - System.out.println(); - for (char c : (name).toCharArray()) { - System.out.print(c + " " + (int) c + ", "); - } - System.out.println(); - for (char c : ("TäöüÄÖÜ").toCharArray()) { - System.out.print(c + " " + (int) c + ", "); - } - System.out.println(); - throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$.:,;_ <>()-"); } if (priority < 0) { @@ -163,7 +143,9 @@ public class Event { } public void setName(String name) { - this.name = convertToASCII(name); + System.out.println(name); + this.name = name; + System.out.println(this.name); } public int getPriority() { @@ -250,9 +232,4 @@ public class Event { "&isFullDay=" + isFullDay() + "&isPrivate=" + isPrivate(); } - - private String convertToASCII(String s) { - byte[] germanBytes = s.getBytes(); - return new String(germanBytes, StandardCharsets.US_ASCII); - } } From 8260c3f73282072255db3ad5e1b9aec201cad96e Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Mon, 24 Jan 2022 12:46:53 +0100 Subject: [PATCH 21/43] Removed file --- .../java/main/MainApplication_structure.puml | 109 ------------------ 1 file changed, 109 deletions(-) delete mode 100644 client/app/src/main/java/main/MainApplication_structure.puml diff --git a/client/app/src/main/java/main/MainApplication_structure.puml b/client/app/src/main/java/main/MainApplication_structure.puml deleted file mode 100644 index 65371cd..0000000 --- a/client/app/src/main/java/main/MainApplication_structure.puml +++ /dev/null @@ -1,109 +0,0 @@ -@startuml - -/' diagram meta data start -config=StructureConfiguration; -{ - "projectClassification": { - "searchMode": "OpenProject", // OpenProject, AllProjects - "includedProjects": "", - "pathEndKeywords": "*.impl", - "isClientPath": "", - "isClientName": "", - "isTestPath": "", - "isTestName": "", - "isMappingPath": "", - "isMappingName": "", - "isDataAccessPath": "", - "isDataAccessName": "", - "isDataStructurePath": "", - "isDataStructureName": "", - "isInterfaceStructuresPath": "", - "isInterfaceStructuresName": "", - "isEntryPointPath": "", - "isEntryPointName": "" - }, - "graphRestriction": { - "classPackageExcludeFilter": "", - "classPackageIncludeFilter": "", - "classNameExcludeFilter": "", - "classNameIncludeFilter": "", - "methodNameExcludeFilter": "", - "methodNameIncludeFilter": "", - "removeByInheritance": "", // inheritance/annotation based filtering is done in a second step - "removeByAnnotation": "", - "removeByClassPackage": "", // cleanup the graph after inheritance/annotation based filtering is done - "removeByClassName": "", - "cutMappings": false, - "cutEnum": true, - "cutTests": true, - "cutClient": true, - "cutDataAccess": false, - "cutInterfaceStructures": false, - "cutDataStructures": false, - "cutGetterAndSetter": true, - "cutConstructors": true - }, - "graphTraversal": { - "forwardDepth": 3, - "backwardDepth": 3, - "classPackageExcludeFilter": "", - "classPackageIncludeFilter": "", - "classNameExcludeFilter": "", - "classNameIncludeFilter": "", - "methodNameExcludeFilter": "", - "methodNameIncludeFilter": "", - "hideMappings": false, - "hideDataStructures": false, - "hidePrivateMethods": true, - "hideInterfaceCalls": true, // indirection: implementation -> interface (is hidden) -> implementation - "onlyShowApplicationEntryPoints": false // root node is included - }, - "details": { - "aggregation": "GroupByClass", // ByClass, GroupByClass, None - "showClassGenericTypes": true, - "showMethods": true, - "showMethodParameterNames": true, - "showMethodParameterTypes": true, - "showMethodReturnType": true, - "showPackageLevels": 2, - "showDetailedClassStructure": true - }, - "rootClass": "main.MainApplication" -} -diagram meta data end '/ - - - -digraph g { - rankdir="TB" - splines=polyline - - -'nodes -subgraph cluster_3343801 { - label=main - labeljust=l - fillcolor="#ececec" - style=filled - - MainApplication3343801[ - label=< - -
- - - - -
(C)MainApplication
- loadLoginScene()
- loadMainScene(stage: Stage)
+ main(args: String[])
+ start(stage: Stage)
> - style=filled - margin=0 - shape=plaintext - fillcolor="#FFFFFF" -]; -} - -'edges - - -} -@enduml \ No newline at end of file From 4f6d9670d06a8bcbc6f2751e32ae3a1bd57d85c3 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Mon, 24 Jan 2022 13:28:19 +0100 Subject: [PATCH 22/43] Added logout function --- .../app/src/main/java/main/MainController.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 2fb1398..dbc8948 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -1,5 +1,7 @@ package main; +import config.Config; +import config.ConfigLoader; import customUI.Button; import customUI.Label; import helper.SvgBtnCreator; @@ -8,6 +10,7 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.geometry.Pos; import javafx.scene.Group; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; import javafx.scene.layout.GridPane; @@ -18,6 +21,9 @@ import javafx.stage.Stage; import res.DataController; import res.Event; +import javafx.event.ActionEvent; +import res.HttpRequest; + import java.io.IOException; import java.time.Duration; import java.time.LocalDateTime; @@ -123,8 +129,12 @@ public class MainController { } - protected void onLogoutBtnClick(){ - + protected void onLogoutBtnClick(ActionEvent event){ + ConfigLoader.save(new Config()); + DataController.USER_ID = -1; + HttpRequest.TOKEN = ""; + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + stage.close(); } private void createWeek() { @@ -296,7 +306,7 @@ public class MainController { "white", "gray") ); Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40, "main-btn", "Abmelden"); - logoutBtn.setOnAction(e -> onLogoutBtnClick()); + logoutBtn.setOnAction(this::onLogoutBtnClick); logoutBtn.getStyleClass().add("main-btn"); leftNav.getChildren().add(logoutBtn); From 057c4504d4b4c517ddfaf98fa92962a819b9a72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Mon, 24 Jan 2022 13:42:11 +0100 Subject: [PATCH 23/43] First view draft and create user connected --- .gitignore | 2 + .../src/main/java/main/MainController.java | 16 ++++- .../src/main/java/main/OptionController.java | 62 ++++++++++++++++++ .../src/main/resources/main/option-view.css | 64 +++++++++++++++++++ .../src/main/resources/main/option-view.fxml | 54 ++++++++++++++++ client/config.json | 1 - 6 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 client/app/src/main/java/main/OptionController.java create mode 100644 client/app/src/main/resources/main/option-view.css create mode 100644 client/app/src/main/resources/main/option-view.fxml delete mode 100644 client/config.json diff --git a/.gitignore b/.gitignore index f0ded7c..2532936 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,5 @@ crashlytics-build.properties .gradle/ build/ + +/client/config.json \ No newline at end of file diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 2fb1398..39a2f77 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -120,7 +120,21 @@ public class MainController { } protected void onSettingBtnClick(){ - + try{ + FXMLLoader fxmlLoader = new FXMLLoader( + MainApplication.class.getResource("option-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 650, 650); + scene.getStylesheets().add(Objects.requireNonNull( + MainApplication.class.getResource("option-view.css")).toExternalForm()); + Stage stage = new Stage(); + stage.setTitle("Einstellungen"); + stage.setScene(scene); + stage.initModality(Modality.APPLICATION_MODAL); + stage.setResizable(false); + stage.showAndWait(); + } catch (IOException e) { + e.printStackTrace(); + } } protected void onLogoutBtnClick(){ diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java new file mode 100644 index 0000000..8ca0b93 --- /dev/null +++ b/client/app/src/main/java/main/OptionController.java @@ -0,0 +1,62 @@ +package main; + +import com.jfoenix.controls.*; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.stage.Modality; +import javafx.stage.Stage; + +import java.io.IOException; +import java.util.Objects; + +public class OptionController { + + @FXML + public JFXButton updateUserBtn; + @FXML + public JFXButton deleteUserBtn; + @FXML + public JFXButton createUserBtn; + @FXML + public JFXToggleButton saveLoginTBtn; + @FXML + public Label labelError; + @FXML + public JFXComboBox userCmb; + + public void onBackBtnClick(ActionEvent actionEvent) { + Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); + stage.close(); + } + + public void onCreateBtnClick(ActionEvent actionEvent) { + try{ + FXMLLoader fxmlLoader = new FXMLLoader( + MainApplication.class.getResource("../users/create-user.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 800, 650); + scene.getStylesheets().add(Objects.requireNonNull( + MainApplication.class.getResource("../users/create-user.css")).toExternalForm()); + Stage stage = new Stage(); + stage.setTitle("User erstellen"); + stage.setScene(scene); + stage.initModality(Modality.APPLICATION_MODAL); + stage.setResizable(false); + stage.showAndWait(); + Stage stageOld = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); + stageOld.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void onUpdateBtnClick(ActionEvent actionEvent) { + } + + public void onDeleteBtnClick(ActionEvent actionEvent) { + } +} diff --git a/client/app/src/main/resources/main/option-view.css b/client/app/src/main/resources/main/option-view.css new file mode 100644 index 0000000..be03557 --- /dev/null +++ b/client/app/src/main/resources/main/option-view.css @@ -0,0 +1,64 @@ +GridPane{ + -fx-background-color: #3E415F; + -fx-padding: 20px; + -fx-font-size: 20px; + -fx-font-family: Segoe UI; + + -fx-border-insets: 1; + -fx-border-color: #B0B0B0; + -fx-border-style: solid; + -fx-border-width: 2; + -fx-effect: dropshadow(three-pass-box, rgba(100, 100, 100, 1), 24, 0.5, 0, 0); +} + +Label{ + -fx-text-fill: white; + -fx-max-width: 150px; + -fx-min-width: 150px; +} + +.mainLabel{ + -fx-background-color: #8D99AE; + -fx-padding: 10px; + -fx-max-width: 200px; + -fx-min-width: 200px; + -fx-font-weight: bold; + -fx-alignment: center; +} + +.inputField{ + -fx-padding: 10px; + -fx-background-color: white; +} + +.mainButton{ + -fx-font-weight: bold; + -fx-background-color: white; +} + +JFXButton{ + -fx-background-color: white; +} + +#labelError{ + -fx-font-weight: bold; + -fx-max-width: 1000px; + -fx-text-fill: #ff5555; + -fx-padding: 16px; + -fx-min-height: 140px; + -fx-max-height: 400px; + -fx-wrap-text: true; + -fx-font-size: 16px; +} + +.inputDate{ + -fx-background-color: white; +} + +.comboBox{ + -fx-background-color: white; +} + +.timePicker{ + -fx-background-color: white; +} \ No newline at end of file diff --git a/client/app/src/main/resources/main/option-view.fxml b/client/app/src/main/resources/main/option-view.fxml new file mode 100644 index 0000000..eba5db6 --- /dev/null +++ b/client/app/src/main/resources/main/option-view.fxml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + User bearbeiten + User löschen + User anlegen + + + + + diff --git a/client/config.json b/client/config.json deleted file mode 100644 index e80bf9d..0000000 --- a/client/config.json +++ /dev/null @@ -1 +0,0 @@ -{"saveLogin":true,"id":1,"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtYXJjIn0.NdOMxKKgH4ZNZ84uA81L57vJtR9OhTVyKwtNsOuZhFQ"} \ No newline at end of file From b963a53d855bbca06d954f8d5246832dcc60b53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Mon, 24 Jan 2022 13:44:48 +0100 Subject: [PATCH 24/43] Fixed gitignore --- .gitignore | 2 ++ client/config.json | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 client/config.json diff --git a/.gitignore b/.gitignore index f0ded7c..2532936 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,5 @@ crashlytics-build.properties .gradle/ build/ + +/client/config.json \ No newline at end of file diff --git a/client/config.json b/client/config.json deleted file mode 100644 index 65c46cc..0000000 --- a/client/config.json +++ /dev/null @@ -1 +0,0 @@ -{"saveLogin":true,"id":1,"token":"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtYXJjIn0.c7OHtcVGdTTVI2VmuY3qSlSscAM2t-aP2piRvf4R9jo"} \ No newline at end of file From 3848baddb662dcbfba2aff7f45afc747bdd0976d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Mon, 24 Jan 2022 14:11:34 +0100 Subject: [PATCH 25/43] Updated ui --- .../src/main/resources/main/option-view.css | 20 +++++--------- .../src/main/resources/main/option-view.fxml | 27 ++++++++++++------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/client/app/src/main/resources/main/option-view.css b/client/app/src/main/resources/main/option-view.css index be03557..291a5d3 100644 --- a/client/app/src/main/resources/main/option-view.css +++ b/client/app/src/main/resources/main/option-view.css @@ -13,8 +13,8 @@ GridPane{ Label{ -fx-text-fill: white; - -fx-max-width: 150px; - -fx-min-width: 150px; + -fx-max-width: 200px; + -fx-min-width: 200px; } .mainLabel{ @@ -26,11 +26,6 @@ Label{ -fx-alignment: center; } -.inputField{ - -fx-padding: 10px; - -fx-background-color: white; -} - .mainButton{ -fx-font-weight: bold; -fx-background-color: white; @@ -51,14 +46,13 @@ JFXButton{ -fx-font-size: 16px; } -.inputDate{ - -fx-background-color: white; -} - .comboBox{ -fx-background-color: white; + -fx-max-width: 200px; + -fx-min-width: 200px; } -.timePicker{ - -fx-background-color: white; +.userBtn{ + -fx-max-width: 200px; + -fx-min-width: 200px; } \ No newline at end of file diff --git a/client/app/src/main/resources/main/option-view.fxml b/client/app/src/main/resources/main/option-view.fxml index eba5db6..86fcae3 100644 --- a/client/app/src/main/resources/main/option-view.fxml +++ b/client/app/src/main/resources/main/option-view.fxml @@ -14,7 +14,7 @@ - + @@ -27,28 +27,35 @@ + + - - + + + - User bearbeiten - User löschen - User anlegen + User bearbeiten + User löschen + User anlegen - - + + -
From f1f07a35151c7c31a7a3e99326fe0e50056a77f5 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Tue, 25 Jan 2022 19:18:38 +0100 Subject: [PATCH 26/43] Fixed main class --- client/app/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/app/build.gradle.kts b/client/app/build.gradle.kts index 9661289..d75d3b4 100644 --- a/client/app/build.gradle.kts +++ b/client/app/build.gradle.kts @@ -13,7 +13,7 @@ javafx { } application { - mainClassName = "client.MainApplication" + mainClassName = "main.MainApplication" } repositories { @@ -27,7 +27,7 @@ dependencies { val jar by tasks.getting(Jar::class) { manifest { - attributes["Main-Class"] = "client.Launcher" + attributes["Main-Class"] = "main.Launcher" } from({ configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) } From f0e431bf6c2f6669d411bccbfd439e83e2f7a273 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Tue, 25 Jan 2022 19:19:18 +0100 Subject: [PATCH 27/43] Refactored send get-request --- .../data/src/main/java/res/HttpRequest.java | 91 +++++++------------ 1 file changed, 34 insertions(+), 57 deletions(-) diff --git a/client/data/src/main/java/res/HttpRequest.java b/client/data/src/main/java/res/HttpRequest.java index 311fad4..c1cb4ad 100644 --- a/client/data/src/main/java/res/HttpRequest.java +++ b/client/data/src/main/java/res/HttpRequest.java @@ -4,6 +4,7 @@ import helper.Tuple; import java.io.BufferedReader; import java.io.DataOutputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -17,48 +18,52 @@ public class HttpRequest { byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); int postDataLength = postData.length; - /* - URL url = new URL("http://test.de:8080/event/add"); - HttpURLConnection http = (HttpURLConnection)url.openConnection(); - http.setRequestMethod("POST"); - http.setDoOutput(true); - http.setRequestProperty("Accept", "application/json"); - http.setRequestProperty("Authorization", "Bearer {token}"); - http.setRequestProperty("Content-Type", ""); - http.setRequestProperty("Content-Length", "0"); - - System.out.println(http.getResponseCode() + " " + http.getResponseMessage()); - http.disconnect(); - */ URL url = new URL(urlString); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - con.setDoOutput(true); - con.setInstanceFollowRedirects(false); - con.setRequestMethod("POST"); - con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - con.setRequestProperty("charset", "utf-8"); - con.setRequestProperty("Content-Length", Integer.toString(postDataLength)); - con.setUseCaches(false); + connection.setDoOutput(true); + connection.setInstanceFollowRedirects(false); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("charset", "utf-8"); + connection.setRequestProperty("Content-Length", Integer.toString(postDataLength)); + connection.setUseCaches(false); if(sendAuth){ - con.setRequestProperty("Accept", "application/json"); - con.setRequestProperty("Authorization", "Bearer " + TOKEN); + connection.setRequestProperty("Accept", "application/json"); + connection.setRequestProperty("Authorization", "Bearer " + TOKEN); } - try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) { - wr.write(postData); + try (DataOutputStream writer = new DataOutputStream(connection.getOutputStream())) { + writer.write(postData); } - int status = con.getResponseCode(); + return getHttpTuple(connection); + } + + public Tuple sendGetRequest(String urlString) throws Exception { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + + int status = connection.getResponseCode(); + + return getHttpTuple(connection); + } + + private Tuple getHttpTuple(HttpURLConnection connection) throws IOException { + int status = connection.getResponseCode(); String inputLine; StringBuilder content = new StringBuilder(); BufferedReader in; if (status == 200) { - in = new BufferedReader(new InputStreamReader(con.getInputStream())); + in = new BufferedReader(new InputStreamReader(connection.getInputStream())); } else { - in = new BufferedReader(new InputStreamReader(con.getErrorStream())); + in = new BufferedReader(new InputStreamReader(connection.getErrorStream())); } while ((inputLine = in.readLine()) != null) { @@ -66,36 +71,8 @@ public class HttpRequest { } in.close(); - con.disconnect(); + connection.disconnect(); return new Tuple<>(status, content.toString()); } - - public String sendGetRequest(String urlString) throws Exception { - URL url = new URL(urlString); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setRequestMethod("GET"); - - con.setConnectTimeout(5000); - con.setReadTimeout(5000); - - int status = con.getResponseCode(); - if (status == 200) { - BufferedReader in = new BufferedReader( - new InputStreamReader(con.getInputStream())); - String inputLine; - StringBuilder content = new StringBuilder(); - while ((inputLine = in.readLine()) != null) { - content.append(inputLine); - } - in.close(); - - con.disconnect(); - return content.toString(); - - } else { - con.disconnect(); - throw new Exception("Status: " + status); - } - } } From 5e9a09fc7d3f38c1a7bc1f780ead49c123d06a4d Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Tue, 25 Jan 2022 19:20:06 +0100 Subject: [PATCH 28/43] print msg when config.json is missing --- client/data/src/main/java/config/ConfigLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/data/src/main/java/config/ConfigLoader.java b/client/data/src/main/java/config/ConfigLoader.java index 56e195e..a062d5a 100644 --- a/client/data/src/main/java/config/ConfigLoader.java +++ b/client/data/src/main/java/config/ConfigLoader.java @@ -17,7 +17,7 @@ public class ConfigLoader { objectMapper.findAndRegisterModules(); return objectMapper.readValue(jsonString, Config.class); } catch (IOException e) { - e.printStackTrace(); + System.out.println("config.json missing"); } return null; } From c4e24549d5af406ad2aada0dd0ce54667cb9a357 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Tue, 25 Jan 2022 19:37:49 +0100 Subject: [PATCH 29/43] Use edit-event-endpoint to edit events --- .../main/java/main/EditEventController.java | 6 +- .../src/main/java/res/DataController.java | 33 +++++++++- client/data/src/main/java/res/Event.java | 63 +------------------ 3 files changed, 34 insertions(+), 68 deletions(-) diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index 58d1ea6..ad81707 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -30,13 +30,9 @@ public class EditEventController extends CreateEventController{ //timeEnd.setValue(currentEvent.getEnd()); } - - - @Override protected void sendHttpRequest(Event event) throws HttpRequestException { DataController dataController = new DataController(); - dataController.deleteEvent(currentEvent.getOwnerId(), currentEvent.getId(), currentEvent.getDate()); - dataController.createEvent(event); + dataController.editEvent(currentEvent, event); } } diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index f920bac..90640d3 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -23,10 +23,15 @@ public class DataController { private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/event/all"; private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/event/add"; private static final String DELETE_EVENT_ENDPOINT = "http://localhost:8080/event/del"; + private static final String EDIT_EVENT_ENDPOINT = "http://localhost:8080/event/edit"; + + private static final String ALL_USER_ENDPOINT = "http://localhost:8080/user/all"; + private static final String ADD_USER_ENDPOINT = "http://localhost:8080/user/add"; + private static final String DELETE_USER_ENDPOINT = "http://localhost:8080/user/del"; + private static final String EDIT_USER_ENDPOINT = "http://localhost:8080/user/edit"; private static final String LOGIN_ENDPOINT = "http://localhost:8080/user/login"; private static final String LOGIN_WITH_TOKEN_ENDPOINT = "http://localhost:8080/user/login-with-token"; - private static final String ALL_USERS_ENDPOINT = "http://localhost:8080/user/all"; private static final String HEADER_TEST_ENDPOINT = "http://localhost:8080/vpr/header-test"; private final HttpRequest httpRequest; @@ -114,6 +119,32 @@ public class DataController { } } + public void editEvent(Event oldEvent, Event event) throws HttpRequestException { + try { + Tuple response = httpRequest.sendPostRequest( + EDIT_EVENT_ENDPOINT, + "eventId=" + oldEvent.getId() + + "&userId=" + oldEvent.getOwnerId() + + "&date=" + oldEvent.getDate().toLocalDate() + + "&newDate=" + event.getDate().toLocalDate() + + "&newName=" + event.getName() + + "&newStart=" + event.getStart() + + "&newEnd=" + event.getEnd() + + "&newPriority=" + event.getPriority() + + "&newIsFullDay=" + event.isFullDay() + + "&newIsPrivate=" + event.isPrivate(), + true + ); + if(response.getKey() != 200){ + throw new HttpRequestException(response); + } + }catch (HttpRequestException e){ + throw e; + }catch (Exception e) { + throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); + } + } + public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException { ArrayList eventList = new ArrayList<>(); try { diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index efabe57..179f622 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -30,68 +30,7 @@ public class Event { private int ownerId; private String ownerName; - /* - Constructor for SELECT: - e.id AS eid, - e.name AS ename, - e.start, - e.end, - e.priority, - e.is_full_day, - - ue.date, - - u.id AS uid, - u.forename, - u.name AS uname - */ - - public 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"); - - - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); - date = LocalDateTime.parse(arr.get(6) + " 00:00", formatter); - - ownerId = (int) arr.get(7); - ownerName = arr.get(8) + " " + arr.get(9); - } - - public Event( - int id, - String name, - int priority, - boolean isFullDay, - boolean isPrivate, - String start, - String end, - String date, - int ownerId, - String ownerName - ) { - this.ownerId = ownerId; - this.ownerName = ownerName; - this.id = id; - this.name = name; - this.start = start; - this.end = end; - this.priority = priority; - this.isFullDay = isFullDay; - - - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); - this.date = LocalDateTime.parse(date + " 00:00", formatter); - - } + public Event() {} public Event(String name, int priority, From 2147ca1ad86cc022825092ca01cc78622e36cbc9 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Tue, 25 Jan 2022 20:01:22 +0100 Subject: [PATCH 30/43] Added user methods --- .../src/main/java/res/DataController.java | 138 ++++++++++-------- 1 file changed, 78 insertions(+), 60 deletions(-) diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 90640d3..b42152a 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -52,13 +52,6 @@ public class DataController { USER_ID = Long.parseLong(data[1]); HttpRequest.TOKEN = data[0]; - - Tuple auth = httpRequest.sendPostRequest( - HEADER_TEST_ENDPOINT, - "", - true - ); - System.out.println("auth " + auth); } catch (Exception e) { e.printStackTrace(); return false; @@ -78,7 +71,7 @@ public class DataController { System.out.println(response.getKey() + " " + response.getValue()); - if(response.getKey() != 200) return false; + if (response.getKey() != 200) return false; } catch (Exception e) { e.printStackTrace(); return false; @@ -88,61 +81,40 @@ public class DataController { return USER_ID >= 0; } + /********* + * Event * + *********/ public void createEvent(Event event) throws HttpRequestException { - try { - Tuple response = httpRequest.sendPostRequest(ADD_EVENT_ENDPOINT, event.getAsUrlParam(), true); - if(response.getKey() != 200){ - throw new HttpRequestException(response); - } - }catch (HttpRequestException e){ - throw e; - }catch (Exception e) { - throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); - } + sendBasicHttpRequest( + ADD_EVENT_ENDPOINT, + event.getAsUrlParam(), + true + ); } public void deleteEvent(int userId, int eventId, LocalDateTime date) throws HttpRequestException { - try { - System.out.println("DELETE: userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate()); - Tuple response = httpRequest.sendPostRequest( - DELETE_EVENT_ENDPOINT, - "userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(), - true - ); - if(response.getKey() != 200){ - throw new HttpRequestException(response); - } - }catch (HttpRequestException e){ - throw e; - }catch (Exception e) { - throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); - } + sendBasicHttpRequest( + DELETE_EVENT_ENDPOINT, + "userId=" + userId + "&eventId=" + eventId + "&date=" + date.toLocalDate(), + true + ); } public void editEvent(Event oldEvent, Event event) throws HttpRequestException { - try { - Tuple response = httpRequest.sendPostRequest( - EDIT_EVENT_ENDPOINT, - "eventId=" + oldEvent.getId() + - "&userId=" + oldEvent.getOwnerId() + - "&date=" + oldEvent.getDate().toLocalDate() + - "&newDate=" + event.getDate().toLocalDate() + - "&newName=" + event.getName() + - "&newStart=" + event.getStart() + - "&newEnd=" + event.getEnd() + - "&newPriority=" + event.getPriority() + - "&newIsFullDay=" + event.isFullDay() + - "&newIsPrivate=" + event.isPrivate(), - true - ); - if(response.getKey() != 200){ - throw new HttpRequestException(response); - } - }catch (HttpRequestException e){ - throw e; - }catch (Exception e) { - throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); - } + sendBasicHttpRequest( + EDIT_EVENT_ENDPOINT, + "eventId=" + oldEvent.getId() + + "&userId=" + oldEvent.getOwnerId() + + "&date=" + oldEvent.getDate().toLocalDate() + + "&newDate=" + event.getDate().toLocalDate() + + "&newName=" + event.getName() + + "&newStart=" + event.getStart() + + "&newEnd=" + event.getEnd() + + "&newPriority=" + event.getPriority() + + "&newIsFullDay=" + event.isFullDay() + + "&newIsPrivate=" + event.isPrivate(), + true + ); } public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException { @@ -153,7 +125,7 @@ public class DataController { "userId=" + USER_ID + "&startDate=" + startDate.toLocalDate() + "&endDate=" + endDate.toLocalDate(), true ); - if(response.getKey() != 200){ + if (response.getKey() != 200) { throw new HttpRequestException(response); } String jsonResponse = response.getValue(); @@ -161,17 +133,63 @@ public class DataController { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); - eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>(){}); + eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>() { + }); - }catch (HttpRequestException e){ + } catch (HttpRequestException e) { throw e; - }catch (Exception e) { + } catch (Exception e) { throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); } return eventList; } + /******** + * User * + ********/ + /* + public void createUser(User user) throws HttpRequestException { + sendBasicHttpRequest( + ADD_USER_ENDPOINT, + user.getAsUrlParam(), + true + ); + } + + public void deleteUser(User user) throws HttpRequestException { + sendBasicHttpRequest( + DELETE_USER_ENDPOINT, + user.getAsUrlParam(), + true + ); + } + + public void editUser(User oldUser, User user) throws HttpRequestException { + sendBasicHttpRequest( + EDIT_USER_ENDPOINT, + user.getAsUrlParam(), + true + ); + } + */ + + private void sendBasicHttpRequest(String urlString, String urlParameters, boolean sendAuth) throws HttpRequestException { + try { + Tuple response = httpRequest.sendPostRequest( + urlString, + urlParameters, + sendAuth + ); + if (response.getKey() != 200) { + throw new HttpRequestException(response); + } + } catch (HttpRequestException e) { + throw e; + } catch (Exception e) { + throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); + } + } } \ No newline at end of file From cb5982ef2d5fbbf85636f3e28d752f79c928b091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Wed, 26 Jan 2022 13:18:05 +0100 Subject: [PATCH 31/43] Added user class --- .../src/main/java/main/OptionController.java | 6 +++ .../src/main/resources/main/option-view.fxml | 7 +-- .../src/main/java/res/DataController.java | 8 ++++ client/data/src/main/java/res/User.java | 44 +++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 client/data/src/main/java/res/User.java diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index 8ca0b93..5b1f7d3 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -2,6 +2,7 @@ package main; import com.jfoenix.controls.*; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -29,6 +30,11 @@ public class OptionController { @FXML public JFXComboBox userCmb; + @FXML + public void initialize(){ + + } + public void onBackBtnClick(ActionEvent actionEvent) { Stage stage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stage.close(); diff --git a/client/app/src/main/resources/main/option-view.fxml b/client/app/src/main/resources/main/option-view.fxml index 86fcae3..7e3edef 100644 --- a/client/app/src/main/resources/main/option-view.fxml +++ b/client/app/src/main/resources/main/option-view.fxml @@ -3,9 +3,8 @@ - - + - - - + diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index f920bac..5e8777e 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -142,5 +142,13 @@ public class DataController { return eventList; } + public List getAllUseres(){ + List users = new ArrayList<>(); + + + + return users; + } + } \ No newline at end of file diff --git a/client/data/src/main/java/res/User.java b/client/data/src/main/java/res/User.java new file mode 100644 index 0000000..5ff062d --- /dev/null +++ b/client/data/src/main/java/res/User.java @@ -0,0 +1,44 @@ +package res; + +public class User { + + private int id; + private String loginName; + private String forename; + private String name; + + public User(){ + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getLoginName() { + return loginName; + } + + public void setLoginName(String loginName) { + this.loginName = loginName; + } + + public String getForename() { + return forename; + } + + public void setForename(String forename) { + this.forename = forename; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} From f133257194cc7626ac8a9a04035146c3d454c3dd Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Wed, 26 Jan 2022 13:55:12 +0100 Subject: [PATCH 32/43] Map user with JSON --- .../src/main/java/res/DataController.java | 36 ++++++++++++------- client/data/src/main/java/res/User.java | 34 +++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index b42152a..99a75eb 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -118,7 +118,6 @@ public class DataController { } public ArrayList getAllVisibleEvents(LocalDateTime startDate, LocalDateTime endDate) throws HttpRequestException { - ArrayList eventList = new ArrayList<>(); try { Tuple response = httpRequest.sendPostRequest( ALL_EVENTS_ENDPOINT, @@ -133,28 +132,40 @@ public class DataController { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); - eventList = (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>() { - }); - + return (ArrayList) objectMapper.readValue(jsonResponse, new TypeReference>() {}); } catch (HttpRequestException e) { throw e; } catch (Exception e) { throw new HttpRequestException("Es konnte keine Verbindung mit dem Server hergestellt werden.", 600); } - - return eventList; } /******** * User * ********/ - /* + public List getUser() throws HttpRequestException { + String userJSON = sendBasicHttpRequest( + ALL_USER_ENDPOINT, + "", + true + ); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + try { + return objectMapper.readValue(userJSON, new TypeReference>() {}); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return new ArrayList<>(); + } + public void createUser(User user) throws HttpRequestException { sendBasicHttpRequest( ADD_USER_ENDPOINT, - user.getAsUrlParam(), + "", true ); } @@ -162,7 +173,7 @@ public class DataController { public void deleteUser(User user) throws HttpRequestException { sendBasicHttpRequest( DELETE_USER_ENDPOINT, - user.getAsUrlParam(), + "userId=" + user.getUserId(), true ); } @@ -170,13 +181,12 @@ public class DataController { public void editUser(User oldUser, User user) throws HttpRequestException { sendBasicHttpRequest( EDIT_USER_ENDPOINT, - user.getAsUrlParam(), + "", true ); } - */ - private void sendBasicHttpRequest(String urlString, String urlParameters, boolean sendAuth) throws HttpRequestException { + private String sendBasicHttpRequest(String urlString, String urlParameters, boolean sendAuth) throws HttpRequestException { try { Tuple response = httpRequest.sendPostRequest( urlString, @@ -186,6 +196,8 @@ public class DataController { if (response.getKey() != 200) { throw new HttpRequestException(response); } + + return response.getValue(); } catch (HttpRequestException e) { throw e; } catch (Exception e) { diff --git a/client/data/src/main/java/res/User.java b/client/data/src/main/java/res/User.java index 5ff062d..c917e7e 100644 --- a/client/data/src/main/java/res/User.java +++ b/client/data/src/main/java/res/User.java @@ -2,28 +2,28 @@ package res; public class User { - private int id; - private String loginName; + private int userId; + private String login; private String forename; private String name; + private boolean isAdmin; - public User(){ + public User(){} + + public int getUserId() { + return userId; } - public int getId() { - return id; + public void setUserId(int userId) { + this.userId = userId; } - public void setId(int id) { - this.id = id; + public String getLogin() { + return login; } - public String getLoginName() { - return loginName; - } - - public void setLoginName(String loginName) { - this.loginName = loginName; + public void setLogin(String login) { + this.login = login; } public String getForename() { @@ -41,4 +41,12 @@ public class User { public void setName(String name) { this.name = name; } + + public boolean isAdmin() { + return isAdmin; + } + + public void setAdmin(boolean admin) { + isAdmin = admin; + } } From 596343fe47738f5db1ce9733ff9ef34daf3fc460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Wed, 26 Jan 2022 14:27:16 +0100 Subject: [PATCH 33/43] Removed unused imports --- client/app/src/main/java/main/EditEventController.java | 7 ------- client/app/src/main/java/main/OptionController.java | 2 -- client/data/src/main/java/config/ConfigLoader.java | 1 - client/data/src/main/java/res/DataController.java | 7 ------- 4 files changed, 17 deletions(-) diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index ad81707..b562fb5 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -2,16 +2,9 @@ package main; import customUI.Converter; import helper.HttpRequestException; -import javafx.fxml.FXML; -import javafx.util.StringConverter; -import javafx.util.converter.LocalTimeStringConverter; import res.DataController; import res.Event; -import java.time.LocalTime; -import java.time.format.FormatStyle; -import java.util.Locale; - public class EditEventController extends CreateEventController{ private Event currentEvent; diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index 5b1f7d3..8601856 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -1,8 +1,6 @@ package main; import com.jfoenix.controls.*; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; diff --git a/client/data/src/main/java/config/ConfigLoader.java b/client/data/src/main/java/config/ConfigLoader.java index a062d5a..109e97d 100644 --- a/client/data/src/main/java/config/ConfigLoader.java +++ b/client/data/src/main/java/config/ConfigLoader.java @@ -1,7 +1,6 @@ package config; import com.fasterxml.jackson.databind.ObjectMapper; -import res.DataController; import java.io.IOException; import java.nio.file.Files; diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 99a75eb..84d4076 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -6,13 +6,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import helper.HttpRequestException; import helper.Tuple; -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.*; From 91daf95990bbbbccf3db75ff97be8e5411ccf1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Wed, 26 Jan 2022 15:04:32 +0100 Subject: [PATCH 34/43] Tried adding comboBox content --- .../src/main/java/main/OptionController.java | 25 +++++++++++++++++++ .../src/main/resources/main/option-view.fxml | 11 ++------ .../src/main/java/res/DataController.java | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index 8601856..9059203 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -1,16 +1,24 @@ package main; import com.jfoenix.controls.*; +import helper.HttpRequestException; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Label; +import javafx.scene.layout.GridPane; import javafx.stage.Modality; import javafx.stage.Stage; +import res.DataController; +import res.User; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class OptionController { @@ -27,9 +35,26 @@ public class OptionController { public Label labelError; @FXML public JFXComboBox userCmb; + @FXML + public GridPane mainGrid; @FXML public void initialize(){ + DataController dataController = new DataController(); + List users; + try{ + users = dataController.getAllUser(); + } catch (HttpRequestException e){ + users = new ArrayList<>(); + } + + ObservableList observableUserList = FXCollections.observableArrayList(); + for (User user: users) { + observableUserList.add(user.getLogin()); + } + JFXComboBox comboBox = new JFXComboBox(observableUserList); + comboBox.getStyleClass().add("comboBox"); + mainGrid.add(comboBox, 2,2); } diff --git a/client/app/src/main/resources/main/option-view.fxml b/client/app/src/main/resources/main/option-view.fxml index 7e3edef..e54f1fc 100644 --- a/client/app/src/main/resources/main/option-view.fxml +++ b/client/app/src/main/resources/main/option-view.fxml @@ -3,12 +3,12 @@ - + prefHeight="400.0" prefWidth="600.0" +fx:id="mainGrid"> @@ -33,13 +33,6 @@ - - - - - - - User bearbeiten diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 84d4076..181227e 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -138,7 +138,7 @@ public class DataController { * User * ********/ - public List getUser() throws HttpRequestException { + public List getAllUser() throws HttpRequestException { String userJSON = sendBasicHttpRequest( ALL_USER_ENDPOINT, "", From a4ce8940abe8f9174a09ff381a63deebe9254b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=BChn?= Date: Wed, 26 Jan 2022 15:08:44 +0100 Subject: [PATCH 35/43] Fixed raw use of parameterized class 'JFXComboBox' --- client/app/src/main/java/main/OptionController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index 9059203..11fae92 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -34,8 +34,6 @@ public class OptionController { @FXML public Label labelError; @FXML - public JFXComboBox userCmb; - @FXML public GridPane mainGrid; @FXML @@ -52,7 +50,7 @@ public class OptionController { for (User user: users) { observableUserList.add(user.getLogin()); } - JFXComboBox comboBox = new JFXComboBox(observableUserList); + JFXComboBox comboBox = new JFXComboBox<>(observableUserList); comboBox.getStyleClass().add("comboBox"); mainGrid.add(comboBox, 2,2); From 2f70515407421bedcbed2ebac5eaad9bd2e71eeb Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Fri, 28 Jan 2022 05:53:53 +0100 Subject: [PATCH 36/43] Format --- client/app/src/main/java/main/CreateEventController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index e36cd4a..999bd19 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -44,7 +44,6 @@ public class CreateEventController { @FXML public void initialize() { - StringConverter defaultConverter = new LocalTimeStringConverter(FormatStyle.SHORT, Locale.GERMANY); timeStart.set24HourView(true); timeStart.setConverter(defaultConverter); From 4e07b01b6ad7e8ce63f0586951bb0dcec0b76c74 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Fri, 28 Jan 2022 05:54:26 +0100 Subject: [PATCH 37/43] Get all user --- client/data/src/main/java/res/DataController.java | 8 ++++++-- client/data/src/main/java/res/User.java | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 181227e..2a4fb2f 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -148,7 +148,7 @@ public class DataController { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); try { - return objectMapper.readValue(userJSON, new TypeReference>() {}); + return (List)objectMapper.readValue(userJSON, new TypeReference>() {}); } catch (JsonProcessingException e) { e.printStackTrace(); } @@ -158,7 +158,11 @@ public class DataController { public void createUser(User user) throws HttpRequestException { sendBasicHttpRequest( ADD_USER_ENDPOINT, - "", + "name=" + user.getName() + + "&forename=" + user.getForename() + + "&login=" + user.getLogin() + + "&password=" + user.getPassword() + + "&isAdmin=" + user.isAdmin(), true ); } diff --git a/client/data/src/main/java/res/User.java b/client/data/src/main/java/res/User.java index c917e7e..d58461b 100644 --- a/client/data/src/main/java/res/User.java +++ b/client/data/src/main/java/res/User.java @@ -6,6 +6,7 @@ public class User { private String login; private String forename; private String name; + private String password; private boolean isAdmin; public User(){} @@ -49,4 +50,12 @@ public class User { public void setAdmin(boolean admin) { isAdmin = admin; } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } } From 780ecbee0fdbb603f4c5091248334a8cccc3d8e3 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sat, 29 Jan 2022 10:06:28 +0100 Subject: [PATCH 38/43] Changed encoding to utf-8 --- client/app/build.gradle.kts | 6 +- client/app/src/main/java/customUI/Button.java | 8 --- .../app/src/main/java/customUI/Converter.java | 21 ------- client/app/src/main/java/customUI/Label.java | 15 ----- .../app/src/main/java/customUI/Tooltip.java | 9 --- .../src/main/java/helper/SvgBtnCreator.java | 4 +- .../main/java/main/EditEventController.java | 3 +- .../src/main/java/main/MainController.java | 10 ++-- .../src/main/java/main/OptionController.java | 51 ++++++++++++----- .../main/java/users/EditUserController.java | 19 +++++++ .../src/main/resources/users/create-user.fxml | 5 +- .../src/main/resources/users/edit-user.fxml | 57 +++++++++++++++++++ client/data/build.gradle.kts | 4 ++ client/data/src/main/java/res/Event.java | 18 ++---- 14 files changed, 135 insertions(+), 95 deletions(-) delete mode 100644 client/app/src/main/java/customUI/Button.java delete mode 100644 client/app/src/main/java/customUI/Converter.java delete mode 100644 client/app/src/main/java/customUI/Label.java delete mode 100644 client/app/src/main/java/customUI/Tooltip.java create mode 100644 client/app/src/main/java/users/EditUserController.java create mode 100644 client/app/src/main/resources/users/edit-user.fxml diff --git a/client/app/build.gradle.kts b/client/app/build.gradle.kts index d75d3b4..3a8a5d6 100644 --- a/client/app/build.gradle.kts +++ b/client/app/build.gradle.kts @@ -5,13 +5,17 @@ plugins { } javafx { - version = "11" + version = "11.0.2" modules( "javafx.controls", "javafx.fxml" ) } +tasks.withType { + options.encoding = "UTF-8" +} + application { mainClassName = "main.MainApplication" } diff --git a/client/app/src/main/java/customUI/Button.java b/client/app/src/main/java/customUI/Button.java deleted file mode 100644 index 61df976..0000000 --- a/client/app/src/main/java/customUI/Button.java +++ /dev/null @@ -1,8 +0,0 @@ -package customUI; - -public class Button extends javafx.scene.control.Button { - - public void setTextValue(String text){ - super.setText(Converter.convertString(text)); - } -} diff --git a/client/app/src/main/java/customUI/Converter.java b/client/app/src/main/java/customUI/Converter.java deleted file mode 100644 index dc737af..0000000 --- a/client/app/src/main/java/customUI/Converter.java +++ /dev/null @@ -1,21 +0,0 @@ -package customUI; - -public class Converter { - /* - Ä, ä \u00c4, \u00e4 - Ö, ö \u00d6, \u00f6 - Ü, ü \u00dc, \u00fc - ß \u00df - */ - @SuppressWarnings("all") - public static String convertString(String str){ - return str - .replace("ä", "\u00e4") - .replace("Ä", "\u00c4") - .replace("ö", "\u00f6") - .replace("Ö", "\u00d6") - .replace("ü", "\u00fc") - .replace("Ü", "\u00dc") - .replace("ß", "\u00df"); - } -} diff --git a/client/app/src/main/java/customUI/Label.java b/client/app/src/main/java/customUI/Label.java deleted file mode 100644 index ad5321e..0000000 --- a/client/app/src/main/java/customUI/Label.java +++ /dev/null @@ -1,15 +0,0 @@ -package customUI; - -public class Label extends javafx.scene.control.Label { - public Label(String content){ - super(Converter.convertString(content)); - } - - public Label(){ - super(); - } - - public void setTextValue(String text){ - super.setText(Converter.convertString(text)); - } -} diff --git a/client/app/src/main/java/customUI/Tooltip.java b/client/app/src/main/java/customUI/Tooltip.java deleted file mode 100644 index 2a5324a..0000000 --- a/client/app/src/main/java/customUI/Tooltip.java +++ /dev/null @@ -1,9 +0,0 @@ -package customUI; - -public class Tooltip extends javafx.scene.control.Tooltip { - - public Tooltip(String tollTipText){ - super(Converter.convertString(tollTipText)); - } - -} diff --git a/client/app/src/main/java/helper/SvgBtnCreator.java b/client/app/src/main/java/helper/SvgBtnCreator.java index c9546fe..2dbf4cd 100644 --- a/client/app/src/main/java/helper/SvgBtnCreator.java +++ b/client/app/src/main/java/helper/SvgBtnCreator.java @@ -2,9 +2,7 @@ package helper; import javafx.geometry.Bounds; import javafx.scene.Group; -import customUI.Button; -import javafx.scene.control.ContentDisplay; -import customUI.Tooltip; +import javafx.scene.control.*; import javafx.scene.shape.SVGPath; public class SvgBtnCreator { diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index b562fb5..a6f811f 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -1,6 +1,5 @@ package main; -import customUI.Converter; import helper.HttpRequestException; import res.DataController; import res.Event; @@ -16,7 +15,7 @@ public class EditEventController extends CreateEventController{ public void setCurrentEvent(Event currentEvent) { this.currentEvent = currentEvent; - textName.setText(Converter.convertString(currentEvent.getName())); + textName.setText(currentEvent.getName()); datePickerDate.setValue(currentEvent.getDate().toLocalDate()); ComboBoxPriotity.getSelectionModel().select(currentEvent.getPriority()); diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 0a5ae54..02b80e3 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -2,8 +2,6 @@ package main; import config.Config; import config.ConfigLoader; -import customUI.Button; -import customUI.Label; import helper.SvgBtnCreator; import helper.HttpRequestException; import javafx.fxml.FXML; @@ -12,7 +10,7 @@ import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; -import javafx.scene.control.ScrollPane; +import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -154,7 +152,7 @@ public class MainController { private void createWeek() { for (int i = 0; i < 7; i++) { Label label = new Label(); - label.setTextValue(dayNames[i]); + label.setText(dayNames[i]); label.setMaxHeight(Double.MAX_VALUE); label.setMaxWidth(Double.MAX_VALUE); label.getStyleClass().add("labelDays"); @@ -248,7 +246,7 @@ public class MainController { Label typeLabel = new Label("Wer: " + event.getOwnerName()); vBox.getChildren().add(typeLabel); - Label prioLabel = new Label("Priorit\u00e4t: " + event.getPriority()); + Label prioLabel = new Label("Priorität: " + event.getPriority()); vBox.getChildren().add(prioLabel); if (event.isFullDay()) { @@ -286,7 +284,7 @@ public class MainController { weekStartDateTime = now.plusDays(weekOffset * 7L - dayOfWeek + 1); for (int i = 0; i < 7; i++) { - dayLabel[i].setTextValue(dayFormatter.format(weekStartDateTime.plusDays(i))); + dayLabel[i].setText(dayFormatter.format(weekStartDateTime.plusDays(i))); } LabelMonth.setText(dateFormatter.format(weekStartDateTime)); diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index 11fae92..aefd27a 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -9,6 +9,8 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Modality; @@ -20,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; public class OptionController { @@ -36,10 +39,13 @@ public class OptionController { @FXML public GridPane mainGrid; + private JFXComboBox comboBox; + private DataController dataController; + private List users; + @FXML public void initialize(){ - DataController dataController = new DataController(); - List users; + dataController = new DataController(); try{ users = dataController.getAllUser(); } catch (HttpRequestException e){ @@ -50,7 +56,7 @@ public class OptionController { for (User user: users) { observableUserList.add(user.getLogin()); } - JFXComboBox comboBox = new JFXComboBox<>(observableUserList); + comboBox = new JFXComboBox<>(observableUserList); comboBox.getStyleClass().add("comboBox"); mainGrid.add(comboBox, 2,2); @@ -62,14 +68,36 @@ public class OptionController { } public void onCreateBtnClick(ActionEvent actionEvent) { - try{ - FXMLLoader fxmlLoader = new FXMLLoader( - MainApplication.class.getResource("../users/create-user.fxml")); - Scene scene = new Scene(fxmlLoader.load(), 800, 650); + loadUserScene(actionEvent, "User erstellen", "../users/create-user.fxml"); + } + + public void onUpdateBtnClick(ActionEvent actionEvent) { + loadUserScene(actionEvent, "User bearbeiten", "../users/edit-user.fxml"); + } + + public void onDeleteBtnClick(ActionEvent actionEvent) { + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Wirklich löschen?"); + Optional result = alert.showAndWait(); + if(result.isPresent() && result.get() == ButtonType.OK){ + try { + dataController.deleteUser(users.get(comboBox.getSelectionModel().getSelectedIndex())); + } catch (HttpRequestException e) { + Alert alert1 = new Alert(Alert.AlertType.ERROR, e.getMessage()); + alert1.showAndWait(); + } + } + } + + private Scene loadUserScene(ActionEvent actionEvent, String title, String fxml) { + FXMLLoader fxmlLoader = new FXMLLoader( + MainApplication.class.getResource(fxml)); + Scene scene = null; + try { + scene = new Scene(fxmlLoader.load(), 800, 650); scene.getStylesheets().add(Objects.requireNonNull( MainApplication.class.getResource("../users/create-user.css")).toExternalForm()); Stage stage = new Stage(); - stage.setTitle("User erstellen"); + stage.setTitle(title); stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); @@ -79,11 +107,6 @@ public class OptionController { } catch (IOException e) { e.printStackTrace(); } - } - - public void onUpdateBtnClick(ActionEvent actionEvent) { - } - - public void onDeleteBtnClick(ActionEvent actionEvent) { + return scene; } } diff --git a/client/app/src/main/java/users/EditUserController.java b/client/app/src/main/java/users/EditUserController.java new file mode 100644 index 0000000..e51ffbc --- /dev/null +++ b/client/app/src/main/java/users/EditUserController.java @@ -0,0 +1,19 @@ +package users; + +import res.User; + +public class EditUserController extends CreateUserController{ + private User currentUser; + + public User getCurrentUser() { + return currentUser; + } + + public void setCurrentUser(User currentUser) { + this.currentUser = currentUser; + + textForename.setText(currentUser.getForename()); + textName.setText(currentUser.getName()); + textLogin.setText(currentUser.getLogin()); + } +} diff --git a/client/app/src/main/resources/users/create-user.fxml b/client/app/src/main/resources/users/create-user.fxml index e542f73..c4741a9 100644 --- a/client/app/src/main/resources/users/create-user.fxml +++ b/client/app/src/main/resources/users/create-user.fxml @@ -3,6 +3,7 @@ + @@ -40,7 +41,7 @@ - + diff --git a/client/app/src/main/resources/users/edit-user.fxml b/client/app/src/main/resources/users/edit-user.fxml new file mode 100644 index 0000000..3f89f8b --- /dev/null +++ b/client/app/src/main/resources/users/edit-user.fxml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/data/build.gradle.kts b/client/data/build.gradle.kts index 147ec02..790eeb5 100644 --- a/client/data/build.gradle.kts +++ b/client/data/build.gradle.kts @@ -2,6 +2,10 @@ plugins { java } +tasks.withType { + options.encoding = "UTF-8" +} + dependencies { val jacksonVersion = "2.13.0" implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index 179f622..0520e06 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -1,19 +1,11 @@ package res; -import com.sun.jdi.event.StepEvent; - -import java.io.Serializable; -import java.nio.charset.StandardCharsets; -import java.sql.SQLOutput; import java.time.Duration; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; public class Event { @@ -44,15 +36,15 @@ public class Event { System.out.println("Create Event"); if (name.length() < 3) { - throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben."); + throw new IllegalArgumentException("Der Name muss eine Länge von 3 haben."); } - Pattern pattern = Pattern.compile("[A-Za-z\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-9 =!?+*/$.:,;_<>()-]*"); + Pattern pattern = Pattern.compile("[A-Za-zäöüÄÖÜß0-9 =!?+*/$.:,;_<>()-]*"); Matcher matcher = pattern.matcher(name); if (!matcher.matches()) { - throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$.:,;_ <>()-"); + throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: äöü ÄÖÜ ß =!?+*/$.:,;_ <>()-"); } if (priority < 0) { - throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen."); + throw new IllegalArgumentException("Bitte eine Priorität wählen."); } LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay(); if (Duration.between(today, date).isNegative()) { @@ -82,9 +74,7 @@ public class Event { } public void setName(String name) { - System.out.println(name); this.name = name; - System.out.println(this.name); } public int getPriority() { From 72fdce471b73717531cf3911205eec350c2ce747 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sat, 29 Jan 2022 11:44:25 +0100 Subject: [PATCH 39/43] Fixed encoding at http-request --- client/data/src/main/java/res/HttpRequest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/data/src/main/java/res/HttpRequest.java b/client/data/src/main/java/res/HttpRequest.java index c1cb4ad..7dba427 100644 --- a/client/data/src/main/java/res/HttpRequest.java +++ b/client/data/src/main/java/res/HttpRequest.java @@ -61,9 +61,9 @@ public class HttpRequest { BufferedReader in; if (status == 200) { - in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); } else { - in = new BufferedReader(new InputStreamReader(connection.getErrorStream())); + in = new BufferedReader(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8)); } while ((inputLine = in.readLine()) != null) { From 245314a887a04e9069fb972158376abfb4e1b0da Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sat, 29 Jan 2022 12:03:09 +0100 Subject: [PATCH 40/43] Renamed package; Implemented create user --- .../main/java/main/CreateEventController.java | 4 ++-- .../main/java/main/EditEventController.java | 4 ++-- .../src/main/java/main/MainApplication.java | 4 ++-- .../src/main/java/main/MainController.java | 6 ++--- .../src/main/java/main/OptionController.java | 10 +++++--- .../main/java/users/CreateUserController.java | 24 +++++++++++++++++++ .../main/java/users/EditUserController.java | 2 +- .../src/main/java/users/LoginController.java | 2 +- .../{res => container}/DataController.java | 4 ++-- .../main/java/{res => container}/Event.java | 2 +- .../java/{res => container}/HttpRequest.java | 3 +-- .../main/java/{res => container}/User.java | 4 +++- 12 files changed, 49 insertions(+), 20 deletions(-) rename client/data/src/main/java/{res => container}/DataController.java (98%) rename client/data/src/main/java/{res => container}/Event.java (99%) rename client/data/src/main/java/{res => container}/HttpRequest.java (98%) rename client/data/src/main/java/{res => container}/User.java (98%) diff --git a/client/app/src/main/java/main/CreateEventController.java b/client/app/src/main/java/main/CreateEventController.java index 999bd19..ed86f69 100644 --- a/client/app/src/main/java/main/CreateEventController.java +++ b/client/app/src/main/java/main/CreateEventController.java @@ -10,8 +10,8 @@ import javafx.scene.layout.GridPane; import javafx.stage.Stage; import javafx.util.StringConverter; import javafx.util.converter.LocalTimeStringConverter; -import res.DataController; -import res.Event; +import container.DataController; +import container.Event; import java.time.LocalTime; import java.time.format.FormatStyle; diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index a6f811f..cce82d9 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -1,8 +1,8 @@ package main; import helper.HttpRequestException; -import res.DataController; -import res.Event; +import container.DataController; +import container.Event; public class EditEventController extends CreateEventController{ diff --git a/client/app/src/main/java/main/MainApplication.java b/client/app/src/main/java/main/MainApplication.java index 09274f4..4e514f0 100644 --- a/client/app/src/main/java/main/MainApplication.java +++ b/client/app/src/main/java/main/MainApplication.java @@ -6,8 +6,8 @@ import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import res.DataController; -import res.HttpRequest; +import container.DataController; +import container.HttpRequest; import java.io.IOException; import java.util.Objects; diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 02b80e3..cca56f8 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -16,11 +16,11 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Modality; import javafx.stage.Stage; -import res.DataController; -import res.Event; +import container.DataController; +import container.Event; import javafx.event.ActionEvent; -import res.HttpRequest; +import container.HttpRequest; import java.io.IOException; import java.time.Duration; diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index aefd27a..bca3c9f 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -15,8 +15,8 @@ import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Modality; import javafx.stage.Stage; -import res.DataController; -import res.User; +import container.DataController; +import container.User; import java.io.IOException; import java.util.ArrayList; @@ -79,12 +79,16 @@ public class OptionController { Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Wirklich löschen?"); Optional result = alert.showAndWait(); if(result.isPresent() && result.get() == ButtonType.OK){ + int removeIndex = comboBox.getSelectionModel().getSelectedIndex(); try { - dataController.deleteUser(users.get(comboBox.getSelectionModel().getSelectedIndex())); + dataController.deleteUser(users.get(removeIndex)); } catch (HttpRequestException e) { Alert alert1 = new Alert(Alert.AlertType.ERROR, e.getMessage()); alert1.showAndWait(); + return; } + comboBox.getItems().remove(removeIndex); + users.remove(removeIndex); } } diff --git a/client/app/src/main/java/users/CreateUserController.java b/client/app/src/main/java/users/CreateUserController.java index 3f54a46..bfce642 100644 --- a/client/app/src/main/java/users/CreateUserController.java +++ b/client/app/src/main/java/users/CreateUserController.java @@ -1,5 +1,6 @@ package users; +import helper.HttpRequestException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; @@ -8,6 +9,8 @@ import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.control.ToggleButton; import javafx.stage.Stage; +import container.DataController; +import container.User; import java.util.Objects; @@ -39,15 +42,36 @@ public class CreateUserController { labelError.setText("Bitte Passwort eingeben!"); return; } + if (textPassword.getText().trim().length() < 8) { + labelError.setText("Das Passwort muss mindestens 8 Zeichen lang sein!"); + return; + } if (!Objects.equals(textPassword.getText(), textPasswordSecond.getText())){ labelError.setText("Passwörter stimmen nicht überein!"); return; } + User user = new User(); + user.setLogin(textLogin.getText().trim()); + user.setForename(textForename.getText().trim()); + user.setName(textName.getText().trim()); + user.setPassword(textPassword.getText().trim()); + + try { + sendHttpRequest(user); + } catch (HttpRequestException e) { + labelError.setText(e.getMessage()); + } + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); stage.close(); } + protected void sendHttpRequest(User user) throws HttpRequestException { + DataController dataController = new DataController(); + dataController.createUser(user); + } + @FXML protected void abortBtnClick(ActionEvent event) { Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); diff --git a/client/app/src/main/java/users/EditUserController.java b/client/app/src/main/java/users/EditUserController.java index e51ffbc..6063a59 100644 --- a/client/app/src/main/java/users/EditUserController.java +++ b/client/app/src/main/java/users/EditUserController.java @@ -1,6 +1,6 @@ package users; -import res.User; +import container.User; public class EditUserController extends CreateUserController{ private User currentUser; diff --git a/client/app/src/main/java/users/LoginController.java b/client/app/src/main/java/users/LoginController.java index 3bce950..37da4be 100644 --- a/client/app/src/main/java/users/LoginController.java +++ b/client/app/src/main/java/users/LoginController.java @@ -6,7 +6,7 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Label; import javafx.stage.Stage; -import res.DataController; +import container.DataController; public class LoginController { @FXML diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/container/DataController.java similarity index 98% rename from client/data/src/main/java/res/DataController.java rename to client/data/src/main/java/container/DataController.java index 2a4fb2f..52c2a95 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/container/DataController.java @@ -1,4 +1,4 @@ -package res; +package container; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -148,7 +148,7 @@ public class DataController { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); try { - return (List)objectMapper.readValue(userJSON, new TypeReference>() {}); + return objectMapper.readValue(userJSON, new TypeReference<>() {}); } catch (JsonProcessingException e) { e.printStackTrace(); } diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/container/Event.java similarity index 99% rename from client/data/src/main/java/res/Event.java rename to client/data/src/main/java/container/Event.java index 0520e06..35c1d35 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/container/Event.java @@ -1,4 +1,4 @@ -package res; +package container; import java.time.Duration; import java.time.LocalDateTime; diff --git a/client/data/src/main/java/res/HttpRequest.java b/client/data/src/main/java/container/HttpRequest.java similarity index 98% rename from client/data/src/main/java/res/HttpRequest.java rename to client/data/src/main/java/container/HttpRequest.java index 7dba427..8ddf2d2 100644 --- a/client/data/src/main/java/res/HttpRequest.java +++ b/client/data/src/main/java/container/HttpRequest.java @@ -1,4 +1,4 @@ -package res; +package container; import helper.Tuple; @@ -9,7 +9,6 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Arrays; public class HttpRequest { public static String TOKEN = ""; diff --git a/client/data/src/main/java/res/User.java b/client/data/src/main/java/container/User.java similarity index 98% rename from client/data/src/main/java/res/User.java rename to client/data/src/main/java/container/User.java index d58461b..c77b320 100644 --- a/client/data/src/main/java/res/User.java +++ b/client/data/src/main/java/container/User.java @@ -1,4 +1,4 @@ -package res; +package container; public class User { @@ -11,6 +11,8 @@ public class User { public User(){} + + public int getUserId() { return userId; } From db339eeada429c899ca66d5b016b69be2f2ae8ad Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sat, 29 Jan 2022 19:27:06 +0100 Subject: [PATCH 41/43] Refactor --- .../src/main/java/main/MainController.java | 2 + .../src/main/java/main/OptionController.java | 33 +++++++-- .../main/java/users/CreateUserController.java | 2 + .../main/java/users/EditUserController.java | 73 +++++++++++++++++++ .../src/main/resources/users/create-user.fxml | 2 +- .../src/main/resources/users/edit-user.fxml | 2 +- .../main/java/container/DataController.java | 23 +++++- client/data/src/main/java/container/User.java | 12 +++ 8 files changed, 137 insertions(+), 12 deletions(-) diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index cca56f8..c8dc029 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -234,6 +234,7 @@ public class MainController { vBox.getChildren().add(btnHBox); Label nameLabel = new Label(event.getName()); + nameLabel.setWrapText(true); vBox.getChildren().add(nameLabel); if (event.getStart() != null || event.getEnd() != null) { @@ -251,6 +252,7 @@ public class MainController { if (event.isFullDay()) { Label fullDayLabel = new Label("Dieser Termin bockiert den ganzen Tag!"); + fullDayLabel.setWrapText(true); vBox.getChildren().add(fullDayLabel); } diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index bca3c9f..2e82e48 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -17,12 +17,15 @@ import javafx.stage.Modality; import javafx.stage.Stage; import container.DataController; import container.User; +import users.EditUserController; +import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Consumer; public class OptionController { @@ -68,11 +71,20 @@ public class OptionController { } public void onCreateBtnClick(ActionEvent actionEvent) { - loadUserScene(actionEvent, "User erstellen", "../users/create-user.fxml"); + loadUserScene(actionEvent, "User erstellen", "../users/create-user.fxml", null); } public void onUpdateBtnClick(ActionEvent actionEvent) { - loadUserScene(actionEvent, "User bearbeiten", "../users/edit-user.fxml"); + int editIndex = comboBox.getSelectionModel().getSelectedIndex(); + + if(editIndex < 0 || editIndex >= users.size()) return; + + FXMLLoader fxmlLoader = loadUserScene( + actionEvent, + "User bearbeiten", + "../users/edit-user.fxml", + this::setUserAtController + ); } public void onDeleteBtnClick(ActionEvent actionEvent) { @@ -92,12 +104,11 @@ public class OptionController { } } - private Scene loadUserScene(ActionEvent actionEvent, String title, String fxml) { + private FXMLLoader loadUserScene(ActionEvent actionEvent, String title, String fxml, Consumer method) { FXMLLoader fxmlLoader = new FXMLLoader( MainApplication.class.getResource(fxml)); - Scene scene = null; try { - scene = new Scene(fxmlLoader.load(), 800, 650); + Scene scene = new Scene(fxmlLoader.load(), 800, 650); scene.getStylesheets().add(Objects.requireNonNull( MainApplication.class.getResource("../users/create-user.css")).toExternalForm()); Stage stage = new Stage(); @@ -105,12 +116,22 @@ public class OptionController { stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); + + if(method != null)method.accept(fxmlLoader); + stage.showAndWait(); Stage stageOld = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow(); stageOld.close(); } catch (IOException e) { e.printStackTrace(); + e.printStackTrace(); } - return scene; + return fxmlLoader; + } + + private void setUserAtController(FXMLLoader fxmlLoader){ + int editIndex = comboBox.getSelectionModel().getSelectedIndex(); + EditUserController editUserController = fxmlLoader.getController(); + editUserController.setCurrentUser(users.get(editIndex)); } } diff --git a/client/app/src/main/java/users/CreateUserController.java b/client/app/src/main/java/users/CreateUserController.java index bfce642..82f795d 100644 --- a/client/app/src/main/java/users/CreateUserController.java +++ b/client/app/src/main/java/users/CreateUserController.java @@ -56,11 +56,13 @@ public class CreateUserController { user.setForename(textForename.getText().trim()); user.setName(textName.getText().trim()); user.setPassword(textPassword.getText().trim()); + user.setAdmin(checkButtonIsAdmin.isSelected()); try { sendHttpRequest(user); } catch (HttpRequestException e) { labelError.setText(e.getMessage()); + return; } Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); diff --git a/client/app/src/main/java/users/EditUserController.java b/client/app/src/main/java/users/EditUserController.java index 6063a59..fa021e4 100644 --- a/client/app/src/main/java/users/EditUserController.java +++ b/client/app/src/main/java/users/EditUserController.java @@ -1,6 +1,14 @@ package users; +import container.DataController; import container.User; +import helper.HttpRequestException; +import javafx.event.ActionEvent; +import javafx.scene.Node; +import javafx.scene.control.Alert; +import javafx.stage.Stage; + +import java.util.Objects; public class EditUserController extends CreateUserController{ private User currentUser; @@ -15,5 +23,70 @@ public class EditUserController extends CreateUserController{ textForename.setText(currentUser.getForename()); textName.setText(currentUser.getName()); textLogin.setText(currentUser.getLogin()); + checkButtonIsAdmin.setSelected(currentUser.isAdmin()); + } + + @Override + protected void createUser(ActionEvent event){ + if (textLogin.getText().trim().isEmpty()){ + labelError.setText("Bitte Login Namen angeben"); + return; + } + if (textForename.getText().trim().isEmpty()) { + labelError.setText("Bitte Vornamen eingeben!"); + return; + } + if (textName.getText().trim().isEmpty()) { + labelError.setText("Bitte Nachnamen eingeben!"); + return; + } + + User user = new User(); + + if(!textPassword.getText().trim().isEmpty() || !textPasswordSecond.getText().trim().isEmpty()){ + if (textPassword.getText().trim().isEmpty()) { + labelError.setText("Bitte Passwort eingeben!"); + return; + } + if (textPassword.getText().trim().length() < 8) { + labelError.setText("Das Passwort muss mindestens 8 Zeichen lang sein!"); + return; + } + if (!Objects.equals(textPassword.getText(), textPasswordSecond.getText())){ + labelError.setText("Passwörter stimmen nicht überein!"); + return; + } + user.setPassword(textPassword.getText().trim()); + } + + user.setUserId(currentUser.getUserId()); + user.setLogin(textLogin.getText().trim()); + user.setForename(textForename.getText().trim()); + user.setName(textName.getText().trim()); + user.setAdmin(checkButtonIsAdmin.isSelected()); + + try { + sendHttpRequest(user); + } catch (HttpRequestException e) { + labelError.setText(e.getMessage()); + return; + } + + if(currentUser.getUserId() == DataController.USER_ID){ + Alert alert = new Alert( + Alert.AlertType.WARNING, + "Bitte starte das Programm neu um die Änderungen anzuwenden." + ); + alert.showAndWait(); + } + + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + stage.close(); + } + + @Override + protected void sendHttpRequest(User user) throws HttpRequestException { + DataController dataController = new DataController(); + dataController.editUser(user); } } diff --git a/client/app/src/main/resources/users/create-user.fxml b/client/app/src/main/resources/users/create-user.fxml index c4741a9..ec367cc 100644 --- a/client/app/src/main/resources/users/create-user.fxml +++ b/client/app/src/main/resources/users/create-user.fxml @@ -43,7 +43,7 @@ -