Skip to content

Commit 1add612

Browse files
authored
fix: TT-262 disable buttons futures in time entries and disable input date futures (#697)
* fix: TT-262 disable buttoms futures in time entries and disable input-date futures in reports, test of method monthEnable * fix: TT-262 disable buttoms futures in time entries and disable input-date futures in reports, test of method monthEnable * fix: TT-262 refactor code based on PR reviews
1 parent 5124806 commit 1add612

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ testem.log
4444
keys.ts
4545
src/environments/keys.ts
4646
debug.log
47+
*.vscode
4748

4849
# System Files
4950
.DS_Store

src/app/modules/reports/components/time-range-form/time-range-form.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ export class TimeRangeFormComponent implements OnInit {
3030
setInitialDataOnScreen() {
3131
this.reportForm.setValue({
3232
startDate: formatDate(moment().startOf('week').format('l'), DATE_FORMAT, 'en'),
33-
endDate: formatDate(moment().endOf('week').format('l'), DATE_FORMAT, 'en')
33+
endDate: formatDate(moment().format('l'), DATE_FORMAT, 'en')
3434
});
3535
this.onSubmit();
3636
}
37-
3837
onSubmit() {
3938
const endDate = moment(this.endDate.value).endOf('day');
4039
const startDate = moment(this.startDate.value).startOf('day');

src/app/modules/shared/components/input-date/input-date.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
required="required"
99
[matDatepicker]="datepicker"
1010
(click)="openOrCloseDatePicker(datepicker)"
11+
[max]="getCurrentDate()"
1112
/>
1213
<mat-datepicker #datepicker ></mat-datepicker>

src/app/modules/shared/components/input-date/input-date.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ export class InputDateComponent implements ControlValueAccessor {
5454
openOrCloseDatePicker(datepicker: MatDatepicker<Date>): void {
5555
return datepicker.opened ? datepicker.close() : datepicker.open();
5656
}
57+
getCurrentDate(): string {
58+
return moment(new Date()).format(DATE_FORMAT_YEAR);
59+
}
5760
}

src/app/modules/shared/components/month-picker/month-picker.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
<div class="spacing col-xl-1 col-lg-1 col-md-2 col-2" *ngFor="let month of months; let i = index">
2424
<button class="btn btn-light btn-block"
2525
[ngClass]="{'btn-primary': isSelectedMonth(i)}"
26-
(click)="selectMonth(i)">
26+
(click)="selectMonth(i)"
27+
[disabled]="monthEnable(i)">
2728
<small>{{ month.slice(0, 3) }}</small>
2829
</button>
2930
</div>

src/app/modules/shared/components/month-picker/month-picker.component.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { MonthPickerComponent } from './month-picker.component';
77
describe('MonthPickerComponent', () => {
88
let component: MonthPickerComponent;
99
let fixture: ComponentFixture<MonthPickerComponent>;
10-
1110
beforeEach(waitForAsync(() => {
1211
TestBed.configureTestingModule({
1312
declarations: [ MonthPickerComponent ]
@@ -69,4 +68,9 @@ describe('MonthPickerComponent', () => {
6968
expect(component.selectDate).toHaveBeenCalledWith(monthSelect, yearSelect);
7069
});
7170

71+
it('monthEnable sets disabled to true on futures months', () => {
72+
const monthFuture = component.monthCurrent + 1;
73+
expect(component.monthEnable(monthFuture)).toBeTrue();
74+
});
75+
7276
});

src/app/modules/shared/components/month-picker/month-picker.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class MonthPickerComponent implements OnInit {
2020
months: Array<string> = [];
2121
currentYear = new Date().getFullYear();
2222
showArrowNext = false;
23-
23+
monthCurrent = moment().month();
2424
constructor() {
2525
this.selectedYearMoment = moment();
2626
this.selectedMonthMoment = moment();
@@ -49,7 +49,12 @@ export class MonthPickerComponent implements OnInit {
4949
this.selectedMonthIndex = monthIndex;
5050
this.selectDate(this.selectedMonthIndex, this.selectedYear);
5151
}
52-
52+
monthEnable(monthIndex: number){
53+
return(
54+
this.monthCurrent < monthIndex &&
55+
this.selectedYear === this.currentYear
56+
);
57+
}
5358
isSelectedMonth(monthIndex: number) {
5459
return (
5560
this.selectedMonthIndex === monthIndex &&

0 commit comments

Comments
 (0)