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({
DateRangeSelectComponent,
DateTimeSelectComponent,
FileReaderComponent,
- IdlClassTemplateDirective
+ IdlClassTemplateDirective,
+ IntervalInputComponent,
],
imports: [
CommonModule,
DateTimeSelectComponent,
ContextMenuModule,
FileReaderComponent,
+ IntervalInputComponent,
],
})
--- /dev/null
+<div class="input-group">
+ <input class="form-control" type="numeric" [(ngModel)]="period" (ngModelChange)="changeListener()" />
+ <select class="form-control" [(ngModel)]="unit" (ngModelChange)="changeListener()">
+ <option value="hours" i18n>hours</option>
+ <option value="days" i18n>days</option>
+ <option value="weeks" i18n>weeks</option>
+ <option value="months" i18n>months</option>
+ <option value="years" i18n>years</option>
+ </select>
+</div>
--- /dev/null
+/**
+ * <eg-interval-input [(ngModel)]="interval">
+ * </eg-interval-input>
+ */
+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;
+ }
+}