Skip to content

Commit

Permalink
Merge pull request #47 from itsallcode/#44_update_activities_duration
Browse files Browse the repository at this point in the history
#44 update activities duration
  • Loading branch information
kaklakariada authored Nov 25, 2020
2 parents 2bfb4d1 + 91ccb33 commit 44fc5cb
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 62 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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)

### 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
* [#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)
29 changes: 1 addition & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A time recording tool

* [Features](#features)
* [Usage](#usage)
* [Recent changes](#changes)
* [Changelog](CHANGELOG.md)

![Screenshot of WhiteRabbit](screenshot.png)

Expand Down Expand Up @@ -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.

## <a name="changes"></a>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)

## <a name="usage"></a>Usage

### Requirements
Expand Down
16 changes: 16 additions & 0 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/AppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +27,9 @@ public final class AppState
public final BooleanProperty stoppedWorkingForToday = new SimpleBooleanProperty(false);
public final ObservableList<YearMonth> availableMonths = FXCollections.observableArrayList();

public final SimpleObjectProperty<DayRecord> selectedDay = new SimpleObjectProperty<>(null);
public final SimpleObjectProperty<Activity> selectedActivity = new SimpleObjectProperty<>(null);

public final ScheduledProperty<LocalDate> currentDateProperty;
public final ScheduledProperty<Instant> currentTimeProperty;

Expand All @@ -39,6 +45,16 @@ static AppState create(AppService appService)
return new AppState(clockPropertyFactory.currentDateProperty(), clockPropertyFactory.currentTimeProperty());
}

public Optional<DayRecord> getSelectedDay()
{
return Optional.ofNullable(selectedDay.getValue());
}

public Optional<Activity> getSelectedActivity()
{
return Optional.ofNullable(selectedActivity.get());
}

void shutdown()
{
currentDateProperty.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void bringWindowToFront()

public void addActivity()
{
final Optional<DayRecord> selectedDay = ui.getSelectedDay();
final Optional<DayRecord> selectedDay = state.getSelectedDay();
if (selectedDay.isEmpty())
{
LOG.warn("No day selected, can't add an activity");
Expand All @@ -237,7 +237,7 @@ public void addActivity()

public void removeActivity()
{
final Optional<Activity> selectedActivity = ui.getSelectedActivity();
final Optional<Activity> selectedActivity = state.getSelectedActivity();
if (selectedActivity.isEmpty())
{
LOG.info("No activity selected to be removed");
Expand Down Expand Up @@ -334,8 +334,7 @@ public void recordUpdated(DayRecord record)

private boolean daySelected(DayRecord record)
{

final Optional<DayRecord> selectedDay = ui.getSelectedDay();
final Optional<DayRecord> selectedDay = state.getSelectedDay();
return selectedDay.isPresent() && selectedDay.get().getDate().equals(record.getDate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ public class ActivitiesTable
private static final Logger LOG = LogManager.getLogger(ActivitiesTable.class);

private final ObservableList<ActivityPropertyAdapter> activities = FXCollections.observableArrayList();
private final SimpleObjectProperty<Activity> selectedActivity = new SimpleObjectProperty<>(null);
private final SimpleObjectProperty<Activity> selectedActivity;

private final EditListener<DayRecord> editListener;
private final FormatterService formatterService;
private final ProjectService projectService;

public ActivitiesTable(ReadOnlyProperty<DayRecord> selectedDay, EditListener<DayRecord> editListener,
public ActivitiesTable(ReadOnlyProperty<DayRecord> selectedDay, SimpleObjectProperty<Activity> selectedActivity,
EditListener<DayRecord> editListener,
FormatterService formatterService, ProjectService projectService)
{
this.selectedActivity = selectedActivity;
this.editListener = editListener;
this.formatterService = formatterService;
this.projectService = projectService;
Expand Down Expand Up @@ -162,9 +164,4 @@ public void refresh()
{
activities.forEach(ActivityPropertyAdapter::update);
}

public SimpleObjectProperty<Activity> selectedActivity()
{
return selectedActivity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,15 +48,17 @@ public class DayRecordTable
private final EditListener<DayRecord> editListener;
private final FormatterService formatterService;
private final Locale locale;
private final SimpleObjectProperty<DayRecord> selectedDay = new SimpleObjectProperty<>(null);
private final SimpleObjectProperty<DayRecord> selectedDay;
private TableView<DayRecordPropertyAdapter> table;

public DayRecordTable(Locale locale, ObjectProperty<MonthIndex> currentMonth, EditListener<DayRecord> editListener,
public DayRecordTable(Locale locale, SimpleObjectProperty<DayRecord> selectedDay,
ObjectProperty<MonthIndex> currentMonth, EditListener<DayRecord> editListener,
FormatterService formatterService)
{
this.editListener = editListener;
this.formatterService = formatterService;
this.locale = locale;
this.selectedDay = selectedDay;
fillTableWith31EmptyRows();
currentMonth.addListener((observable, oldValue, newValue) -> updateTableValues(newValue));
}
Expand All @@ -78,11 +79,6 @@ public TableView<DayRecordPropertyAdapter> initTable()
return table;
}

public ReadOnlyProperty<DayRecord> selectedDay()
{
return selectedDay;
}

public void selectRow(LocalDate date)
{
Objects.requireNonNull(table, "Table not yet initialized");
Expand Down
23 changes: 9 additions & 14 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/AppUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +19,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;
Expand Down Expand Up @@ -79,16 +77,6 @@ public void selectDay(LocalDate date)
dayRecordTable.selectRow(date);
}

public Optional<DayRecord> getSelectedDay()
{
return Optional.ofNullable(dayRecordTable.selectedDay().getValue());
}

public Optional<Activity> getSelectedActivity()
{
return Optional.ofNullable(activitiesTable.selectedActivity().get());
}

public void updateActivities(DayRecord record)
{
activitiesTable.updateTableValues(record);
Expand Down Expand Up @@ -121,9 +109,16 @@ 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(dayRecordTable.selectedDay(), record -> {
activitiesTable = new ActivitiesTable(state.selectedDay, state.selectedActivity, record -> {
appService.store(record);
activitiesTable.refresh();
}, appService.formatter(), appService.projects());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 44fc5cb

Please sign in to comment.