Skip to content

Commit bd6bcc6

Browse files
committed
fixed timelines after editing considering start date
1 parent db44335 commit bd6bcc6

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/main/java/de/doubleslash/keeptime/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ private void initialiseApplication(final Stage primaryStage) throws Exception {
137137
FontProvider.loadFonts();
138138
readSettings();
139139

140-
final List<Work> todaysWorkItems = model.getWorkRepository().findByCreationDate(LocalDate.now());
140+
final List<Work> todaysWorkItems = model.getWorkRepository()
141+
.findByCreationDateOrderByStartTimeAsc(LocalDate.now());
141142
LOG.info("Found {} past work items", todaysWorkItems.size());
142143
model.getPastWorkItems().addAll(todaysWorkItems);
143144

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,17 @@ public void editProject(final Project projectToBeUpdated, final Project newValue
186186

187187
public void editWork(final Work workToBeEdited, final Work newValuedWork) {
188188
LOG.info("Changing work '{}' to '{}'.", workToBeEdited, newValuedWork);
189-
Work toRemove = null;
190-
for (final Work w : model.getPastWorkItems()) {
191-
if (w.getId() == workToBeEdited.getId()) {
192-
toRemove = w;
193-
LOG.debug("changing past Work");
189+
int index = model.getPastWorkItems().size() - 1;
190+
for (int i = 0; i < model.getPastWorkItems().size(); i++) {
191+
final Work work = model.getPastWorkItems().get(i);
192+
if (work.getId() == workToBeEdited.getId()) {
193+
model.getPastWorkItems().remove(work);
194+
continue;
195+
}
196+
if (work.getStartTime().isAfter(newValuedWork.getStartTime())) {
197+
index = i;
198+
break;
194199
}
195-
}
196-
197-
int index;
198-
if (toRemove != null) {
199-
index = model.getPastWorkItems().indexOf(toRemove);
200-
model.getPastWorkItems().remove(index);
201-
} else {
202-
// TODO sort in right Place
203-
index = model.getPastWorkItems().size() - 1;
204200
}
205201

206202
workToBeEdited.setCreationDate(newValuedWork.getCreationDate());

src/main/java/de/doubleslash/keeptime/model/repos/WorkRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@
2828
public interface WorkRepository extends JpaRepository<Work, Long> {
2929

3030
List<Work> findByCreationDate(LocalDate creationDate);
31+
32+
List<Work> findByCreationDateOrderByStartTimeAsc(LocalDate creationDate);
3133
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ private void updateReport(final LocalDate dateToShow) {
124124
reportRoot.requestFocus();
125125

126126
this.currentDayLabel.setText(DateFormatter.toDayDateString(dateToShow));
127-
final List<Work> currentWorkItems = model.getWorkRepository().findByCreationDate(dateToShow);
127+
final List<Work> currentWorkItems = model.getWorkRepository().findByCreationDateOrderByStartTimeAsc(dateToShow);
128+
;
128129

129130
colorTimeLine.update(currentWorkItems, controller.calcSeconds(currentWorkItems));
130131

0 commit comments

Comments
 (0)