Skip to content

Commit a914e06

Browse files
authored
Merge pull request #42 from doubleSlashde/feature/#28_edit_work_times
Feature/#28 edit work times
2 parents 4fa50bf + 5f2a55a commit a914e06

File tree

12 files changed

+610
-52
lines changed

12 files changed

+610
-52
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/common/Resources.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public enum RESOURCE {
3939
FXML_REPORT("/layouts/report.fxml"),
4040
FXML_ABOUT("/layouts/about.fxml"),
4141
FXML_MANAGE_PROJECT("/layouts/manage-project.fxml"),
42+
FXML_MANAGE_WORK("/layouts/manage-work.fxml"),
4243

4344
// icon
4445
ICON_MAIN("/icons/icon.png"),
4546

4647
;
48+
4749
String resourceLocation;
4850

4951
private RESOURCE(final String resourceLocation) {

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,38 @@ public void editProject(final Project projectToBeUpdated, final Project newValue
184184
model.getProjectRepository().saveAll(changedProjects);
185185
}
186186

187+
public void editWork(final Work workToBeEdited, final Work newValuedWork) {
188+
LOG.info("Changing work '{}' to '{}'.", workToBeEdited, newValuedWork);
189+
190+
workToBeEdited.setCreationDate(newValuedWork.getCreationDate());
191+
workToBeEdited.setStartTime(newValuedWork.getStartTime());
192+
workToBeEdited.setEndTime(newValuedWork.getEndTime());
193+
workToBeEdited.setNotes(newValuedWork.getNotes());
194+
workToBeEdited.setProject(newValuedWork.getProject());
195+
196+
final Work editedWork = model.getWorkRepository().save(workToBeEdited);
197+
198+
// remove old
199+
model.getPastWorkItems().removeIf(w -> (w.getId() == workToBeEdited.getId()));
200+
// add if started today
201+
final LocalDate dateNow = dateProvider.dateTimeNow().toLocalDate();
202+
if (dateNow.equals(editedWork.getCreationDate())) {
203+
model.getPastWorkItems().add(editedWork);
204+
}
205+
206+
}
207+
187208
/**
188209
* Changes the indexes of the originalList parameter to have a consistent order.
189210
*
190211
* @param originalList
191-
* list of all projects to adapt the indexes for
212+
* list of all projects to adapt the indexes for
192213
* @param changedProject
193-
* the project which has changed which already has the new index
214+
* the project which has changed which already has the new index
194215
* @param oldIndex
195-
* the old index of the changed project
216+
* the old index of the changed project
196217
* @param newIndex
197-
* the new index of the changed project (which the projects also already has)
218+
* the new index of the changed project (which the projects also already has)
198219
* @return all projects whose index has been adapted
199220
*/
200221
List<Project> resortProjectIndexes(final List<Project> originalList, final Project changedProject,
@@ -231,9 +252,9 @@ List<Project> resortProjectIndexes(final List<Project> originalList, final Proje
231252
* Decreases all indexes by one, after the removed index
232253
*
233254
* @param originalList
234-
* list of all projects to adapt the indexes for
255+
* list of all projects to adapt the indexes for
235256
* @param removedIndex
236-
* the index which has been removed
257+
* the index which has been removed
237258
* @return all projects whose index has been adapted
238259
*/
239260
List<Project> adaptProjectIndexesAfterRemoving(final List<Project> originalList, final int removedIndex) {
@@ -298,4 +319,5 @@ public long calcSeconds(final List<Work> workItems) {
298319

299320
return seconds;
300321
}
322+
301323
}

src/main/java/de/doubleslash/keeptime/model/Model.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Comparator;
2020

2121
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.context.ConfigurableApplicationContext;
2223
import org.springframework.stereotype.Component;
2324

2425
import de.doubleslash.keeptime.model.repos.ProjectRepository;
@@ -63,6 +64,8 @@ public Model(final ProjectRepository projectRepository, final WorkRepository wor
6364
private ObservableList<Project> allProjects = FXCollections.observableArrayList();
6465

6566
protected final ObservableList<Work> pastWorkItems = FXCollections.observableArrayList();
67+
private final SortedList<Work> sortedPastWorkItems = new SortedList<>(pastWorkItems,
68+
Comparator.comparing(Work::getStartTime));
6669
public final ObjectProperty<Work> activeWorkItem = new SimpleObjectProperty<>();
6770

6871
public final ObjectProperty<Color> taskBarColor = new SimpleObjectProperty<>(ORIGINAL_TASK_BAR_FONT_COLOR);
@@ -76,6 +79,9 @@ public Model(final ProjectRepository projectRepository, final WorkRepository wor
7679
public final ObjectProperty<Boolean> useHotkey = new SimpleObjectProperty<>(false);
7780
public final ObjectProperty<Boolean> displayProjectsRight = new SimpleObjectProperty<>(false);
7881
public final ObjectProperty<Boolean> hideProjectsOnMouseExit = new SimpleObjectProperty<>(true);
82+
public final ObjectProperty<Boolean> emptyNoteReminder = new SimpleObjectProperty<>(false);
83+
84+
private ConfigurableApplicationContext springContext;
7985

8086
public void setWorkRepository(final WorkRepository workRepository) {
8187
this.workRepository = workRepository;
@@ -128,4 +134,16 @@ public ObservableList<Project> getAvailableProjects() {
128134
public ObservableList<Project> getAllProjects() {
129135
return allProjects;
130136
}
137+
138+
public void setSpringContext(final ConfigurableApplicationContext springContext) {
139+
this.springContext = springContext;
140+
}
141+
142+
public ConfigurableApplicationContext getSpringContext() {
143+
return this.springContext;
144+
}
145+
146+
public SortedList<Work> getSortedPastWorkItems() {
147+
return sortedPastWorkItems;
148+
}
131149
}

src/main/java/de/doubleslash/keeptime/model/Work.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class Work {
3636
@Column(name = "id", updatable = false, nullable = false)
3737
private long id;
3838

39+
// TODO revise CreationDate Logic to use Date of StartTime
3940
private LocalDate creationDate;
4041
private LocalDateTime startTime;
4142
private LocalDateTime endTime;
@@ -45,7 +46,8 @@ public class Work {
4546
@Lob
4647
private String notes;
4748

48-
public Work() {}
49+
public Work() {
50+
}
4951

5052
public Work(final LocalDate creationDate, final LocalDateTime startTime, final LocalDateTime endTime,
5153
final Project project, final String notes) {
@@ -89,6 +91,10 @@ public Project getProject() {
8991
return project;
9092
}
9193

94+
public void setProject(final Project project) {
95+
this.project = project;
96+
}
97+
9298
public String getNotes() {
9399
return notes;
94100
}
@@ -97,4 +103,10 @@ public void setNotes(final String notes) {
97103
this.notes = notes;
98104
}
99105

106+
@Override
107+
public String toString() {
108+
return "Work [id=" + id + ", creationDate=" + creationDate + ", startTime=" + startTime + ", endTime=" + endTime
109+
+ ", projectName=" + project.getName() + ", notes=" + notes + "]";
110+
}
111+
100112
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
@Repository
2828
public interface WorkRepository extends JpaRepository<Work, Long> {
2929

30-
List<Work> findByCreationDate(LocalDate creationDate);
30+
List<Work> findByCreationDateOrderByStartTimeAsc(LocalDate creationDate);
3131
}

0 commit comments

Comments
 (0)