Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/app/modules/time-entries/pages/time-entries.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,30 @@ describe('TimeEntriesComponent', () => {
component.resetDraggablePosition(dragEndEventStub);
expect(dragEndEventStub.source._dragRef.reset).toHaveBeenCalled();
});

it('component.doSave shouldn´t be called when saving the runningEntry with start_date overlapped', () => {
const startDate = new Date(2021, 6, 1, 10, 0);
const endDate = new Date(2021, 6, 1, 10, 55);
const newRunningEntry = { start_date: endDate, id: '1234', technologies: [], project_name: 'time-tracker', running: true };
const newEntry = { start_date: startDate, end_date: endDate, id: '4321', technologies: [], project_name: 'time-tracker'};

state.timeEntriesDataSource.data = [newRunningEntry, newEntry];
component.activeTimeEntry = newRunningEntry;
component.entryId = newRunningEntry.id;
spyOn(component, 'doSave');

const startDateModified = new Date(2021, 6, 1, 10, 50);
Copy link
Collaborator

@scastillo-jp scastillo-jp Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is correct this format?

const RunningEntryModified = {
entry: {
start_date: startDateModified,
id: '1234',
technologies: ['py'],
project_name: 'time-tracker',
running: true
}, shouldRestartEntry: false
};
component.saveEntry(RunningEntryModified);

expect(component.doSave).toHaveBeenCalledTimes(0);
});
});
20 changes: 18 additions & 2 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
selectedMonth: number;
selectedYear: number;
selectedMonthAsText: string;
isActiveEntryOverlapping = false;
constructor(private store: Store<EntryState>, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) {
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
}
Expand Down Expand Up @@ -104,8 +105,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate;
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
this.checkIfActiveEntryOverlapping(isEditingEntryEqualToActiveEntry, startDateAsLocalDate);
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping || this.isActiveEntryOverlapping ) {
const message = this.isActiveEntryOverlapping ? 'try another "Time in"' : 'try with earlier times';
this.toastrService.error(`You are on the clock and this entry overlaps it, ${message}.`);
this.isActiveEntryOverlapping = false;
} else {
this.doSave(event);
}
Expand Down Expand Up @@ -170,4 +174,16 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
resetDraggablePosition(event: any): void {
event.source._dragRef.reset();
}

checkIfActiveEntryOverlapping(isEditingEntryEqualToActiveEntry: boolean, startDateAsLocalDate: Date) {
if (isEditingEntryEqualToActiveEntry) {
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
const overlappingEntry = ds.data.find((item) => {
const itemEndDate = new Date(item.end_date);
return startDateAsLocalDate < itemEndDate;
});
this.isActiveEntryOverlapping = overlappingEntry ? true : false;
});
}
}
}