From: Bill Erickson Date: Thu, 3 Nov 2022 16:34:54 +0000 (-0400) Subject: LP1995623 DateTime picker gets min/max date support X-Git-Url: http://git.equinoxoli.org/?p=evergreen-equinox.git;a=commitdiff_plain;h=a4809bac53a250f11aa8b4a1b83862da135077b2 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 --- 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 f25e29a..48f10cb 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 ed20e84..d9564a3 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 bca1596..681ba18 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]) + }; + } }