From 4c9024851ae451eacd3b06a19d72f921ce402cd5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 7 Oct 2021 12:35:29 -0400 Subject: [PATCH] LP1840782 component Signed-off-by: Bill Erickson --- .../src/eg2/src/app/share/common-widgets.module.ts | 3 ++ .../date-select-native.component.html | 12 +++++ .../date-select-native.component.ts | 62 ++++++++++++++++++++++ .../src/app/staff/sandbox/sandbox.component.html | 11 ++++ .../eg2/src/app/staff/sandbox/sandbox.component.ts | 2 + 5 files changed, 90 insertions(+) create mode 100644 Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.html create mode 100644 Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.ts diff --git a/Open-ILS/src/eg2/src/app/share/common-widgets.module.ts b/Open-ILS/src/eg2/src/app/share/common-widgets.module.ts index fda671ec2c..0e961f4377 100644 --- a/Open-ILS/src/eg2/src/app/share/common-widgets.module.ts +++ b/Open-ILS/src/eg2/src/app/share/common-widgets.module.ts @@ -17,6 +17,7 @@ import {DateTimeSelectComponent} from '@eg/share/datetime-select/datetime-select import {ContextMenuModule} from '@eg/share/context-menu/context-menu.module'; import {FileReaderComponent} from '@eg/share/file-reader/file-reader.component'; import {IntervalInputComponent} from '@eg/share/interval-input/interval-input.component'; +import {DateSelectNativeComponent} from '@eg/share/date-select-native/date-select-native.component'; @NgModule({ @@ -29,6 +30,7 @@ import {IntervalInputComponent} from '@eg/share/interval-input/interval-input.co DateTimeSelectComponent, FileReaderComponent, IdlClassTemplateDirective, + DateSelectNativeComponent, IntervalInputComponent, ], imports: [ @@ -52,6 +54,7 @@ import {IntervalInputComponent} from '@eg/share/interval-input/interval-input.co DateTimeSelectComponent, ContextMenuModule, FileReaderComponent, + DateSelectNativeComponent, IntervalInputComponent, ], }) diff --git a/Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.html b/Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.html new file mode 100644 index 0000000000..a92fe3ed02 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.html @@ -0,0 +1,12 @@ + + diff --git a/Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.ts b/Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.ts new file mode 100644 index 0000000000..5fe5aa781c --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/date-select-native/date-select-native.component.ts @@ -0,0 +1,62 @@ +import {Component, OnInit, Input, Output, ViewChild, EventEmitter, forwardRef} from '@angular/core'; +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; +import {DateUtil} from '@eg/share/util/date'; + + +@Component({ + selector: 'eg-date-select-native', + templateUrl: './date-select-native.component.html', + providers: [{ + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => DateSelectNativeComponent), + multi: true + }] +}) +export class DateSelectNativeComponent implements OnInit, ControlValueAccessor { + + static domAutoId = 1; + + @Input() fieldName = ''; + @Input() required = false; + @Input() disabled = false; // Also works for readOnly + @Input() min = ''; // YYYY-MM-DD + @Input() max = ''; // YYYY-MM-DD + @Input() domId = 'eg-date-select-native-' + DateSelectNativeComponent.domAutoId++; + + // Emits YYYY-MM-DD on value change, null on empty. + @Output() dateChange: EventEmitter = new EventEmitter(); + + // Stub functions required by ControlValueAccessor + propagateChange = (_: any) => {}; + propagateTouch = () => {}; + + constructor() { } + + ngOnInit() { } + + input(): HTMLInputElement { + return document.getElementById(this.domId) as HTMLInputElement; + } + + inputChange(evt: Event) { + const value = this.input().value; + this.dateChange.emit(value || null); + this.propagateChange(value); + } + + writeValue(ymd: string) { + if (this.input()) { + this.input().value = ymd; + } + } + + registerOnChange(fn) { + this.propagateChange = fn; + } + + registerOnTouched(fn) { + this.propagateTouch = fn; + } +} + + diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 4415ecad02..c564da575e 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -2,6 +2,17 @@ +

Native Date Select

+
+
+ +
+
+ Value: {{nativeDate}} +
+
+