From a4809bac53a250f11aa8b4a1b83862da135077b2 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 3 Nov 2022 12:34:54 -0400 Subject: [PATCH] LP1995623 DateTime picker gets min/max date support Note this only affects the date select, since the time picker has no notion of a minimum time. Signed-off-by: Bill Erickson Signed-off-by: Susan Morrison Signed-off-by: Galen Charlton --- .../share/datetime-select/datetime-select.component.html | 4 +++- .../share/datetime-select/datetime-select.component.ts | 11 +++++++++++ Open-ILS/src/eg2/src/app/share/util/date.ts | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html index f25e29acee..48f10cbf50 100644 --- a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html @@ -29,9 +29,11 @@ role="alert" class="alert alert-danger"> error - {{firstError(controlDir.control.errors)}} + {{firstError(controlDir.control.errors)}} diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts index ed20e841a4..d9564a3dfd 100644 --- a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts @@ -4,6 +4,7 @@ import {AbstractControl, ControlValueAccessor, FormControl, FormGroup, NgControl import {NgbDatepicker, NgbTimeStruct, NgbDateStruct} from '@ng-bootstrap/ng-bootstrap'; import {DatetimeValidator} from '@eg/share/validators/datetime_validator.directive'; import * as moment from 'moment-timezone'; +import {DateUtil} from '@eg/share/util/date'; @Component({ selector: 'eg-datetime-select', @@ -18,6 +19,10 @@ export class DateTimeSelectComponent implements OnInit, ControlValueAccessor { @Input() showTZ = true; @Input() timezone: string = this.format.wsOrgTimezone; @Input() readOnly = false; + @Input() noPast = false; + @Input() noFuture = false; + @Input() minDate: any; + @Input() maxDate: any; @Output() onChangeAsIso: EventEmitter; dateTimeForm: FormGroup; @@ -53,6 +58,12 @@ export class DateTimeSelectComponent implements OnInit, ControlValueAccessor { } ngOnInit() { + if (this.noPast) { + this.minDate = DateUtil.localYmdPartsFromDate(); + } + if (this.noFuture) { + this.maxDate = DateUtil.localYmdPartsFromDate(); + } if (!this.timezone) { this.timezone = this.format.wsOrgTimezone; } diff --git a/Open-ILS/src/eg2/src/app/share/util/date.ts b/Open-ILS/src/eg2/src/app/share/util/date.ts index bca15963f3..681ba1883f 100644 --- a/Open-ILS/src/eg2/src/app/share/util/date.ts +++ b/Open-ILS/src/eg2/src/app/share/util/date.ts @@ -1,6 +1,12 @@ /* Utility code for dates */ +export interface YmdParts { + year: number; + month: number; + day: number; +} + export class DateUtil { /** @@ -66,5 +72,15 @@ export class DateUtil { ((now.getMonth() + 1) + '').padStart(2, '0') + '-' + (now.getDate() + '').padStart(2, '0'); } + + static localYmdPartsFromDate(date?: Date): YmdParts { + const ymd = DateUtil.localYmdFromDate(date); + const parts = ymd.split(/-/); + return { + year: Number(parts[0]), + month: Number(parts[1]), + day: Number(parts[2]) + }; + } } -- 2.11.0