Skip to content

Commit

Permalink
Merge pull request #202 from itsallcode/#177-month-buttons
Browse files Browse the repository at this point in the history
#177: Add buttons for selecting the previous/next month
  • Loading branch information
kaklakariada authored Jul 19, 2021
2 parents 68818c9 + 1785751 commit 6f4f047
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ See [Release](https://github.com/itsallcode/white-rabbit/releases/tag/v1.7.0) /
* [#164](https://github.com/itsallcode/white-rabbit/pull/164): Improve label of empty activities table.
* [#115](https://github.com/itsallcode/white-rabbit/issues/115): Added holiday-calculator plugin: calculate holidays, see [README.md](README.md#holidays_calculator) for details.
* [#175](https://github.com/itsallcode/white-rabbit/pull/175): CSV Exporter Plugin: Initial version.
* [#177](https://github.com/itsallcode/white-rabbit/issues/177) / [PR #202](https://github.com/itsallcode/white-rabbit/pull/202): Add buttons for selecting the previous/next month. Store new month when holidays where found.

### Changed

Expand Down
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ Optionally you can configure pmsmart plugin to skip transfer of a comment for ea

For each activity in WhiteRabbit you can enter a comment. By default pmsmart plugin transfers these comment to pm-smart. As the web ui is quite slow, transfer of comments can take a while. If you want to speed-up pm-smart export by skipping transfer of comments you can add an optional property to WhiteRabbit configuration file:

```properties
pmsmart.transfer.comments = false
```
```properties
pmsmart.transfer.comments = false
```

Optionally you can configure pmsmart plugin to clear durations for all other projects, not matching any activity recorded in WhiteRabbit.

For each day pm-smart plugin by default transfers the durations of all activities entered into WhiteRabbit. If pm-smart contains durations for other projects then pm-smart plugin does not overwrite these. This will especially happen if users export their time recordings for a particular month multiple times and change the selection of activities in between. In order to ensure consistent data in pm-smart you can add an optional property to WhiteRabbit configuration file:

```properties
pmsmart.clear_other_projects = true
```
```properties
pmsmart.clear_other_projects = true
```

#### <a name="holidays_calculator"></a>Using holidays-calculator

Expand All @@ -187,13 +187,10 @@ Optionally you can configure holidays-calculator plugin to enable WhiteRabbit to

Create a file named `holidays.cfg` in your data directory defined in the [configuration file](README.md#configuration) of WhiteRabbit.

You can use one of the predefined holiday definition files available at
<https://github.com/itsallcode/holiday-calculator> or you can edit the file
and add or remove holidays to your own taste, see
<https://github.com/itsallcode/holiday-calculator> for detailed description of
the syntax.
You can use one of the <a href="https://github.com/itsallcode/holiday-calculator/tree/main/holidays">predefined holiday definition files</a> or you can edit the file
and add or remove holidays to your own taste, see the <a href="https://github.com/itsallcode/holiday-calculator/blob/main/README.md#configuration-file">holiday-calculator documentation</a> for a detailed description of the syntax.

Note: WhiteRabbit adds holidays provided by plugins only to new months without any time recordings. As soon as the user adds a time recording for a particular month, WhiteRabbit saves the time recordings for this month including any holidays whether provided by plugins or entered manually. After this point in time for the given month WhiteRabbit uses only on the saved file and will not ask any plugin to update the holidays.
**Note:** WhiteRabbit adds holidays provided by plugins only to new months without any time recordings. As soon as the user adds a time recording for a particular month, WhiteRabbit saves the time recordings for this month including any holidays whether provided by plugins or entered manually. After this point in time for the given month WhiteRabbit uses only on the saved file and will not ask any plugin to update the holidays.

### <a name="development"></a>Development

Expand Down Expand Up @@ -231,18 +228,19 @@ the correct export.

Currently, you can configure the destination path, separator and flag in white rabbit's configuration file:

```properties
csv.destination = ~/working_time_reports
csv.separator = \t
csv.filter_for_weekdays = True
```
```properties
csv.destination = ~/working_time_reports
csv.separator = \t
csv.filter_for_weekdays = True
```

The default values are:

```Default Values
csv.destination = $HOME
csv.separator = ","
csv.filter_for_weekdays = False
```
```Default Values
csv.destination = $HOME
csv.separator = ","
csv.filter_for_weekdays = False
```

### <a name="development"></a>Development

Expand Down
29 changes: 19 additions & 10 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,21 @@ private void loadInitialData()
public void loadMonth(final YearMonth month)
{
final MonthIndex record = appService.getOrCreateMonth(month);
ensureMonthAvailable(month);
state.currentMonth.setValue(record);
}

private void ensureMonthAvailable(final YearMonth month)
{
JavaFxUtil.runOnFxApplicationThread(() -> {
if (!state.availableMonths.isEmpty() && !state.availableMonths.contains(month))
{
LOG.trace("Adding month {} to combo box", month);
state.availableMonths.add(month);
}
});
}

@Override
public void stop()
{
Expand Down Expand Up @@ -312,20 +324,17 @@ private boolean isButton(Optional<ButtonType> button, ButtonData data)
}

@Override
public void recordUpdated(DayRecord record)
public void recordUpdated(DayRecord day)
{
final YearMonth month = YearMonth.from(day.getDate());
JavaFxUtil.runOnFxApplicationThread(() -> {
final YearMonth recordMonth = YearMonth.from(record.getDate());
if (!state.availableMonths.isEmpty() && !state.availableMonths.contains(recordMonth))
{
state.availableMonths.add(recordMonth);
}
if (state.currentMonth.get().getYearMonth().equals(recordMonth))
ensureMonthAvailable(month);
if (state.currentMonth.get().getYearMonth().equals(month))
{
state.currentMonth.setValue(record.getMonth());
if (daySelected(record))
state.currentMonth.setValue(day.getMonth());
if (daySelected(day))
{
ui.updateActivities(record);
ui.updateActivities(day);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ private ToolBar createToolBar()
e -> app.startManualInterruption());
startInterruptionButton.disableProperty().bind(state.interruption.isNotNull());

return new ToolBar(monthDropDownBox(),
return new ToolBar(
UiWidget.button("previous-month-button", "<", "Select previous month", e -> gotoMonth(-1)),
monthDropDownBox(),
UiWidget.button("next-month-button", ">", "Select next month", e -> gotoMonth(+1)),
new Separator(),
startInterruptionButton,
interruptionPreset.createButton(),
Expand All @@ -269,6 +272,12 @@ private ToolBar createToolBar()
UiWidget.button("update-button", "Update", e -> appService.updateNow()));
}

private void gotoMonth(int step)
{
final YearMonth selecteMonth = state.currentMonth.get().getYearMonth().plusMonths(step);
app.loadMonth(selecteMonth);
}

private Button createStopWorkForTodayButton()
{
final Button button = new Button();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.itsallcode.whiterabbit.jfxui.testutil.TestUtil;
import org.itsallcode.whiterabbit.jfxui.testutil.model.DayTable;
import org.itsallcode.whiterabbit.jfxui.testutil.model.JavaFxTable;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
Expand Down Expand Up @@ -273,7 +272,6 @@ void higlightedWeekends()
}

@Test
@Disabled("Test is instable")
void higlightedWeekendsUpdatedWhenMonthChanges()
{
final DayTable dayTable = app().dayTable();
Expand All @@ -297,6 +295,22 @@ void higlightedWeekendsUpdatedWhenMonthChanges()
25, 26, 27, 30);
}

@Test
void nextButtonSelectsNextMonth()
{
assertThat(app().getSelectedMonth()).isEqualTo(YearMonth.of(2007, Month.DECEMBER));
app().gotoNextMonth();
assertThat(app().getSelectedMonth()).isEqualTo(YearMonth.of(2008, Month.JANUARY));
}

@Test
void prevButtonSelectsPrevMonth()
{
assertThat(app().getSelectedMonth()).isEqualTo(YearMonth.of(2007, Month.DECEMBER));
app().gotoPreviousMonth();
assertThat(app().getSelectedMonth()).isEqualTo(YearMonth.of(2007, Month.NOVEMBER));
}

@Test
void typingF5UpdatesData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ public void setSelectedMonth(YearMonth month)
JavaFxUtil.runOnFxApplicationThread(() -> getSelectedMonthComboBox().setValue(month));
}

public void gotoNextMonth()
{
clickButton("#next-month-button");
}

public void gotoPreviousMonth()
{
clickButton("#previous-month-button");
}

private void clickButton(String query)
{
final Button button = robot.lookup(query).queryButton();
robot.clickOn(button);
}

private ComboBox<YearMonth> getSelectedMonthComboBox()
{
return robot.lookup("#selected-month-combobox").queryComboBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,22 @@ public List<YearMonth> getAvailableDataMonths()
return fileStorage.getAvailableDataMonths();
}

private MonthIndex createNewMonth(YearMonth date)
private MonthIndex createNewMonth(YearMonth month)
{
final ModelFactory factory = fileStorage.getModelFactory();
final MonthData month = factory.createMonthData();
month.setYear(date.getYear());
month.setMonth(date.getMonth());
final List<DayData> days = holidayService.getHolidays(factory, date);
month.setDays(days);
month.setOvertimePreviousMonth(loadPreviousMonthOvertime(date));
return createMonthIndex(month);
final MonthData monthData = factory.createMonthData();
monthData.setYear(month.getYear());
monthData.setMonth(month.getMonth());
final List<DayData> days = holidayService.getHolidays(factory, month);
monthData.setDays(days);
monthData.setOvertimePreviousMonth(loadPreviousMonthOvertime(month));
final MonthIndex monthIndex = createMonthIndex(monthData);
if (!days.isEmpty())
{
LOG.trace("Found {} holidays: store month {}", days.size(), month);
storeMonth(monthIndex);
}
return monthIndex;
}

private MonthIndex createMonthIndex(final MonthData jsonMonth)
Expand Down

0 comments on commit 6f4f047

Please sign in to comment.