diff --git a/src/app/modules/shared/components/month-picker/month-picker.component.spec.ts b/src/app/modules/shared/components/month-picker/month-picker.component.spec.ts index 14f5f49ac..ea46623f0 100644 --- a/src/app/modules/shared/components/month-picker/month-picker.component.spec.ts +++ b/src/app/modules/shared/components/month-picker/month-picker.component.spec.ts @@ -33,6 +33,7 @@ describe('MonthPickerComponent', () => { expect(component.dateSelected.emit({ monthIndex: month, year: year })); }); + it('should add a year to current year', () => { component.selectedYearMoment = moment(); const incrementYear = moment().add(1, 'year').format('Y'); @@ -57,4 +58,13 @@ describe('MonthPickerComponent', () => { expect(component.selectedYearMoment.format('Y')).toEqual(decrementYear); }); + + it('selectMonth should call selectDates', () => { + spyOn(component, 'selectDate'); + + component.selectMonth(8); + + expect(component.selectDate).toHaveBeenCalledWith(8, 2020); + }); + }); diff --git a/src/app/modules/shared/components/month-picker/month-picker.component.ts b/src/app/modules/shared/components/month-picker/month-picker.component.ts index 8041c9efc..902b13de9 100644 --- a/src/app/modules/shared/components/month-picker/month-picker.component.ts +++ b/src/app/modules/shared/components/month-picker/month-picker.component.ts @@ -1,4 +1,3 @@ -import { SubstractDatePipe } from './../../pipes/substract-date/substract-date.pipe'; import { Component, OnInit, Output, EventEmitter } from '@angular/core'; import * as moment from 'moment'; diff --git a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts index b799c4b6b..d5327d8c1 100644 --- a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts +++ b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts @@ -32,8 +32,6 @@ export class EntryFieldsComponent implements OnInit { newData; lastEntry; showTimeInbuttons = false; - month = new Date().getMonth(); - year = new Date().getFullYear(); constructor( private formBuilder: FormBuilder, @@ -52,7 +50,7 @@ export class EntryFieldsComponent implements OnInit { ngOnInit(): void { this.store.dispatch(new LoadActivities()); - this.store.dispatch(new entryActions.LoadEntries(this.month, this.year)); + this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1, new Date().getFullYear())); this.actionsSubject$ .pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS)) .subscribe((action) => { diff --git a/src/app/modules/time-clock/services/entry.service.spec.ts b/src/app/modules/time-clock/services/entry.service.spec.ts index 681fe51e0..ca2630120 100644 --- a/src/app/modules/time-clock/services/entry.service.spec.ts +++ b/src/app/modules/time-clock/services/entry.service.spec.ts @@ -58,7 +58,7 @@ describe('EntryService', () => { const month = new Date().getMonth(); const timezoneOffset = new Date().getTimezoneOffset(); - service.loadEntries(year, month).subscribe(); + service.loadEntries({ year, month }).subscribe(); const loadEntryRequest = httpMock.expectOne(`${service.baseUrl}?month=${month}&year=${year}&timezone_offset=${timezoneOffset}`); expect(loadEntryRequest.request.method).toBe('GET'); diff --git a/src/app/modules/time-clock/services/entry.service.ts b/src/app/modules/time-clock/services/entry.service.ts index 25d64ea80..2506b4a5b 100644 --- a/src/app/modules/time-clock/services/entry.service.ts +++ b/src/app/modules/time-clock/services/entry.service.ts @@ -23,9 +23,9 @@ export class EntryService { return this.http.get(`${this.baseUrl}/running`); } - loadEntries(year, month): Observable { + loadEntries(date): Observable { const timezoneOffset = new Date().getTimezoneOffset(); - return this.http.get(`${this.baseUrl}?month=${month}&year=${year}&timezone_offset=${timezoneOffset}`); + return this.http.get(`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`); } createEntry(entryData): Observable { diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index ea5973c4e..58aa988ad 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -87,10 +87,9 @@ export class EntryEffects { @Effect() loadEntries$: Observable = this.actions$.pipe( ofType(actions.EntryActionTypes.LOAD_ENTRIES), - // tslint:disable-next-line:no-unused-expression - map((action: actions.LoadEntries) => (action.month, action.year)), - mergeMap((month, year) => - this.entryService.loadEntries(month, year).pipe( + map((action: actions.LoadEntries) => action), + mergeMap((date) => + this.entryService.loadEntries({ month: date.month, year: date.year }).pipe( map((entries) => new actions.LoadEntriesSuccess(entries)), catchError((error) => { this.toastrService.warning(`The data could not be loaded`); @@ -98,7 +97,6 @@ export class EntryEffects { }) ) ) - ); @Effect() @@ -228,7 +226,10 @@ export class EntryEffects { ofType(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY), map((action: actions.UpdateCurrentOrLastEntry) => action.payload), switchMap((entry) => - this.entryService.loadEntries(new Date().getMonth() + 1, new Date().getFullYear()).pipe( + this.entryService.loadEntries({ + month : new Date().getMonth() + 1, + year: new Date().getFullYear() + }).pipe( map((entries) => { const lastEntry = entries[1]; const isStartTimeInLastEntry = moment(entry.start_date).isBefore(lastEntry.end_date); diff --git a/src/app/modules/time-entries/pages/time-entries.component.spec.ts b/src/app/modules/time-entries/pages/time-entries.component.spec.ts index 2d83a344e..05168742e 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.spec.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.spec.ts @@ -126,7 +126,7 @@ describe('TimeEntriesComponent', () => { })); it('when create time entries, the time entries should be queried', () => { - const currentMonth = new Date().getMonth(); + const currentMonth = new Date().getMonth() + 1; const year = new Date().getFullYear(); const entryToSave = { entry: { diff --git a/src/app/modules/time-entries/pages/time-entries.component.ts b/src/app/modules/time-entries/pages/time-entries.component.ts index 62503d972..6e86b6067 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.ts @@ -1,4 +1,3 @@ -import { formatDate } from '@angular/common'; import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActionsSubject, select, Store } from '@ngrx/store'; import { ToastrService } from 'ngx-toastr'; @@ -32,9 +31,6 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { selectedMonthIndex: number; selectedMonthAsText: string; - currentMonth = new Date().getMonth(); - year = new Date().getFullYear(); - constructor(private store: Store, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) { this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource)); } @@ -44,9 +40,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { } ngOnInit(): void { - - this.store.dispatch(new entryActions.LoadEntries(this.selectedMonthIndex, this.year)); - + this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1, new Date().getFullYear())); this.loadActiveEntry(); this.entriesSubscription = this.actionsSubject$.pipe( @@ -58,6 +52,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { ) ).subscribe((action) => { this.loadActiveEntry(); + this.store.dispatch(new entryActions.LoadEntries(this.selectedMonthIndex, new Date().getFullYear())); }); } @@ -116,7 +111,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { const isEditingEntryEqualToActiveEntry = this.entryId === this.activeTimeEntry.id; const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate; const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate; - if (!isEditingEntryEqualToActiveEntry && (isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry)){ + const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry; + if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) { this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.'); } else { this.doSave(event); @@ -171,9 +167,9 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { dateSelected(event: { monthIndex: number; year: number }) { this.selectedYearAsText = event.year.toString(); - this.selectedMonthIndex = event.monthIndex; + this.selectedMonthIndex = event.monthIndex + 1; this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM'); - this.store.dispatch(new entryActions.LoadEntries(event.monthIndex + 1, event.year)); + this.store.dispatch(new entryActions.LoadEntries(this.selectedMonthIndex, event.year)); } openModal(item: any) { diff --git a/tslint.json b/tslint.json index eda9ad204..37c500fe1 100644 --- a/tslint.json +++ b/tslint.json @@ -76,7 +76,6 @@ "no-redundant-jsdoc": true, "no-switch-case-fall-through": true, "no-var-requires": false, - "object-literal-shorthand": false, "object-literal-key-quotes": [ true, "as-needed"