@bi8/am-dyn-form
Version:
ng update @angular/cli yarn add @angular/cli
1,418 lines • 65 kB
JavaScript
import { __decorate, __metadata, __extends, __spread, __values, __param } from 'tslib';
import { Injectable, Optional, Host, SkipSelf, ElementRef, Input, ViewChild, Component, forwardRef, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormGroup, FormArray, Validators, FormControl, ControlContainer, NG_VALUE_ACCESSOR, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule, MatCardModule, MatButtonModule, MatCheckboxModule, MatDatepickerModule, MatNativeDateModule, MatTooltipModule, MatInputModule, MatSelectModule, MatOptionModule, MatDialogModule, MatToolbarModule, MatIconModule, MatSidenavModule, MatMenuModule, MatTableModule, MatListModule } from '@angular/material';
import { tap, filter, debounceTime, distinctUntilChanged, map, takeWhile } from 'rxjs/operators';
import { pipeFromArray } from 'rxjs/internal/util/pipe';
import { NgSelectComponent, NgSelectModule } from '@ng-select/ng-select';
import { Subject, of, ReplaySubject, BehaviorSubject, Observable } from 'rxjs';
import { EventType } from '@bi8/am-io';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { FlexLayoutModule } from '@angular/flex-layout';
import { get, isNil, isObject, chunk } from 'lodash';
import * as moment_ from 'moment';
import { of as of$1 } from 'rxjs/internal/observable/of';
var DynFormService = /** @class */ (function () {
function DynFormService() {
}
DynFormService = __decorate([
Injectable(),
__metadata("design:paramtypes", [])
], DynFormService);
return DynFormService;
}());
var DynFormGroup = /** @class */ (function (_super) {
__extends(DynFormGroup, _super);
function DynFormGroup(options, controls) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, controls) || this;
_this.config = {};
if (options) {
_this.key = options.key || '';
_this.dir = options.dir || '';
}
return _this;
}
DynFormGroup.prototype.addSlaveObserver = function (master, slave, options) {
var masterField = this.get(master);
var slaveField = this.get(slave);
if (!options) {
options = { disable: true, reset: true, apply: true };
}
else {
if (options.reset === undefined) {
options.reset = true;
}
if (options.disable === undefined) {
options.disable = true;
}
if (options.apply === undefined) {
options.apply = options.disable;
}
}
var ops = [];
if (options.reset) {
ops.push(tap(function () { return slaveField.reset(); }));
}
if (options.disable) {
ops.push(tap(function () { return slaveField.disable(); }));
if (options.apply) {
slaveField.disable({ onlySelf: true });
}
}
ops.push(filter(function (value) {
if (!value) {
return false;
}
else {
return value instanceof Array ? value.length > 0 : true;
}
}));
if (options.disable) {
ops.push(tap(function () { return slaveField.enable(); }));
}
if (options.ops) {
ops.push.apply(ops, __spread(options.ops));
}
return masterField.valueChanges.pipe(pipeFromArray(__spread(ops)));
};
return DynFormGroup;
}(FormGroup));
var DynFormArray = /** @class */ (function (_super) {
__extends(DynFormArray, _super);
function DynFormArray(options, controls) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, controls) || this;
_this.config = {};
if (options) {
_this.key = options.key || '';
_this.dir = options.dir || '';
}
return _this;
}
DynFormArray.prototype.add = function (values) {
};
return DynFormArray;
}(FormArray));
var DynFormControl = /** @class */ (function (_super) {
__extends(DynFormControl, _super);
function DynFormControl(options, validator, asyncValidator) {
var e_1, _a;
if (options === void 0) { options = {}; }
var _this = _super.call(this, options.defaultValue != undefined ? options.defaultValue : null, validator, asyncValidator) || this;
_this.config = {};
_this.key = options.key || '';
if (options) {
_this.config.required = options.required != undefined ? options.required : false;
_this.config.hint = options.hint;
_this.config.placeholder = options.placeholder;
_this.config.dir = options.dir || 'ltr';
_this.config.messages = options.messages || [];
_this.config.useDefaultErrorMessages = options.useDefaultErrorMessages || false;
_this.config.loadFn = options.loadFn || null;
_this.config.disable = options.disable || false;
_this.config.appearance = options.appearance || 'standard';
_this.config.compact = options.compact === undefined ? true : options.compact;
if (_this.config.loadFn) {
_this.loadValue(options.defaultValue, _this.config.loadFn, { onlySelf: true });
}
if (_this.config.disable) {
_this.disable({ onlySelf: true });
}
if (validator) {
if (validator instanceof Array) {
try {
for (var validator_1 = __values(validator), validator_1_1 = validator_1.next(); !validator_1_1.done; validator_1_1 = validator_1.next()) {
var v = validator_1_1.value;
if (v == Validators.required) {
_this.config.required = true;
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (validator_1_1 && !validator_1_1.done && (_a = validator_1.return)) _a.call(validator_1);
}
finally { if (e_1) throw e_1.error; }
}
}
else if (validator == Validators.required) {
_this.config.required = true;
}
}
}
return _this;
}
DynFormControl.prototype.removeRequired = function () {
this.config.required = false;
this.removeValidator(Validators.required);
this.updateValueAndValidity();
};
DynFormControl.prototype.addRequired = function () {
this.config.required = true;
this.setValidator(Validators.required);
this.updateValueAndValidity();
};
DynFormControl.prototype.isRequired = function () {
return this.isValidator(Validators.required);
};
DynFormControl.prototype.isValidator = function (validator) {
if (!this.validator) {
return false;
}
if (this.validator instanceof Array) {
return this.validator.find(function (v) { return v == validator; }) != undefined;
}
else {
return this.validator = validator;
}
};
DynFormControl.prototype.setValidator = function (validator) {
if (!this.isValidator(validator)) {
if (this.validator instanceof Array) {
return this.validator.push(validator);
}
else {
return this.validator = validator;
}
}
};
DynFormControl.prototype.removeValidator = function (validator) {
if (this.isValidator(validator)) {
if (this.validator instanceof Array) {
this.setValidators(this.validator.filter(function (v) { return v != validator; }));
}
else {
this.setValidators([]);
}
}
};
DynFormControl.prototype.setLogicalError = function (message) {
this.logicalErrorMessage = message;
this.markAsTouched();
var errors = this.errors;
if (!errors) {
errors = {};
}
errors.logical = true;
this.setErrors(errors);
};
DynFormControl.prototype.clearLogicalError = function () {
this.logicalErrorMessage = null;
if (this.errors) {
this.errors.logical = false;
this.setErrors(this.errors);
}
};
DynFormControl.prototype.activateValidators = function () {
};
DynFormControl.prototype.setValue = function (value, options) {
var _this = this;
if (options && options.loadFn) {
options.loadFn(value).subscribe(function (result) {
_super.prototype.setValue.call(_this, result, options);
});
}
else {
if (value == null) {
_super.prototype.setValue.call(this, '', options);
}
else {
_super.prototype.setValue.call(this, value, options);
}
}
};
DynFormControl.prototype.loadValue = function (param, loadFn, options) {
var _this = this;
loadFn(param).subscribe(function (result) {
_super.prototype.setValue.call(_this, result, options);
});
};
return DynFormControl;
}(FormControl));
var DynAutoSelectControl = /** @class */ (function (_super) {
__extends(DynAutoSelectControl, _super);
function DynAutoSelectControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'autoselect';
_this.hasValue = false;
_this.loading = false;
_this.multiple = false;
_this.searchable = true;
_this.clearToggle = false;
_this.showNone = options['showNone'] || false;
_this.noneLabel = options['noneLabel'];
_this.multiple = options['multiple'] || false;
_this.debounce = options['debounce'] || 500;
_this.searchable = options['searchable'] || false;
var debounceOp = debounceTime(200);
var showTappet = tap(function () { return _this.loading = true; });
var hideTappet = tap(function () { return _this.loading = false; });
if (options['bindLabel']) {
_this.bindLabel = options['bindLabel'];
}
else {
_this.bindLabel = 'name';
}
if (options['bindValue']) {
_this.bindValue = options['bindValue'];
}
_this.labelTemplate = options['labelTemplate'];
_this.optionTemplate = options['optionTemplate'];
if (options['channel']) {
_this.channel = options['channel'];
_this.channel.asEventObservable().subscribe(function (event) {
switch (event.observeType) {
case EventType.on_next:
_this.loading = true;
break;
default:
_this.loading = false;
break;
}
});
if (_this.searchable) {
_this.typeahead$ = new Subject();
_this.typeahead$.pipe(debounceTime(_this.debounce), distinctUntilChanged()).subscribe(_this.channel);
}
else {
_this.typeahead$ = null;
}
_this.items$ = _this.channel.asObservable();
}
_this.valueChanges.subscribe(function (value) {
_this.checkHasValue(value);
_this.hasValue = !(!value);
});
_this.channel.next();
return _this;
}
DynAutoSelectControl.prototype.checkHasValue = function (value) {
var _this = this;
setTimeout(function () {
if (_this.element) {
if (!value || value.length === 0) {
_this.element.classList.remove("ng-has-value");
}
else {
_this.element.classList.add("ng-has-value");
}
}
});
};
DynAutoSelectControl.prototype.reload = function (param) {
this.channel.next(param);
};
DynAutoSelectControl.prototype.getCustomPlaceholder = function () {
return this.isRequired() ? this.config.placeholder + ' *' : this.config.placeholder;
};
return DynAutoSelectControl;
}(DynFormControl));
//import {LogService, Logger} from "@bi8/am-logger";
/*@Directive({selector: '[class]'})
export class Class {
@HostBinding('class') @Input('class') className: string = '';
}*/
var DynFieldComponent = /** @class */ (function () {
//@ContentChild('.ng-has-value') stuff;
//@ViewChildren(Class, {read: ElementRef}) classes: QueryList<ElementRef>;
function DynFieldComponent(controlContainer, elRef) {
this.controlContainer = controlContainer;
this.elRef = elRef;
this.paths = [];
this.messages = new Map();
}
DynFieldComponent.prototype.ngAfterContentInit = function () {
};
DynFieldComponent.prototype.ngAfterViewInit = function () {
var bling = this.elRef.nativeElement.querySelector('.ng-select-container');
if (bling) {
if (this.dfc instanceof DynAutoSelectControl) {
this.dfc.element = bling;
}
}
if (this.ngSelect && this.dfc instanceof DynAutoSelectControl) {
this.dfc.ngSelectComponent = this.ngSelect;
}
};
/*removeClass(){
if ( this.classes && this.classes.length ) {
return this
.classes
.map((elRef:ElementRef):Element => elRef.nativeElement)
.filter( (element: Element) => element.classList.remove('ng-has-value'));
}
}*/
DynFieldComponent.prototype.ngOnInit = function () {
var e_1, _a;
this.dfc = this.controlContainer.control.get(this.name);
this.placeholder = this.dfc.config.placeholder;
this.hint = this.dfc.config.hint;
try {
for (var _b = __values(this.dfc.config.messages), _c = _b.next(); !_c.done; _c = _b.next()) {
var entry = _c.value;
this.messages.set(entry.key, entry.value);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
this.path = this.resolvePath();
};
DynFieldComponent.prototype.resolvePath = function () {
var _this = this;
var paths = [this.dfc.key];
this.resolveParentPath(this.dfc.parent, paths);
var resolvedPath = '';
paths.reverse().forEach(function (path, index) {
if (path) {
if (resolvedPath) {
resolvedPath += '.';
}
resolvedPath += path;
_this.paths.push(resolvedPath);
}
});
return resolvedPath;
};
DynFieldComponent.prototype.resolveParentPath = function (control, paths) {
if (control instanceof DynFormGroup) {
paths.push(control.key);
}
else if (control instanceof DynFormArray) {
paths.push(control.key);
}
if (control.parent) {
this.resolveParentPath(control.parent, paths);
}
};
DynFieldComponent.prototype.resolveValidationMessage = function (type) {
var message = '';
if (this.messages.has(type)) {
message = this.messages.get(type);
}
else if (this.dfc.config.useDefaultErrorMessages) {
switch (type) {
case 'required':
message = 'Value required';
break;
case 'pattern':
message = 'Invalid format';
break;
case 'email':
message = 'Invalid email';
break;
}
}
return message;
};
DynFieldComponent.ctorParameters = function () { return [
{ type: ControlContainer, decorators: [{ type: Optional }, { type: Host }, { type: SkipSelf }] },
{ type: ElementRef }
]; };
__decorate([
Input(),
__metadata("design:type", Object)
], DynFieldComponent.prototype, "name", void 0);
__decorate([
ViewChild('ngselect', { static: false }),
__metadata("design:type", NgSelectComponent)
], DynFieldComponent.prototype, "ngSelect", void 0);
DynFieldComponent = __decorate([
Component({
selector: 'dyn-field',
template: "<ng-container [ngSwitch]=\"dfc.type\">\r\n <div fxLayout=\"row\" class=\"am-field-row\">\r\n <!--=====[ AUTO SELECT FIELD ]=====-->\r\n <ng-container *ngSwitchCase=\"'autoselect'\">\r\n <div class=\"am-field-container\" fxLayout=\"row\" fxFlex>\r\n <ng-select #ngselect [items]=\"dfc.items$ | async\"\r\n [formControl]=\"dfc\"\r\n [placeholder]=\"dfc.getCustomPlaceholder()\"\r\n [bindLabel]=\"dfc.bindLabel\"\r\n [typeahead]=\"dfc.typeahead$\"\r\n [loading]=\"dfc.loading\"\r\n [bindValue]=\"dfc.bindValue\"\r\n [multiple]=\"dfc.multiple\"\r\n [searchable]=\"dfc.searchable\"\r\n fxFlex=\"1 1 auto\"\r\n [ngClass]=\"{'am-has-value': dfc.hasValue, 'am-no-value' : !dfc.hasValue}\"\r\n style=\"width: 100px;\">\r\n <ng-template ng-label-tmp let-item=\"item\" *ngIf=\"dfc.labelTemplate\" let-clear=\"clear\">\r\n <ng-container [ngTemplateOutlet]=\"dfc.labelTemplate\" [ngTemplateOutletContext]=\"{item: item, clear: clear}\"></ng-container>\r\n </ng-template>\r\n\r\n <ng-template ng-option-tmp let-item=\"item\" let-index=\"index\" let-search=\"searchTerm\" *ngIf=\"dfc.optionTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"dfc.optionTemplate\" [ngTemplateOutletContext]=\"{item: item, index: index, search: search}\"></ng-container>\r\n </ng-template>\r\n </ng-select>\r\n <span class=\"am-select-error\" *ngIf=\"dfc.hasError('required') && dfc.touched\">{{resolveValidationMessage('required')}}</span>\r\n <span class=\"am-select-error\" *ngIf=\"dfc.hasError('pattern') && dfc.touched\">{{resolveValidationMessage('pattern')}}</span>\r\n <span class=\"am-select-error\" *ngIf=\"dfc.hasError('email') && dfc.touched\">{{resolveValidationMessage('email')}}</span>\r\n <span class=\"am-select-error\" *ngIf=\"dfc.hasError('match') && dfc.touched\">{{resolveValidationMessage('match')}}</span>\r\n <span class=\"am-select-error\" *ngIf=\"dfc.hasError('time') && dfc.touched\">{{resolveValidationMessage('time')}}</span>\r\n <span class=\"am-select-error\" *ngIf=\"dfc.hasError('logical') && dfc.touched\">{{dfc.logicalErrorMessage}}</span>\r\n </div>\r\n </ng-container>\r\n\r\n <!--=====[ TEXT FIELD ]=====-->\r\n <mat-form-field *ngSwitchCase=\"'text'\" [hintLabel]=\"hint\" fxFlex>\r\n <input matInput\r\n hideRequiredMarker=\"false\"\r\n [name]=\"dfc.key\"\r\n [formControl]=\"dfc\"\r\n [type]=\"dfc.config.format\"\r\n [placeholder]=\"placeholder\"\r\n [maxlength]=\"dfc.config.maxlimit\"\r\n [required]=\"dfc.config.required\"\r\n [dir]=\"dfc.config.dir\">\r\n\r\n <mat-hint *ngIf=\"dfc.config.counter && dfc.config.maxlimit\" align=\"end\" class=\"no-text-wrap\">{{dfc.value ? dfc.value.length : 0}} / {{dfc.config.maxlimit}}</mat-hint>\r\n\r\n <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('pattern')\">{{resolveValidationMessage('pattern')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('email')\">{{resolveValidationMessage('email')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('time')\">{{resolveValidationMessage('time')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n </mat-form-field>\r\n\r\n <!--=====[ TEXTAREA FIELD ]=====-->\r\n <mat-form-field *ngSwitchCase=\"'textarea'\" [hintLabel]=\"hint\" fxFlex>\r\n <textarea matInput\r\n hideRequiredMarker=\"false\"\r\n matTextareaAutosize\r\n [matAutosizeMinRows]=\"dfc.config.minRows\"\r\n [matAutosizeMaxRows]=\"dfc.config.maxRows\"\r\n [name]=\"dfc.key\"\r\n [formControl]=\"dfc\"\r\n [placeholder]=\"placeholder\"\r\n [maxlength]=\"dfc.config.maxlimit\"\r\n [required]=\"dfc.config.required\"\r\n [dir]=\"dfc.config.dir\"></textarea>\r\n\r\n <mat-hint *ngIf=\"dfc.config.counter && dfc.config.maxlimit\" align=\"end\" class=\"no-text-wrap\">{{dfc.value ? dfc.value.length : 0}} / {{dfc.config.maxlimit}}</mat-hint>\r\n <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('pattern')\">{{resolveValidationMessage('pattern')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('email')\">{{resolveValidationMessage('email')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n </mat-form-field>\r\n\r\n <!--=====[ AUTOCOMPLETE ]=====-->\r\n <ng-container *ngSwitchCase=\"'auto-complete'\">\r\n <mat-form-field fxFlex>\r\n <input matInput\r\n [name]=\"dfc.key\"\r\n [placeholder]=\"placeholder\"\r\n [matAutocomplete]=\"auto\"\r\n [formControl]=\"dfc\"\r\n [required]=\"dfc.config.required\"\r\n [dir]=\"dfc.config.dir\">\r\n\r\n <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n\r\n <mat-autocomplete #auto=\"matAutocomplete\" [displayWith]=\"dfc.displayFn.bind(dfc)\">\r\n <mat-option *ngFor=\"let opt of dfc.selectOptions$ | async\" [value]=\"opt\">\r\n {{dfc.displayFn(opt)}}\r\n </mat-option>\r\n </mat-autocomplete>\r\n </mat-form-field>\r\n </ng-container>\r\n\r\n <!--=====[ DATE ]=====-->\r\n <ng-container *ngSwitchCase=\"'date'\">\r\n <mat-form-field fxFlex>\r\n <input matInput\r\n hideRequiredMarker=\"false\"\r\n [name]=\"dfc.key\"\r\n [formControl]=\"dfc\"\r\n type=\"text\"\r\n [min]=\"dfc.minDate\"\r\n [max]=\"dfc.maxDate\"\r\n [required]=\"dfc.config.required\"\r\n [matDatepicker]=\"picker\"\r\n [placeholder]=\"placeholder\"\r\n style=\"pointer-events:none;\" />\r\n\r\n <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n <mat-datepicker #picker></mat-datepicker>\r\n\r\n <mat-error *ngIf=\"dfc.hasError('required')\">{{resolveValidationMessage('required')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('pattern')\">{{resolveValidationMessage('pattern')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('match')\">{{resolveValidationMessage('match')}}</mat-error>\r\n <mat-error *ngIf=\"dfc.hasError('logical')\">{{dfc.logicalErrorMessage}}</mat-error>\r\n </mat-form-field>\r\n </ng-container>\r\n\r\n <!--=====[ DATE ]=====-->\r\n <ng-container *ngSwitchCase=\"'time'\">\r\n <am-timepicker [formControl]=\"dfc\"></am-timepicker>\r\n </ng-container>\r\n\r\n <!--=====[ SELECT FIELD ]=====-->\r\n <ng-container *ngSwitchCase=\"'select'\" >\r\n <mat-form-field fxFlex>\r\n <mat-select [formControl]=\"dfc\"\r\n [placeholder]=\"placeholder\"\r\n [required]=\"dfc.config.required\"\r\n required=\"true\"\r\n [multiple]=\"dfc.multiple\">\r\n <mat-option *ngIf=\"dfc.showNone\" (click)=\"dfc.reset()\">{{dfc.noneLabel}}</mat-option>\r\n <mat-option *ngFor=\"let opt of dfc.selectOptions$ | async\" [value]=\"opt.code\">{{opt.value}}</mat-option>\r\n </mat-select>\r\n <mat-error *ngIf=\"dfc.hasError('required') && dfc.touched\">This option is required</mat-error>\r\n </mat-form-field>\r\n </ng-container>\r\n\r\n <!--=====[ CHECK BOX ]=====-->\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <mat-checkbox [formControl]=\"dfc\" fxFlex>\r\n {{placeholder}}\r\n </mat-checkbox>\r\n </ng-container>\r\n\r\n <!--=====[ LABEL ]=====-->\r\n <ng-container *ngSwitchCase=\"'label'\">\r\n <div fxFlex>{{placeholder}}</div>\r\n </ng-container>\r\n </div>\r\n</ng-container>\r\n",
styles: [""]
}),
__param(0, Optional()), __param(0, Host()), __param(0, SkipSelf()),
__metadata("design:paramtypes", [ControlContainer, ElementRef])
], DynFieldComponent);
return DynFieldComponent;
}());
var DynToolbarPanelComponent = /** @class */ (function () {
function DynToolbarPanelComponent() {
}
DynToolbarPanelComponent.prototype.ngOnInit = function () {
};
__decorate([
Input(),
__metadata("design:type", String)
], DynToolbarPanelComponent.prototype, "header", void 0);
DynToolbarPanelComponent = __decorate([
Component({
selector: 'dyn-toolbar-panel',
template: "<mat-card class=\"container\">\r\n <mat-toolbar *ngIf=\"header\" color=\"primary\"> {{header}}</mat-toolbar>\r\n <div class=\"body\">\r\n <ng-content></ng-content>\r\n </div>\r\n</mat-card>\r\n",
styles: [""]
}),
__metadata("design:paramtypes", [])
], DynToolbarPanelComponent);
return DynToolbarPanelComponent;
}());
var DynFieldSetComponent = /** @class */ (function () {
function DynFieldSetComponent() {
}
DynFieldSetComponent.prototype.ngOnInit = function () {
};
__decorate([
Input(),
__metadata("design:type", String)
], DynFieldSetComponent.prototype, "header", void 0);
DynFieldSetComponent = __decorate([
Component({
selector: 'dyn-field-set',
template: "<fieldset>\r\n <legend *ngIf=\"header\">{{header}}</legend>\r\n <ng-content></ng-content>\r\n</fieldset>\r\n",
styles: [""]
}),
__metadata("design:paramtypes", [])
], DynFieldSetComponent);
return DynFieldSetComponent;
}());
var AmTimepickerComponent = /** @class */ (function () {
function AmTimepickerComponent(_elementRef) {
this._elementRef = _elementRef;
this._cvaOnChange = function () { };
this._validatorOnChange = function () { };
this._onTouched = function () { };
this.timeForm = new FormGroup({
hours: new FormControl(),
minutes: new FormControl(),
amPm: new FormControl()
});
}
AmTimepickerComponent_1 = AmTimepickerComponent;
Object.defineProperty(AmTimepickerComponent.prototype, "minHours", {
set: function (minHours) {
this._minHours = minHours;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AmTimepickerComponent.prototype, "maxHours", {
set: function (maxHours) {
this._maxHours = maxHours;
},
enumerable: true,
configurable: true
});
Object.defineProperty(AmTimepickerComponent.prototype, "disabled", {
get: function () { return !!this._disabled; },
set: function (value) {
var newValue = coerceBooleanProperty(value);
if (this._disabled !== newValue) {
this._disabled = newValue;
}
},
enumerable: true,
configurable: true
});
AmTimepickerComponent.prototype.ngAfterContentInit = function () {
};
AmTimepickerComponent.prototype.ngOnDestroy = function () {
};
AmTimepickerComponent.prototype.writeValue = function (value) {
this._data = value;
console.log("writeValue: ", value);
};
AmTimepickerComponent.prototype.registerOnChange = function (fn) {
this._cvaOnChange = fn;
console.log("registerOnChange:", fn);
};
AmTimepickerComponent.prototype.registerOnTouched = function (fn) {
this._onTouched = fn;
console.log("registerOnTouch: ", fn);
};
AmTimepickerComponent.prototype.setDisabledState = function (disabled) {
this.disabled = disabled;
console.log("setDisabled: ", disabled);
};
var AmTimepickerComponent_1;
AmTimepickerComponent.ctorParameters = function () { return [
{ type: ElementRef }
]; };
__decorate([
Input(),
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
], AmTimepickerComponent.prototype, "minHours", null);
__decorate([
Input(),
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
], AmTimepickerComponent.prototype, "maxHours", null);
__decorate([
Input(),
__metadata("design:type", Object),
__metadata("design:paramtypes", [Object])
], AmTimepickerComponent.prototype, "disabled", null);
AmTimepickerComponent = AmTimepickerComponent_1 = __decorate([
Component({
selector: 'am-timepicker',
template: "<form [formGroup]=\"timeForm\" novalidate style=\"display: flex; flex-direction: row;\">\r\n <mat-form-field style=\"width: 40px; padding-right: 5px;\">\r\n <mat-select formControlName=\"hours\">\r\n <mat-option value=\"1\"> 1</mat-option>\r\n <mat-option value=\"2\">2</mat-option>\r\n <mat-option value=\"3\">3</mat-option>\r\n <mat-option value=\"4\">4</mat-option>\r\n <mat-option value=\"5\">5</mat-option>\r\n <mat-option value=\"6\">6</mat-option>\r\n <mat-option value=\"7\">7</mat-option>\r\n <mat-option value=\"8\">8</mat-option>\r\n <mat-option value=\"9\">9</mat-option>\r\n <mat-option value=\"10\">10</mat-option>\r\n <mat-option value=\"11\">11</mat-option>\r\n <mat-option value=\"12\">12</mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n <mat-form-field style=\"width: 40px; padding-right: 5px;\">\r\n <mat-select formControlName=\"minutes\">\r\n <mat-option value=\"1\">00</mat-option>\r\n <mat-option value=\"1\">05</mat-option>\r\n <mat-option value=\"2\">10</mat-option>\r\n <mat-option value=\"3\">15</mat-option>\r\n <mat-option value=\"4\">20</mat-option>\r\n <mat-option value=\"5\">25</mat-option>\r\n <mat-option value=\"6\">30</mat-option>\r\n <mat-option value=\"7\">35</mat-option>\r\n <mat-option value=\"8\">40</mat-option>\r\n <mat-option value=\"9\">45</mat-option>\r\n <mat-option value=\"10\">50</mat-option>\r\n <mat-option value=\"11\">55</mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n <mat-form-field style=\"width: 50px;\">\r\n <mat-select formControlName=\"amPm\">\r\n <mat-option value=\"am\">AM</mat-option>\r\n <mat-option value=\"pm\">PM</mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n</form>\r\n",
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(function () { return AmTimepickerComponent_1; }),
multi: true
}
]
}),
__metadata("design:paramtypes", [ElementRef])
], AmTimepickerComponent);
return AmTimepickerComponent;
}());
var AmDynFormModule = /** @class */ (function () {
function AmDynFormModule() {
}
AmDynFormModule = __decorate([
NgModule({
imports: [
CommonModule,
RouterModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
FlexLayoutModule,
MatAutocompleteModule,
MatCardModule,
MatButtonModule,
MatCheckboxModule,
MatDatepickerModule,
MatNativeDateModule,
MatTooltipModule,
MatInputModule,
MatSelectModule,
MatOptionModule,
MatDialogModule,
MatToolbarModule,
MatIconModule,
MatSidenavModule,
MatMenuModule,
MatTableModule,
MatListModule,
NgSelectModule
],
exports: [
DynFieldComponent,
DynFieldSetComponent,
DynToolbarPanelComponent,
AmTimepickerComponent
],
declarations: [
DynFieldComponent,
DynFieldSetComponent,
DynToolbarPanelComponent,
AmTimepickerComponent
],
providers: [DynFormService]
})
], AmDynFormModule);
return AmDynFormModule;
}());
var DynTextControl = /** @class */ (function (_super) {
__extends(DynTextControl, _super);
function DynTextControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'text';
_this.config.format = options['format'] || 'text';
_this.config.counter = options['counter'] != undefined ? options['counter'] : true;
_this.config.maxlimit = options['maxlimit'];
return _this;
}
return DynTextControl;
}(DynFormControl));
var DynTextareaControl = /** @class */ (function (_super) {
__extends(DynTextareaControl, _super);
function DynTextareaControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'textarea';
_this.config.minRows = options['minRows'] || null;
_this.config.maxRows = options['maxRows'] || null;
_this.config.maxlimit = options['maxlimit'];
return _this;
}
return DynTextareaControl;
}(DynFormControl));
var DynAutoCompleteControl = /** @class */ (function (_super) {
__extends(DynAutoCompleteControl, _super);
function DynAutoCompleteControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'auto-complete';
_this.selectOptions$ = new Subject();
_this.total = 0;
_this.items = [];
_this.loader = options['loader'];
// load the initial values after the first tick
setTimeout(function () {
_this.loadValues(null);
}, 0);
_this.valueChanges.subscribe(function (value) {
_this.loadValues(value);
});
return _this;
}
DynAutoCompleteControl.prototype.loadValues = function (value) {
var _this = this;
//console.log("loading values: ", value);
this.loader.prepare({
value: value
}).subscribe(function (result) {
_this.total = result.total;
_this.items = result.items;
_this.selectOptions$.next(_this.items);
});
};
DynAutoCompleteControl.prototype.displayFn = function (item) {
return get(item, this.loader.valueProperty);
};
return DynAutoCompleteControl;
}(DynFormControl));
var ArrayAutoCompleteLoader = /** @class */ (function () {
function ArrayAutoCompleteLoader(items, filterFn, options) {
this.items = items;
this.filterFn = filterFn;
this.size = !isNil(options.size) ? options.size : 15;
this.page = !isNil(options.page) ? options.page : 0;
this.codeProperty = !isNil(options.codeProperty) ? options.codeProperty : 'code';
this.valueProperty = !isNil(options.valueProperty) ? options.valueProperty : 'value';
}
ArrayAutoCompleteLoader.prototype.prepare = function (value) {
var _this = this;
return of(this.items).pipe(map(function (items) {
var filteredList = [];
// note that when the actual selection takes place, the value will be the actual selected object
// and not the string that we expect. If it is an object, there is no reason for loading the list
var isObject$1 = isObject(value);
items.forEach(function (item, index) {
var itemValue = get(item, _this.valueProperty);
if (isObject$1 || _this.filterFn(item, value.value)) {
filteredList.push(item);
}
});
return _this.processResponse({
total: filteredList.length,
items: filteredList.length > 0 ? chunk(filteredList, _this.size)[_this.page] : filteredList
});
}));
};
ArrayAutoCompleteLoader.prototype.processResponse = function (response) {
return response;
};
return ArrayAutoCompleteLoader;
}());
var ObservableAutoCompleteLoader = /** @class */ (function () {
function ObservableAutoCompleteLoader(loadFn, options) {
this.loadFn = loadFn;
if (options) {
this.size = isNil(options.size) ? options.size : 15;
this.page = isNil(options.page) ? options.page : 0;
}
}
ObservableAutoCompleteLoader.prototype.prepare = function (value) {
var _this = this;
var ctx = {
size: this.size,
page: this.page,
value: value
};
return this.loadFn(ctx).pipe(map(function (response) {
return _this.processResponse(response);
}));
};
ObservableAutoCompleteLoader.prototype.processResponse = function (response) {
return {
total: response.total,
items: response.results
};
};
return ObservableAutoCompleteLoader;
}());
var KeywordAutoCompleteCriteriaLoader = /** @class */ (function () {
function KeywordAutoCompleteCriteriaLoader(loadFn, options) {
this.loadFn = loadFn;
if (options) {
this.size = isNil(options.size) ? options.size : 50;
this.page = isNil(options.page) ? options.page : 0;
this.inclusive = isNil(options.inclusive) ? options.inclusive : true;
this.keywordProperty = options.keywordProperty;
this.codeProperty = !isNil(options.codeProperty) ? options.codeProperty : 'code';
this.valueProperty = !isNil(options.valueProperty) ? options.valueProperty : 'value';
}
}
KeywordAutoCompleteCriteriaLoader.prototype.resolveContext = function (value) {
var ctx = {
size: this.size,
page: this.page,
inclusive: this.inclusive,
criteria: []
};
if (this.keywordProperty && !isObject(value)) {
ctx[this.keywordProperty] = value;
}
return ctx;
};
KeywordAutoCompleteCriteriaLoader.prototype.prepare = function (value) {
var _this = this;
var ctx = this.resolveContext(value);
return this.loadFn(ctx).pipe(map(function (response) {
return _this.processResponse(response);
}));
};
KeywordAutoCompleteCriteriaLoader.prototype.processResponse = function (response) {
return {
total: response.total,
items: response.results
};
};
return KeywordAutoCompleteCriteriaLoader;
}());
var DynCheckboxControl = /** @class */ (function (_super) {
__extends(DynCheckboxControl, _super);
function DynCheckboxControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'checkbox';
_this.config.leadingLabel = options['leadingLabel'];
return _this;
}
return DynCheckboxControl;
}(DynFormControl));
var DynDateControl = /** @class */ (function (_super) {
__extends(DynDateControl, _super);
function DynDateControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'date';
_this.minDate = options['minDate'] || null;
_this.maxDate = options['maxDate'] || null;
return _this;
}
return DynDateControl;
}(DynFormControl));
var DynSelectControl = /** @class */ (function (_super) {
__extends(DynSelectControl, _super);
function DynSelectControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'select';
_this.selectOptions$ = options['selectOptions'] || [];
_this.showNone = options['showNone'] || false;
_this.noneLabel = options['noneLabel'];
_this.multiple = options['multiple'] || false;
return _this;
}
DynSelectControl.prototype.setValue = function (value, options) {
if (value == null) {
_super.prototype.setValue.call(this, '', options);
}
else {
_super.prototype.setValue.call(this, value, options);
}
};
return DynSelectControl;
}(DynFormControl));
var moment = moment_;
function DynMatchValidator(otherControlName) {
var thisControl;
var otherControl;
return function matchOtherValidate(control) {
if (!control.parent) {
return null;
}
// Initializing the validator.
if (!thisControl) {
thisControl = control;
otherControl = control.parent.get(otherControlName);
if (!otherControl) {
throw new Error('matchOtherValidator(): other control is not found in parent group');
}
otherControl.valueChanges.subscribe(function () {
thisControl.updateValueAndValidity();
});
}
if (!otherControl) {
return null;
}
if (otherControl.value !== thisControl.value) {
return {
match: true
};
}
return null;
};
}
function BusinessLogicValidator() {
return function matchOtherValidate(control) {
if (!control.parent) {
return null;
}
return null;
};
}
var TimeUtils = /** @class */ (function () {
function TimeUtils() {
}
TimeUtils.parseTime = function (value) {
var e_1, _a, e_2, _b;
if (!value) {
return null;
}
var formats = ['HH:mm', 'H:mm'];
try {
for (var formats_1 = __values(formats), formats_1_1 = formats_1.next(); !formats_1_1.done; formats_1_1 = formats_1.next()) {
var format = formats_1_1.value;
var dt = moment(value, format, true);
if (dt.isValid()) {
return {
hours: dt.hours(),
minutes: dt.minutes(),
is24Hour: true
};
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (formats_1_1 && !formats_1_1.done && (_a = formats_1.return)) _a.call(formats_1);
}
finally { if (e_1) throw e_1.error; }
}
formats = ['hh:mm a', 'hh:mma', 'h:mm a', 'h:mma', 'h:m a', 'h:ma'];
try {
for (var formats_2 = __values(formats), formats_2_1 = formats_2.next(); !formats_2_1.done; formats_2_1 = formats_2.next()) {
var format = formats_2_1.value;
var dt = moment(value, format, true);
if (dt.isValid()) {
return {
hours: dt.hours(),
minutes: dt.minutes(),
is24Hour: false
};
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (formats_2_1 && !formats_2_1.done && (_b = formats_2.return)) _b.call(formats_2);
}
finally { if (e_2) throw e_2.error; }
}
return null;
};
TimeUtils.formatTime = function (date) {
if (date) {
return date.format('hh:mm a');
}
else if (date) {
return moment(date).format('hh:mm a');
}
};
TimeUtils.applyTime = function (date, time) {
if (date) {
var md = date;
md.hours(time.hours);
md.minutes(time.minutes);
}
else if (date) {
var md = moment(date);
md.hours(time.hours);
md.minutes(time.minutes);
}
};
return TimeUtils;
}());
function TimeValidator() {
return function (control) {
var value = control.value;
if (value) {
var td = TimeUtils.parseTime(value);
if (td != null) {
return null;
}
else {
return { time: true };
}
}
else {
return null;
}
};
}
var DynHiddenControl = /** @class */ (function (_super) {
__extends(DynHiddenControl, _super);
function DynHiddenControl(options, validator, asyncValidator) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options, validator, asyncValidator) || this;
_this.type = 'hidden';
return _this;
}
return DynHiddenControl;
}(DynFormControl));
var NotificationType;
(function (NotificationType) {
NotificationType["init"] = "init";
NotificationType["busy"] = "busy";
NotificationType["idle"] = "idle";
NotificationType["paramFunc"] = "paramFunc";
NotificationType["inputNext"] = "inputNext";
NotificationType["inputComplete"] = "inputComplete";
NotificationType["inputError"] = "inputError";
NotificationType["outputFuncError"] = "outputFuncError";
NotificationType["outputNext"] = "outputNext";
NotificationType["outputError"] = "outputError";
NotificationType["outputComplete"] = "outputComplete";
NotificationType["close"] = "close";
NotificationType["enable"] = "enable";
NotificationType["disable"] = "disable";
})(NotificationType || (NotificationType = {}));
var Channel = /** @class */ (function () {
function Channel(fn, options) {
var _this = this;
this.fn = fn;
this.closed = false;
this.enabled = true;
if (options) {
this.input = options.input || new Subject();
this.output = options.output || new ReplaySubject(1);
this.enabled = options.enabled || true;
this.name = options.name || 'channel';
this.debug = options.debug || false;
this.paramFn = options.paramFn;
this.notificationFn = options.notificationFn;
}
else {
this.input = new Subject();
this.output = new ReplaySubject(1);
this.enabled = true;
this.name = 'channel';
this.debug = false;
}
this.notifications = new BehaviorSubject({ type: NotificationType.init });
//this.observeNotifications().subscribe();
if (this.notificationFn) {
this.observeNotifications().subscribe(this.notificationFn);
}
this.input.pipe(takeWhile(function (value) { return !_this.closed; }), filter(function (value) { return _this.enabled; }), map(function (input) {
_this.emitNotification({ type: NotificationType.busy });
if (_this.paramFn) {
var result = _this.paramFn(input);
_this.emitNotification({ type: NotificationType.paramFunc, data: { before: input, after: result } });
return result;
}
else {
return input;
}
}), tap(function (data) {
_this.inputBusy = true;
_this.emitNotification({ type: NotificationType.inputNext, data: data });
})).subscribe({
next: function (value) {
try {
_this.outputBusy = true;
var observable = _this.fn(value);
observable.pipe(tap(function (data) {
_this.emitNotification({ type: NotificationType.outputNext, data: data });
})).subscribe({
next: function (response) { return _this.output.next(response); },
error: function (err) {
_this.emitNotification({ type: NotificationType.outputError, error: err });
_this.output.error(err);
},
complete: function () {
_this.outputBusy = false;
_this.emitNotification({ type: NotificationType.outputComplete });
_this.emitNotification({ type: NotificationType.idle });
}
});
}
catch (err) {
_this.emitNotification({ type: NotificationType.outputFuncError, error: err });
_this.outputBusy = false;
}
},
error: function (err) {
_this.emitNotification({ type: NotificationType.outputFuncError, error: err });
},
complete: function () {
_this.inputBusy = false;
}
});
}
Channel.prototype.isBusy = function () {
return this.inputBusy || this.outputBusy;
};
Channel.prototype.isInputBusy = function () {
return this.inputBusy;
};
Channel.prototype.isOutputBusy = function () {
return this.outputBusy;
};
Channel.prototype.next = function (value) {
this.input.next(value);
return this;
};
Channel.prototype.emit = function (value) {
this.output.next(value);
};
Channel.prototype.observe = function (value) {
var _this = this;
var ops = [];
for (var _i = 1; _i < arguments.length; _i++) {
ops[_i - 1] = arguments[_i];
}
setInterval(function () {
_this.next(value);
});
return this.output.pipe(pipeFromArray(__spread(ops)));
};
Channel.prototype.link = function (observer) {
var _this = this;
var ops = [];
for (var _i = 1; _i < arguments.length; _i++) {
ops[_i - 1] = arguments[_i];
}
observer.pipe(pipeFromArray(__spread(ops))).subscribe(function (value) { return _this.next(value); });
};
Channel.prototype.pipe = function (observer) {
var _this = this;
var ops = [];
for (var _i = 1; _i < arguments.length; _i++) {
ops[_i - 1] = arguments[_i];
}
observer.pipe(pipeFromArray(__spread(ops))).subscribe(function (value) { return _this.emit(value); });
};
Channel.prototype.asObservable = function () {
return this.output.asObservable();
};
Channel.prototype.observeNotifications = function () {
return this.notifications.asObservable();
};
Channel.prototype.emitNotification = function (notification) {
notification.name = this.name;
if (this.debug) {
switch (notification.type) {
case NotificationType.inputError:
case NotificationType.outputError:
case NotificationType.outputFuncError:
console.error("[" + notification.name + ":" + notification.type + "] ", notification.error || '');
break;
default:
console.debug("[" + notification.name + ":" + notification.type + "] ", notification.data || '');
break;
}
}
this.notifications.next(notification);
};
Channel.prototype.enable = function () {
this.enabled = false;
return this;
};
Channel.prototype.disable = function () {
this.enabled = true;
return this;
};
Channel.prototype.close = function () {
this.closed = true;
this.input.unsubscribe();
this.output.unsubscribe();
};
return Channel;
}());
var ChannelSwitch = /** @class */ (function () {
function ChannelSwitch() {
var _this = this;
var channels = [];
for (var _i = 0; _i < arguments.length; _i++) {
channels[_i] = arguments[_i];
}
this.channels = new Map();
channels.forEach(function (config) {
_this.channels.set(config.key, config.channel);
});
}
ChannelSwitch.prototype.set = function (key, channel) {
this.channels.set(key, channel);
return channel;
};
ChannelSwitch.prototype.get = function (key) {
return this.channels.get(key);
};
ChannelSwitch.prototype.isBusy = function (key) {
var channel = this.channels.get(key);
return channel ? channel.isBusy() : false;
};
ChannelSwitch.prototype.isInputBusy = function (key) {
var channel = this.channels.get(key);
return channel ? channel.isInputBusy() : false;
};
ChannelSwitch.prototype.isOutputBusy = function (key) {
var channel = this.channels.get(key);
return channel ? channel.isOutputBusy() : false;
};
ChannelSwitch.prototype.next = function (key, value) {
var channel = this.channels.get(key);
return channel ? channel.next(value) : null;
};
ChannelSwitch.prototype.emit = function (key, value) {
var channel = this.channels.get(key);
return channel ? channel.emit(value) : false;
};
ChannelSwitch.prototype.observe = function (key, value) {
var ops = [];
for (var _i = 2; _i < arguments.length; _i++) {
ops[_i - 2] = arguments[_i];
}
var channel = this.channels.get(key);
return channel ? channel.observe.apply(channel, __spread([value], ops)) : null;
};
ChannelSwitch.prototype.link = function (key, observer) {
var ops = [];
for (var _i = 2; _i < arguments.length; _i++) {
ops[_i - 2] = arguments[_i];
}
var channel = this.channels.get(key);
if (channel) {
channel.link.apply(channel, __spread([observer], ops));
}
};
ChannelSwitch.prototype.pipe = function (key, observer) {
var ops = [];
for (var _i = 2; _i < arguments.length; _i++) {
ops[_i - 2] = arguments[_i];
}
var channel = this.channels.get(key);
if (channel) {
channel.pipe.apply(channel, __spread([observer], ops));
}
};
ChannelSwitch.prototype.asObservable = function (key) {
var channel = this.channels.get(key);
return channel ? channel.asObservable() : null;
};
ChannelSwitch.prototype.observeNotifications = function (key) {
var channel = this.channels.get(key);
return channel ? channel.observeNotifications() : null;
};
ChannelSwitch.prototype.enable = function (key) {
var channel = this.channels.get(key);
return channel ? channel.enable() : null;
};
ChannelSwitch.prototype.disable = function (key) {
var channel = this.channels.get(key);
return channel ? channel.disable() : null;
};
ChannelSwitch.prototype.close = function (key) {
var channel = this.channels.get(key);
return channel ? channel.close() : null;
};
return ChannelSwitch;
}());
var DSPipe = /** @class */ (function () {
function DSPipe(ds, key, obs, ops, enabled) {
if (enabled === void 0) { enabled = true; }
this.ds = ds;
this.key = key;
this.obs = obs;
this.ops = ops;
this.enabled = enabled;
this.connect();
}
DSPipe.prototype.isConnected = function () {
return !(!this.sub);
};
DSPipe.prototype.connect = function () {
var _this = this;
if (this.isConnected()) {
return;
}
this.sub = this.obs.pipe(pipeFromArray(__spread(this.ops))).subscribe(function (value) {
console.log("----> pipe (" + _this.key + ")", value);
_this.ds.next(_this.key, value);
});
};
DSPipe.prototype.disconnect = function () {
if (!this.isConnected()) {
return;
}
this.sub.unsubscribe();
};
DSPipe.prototype.setOperators = function () {
var ops = [];
for (var _i = 0; _i < arguments.length; _i++) {
ops[_i] = arguments[_i];
}
this.disconnect();
this.ops = ops;
this.connect();
};
DSPipe.prototype.enable = function () {
this.enabled = true;
};
DSPipe.prototype.disable = function () {
this.enabled = false;
};
return DSPipe;
}());
var ObservableDS = /** @class */ (function () {
function ObservableDS(options) {
this.connected = false;
this.fnMap = new Map();
this.subjectMap = new Map();
this.input$ = new Subject();
this.inputSub = null;
this.events$ = new Subject();
this.pipes = [];
if (options) {
if (options.autoconnect) {
this.connect();
}
if (options.key && options.obs) {
this.addObservable(options.key, options.obs);
}
}
else {
// we connect by default
this.connect();
}
}
ObservableDS.prototype.isConnected = function () {
return !(!this.inputSub);
};
ObservableDS.prototype.connect = function () {
var _this = this;
if (this.isConnected()) {
return;
}
this.inputSub = this.input$.pipe(filter(function (input) {
if (_this.fnMap.has(input.id)) {
return true;
}
console.error("[obs] observable with id '" + input.id + "' not found");
return false;
}), map(function (input) {
var obsFn = _this.fnMap.get(input.id);
return { event: input, fn: obsFn(input.value), sub: _this.subjectMap.get(input.id) };
}))
.subscribe(function (input) { return _this.relay(input.event, input.fn, input.sub); });
this.connected = true;
};
ObservableDS.prototype.relay = function (event, obs, subject) {
var _this = this;
//console.log(`-----> relay (${subject}: `, event);
obs.pipe(takeWhile(function () { return _this.connected; }),
//tap((response) => { console.log(`-----> tap relay: `, response); subject.next(response) }),
tap(function (response) { return _this.emit({ input: event, output: response }); })).subscribe();
};
ObservableDS.prototype.emit = function (event) {
this.events$.next(event);
};
ObservableDS.prototype.asObservable = function () {
return this.events$.asObservable();
};
ObservableDS.prototype.disconnect = function () {
if (!this.isConnected()) {
return;
}
this.inputSub.unsubscribe();
var bla = of$1([1, 2, 3]);
var blaf = bla.subscribe();
blaf.add(blaf);
var duff = new Subject();
blaf.add(duff.asObservable().subscribe());
};
ObservableDS.prototype.next = function (key, value, options) {
if (!this.connected) {
return;
}
var event = { id: key, options: options, value: value };
//console.log(`-----> next (${event})`, event);
this.input$.next(event);
};
ObservableDS.prototype.addPipe = function (obs, key) {
var operators = [];
for (var _i = 2; _i < arguments.length; _i++) {
operators[_i - 2] = arguments[_i];
}
var pipe = new DSPipe(this, key, obs, operators);
this.pipes.push(pipe);
return pipe;
};
ObservableDS.prototype.clearPipes = function () {
var pipes = [];
for (var _i = 0; _i < arguments.length; _i++) {
pipes[_i] = arguments[_i];
}
pipes.forEach(function (pipe, index) {
pipe.disconnect();
pipes = pipes.splice(index, 1);
});
};
ObservableDS.prototype.clearAllPipes = function () {
this.clearPipes.apply(this, __spread(this.pipes));
};
ObservableDS.prototype.getPipes = function () {
return this.pipes;
};
ObservableDS.prototype.addObservable = function (key, obs, options) {
if (!options) {
options = { behave: true };
}
this.fnMap.set(key, obs instanceof Observable ? function () { return obs; } : obs);
this.subjectMap.set(key, options.behave ? new BehaviorSubject([]) : new Subject());
};
ObservableDS.prototype.observe = function (key, value, options) {
var subject = this.subjectMap.get(key);
try {
return subject.asObservable();
}
finally {
if (value) {
this.next(key, value);
}
}
};
ObservableDS.prototype.destroy = function () {
};
return ObservableDS;
}());
/**
* Generated bundle index. Do not edit.
*/
export { AmDynFormModule, ArrayAutoCompleteLoader, BusinessLogicValidator, Channel, ChannelSwitch, DSPipe, DynAutoCompleteControl, DynAutoSelectControl, DynCheckboxControl, DynDateControl, DynFieldComponent, DynFieldSetComponent, DynFormArray, DynFormControl, DynFormGroup, DynFormService, DynHiddenControl, DynMatchValidator, DynSelectControl, DynTextControl, DynTextareaControl, DynToolbarPanelComponent, KeywordAutoCompleteCriteriaLoader, NotificationType, ObservableAutoCompleteLoader, ObservableDS, TimeUtils, TimeValidator, AmTimepickerComponent as ɵa };
//# sourceMappingURL=bi8-am-dyn-form.js.map