From: Galen Charlton Date: Fri, 31 Jan 2020 23:13:59 +0000 (-0500) Subject: LP#1850547: new eg-interval-input: Angular component for inputting time intervals X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9d79b06e80c053421a05a2298c4c7516e828afa5;p=Evergreen.git LP#1850547: new eg-interval-input: Angular component for inputting time intervals Usage: This provides a simple combination of a numeric input and a drop-down for time interval units. Sponsored-by: Evergreen Community Development Initiative Sponsored-by: Georgia Public Library Service Sponsored-by: Indiana State Library Sponsored-by: C/W MARS Signed-off-by: Galen Charlton Signed-off-by: Tiffany Little Signed-off-by: Bill Erickson --- 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 c0b0f4e821..fda671ec2c 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 @@ -16,6 +16,7 @@ import {DateRangeSelectComponent} from '@eg/share/daterange-select/daterange-sel import {DateTimeSelectComponent} from '@eg/share/datetime-select/datetime-select.component'; 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'; @NgModule({ @@ -27,7 +28,8 @@ import {FileReaderComponent} from '@eg/share/file-reader/file-reader.component'; DateRangeSelectComponent, DateTimeSelectComponent, FileReaderComponent, - IdlClassTemplateDirective + IdlClassTemplateDirective, + IntervalInputComponent, ], imports: [ CommonModule, @@ -50,6 +52,7 @@ import {FileReaderComponent} from '@eg/share/file-reader/file-reader.component'; DateTimeSelectComponent, ContextMenuModule, FileReaderComponent, + IntervalInputComponent, ], }) diff --git a/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.html b/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.html new file mode 100644 index 0000000000..5b9919b90d --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.html @@ -0,0 +1,10 @@ +
+ + +
diff --git a/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts b/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts new file mode 100644 index 0000000000..c3d8a3cef5 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts @@ -0,0 +1,50 @@ +/** + * + * + */ +import {Component, OnInit, Input, Output, ViewChild, + TemplateRef, EventEmitter, ElementRef, forwardRef} from '@angular/core'; +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; +import {Observable, of, Subject} from 'rxjs'; +import {map, tap, reduce, mergeMap, mapTo, debounceTime, distinctUntilChanged, merge, filter} from 'rxjs/operators'; + +@Component({ + selector: 'eg-interval-input', + templateUrl: './interval-input.component.html', + providers: [{ + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => IntervalInputComponent), + multi: true + }] +}) +export class IntervalInputComponent implements ControlValueAccessor, OnInit { + + period: string; + unit = 'days'; + + // Stub functions required by ControlValueAccessor + propagateChange = (_: any) => {}; + propagateTouch = () => {}; + + ngOnInit() { + } + + changeListener(): void { + this.propagateChange(this.period + ' ' + this.unit); + } + + writeValue(value: string) { + if (value) { + this.period = value.split(' ')[0]; + this.unit = value.split(' ')[1]; + } + } + + registerOnChange(fn) { + this.propagateChange = fn; + } + + registerOnTouched(fn) { + this.propagateTouch = fn; + } +}