diff --git a/src/app/modules/shared/components/month-picker/month-picker.component.html b/src/app/modules/shared/components/month-picker/month-picker.component.html index 204ecb6d7..c5656aa4e 100644 --- a/src/app/modules/shared/components/month-picker/month-picker.component.html +++ b/src/app/modules/shared/components/month-picker/month-picker.component.html @@ -1,10 +1,31 @@ -
-
-
{{ month }}
-
+
+
+
+
+ +

+ {{selectedYearText}} +

+ +
+
+ +
+
+
+
+ +
+
+
+
+
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 1a404f058..d0e731fa7 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,5 @@ import { Component, OnInit, Output, EventEmitter } from '@angular/core'; +import * as moment from 'moment'; @Component({ selector: 'app-month-picker', @@ -6,18 +7,62 @@ import { Component, OnInit, Output, EventEmitter } from '@angular/core'; styleUrls: ['./month-picker.component.scss'] }) export class MonthPickerComponent implements OnInit { - @Output() monthSelected = new EventEmitter(); - activeMonth: number; - months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - constructor() { } + @Output() dateSelected = new EventEmitter<{ monthIndex: number; year: number; }>(); - ngOnInit(): void { - this.activeMonth = new Date().getMonth(); + selectedMonthMoment: moment.Moment; + selectedMonthIndex: number; + selectedYearMoment: moment.Moment; + selectedMonthYear: number; + + selectedYearText: string; + months: Array = []; + years: Array = []; + + constructor() { + this.selectedYearMoment = moment(); + this.selectedMonthMoment = moment(); + this.months = moment.months(); + this.selectedMonthIndex = this.selectedMonthMoment.month(); + this.selectedMonthYear = this.selectedYearMoment.year(); + this.updateYearText(); + } + + ngOnInit() { + this.selectDate(this.selectedMonthIndex, this.selectedMonthYear); + } + + updateYearText() { + this.selectedYearText = moment(this.selectedYearMoment).format('YYYY'); + } + + increment() { + this.selectedYearMoment = this.selectedYearMoment.add(1, 'year'); + this.updateYearText(); } - getMonth(month: number) { - this.monthSelected.emit(month + 1); - this.activeMonth = month; + decrement() { + this.selectedYearMoment = this.selectedYearMoment.subtract(1, 'year'); + this.updateYearText(); } + + selectMonth(index: number) { + this.selectedMonthMoment = moment().month(index); + this.selectedMonthIndex = this.selectedMonthMoment.month(); + this.selectedMonthYear = this.selectedYearMoment.year(); + this.selectDate(this.selectedMonthIndex, this.selectedMonthYear); + } + + isSelectedMonth(monthIndex: number) { + return ( + this.selectedMonthIndex === monthIndex && + this.selectedMonthYear === this.selectedYearMoment.year() + ); + } + + selectDate(monthIndex: number, year: number) { + this.dateSelected.emit({ monthIndex: monthIndex, year: year }); + } + } + diff --git a/src/app/modules/time-entries/pages/time-entries.component.html b/src/app/modules/time-entries/pages/time-entries.component.html index 8928eb656..8fabce8a2 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.html +++ b/src/app/modules/time-entries/pages/time-entries.component.html @@ -13,7 +13,7 @@
- +
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 5116b3254..11b924580 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.ts @@ -8,6 +8,7 @@ import { SaveEntryEvent } from '../../shared/components/details-fields/save-entr import { Entry } from '../../shared/models'; import { DataSource } from '../../shared/models/data-source.model'; import * as entryActions from '../../time-clock/store/entry.actions'; +import * as moment from 'moment'; import { EntryState } from '../../time-clock/store/entry.reducer'; import { EntryActionTypes } from './../../time-clock/store/entry.actions'; import { getActiveTimeEntry, getTimeEntriesDataSource } from './../../time-clock/store/entry.selectors'; @@ -26,6 +27,9 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { entriesSubscription: Subscription; canMarkEntryAsWIP = true; timeEntriesDataSource$: Observable>; + selectedYearAsText: string; + selectedMonthIndex: number; + selectedMonthAsText: string; constructor(private store: Store, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) { this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource)); @@ -107,7 +111,7 @@ 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)){ + if (!isEditingEntryEqualToActiveEntry && (isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry)){ this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.'); } else { this.doSave(event); @@ -160,8 +164,11 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { this.showModal = false; } - getMonth(month: number) { - this.store.dispatch(new entryActions.LoadEntries(month)); + dateSelected(event: { monthIndex: number; year: number }) { + this.selectedYearAsText = event.year.toString(); + this.selectedMonthIndex = event.monthIndex; + this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM'); + this.store.dispatch(new entryActions.LoadEntries(event.monthIndex)); } openModal(item: any) { diff --git a/tslint.json b/tslint.json index 37c500fe1..eda9ad204 100644 --- a/tslint.json +++ b/tslint.json @@ -76,6 +76,7 @@ "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"