Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
fix: TT-91 Small code corrections
  • Loading branch information
lenshinoda committed Jun 4, 2021
commit 8fe9384b016ba844fa272d762a244fb4b0e10f9b
23 changes: 13 additions & 10 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate;
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;

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;
});
}
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}.`);
Expand Down Expand Up @@ -183,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;
});
}
}
}