From a3de61b7ebdc190c224afa801811df662960bea0 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 25 Nov 2020 08:51:37 +0100 Subject: [PATCH 1/5] #44 Refactoring: extract state --- .../itsallcode/whiterabbit/jfxui/AppState.java | 16 ++++++++++++++++ .../itsallcode/whiterabbit/jfxui/JavaFxApp.java | 7 +++---- .../jfxui/table/activities/ActivitiesTable.java | 11 ++++------- .../jfxui/table/days/DayRecordTable.java | 12 ++++-------- .../itsallcode/whiterabbit/jfxui/ui/AppUi.java | 13 +------------ 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/AppState.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/AppState.java index 0f263f88..888bccfc 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/AppState.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/AppState.java @@ -3,9 +3,12 @@ import java.time.Instant; import java.time.LocalDate; import java.time.YearMonth; +import java.util.Optional; import org.itsallcode.whiterabbit.jfxui.property.ClockPropertyFactory; import org.itsallcode.whiterabbit.jfxui.property.ScheduledProperty; +import org.itsallcode.whiterabbit.logic.model.Activity; +import org.itsallcode.whiterabbit.logic.model.DayRecord; import org.itsallcode.whiterabbit.logic.model.MonthIndex; import org.itsallcode.whiterabbit.logic.service.AppService; import org.itsallcode.whiterabbit.logic.service.Interruption; @@ -24,6 +27,9 @@ public final class AppState public final BooleanProperty stoppedWorkingForToday = new SimpleBooleanProperty(false); public final ObservableList availableMonths = FXCollections.observableArrayList(); + public final SimpleObjectProperty selectedDay = new SimpleObjectProperty<>(null); + public final SimpleObjectProperty selectedActivity = new SimpleObjectProperty<>(null); + public final ScheduledProperty currentDateProperty; public final ScheduledProperty currentTimeProperty; @@ -39,6 +45,16 @@ static AppState create(AppService appService) return new AppState(clockPropertyFactory.currentDateProperty(), clockPropertyFactory.currentTimeProperty()); } + public Optional getSelectedDay() + { + return Optional.ofNullable(selectedDay.getValue()); + } + + public Optional getSelectedActivity() + { + return Optional.ofNullable(selectedActivity.get()); + } + void shutdown() { currentDateProperty.cancel(); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java index 54ce168f..9bc512e8 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java @@ -226,7 +226,7 @@ public void bringWindowToFront() public void addActivity() { - final Optional selectedDay = ui.getSelectedDay(); + final Optional selectedDay = state.getSelectedDay(); if (selectedDay.isEmpty()) { LOG.warn("No day selected, can't add an activity"); @@ -237,7 +237,7 @@ public void addActivity() public void removeActivity() { - final Optional selectedActivity = ui.getSelectedActivity(); + final Optional selectedActivity = state.getSelectedActivity(); if (selectedActivity.isEmpty()) { LOG.info("No activity selected to be removed"); @@ -334,8 +334,7 @@ public void recordUpdated(DayRecord record) private boolean daySelected(DayRecord record) { - - final Optional selectedDay = ui.getSelectedDay(); + final Optional selectedDay = state.getSelectedDay(); return selectedDay.isPresent() && selectedDay.get().getDate().equals(record.getDate()); } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivitiesTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivitiesTable.java index 3a6f7f99..892b589d 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivitiesTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivitiesTable.java @@ -38,15 +38,17 @@ public class ActivitiesTable private static final Logger LOG = LogManager.getLogger(ActivitiesTable.class); private final ObservableList activities = FXCollections.observableArrayList(); - private final SimpleObjectProperty selectedActivity = new SimpleObjectProperty<>(null); + private final SimpleObjectProperty selectedActivity; private final EditListener editListener; private final FormatterService formatterService; private final ProjectService projectService; - public ActivitiesTable(ReadOnlyProperty selectedDay, EditListener editListener, + public ActivitiesTable(ReadOnlyProperty selectedDay, SimpleObjectProperty selectedActivity, + EditListener editListener, FormatterService formatterService, ProjectService projectService) { + this.selectedActivity = selectedActivity; this.editListener = editListener; this.formatterService = formatterService; this.projectService = projectService; @@ -162,9 +164,4 @@ public void refresh() { activities.forEach(ActivityPropertyAdapter::update); } - - public SimpleObjectProperty selectedActivity() - { - return selectedActivity; - } } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index 6266be6a..3fc0ae37 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -25,7 +25,6 @@ import org.itsallcode.whiterabbit.logic.service.FormatterService; import javafx.beans.property.ObjectProperty; -import javafx.beans.property.ReadOnlyProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; @@ -49,15 +48,17 @@ public class DayRecordTable private final EditListener editListener; private final FormatterService formatterService; private final Locale locale; - private final SimpleObjectProperty selectedDay = new SimpleObjectProperty<>(null); + private final SimpleObjectProperty selectedDay; private TableView table; - public DayRecordTable(Locale locale, ObjectProperty currentMonth, EditListener editListener, + public DayRecordTable(Locale locale, SimpleObjectProperty selectedDay, + ObjectProperty currentMonth, EditListener editListener, FormatterService formatterService) { this.editListener = editListener; this.formatterService = formatterService; this.locale = locale; + this.selectedDay = selectedDay; fillTableWith31EmptyRows(); currentMonth.addListener((observable, oldValue, newValue) -> updateTableValues(newValue)); } @@ -78,11 +79,6 @@ public TableView initTable() return table; } - public ReadOnlyProperty selectedDay() - { - return selectedDay; - } - public void selectRow(LocalDate date) { Objects.requireNonNull(table, "Table not yet initialized"); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java index a75dea4b..d5cc17ff 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java @@ -20,7 +20,6 @@ import org.itsallcode.whiterabbit.jfxui.table.days.DayRecordTable; import org.itsallcode.whiterabbit.jfxui.tray.Tray; import org.itsallcode.whiterabbit.jfxui.tray.TrayCallback; -import org.itsallcode.whiterabbit.logic.model.Activity; import org.itsallcode.whiterabbit.logic.model.DayRecord; import org.itsallcode.whiterabbit.logic.model.MonthIndex; import org.itsallcode.whiterabbit.logic.service.AppService; @@ -79,16 +78,6 @@ public void selectDay(LocalDate date) dayRecordTable.selectRow(date); } - public Optional getSelectedDay() - { - return Optional.ofNullable(dayRecordTable.selectedDay().getValue()); - } - - public Optional getSelectedActivity() - { - return Optional.ofNullable(activitiesTable.selectedActivity().get()); - } - public void updateActivities(DayRecord record) { activitiesTable.updateTableValues(record); @@ -123,7 +112,7 @@ public AppUi build() LOG.debug("Creating user interface"); dayRecordTable = new DayRecordTable(locale, state.currentMonth, appService::store, appService.formatter()); - activitiesTable = new ActivitiesTable(dayRecordTable.selectedDay(), record -> { + activitiesTable = new ActivitiesTable(state.selectedDay, state.selectedActivity, record -> { appService.store(record); activitiesTable.refresh(); }, appService.formatter(), appService.projects()); From 72cd02b5b3c3e9756be49f47a743b7e79d084abb Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 25 Nov 2020 08:52:07 +0100 Subject: [PATCH 2/5] #44 Refresh activities when modifying the selected day --- .../itsallcode/whiterabbit/jfxui/ui/AppUi.java | 10 ++++++++-- .../whiterabbit/jfxui/ActivitiesTest.java | 17 +++++++++++++++++ .../jfxui/testutil/model/DayTable.java | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java index d5cc17ff..e6c92a26 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java @@ -8,7 +8,6 @@ import java.time.LocalDate; import java.time.YearMonth; import java.util.Locale; -import java.util.Optional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -110,7 +109,14 @@ public Builder(JavaFxApp app, UiActions actions, AppService appService, Stage pr public AppUi build() { LOG.debug("Creating user interface"); - dayRecordTable = new DayRecordTable(locale, state.currentMonth, appService::store, appService.formatter()); + dayRecordTable = new DayRecordTable(locale, state.selectedDay, state.currentMonth, record -> { + appService.store(record); + if (record.getDate().equals(state.getSelectedDay().map(DayRecord::getDate).orElse(null))) + { + LOG.debug("Current day {} updated: refresh activieties", record.getDate()); + activitiesTable.refresh(); + } + }, appService.formatter()); activitiesTable = new ActivitiesTable(state.selectedDay, state.selectedActivity, record -> { appService.store(record); diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java index 80bc1999..b90181aa 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/ActivitiesTest.java @@ -299,6 +299,23 @@ void activitiesTableUpdatedWhenDayChanges() table.assertRowCount(0); } + @Test + void activitiesDurationUpdatedWhenChangingBegin() + { + final int row = time().getCurrentDayRowIndex(); + time().tickMinute(); + + final ActivitiesTable activities = app().activitiesTable(); + + activities.addRemainderActivity("act"); + + final Builder expectedRow = ActivitiesTableExpectedRow.defaultRow().withRemainder(true).withComment("act"); + activities.table().assertContent(expectedRow.withDuration(Duration.ZERO).build()); + + app().dayTable().typeBegin(row, "11:00"); + activities.table().assertContent(expectedRow.withDuration(Duration.ofMinutes(16)).build()); + } + private void addActivity() { time().tickMinute(); diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/DayTable.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/DayTable.java index ee5b0266..02b03eb1 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/DayTable.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/DayTable.java @@ -62,7 +62,8 @@ public String getBeginText(int row) public void typeBegin(int row, String value) { final TableCell tableCell = table.getTableCell(row, "begin"); - robot.doubleClickOn(tableCell).write(value).type(KeyCode.TAB); + robot.clickOn(tableCell).clickOn(tableCell).clickOn(tableCell).type(KeyCode.BACK_SPACE).write(value) + .type(KeyCode.TAB); } public LocalTime getEnd(int row) From a591ef7bb86357534f5df27dbe29702bc3af1a4d Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 25 Nov 2020 09:11:55 +0100 Subject: [PATCH 3/5] Move changelog to separate file --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ README.md | 29 +---------------------------- 2 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..23aedb6e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.1] (unreleased) + +See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.1) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/3?closed=1) + +### Fixed + +* [#42](https://github.com/itsallcode/white-rabbit/pull/42): Bugfix: Keep edit focus for activities when table is updated every minute + +## [1.0.0] + +See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.0) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/1?closed=1) + +* [#40](https://github.com/itsallcode/white-rabbit/pull/40): Bugfix: Keep edit focus when table is updated every minute +* [#39](https://github.com/itsallcode/white-rabbit/pull/39): Publish WhiteRabbit using WebStart +* [#5](https://github.com/itsallcode/white-rabbit/issues/5): Add presets for adding interruptions +* [#20](https://github.com/itsallcode/white-rabbit/issues/20): Allow configuring the location of the configuration file, see [details below](#configuration) +* [#22](https://github.com/itsallcode/white-rabbit/issues/22), [#18](https://github.com/itsallcode/white-rabbit/issues/18): Add version number to build, show "About" dialog and build executable jars for all platforms, see [building a release](#building_release) +* [#15](https://github.com/itsallcode/white-rabbit/issues/15): Freeze previous end time on "stop working" in pop-up +* [#29](https://github.com/itsallcode/white-rabbit/issues/29): Relaxed parsing of time and duration +* [#27](https://github.com/itsallcode/white-rabbit/issues/27): Delete begin, end and interruption when changing day type to "not working" +* [#26](https://github.com/itsallcode/white-rabbit/issues/26): Omit "activities" from json when list is empty +* [#10](https://github.com/itsallcode/white-rabbit/issues/10): Facelift: Improved menu. Turned buttons and drop-down into toolbar. Turned OT (thanks to [redcatbear](https://github.com/redcatbear)) +* [#6](https://github.com/itsallcode/white-rabbit/issues/6): Persist cell changes on focus loss +* Text UI is now deprecated, please use the new Java FX UI. +* Keep track of activities for time booking on multiple projects, See [project configuration](#project_config) +* Supports reduced working hours / short-time work, see [configuration option `current_working_time_per_day`](#optional_config) diff --git a/README.md b/README.md index 7919d453..082e6491 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A time recording tool * [Features](#features) * [Usage](#usage) -* [Recent changes](#changes) +* [Changelog](CHANGELOG.md) ![Screenshot of WhiteRabbit](screenshot.png) @@ -113,33 +113,6 @@ This is generated automatically. The Java FX user interface allows you to edit i * If you change the working time in previous months you might need to adjust the `overtimePreviousMonth` field in the following months by selecting menu item `File -> Update overtime for all months` in the Java FX UI. * When you modify config file `time.properties` you need to restart WhiteRabbit manually. -## Recent changes - -### Version 1.0.1 (unreleased) - -See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.1) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/3?closed=1) - -* [#42](https://github.com/itsallcode/white-rabbit/pull/42): Bugfix: Keep edit focus for activities when table is updated every minute - -### Version 1.0.0 - -See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.0) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/1?closed=1) - -* [#40](https://github.com/itsallcode/white-rabbit/pull/40): Bugfix: Keep edit focus when table is updated every minute -* [#39](https://github.com/itsallcode/white-rabbit/pull/39): Publish WhiteRabbit using WebStart -* [#5](https://github.com/itsallcode/white-rabbit/issues/5): Add presets for adding interruptions -* [#20](https://github.com/itsallcode/white-rabbit/issues/20): Allow configuring the location of the configuration file, see [details below](#configuration) -* [#22](https://github.com/itsallcode/white-rabbit/issues/22), [#18](https://github.com/itsallcode/white-rabbit/issues/18): Add version number to build, show "About" dialog and build executable jars for all platforms, see [building a release](#building_release) -* [#15](https://github.com/itsallcode/white-rabbit/issues/15): Freeze previous end time on "stop working" in pop-up -* [#29](https://github.com/itsallcode/white-rabbit/issues/29): Relaxed parsing of time and duration -* [#27](https://github.com/itsallcode/white-rabbit/issues/27): Delete begin, end and interruption when changing day type to "not working" -* [#26](https://github.com/itsallcode/white-rabbit/issues/26): Omit "activities" from json when list is empty -* [#10](https://github.com/itsallcode/white-rabbit/issues/10): Facelift: Improved menu. Turned buttons and drop-down into toolbar. Turned OT (thanks to [redcatbear](https://github.com/redcatbear)) -* [#6](https://github.com/itsallcode/white-rabbit/issues/6): Persist cell changes on focus loss -* Text UI is now deprecated, please use the new Java FX UI. -* Keep track of activities for time booking on multiple projects, See [project configuration](#project_config) -* Supports reduced working hours / short-time work, see [configuration option `current_working_time_per_day`](#optional_config) - ## Usage ### Requirements From f3f81f3c6f30dfaf67e816ebb57e8b8e89d5fbc4 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 25 Nov 2020 09:12:55 +0100 Subject: [PATCH 4/5] #44 Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23aedb6e..ba000235 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.1) / ### Fixed +* [#44](https://github.com/itsallcode/white-rabbit/pull/44): Bugfix: Update activity duration when modifying day entry * [#42](https://github.com/itsallcode/white-rabbit/pull/42): Bugfix: Keep edit focus for activities when table is updated every minute ## [1.0.0] From 91ccb333929b364a440d2eb8a1cf413de16e8bd4 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 25 Nov 2020 09:17:39 +0100 Subject: [PATCH 5/5] #21: Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba000235..12949c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.0.1) / [Milestone](https://github.com/itsallcode/white-rabbit/milestone/3?closed=1) +### Added + +* [#21](https://github.com/itsallcode/white-rabbit/issues/21): Add menu items for editing configuration files + ### Fixed * [#44](https://github.com/itsallcode/white-rabbit/pull/44): Bugfix: Update activity duration when modifying day entry