From b3f839e4a330b47707c2e20d27cda155ca93aa7b Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 27 Nov 2022 20:38:38 +0100 Subject: [PATCH 1/7] update json files for crop and task with ui --- .../CropDetailController.java | 17 ++++--- .../gartenverwaltung/MyGardenController.java | 1 - .../TaskFormularController.java | 47 +++++++++++++------ .../TextFieldFormularController.java | 9 ++++ .../zhaw/gartenverwaltung/models/Garden.java | 13 +++++ .../ch/zhaw/gartenverwaltung/types/Task.java | 16 +++++-- 6 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index bbe7cea..3afec27 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -87,7 +87,7 @@ public class CropDetailController { private ListView pests_listView; @FXML - void addTask() throws IOException { + void addTask() throws IOException, HardinessZoneNotSetException { createTaskDialog(true, null); } @@ -136,7 +136,7 @@ public class CropDetailController { if (plant.image() != null) { imageView.setImage(plant.image()); } - area_label.setText(""); + area_label.setText(String.valueOf(crop.getArea())); location_label.setText(""); setTaskListProperty(crop); @@ -255,7 +255,7 @@ public class CropDetailController { return (event) -> { try { createTaskDialog(false, task); - } catch (IOException e) { + } catch (IOException | HardinessZoneNotSetException e) { e.printStackTrace(); } }; @@ -267,7 +267,7 @@ public class CropDetailController { }; } - private void createTaskDialog(boolean newTask, Task givenTask) throws IOException { + private void createTaskDialog(boolean newTask, Task givenTask) throws IOException, HardinessZoneNotSetException { Dialog dialog = new Dialog<>(); dialog.setTitle("Set Task"); dialog.setHeaderText("Add/Edit Task:"); @@ -289,7 +289,7 @@ public class CropDetailController { if (!newTask) { controller.setTaskValue(givenTask); } - dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult() : null); + dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult(this.crop) : null); dialog.showAndWait() .ifPresent(task -> { @@ -334,8 +334,11 @@ public class CropDetailController { //ToDo method to set location location_label.setText(string); } else { - System.out.println(string); - //ToDo method to set area of crop in garden + try { + garden.updateCrop(this.crop.withArea(Double.parseDouble(string))); + } catch (IOException e) { + e.printStackTrace(); + } area_label.setText(string); } }); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java index b6270ca..34cf1a7 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java @@ -51,7 +51,6 @@ public class MyGardenController { @AfterInject @SuppressWarnings("unused") public void init() { - System.out.println("once"); setIconToButton(addPlant_button, "addIcon.png"); myGarden_listView.itemsProperty().bind(garden.getPlantedCrops()); setCellFactory(); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java index 936bf09..b4bb93b 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java @@ -1,23 +1,35 @@ package ch.zhaw.gartenverwaltung; +import ch.zhaw.gartenverwaltung.bootstrap.AfterInject; +import ch.zhaw.gartenverwaltung.bootstrap.Inject; +import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; +import ch.zhaw.gartenverwaltung.io.PlantList; +import ch.zhaw.gartenverwaltung.models.Garden; +import ch.zhaw.gartenverwaltung.models.GardenSchedule; import ch.zhaw.gartenverwaltung.types.Crop; +import ch.zhaw.gartenverwaltung.types.Plant; import ch.zhaw.gartenverwaltung.types.Task; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.*; import javafx.util.Callback; +import java.io.IOException; import java.net.URL; import java.time.LocalDate; import java.util.ResourceBundle; public class TaskFormularController implements Initializable { private Crop crop; + private Plant plant; + private Task task = null; + + @Inject + private GardenSchedule gardenSchedule; + @Inject + private Garden garden; + @Inject + private PlantList plantList; @FXML private TextArea description_area; @@ -34,19 +46,28 @@ public class TaskFormularController implements Initializable { @FXML private TextField taskName_field; + @AfterInject + @SuppressWarnings("unused") - public Task returnResult() { + public Task returnResult(Crop crop) { + int interval = 0; + if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) { + interval = Integer.parseInt(interval_field.getText()); + } Task task = new Task(taskName_field.getText(), description_area.getText(), start_datePicker.getValue(), end_datePicker.getValue(), - Integer.parseInt(interval_field.getText()), crop.getCropId().get()); + interval, crop.getCropId().get()); + if (this.task != null) return this.task.updateTask(task); return task; } - public void setCorp(Crop crop) { + public void setCorp(Crop crop) throws HardinessZoneNotSetException, IOException { this.crop = crop; + this.plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(); } public void setTaskValue(Task task) { + this.task = task; taskName_field.setText(task.getName()); description_area.setText(task.getDescription()); start_datePicker.setValue(task.getStartDate()); @@ -69,7 +90,7 @@ public class TaskFormularController implements Initializable { setDisable(true); setStyle("-fx-background-color: #ffc0cb;"); - if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) { + if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) { setDisable(false); setStyle("-fx-background-color: #32CD32;"); } @@ -93,7 +114,7 @@ public class TaskFormularController implements Initializable { setDisable(true); setStyle("-fx-background-color: #ffc0cb;"); - if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) { + if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) { setDisable(false); setStyle("-fx-background-color: #32CD32;"); } @@ -114,12 +135,8 @@ public class TaskFormularController implements Initializable { }); button.disableProperty().bind(start_datePicker.valueProperty().isNull() - .or(end_datePicker.valueProperty().isNull()) .or(taskName_field.textProperty().isEmpty()) - .or(description_area.textProperty().isEmpty()) - .or(interval_field.textProperty().isEmpty())); - - + .or(description_area.textProperty().isEmpty())); } @Override diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java index a53c240..97742d9 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java @@ -27,6 +27,15 @@ public class TextFieldFormularController { } public void initSaveButton(Button button) { + text_area.textProperty().addListener((observable, oldValue, newValue) -> { + if (newValue.matches("\\d*\\.?\\d*")) { + text_area.setText(newValue); + } else { + text_area.setText(oldValue); + } + }); + button.disableProperty().bind(text_area.textProperty().isEmpty()); } + } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java b/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java index fd25b2a..617f03c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java @@ -70,6 +70,19 @@ public class Garden { plantedCrops.clear(); plantedCrops.addAll(cropList.getCrops()); } + + /** + * Updates the {@link Crop} from the file and the cache + * + * @param crop The crop which is being updated + * @throws IOException If the database cannot be accessed + */ + public void updateCrop(Crop crop) throws IOException { + cropList.saveCrop(crop); + plantedCrops.clear(); + plantedCrops.addAll(cropList.getCrops()); + } + /** * Returns a list of {@link Crop}s which are currently in the gardenplan. * diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index df15fc4..2023b29 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -10,9 +10,9 @@ import java.util.Optional; */ public class Task { private Long id; - private final String name; - private final String description; - private final LocalDate startDate; + private String name; + private String description; + private LocalDate startDate; private Integer interval; private LocalDate endDate; private long cropId; @@ -74,4 +74,14 @@ public class Task { public Optional getEndDate() { return Optional.ofNullable(endDate); } + + public Task updateTask(Task task) { + this.name = task.getName(); + this.description = task.getDescription(); + this.startDate = task.getStartDate(); + this.endDate = task.getEndDate().orElse(null); + this.interval = task.getInterval().orElse(0); + this.cropId = task.getCropId(); + return this; + } } From aedcfe2be9e526ea116b016dede81aa8ac643fc1 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 27 Nov 2022 20:38:38 +0100 Subject: [PATCH 2/7] update json files for crop and task with ui --- .../CropDetailController.java | 17 ++++--- .../gartenverwaltung/MyGardenController.java | 1 - .../TaskFormularController.java | 47 +++++++++++++------ .../TextFieldFormularController.java | 9 ++++ .../zhaw/gartenverwaltung/models/Garden.java | 13 +++++ .../ch/zhaw/gartenverwaltung/types/Task.java | 16 +++++-- 6 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index bbe7cea..3afec27 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -87,7 +87,7 @@ public class CropDetailController { private ListView pests_listView; @FXML - void addTask() throws IOException { + void addTask() throws IOException, HardinessZoneNotSetException { createTaskDialog(true, null); } @@ -136,7 +136,7 @@ public class CropDetailController { if (plant.image() != null) { imageView.setImage(plant.image()); } - area_label.setText(""); + area_label.setText(String.valueOf(crop.getArea())); location_label.setText(""); setTaskListProperty(crop); @@ -255,7 +255,7 @@ public class CropDetailController { return (event) -> { try { createTaskDialog(false, task); - } catch (IOException e) { + } catch (IOException | HardinessZoneNotSetException e) { e.printStackTrace(); } }; @@ -267,7 +267,7 @@ public class CropDetailController { }; } - private void createTaskDialog(boolean newTask, Task givenTask) throws IOException { + private void createTaskDialog(boolean newTask, Task givenTask) throws IOException, HardinessZoneNotSetException { Dialog dialog = new Dialog<>(); dialog.setTitle("Set Task"); dialog.setHeaderText("Add/Edit Task:"); @@ -289,7 +289,7 @@ public class CropDetailController { if (!newTask) { controller.setTaskValue(givenTask); } - dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult() : null); + dialog.setResultConverter(button -> button.equals(saveTask) ? controller.returnResult(this.crop) : null); dialog.showAndWait() .ifPresent(task -> { @@ -334,8 +334,11 @@ public class CropDetailController { //ToDo method to set location location_label.setText(string); } else { - System.out.println(string); - //ToDo method to set area of crop in garden + try { + garden.updateCrop(this.crop.withArea(Double.parseDouble(string))); + } catch (IOException e) { + e.printStackTrace(); + } area_label.setText(string); } }); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java index b6270ca..34cf1a7 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java @@ -51,7 +51,6 @@ public class MyGardenController { @AfterInject @SuppressWarnings("unused") public void init() { - System.out.println("once"); setIconToButton(addPlant_button, "addIcon.png"); myGarden_listView.itemsProperty().bind(garden.getPlantedCrops()); setCellFactory(); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java index 936bf09..b4bb93b 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java @@ -1,23 +1,35 @@ package ch.zhaw.gartenverwaltung; +import ch.zhaw.gartenverwaltung.bootstrap.AfterInject; +import ch.zhaw.gartenverwaltung.bootstrap.Inject; +import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; +import ch.zhaw.gartenverwaltung.io.PlantList; +import ch.zhaw.gartenverwaltung.models.Garden; +import ch.zhaw.gartenverwaltung.models.GardenSchedule; import ch.zhaw.gartenverwaltung.types.Crop; +import ch.zhaw.gartenverwaltung.types.Plant; import ch.zhaw.gartenverwaltung.types.Task; -import javafx.beans.binding.Binding; -import javafx.beans.binding.Bindings; -import javafx.beans.binding.BooleanBinding; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.*; import javafx.util.Callback; +import java.io.IOException; import java.net.URL; import java.time.LocalDate; import java.util.ResourceBundle; public class TaskFormularController implements Initializable { private Crop crop; + private Plant plant; + private Task task = null; + + @Inject + private GardenSchedule gardenSchedule; + @Inject + private Garden garden; + @Inject + private PlantList plantList; @FXML private TextArea description_area; @@ -34,19 +46,28 @@ public class TaskFormularController implements Initializable { @FXML private TextField taskName_field; + @AfterInject + @SuppressWarnings("unused") - public Task returnResult() { + public Task returnResult(Crop crop) { + int interval = 0; + if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) { + interval = Integer.parseInt(interval_field.getText()); + } Task task = new Task(taskName_field.getText(), description_area.getText(), start_datePicker.getValue(), end_datePicker.getValue(), - Integer.parseInt(interval_field.getText()), crop.getCropId().get()); + interval, crop.getCropId().get()); + if (this.task != null) return this.task.updateTask(task); return task; } - public void setCorp(Crop crop) { + public void setCorp(Crop crop) throws HardinessZoneNotSetException, IOException { this.crop = crop; + this.plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get(); } public void setTaskValue(Task task) { + this.task = task; taskName_field.setText(task.getName()); description_area.setText(task.getDescription()); start_datePicker.setValue(task.getStartDate()); @@ -69,7 +90,7 @@ public class TaskFormularController implements Initializable { setDisable(true); setStyle("-fx-background-color: #ffc0cb;"); - if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) { + if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) { setDisable(false); setStyle("-fx-background-color: #32CD32;"); } @@ -93,7 +114,7 @@ public class TaskFormularController implements Initializable { setDisable(true); setStyle("-fx-background-color: #ffc0cb;"); - if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) { + if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0 && item.compareTo(crop.getStartDate().plusDays(plant.timeToHarvest(0))) < 0) { setDisable(false); setStyle("-fx-background-color: #32CD32;"); } @@ -114,12 +135,8 @@ public class TaskFormularController implements Initializable { }); button.disableProperty().bind(start_datePicker.valueProperty().isNull() - .or(end_datePicker.valueProperty().isNull()) .or(taskName_field.textProperty().isEmpty()) - .or(description_area.textProperty().isEmpty()) - .or(interval_field.textProperty().isEmpty())); - - + .or(description_area.textProperty().isEmpty())); } @Override diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java index a53c240..97742d9 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java @@ -27,6 +27,15 @@ public class TextFieldFormularController { } public void initSaveButton(Button button) { + text_area.textProperty().addListener((observable, oldValue, newValue) -> { + if (newValue.matches("\\d*\\.?\\d*")) { + text_area.setText(newValue); + } else { + text_area.setText(oldValue); + } + }); + button.disableProperty().bind(text_area.textProperty().isEmpty()); } + } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java b/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java index fd25b2a..617f03c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/Garden.java @@ -70,6 +70,19 @@ public class Garden { plantedCrops.clear(); plantedCrops.addAll(cropList.getCrops()); } + + /** + * Updates the {@link Crop} from the file and the cache + * + * @param crop The crop which is being updated + * @throws IOException If the database cannot be accessed + */ + public void updateCrop(Crop crop) throws IOException { + cropList.saveCrop(crop); + plantedCrops.clear(); + plantedCrops.addAll(cropList.getCrops()); + } + /** * Returns a list of {@link Crop}s which are currently in the gardenplan. * diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index 9501861..2426532 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -10,9 +10,9 @@ import java.util.Optional; */ public class Task { private Long id; - private final String name; - private final String description; - private final LocalDate startDate; + private String name; + private String description; + private LocalDate startDate; private Integer interval; private LocalDate endDate; private LocalDate nextExecution; @@ -103,4 +103,14 @@ public class Task { public Optional getEndDate() { return Optional.ofNullable(endDate); } + + public Task updateTask(Task task) { + this.name = task.getName(); + this.description = task.getDescription(); + this.startDate = task.getStartDate(); + this.endDate = task.getEndDate().orElse(null); + this.interval = task.getInterval().orElse(0); + this.cropId = task.getCropId(); + return this; + } } From 2ec37114de94b1222d3692065a4fd6d4847afcf7 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 27 Nov 2022 21:56:12 +0100 Subject: [PATCH 3/7] quick fix task end date can not be null + test data --- .../TaskFormularController.java | 1 + .../gartenverwaltung/types/TaskTemplate.java | 2 +- .../ch/zhaw/gartenverwaltung/io/plantdb.json | 81 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java index b4bb93b..6c46aba 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/TaskFormularController.java @@ -135,6 +135,7 @@ public class TaskFormularController implements Initializable { }); button.disableProperty().bind(start_datePicker.valueProperty().isNull() + .or(end_datePicker.valueProperty().isNull()) .or(taskName_field.textProperty().isEmpty()) .or(description_area.textProperty().isEmpty())); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java index b2cb06f..9a3d57d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/TaskTemplate.java @@ -42,7 +42,7 @@ public class TaskTemplate { } public Task generateTask(LocalDate realStartDate, long cropId) { - LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null; + LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : realStartDate.plusDays(0); if (interval == null) { this.interval = 0; diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json b/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json index fac9a5b..ec76a31 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json +++ b/src/main/resources/ch/zhaw/gartenverwaltung/io/plantdb.json @@ -245,5 +245,86 @@ "measures": "less water" } ] + }, + { + "id": 3, + "name": "Test Potato", + "description": "The potato is a tuber, round or oval, with small white roots called 'eyes', that are growth buds. The size varies depending on the variety; the colour of the skin can be white, yellow or even purple.", + "light": 6, + "spacing": "35", + "soil": "sandy", + "image": "potato.jpg", + "pests": [ + { + "name": "Rot", + "description": "Rot, any of several plant diseases, caused by any of hundreds of species of soil-borne bacteria, fungi, and funguslike organisms (Oomycota). Rot diseases are characterized by plant decomposition and putrefaction. The decay may be hard, dry, spongy, watery, mushy, or slimy and may affect any plant part.", + "measures": "Less water." + } + ], + "lifecycle": [ + { + "startDate": "12-01", + "endDate": "12-02", + "type": "SOW", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Germinate", + "relativeStartDate": -3, + "relativeEndDate": 0, + "description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.", + "interval": null + } + ] + }, + { + "startDate": "12-03", + "endDate": "12-15", + "type": "PLANT", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 25, + "interval": 7, + "notes": [] + }, + "taskTemplates": [ + { + "name": "hilling", + "relativeStartDate": 0, + "relativeEndDate": 10, + "description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.", + "interval": 3 + } + ] + }, + { + "startDate": "12-16", + "endDate": "12-18", + "type": "HARVEST", + "zone": "ZONE_8A", + "group": 0, + "wateringCycle": { + "litersPerSqM": 0, + "interval": null, + "notes": [] + }, + "taskTemplates": [ + { + "name": "Harvest", + "relativeStartDate": 0, + "relativeEndDate": 4, + "description": "Once the foliage has wilted and dried completely, harvest on a dry day. Store in a dark and cool location.", + "interval": null + } + ] + } + ] } ] From e9258fb2381291be16d3a0cd9f8b556c5133763e Mon Sep 17 00:00:00 2001 From: giavaphi Date: Mon, 28 Nov 2022 00:50:41 +0100 Subject: [PATCH 4/7] fix of zero interval --- .../CropDetailController.java | 28 +++++++++++++------ .../models/GardenSchedule.java | 1 + .../ch/zhaw/gartenverwaltung/types/Task.java | 3 +- .../ch/zhaw/gartenverwaltung/CropDetail.fxml | 4 +-- .../zhaw/gartenverwaltung/TaskFormular.fxml | 6 ++-- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index 3afec27..c644865 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -22,6 +22,7 @@ import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; import javafx.scene.layout.Priority; import javafx.stage.Stage; @@ -205,22 +206,28 @@ public class CropDetailController { } private HBox createTaskHBox(Task task) { - HBox hBox = new HBox(); + HBox hBox = new HBox(10); Label taskName = new Label(task.getName()+": "); + taskName.setMinWidth(100); + taskName.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); taskName.setStyle("-fx-font-weight: bold"); Label taskDescription = new Label(task.getDescription()); taskDescription.setWrapText(true); - taskDescription.setMaxWidth(2000); - HBox.setHgrow(taskDescription, Priority.ALWAYS); + taskDescription.setMaxSize(600, Double.MAX_VALUE); + Pane puffer = new Pane(); + HBox.setHgrow(puffer, Priority.ALWAYS); + Button edit = new Button(); Button delete = new Button(); + HBox.setHgrow(edit, Priority.NEVER); + HBox.setHgrow(delete, Priority.NEVER); setIconToButton(edit, "editIcon.png"); setIconToButton(delete, "deleteIcon.png"); edit.setOnAction(getEditTaskEvent(task)); delete.setOnAction(deleteTask(task)); - hBox.getChildren().addAll(taskName, taskDescription, edit, delete); + hBox.getChildren().addAll(taskName, taskDescription, puffer, edit, delete); return hBox; } @@ -229,12 +236,15 @@ public class CropDetailController { label.setStyle("-fx-font-weight: bold"); HBox hBox = new HBox(); hBox.fillHeightProperty(); - Label label1 = new Label(pest.description()); - label1.setAlignment(Pos.TOP_LEFT); - label1.setWrapText(true); - label1.setMaxWidth(600); + Label description = new Label(pest.description()); + description.setAlignment(Pos.TOP_LEFT); + description.setWrapText(true); + description.setMaxWidth(600); + Pane puffer = new Pane(); + HBox.setHgrow(puffer, Priority.ALWAYS); Button button = new Button("Get Counter Measures"); - hBox.getChildren().addAll(label, label1, button); + HBox.setHgrow(button, Priority.NEVER); + hBox.getChildren().addAll(label, description, puffer, button); return hBox; } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index c3292f6..9cb6503 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -151,6 +151,7 @@ public class GardenSchedule { if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) { dayTaskList.get(finalI).add(task); } + if (task.getInterval().orElse(0) == 0) break; checkDate = checkDate.plusDays(task.getInterval().orElse(0)); } while (task.getInterval().isPresent() && checkDate.isBefore(LocalDate.now().plusDays(listLength))); }); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index 2426532..4158057 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -18,6 +18,7 @@ public class Task { private LocalDate nextExecution; private LocalDate nextNotification; private long cropId; + private boolean done; /** * default constructor @@ -69,7 +70,7 @@ public class Task { } public void done(){ - if(interval != null && !nextExecution.plusDays(interval).isAfter(endDate)){ + if(interval != null && interval != 0 && !nextExecution.plusDays(interval).isAfter(endDate)){ nextExecution = nextExecution.plusDays(interval); } else { nextExecution = null; diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml index c0f0a7c..1ee27fb 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml +++ b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml @@ -107,7 +107,7 @@ -