Skip to content

Commit 8fc0ca9

Browse files
authored
fix: TT-91 Time out of the penultimate entry overlaps the entry that is running (#695)
* fix: TT-91 The time out of the penultimate time entry overlaps the time entry that is running * fix: TT-91 Small code corrections
1 parent ac24beb commit 8fc0ca9

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,30 @@ describe('TimeEntriesComponent', () => {
455455
component.resetDraggablePosition(dragEndEventStub);
456456
expect(dragEndEventStub.source._dragRef.reset).toHaveBeenCalled();
457457
});
458+
459+
it('component.doSave shouldn´t be called when saving the runningEntry with start_date overlapped', () => {
460+
const startDate = new Date(2021, 6, 1, 10, 0);
461+
const endDate = new Date(2021, 6, 1, 10, 55);
462+
const newRunningEntry = { start_date: endDate, id: '1234', technologies: [], project_name: 'time-tracker', running: true };
463+
const newEntry = { start_date: startDate, end_date: endDate, id: '4321', technologies: [], project_name: 'time-tracker'};
464+
465+
state.timeEntriesDataSource.data = [newRunningEntry, newEntry];
466+
component.activeTimeEntry = newRunningEntry;
467+
component.entryId = newRunningEntry.id;
468+
spyOn(component, 'doSave');
469+
470+
const startDateModified = new Date(2021, 6, 1, 10, 50);
471+
const RunningEntryModified = {
472+
entry: {
473+
start_date: startDateModified,
474+
id: '1234',
475+
technologies: ['py'],
476+
project_name: 'time-tracker',
477+
running: true
478+
}, shouldRestartEntry: false
479+
};
480+
component.saveEntry(RunningEntryModified);
481+
482+
expect(component.doSave).toHaveBeenCalledTimes(0);
483+
});
458484
});

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
3232
selectedMonth: number;
3333
selectedYear: number;
3434
selectedMonthAsText: string;
35+
isActiveEntryOverlapping = false;
3536
constructor(private store: Store<EntryState>, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) {
3637
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
3738
}
@@ -104,8 +105,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
104105
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate;
105106
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
106107
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;
107-
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) {
108-
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
108+
this.checkIfActiveEntryOverlapping(isEditingEntryEqualToActiveEntry, startDateAsLocalDate);
109+
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping || this.isActiveEntryOverlapping ) {
110+
const message = this.isActiveEntryOverlapping ? 'try another "Time in"' : 'try with earlier times';
111+
this.toastrService.error(`You are on the clock and this entry overlaps it, ${message}.`);
112+
this.isActiveEntryOverlapping = false;
109113
} else {
110114
this.doSave(event);
111115
}
@@ -170,4 +174,16 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
170174
resetDraggablePosition(event: any): void {
171175
event.source._dragRef.reset();
172176
}
177+
178+
checkIfActiveEntryOverlapping(isEditingEntryEqualToActiveEntry: boolean, startDateAsLocalDate: Date) {
179+
if (isEditingEntryEqualToActiveEntry) {
180+
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
181+
const overlappingEntry = ds.data.find((item) => {
182+
const itemEndDate = new Date(item.end_date);
183+
return startDateAsLocalDate < itemEndDate;
184+
});
185+
this.isActiveEntryOverlapping = overlappingEntry ? true : false;
186+
});
187+
}
188+
}
173189
}

0 commit comments

Comments
 (0)