Skip to content

Commit bee4601

Browse files
committed
fixed report day availability and color. verifiyng repo call in change project. improved logging
1 parent ae9aa7e commit bee4601

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

src/main/java/de/doubleslash/keeptime/controller/Controller.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.doubleslash.keeptime.controller;
22

33
import java.time.Duration;
4+
import java.time.LocalDate;
45
import java.time.LocalDateTime;
56
import java.util.ArrayList;
67
import java.util.List;
@@ -45,6 +46,7 @@ public void changeProject(final Project newProject, final long minusSeconds) {
4546

4647
final Work currentWork = model.activeWorkItem.get();
4748

49+
final LocalDate dateNow = dateProvider.dateNow();
4850
final LocalDateTime now = dateProvider.dateTimeNow().minusSeconds(minusSeconds);
4951
if (currentWork != null) {
5052
currentWork.setEndTime(now);
@@ -63,11 +65,13 @@ public void changeProject(final Project newProject, final long minusSeconds) {
6365
}
6466

6567
// Start new work
66-
final Work work = new Work(dateProvider.dateNow(), now, now.plusSeconds(minusSeconds), newProject, "");
68+
final Work work = new Work(dateNow, now, now.plusSeconds(minusSeconds), newProject, "");
6769
model.pastWorkItems.add(work);
68-
if (currentWork != null && !currentWork.getCreationDate().isEqual(work.getCreationDate())) {
69-
Log.info("Removing projects from the other daya then today from list.");
70-
model.pastWorkItems.removeIf(w -> !w.getCreationDate().isEqual(work.getCreationDate()));
70+
if (currentWork != null && !dateNow.isEqual(currentWork.getCreationDate())) {
71+
Log.info("Removing projects with other creation date than today '{}' from list.", dateNow);
72+
final int sizeBefore = model.pastWorkItems.size();
73+
model.pastWorkItems.removeIf(w -> !dateNow.isEqual(w.getCreationDate()));
74+
Log.debug("Removed '{}' work items from past work items.", sizeBefore - model.pastWorkItems.size());
7175
}
7276
model.activeWorkItem.set(work);
7377
}

src/main/java/de/doubleslash/keeptime/view/ReportController.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
public class ReportController {
3333

34-
private static final String FX_BACKGROUND_COLOR_NOT_WORKED = "-fx-background-color: #ffc0cb;";
34+
private static final String FX_BACKGROUND_COLOR_NOT_WORKED = "-fx-background-color: #BBBBBB;";
3535

3636
@FXML
3737
private BorderPane topBorderPane;
@@ -64,15 +64,6 @@ private void initialize() {
6464
LOG.info("Datepicker selected value changed to {}", newvalue);
6565
updateReport(newvalue);
6666
});
67-
68-
// HACK to show calendar from datepicker
69-
// https://stackoverflow.com/questions/34681975/javafx-extract-calendar-popup-from-datepicker-only-show-popup
70-
final DatePickerSkin datePickerSkin = new DatePickerSkin(datePicker);
71-
final Node popupContent = datePickerSkin.getPopupContent();
72-
73-
// root.setCenter(popupContent);
74-
// topBorderPane.getChildren().add(popupContent);
75-
topBorderPane.setRight(popupContent);
7667
}
7768

7869
private void updateReport(final LocalDate newvalue) {
@@ -145,6 +136,9 @@ public void setModelAndController(final Model model, final Controller controller
145136
this.model = model;
146137
this.controller = controller;
147138

139+
// HACK to show calendar from datepicker
140+
// https://stackoverflow.com/questions/34681975/javafx-extract-calendar-popup-from-datepicker-only-show-popup
141+
final DatePickerSkin datePickerSkin = new DatePickerSkin(datePicker);
148142
final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
149143
@Override
150144
public DateCell call(final DatePicker datePicker) {
@@ -161,6 +155,8 @@ public void updateItem(final LocalDate item, final boolean empty) {
161155
}
162156
};
163157
datePicker.setDayCellFactory(dayCellFactory);
158+
final Node popupContent = datePickerSkin.getPopupContent();
159+
topBorderPane.setRight(popupContent);
164160
}
165161

166162
public void update() {

src/test/java/de/doubleslash/keeptime/controller/ControllerTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ public void changeProjectSameDayTest() {
186186
Mockito.when(mockedDateProvider.dateNow()).thenReturn(secondProjectDate);
187187
testee.changeProject(secondProject);
188188

189+
Mockito.verify(model.workRepository, Mockito.times(1)).save(Mockito.argThat((final Work savedWork) -> {
190+
if (savedWork.getProject() != firstProject) {
191+
return false;
192+
}
193+
if (!savedWork.getStartTime().equals(firstProjectDateTime)) {
194+
return false;
195+
}
196+
if (!savedWork.getEndTime().equals(secondProjectDateTime)) {
197+
return false;
198+
}
199+
return true;
200+
}));
189201
assertThat("Two project should be in the past work items", model.pastWorkItems.size(), is(2));
190202
assertThat("The first project should be the past work project", model.pastWorkItems.get(0).getProject(),
191203
is(firstProject));
@@ -209,7 +221,18 @@ public void changeProjectOtherDayTest() {
209221
Mockito.when(mockedDateProvider.dateNow()).thenReturn(secondProjectDate);
210222
testee.changeProject(secondProject);
211223

212-
Mockito.verify(model.workRepository, Mockito.times(1)).save(Mockito.any(Work.class));
224+
Mockito.verify(model.workRepository, Mockito.times(1)).save(Mockito.argThat((final Work savedWork) -> {
225+
if (savedWork.getProject() != firstProject) {
226+
return false;
227+
}
228+
if (!savedWork.getStartTime().equals(firstProjectDateTime)) {
229+
return false;
230+
}
231+
if (!savedWork.getEndTime().equals(secondProjectDateTime)) {
232+
return false;
233+
}
234+
return true;
235+
}));
213236
assertThat("One projects should be in the past work items", model.pastWorkItems.size(), is(1));
214237
assertThat("The project should be the second work project", model.pastWorkItems.get(0).getProject(),
215238
is(secondProject));

0 commit comments

Comments
 (0)