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 @@
-
-
+
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 @@