UNPKG

@asoftwareworld/form-builder

Version:

ASW Form Builder helps you with rapid development and designed web forms which includes several controls. The key feature of Form Builder is to make your content attractive and effective. We can customize our control at run time and preview the same befor

327 lines (320 loc) 42.1 kB
import * as i0 from '@angular/core'; import { Component, Inject, EventEmitter, Input, Output, NgModule } from '@angular/core'; import { AswConfirmDialog, AswConfirmDialogModule } from '@asoftwareworld/form-builder/form-control/confirm-dialog'; import { Constants, ObjectUtils } from '@asoftwareworld/form-builder/form-control/core'; import * as i1 from '@angular/forms'; import { Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import * as i2 from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; import * as i3 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i4 from '@angular/material/input'; import { MatInputModule } from '@angular/material/input'; import * as i5 from '@angular/material/form-field'; import * as i6 from '@angular/material/select'; import { MatSelectModule } from '@angular/material/select'; import * as i7 from '@angular/material/core'; import * as i8 from '@angular/material/tooltip'; import { MatTooltipModule } from '@angular/material/tooltip'; import * as i9 from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon'; import * as i10 from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button'; import { MatDividerModule } from '@angular/material/divider'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; /** * @license * Copyright ASW (A Software World) All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file */ class AswCalculationDialog { formBuilder; dialogRef; data; constants = Constants; aswEditCalculationForm; constructor(formBuilder, dialogRef, data) { this.formBuilder = formBuilder; this.dialogRef = dialogRef; this.data = data; } ngOnInit() { this.validateFormBuilder(); this.editProperty(this.data.control); } validateFormBuilder() { this.aswEditCalculationForm = this.formBuilder.group({ tooltip: [], label: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(25)]], value: [{ value: '', disabled: true }], style: ['', [Validators.required]], column: [], customClass: [], operations: this.formBuilder.array([this.createOperations()]), }); } editProperty(control) { this.aswEditCalculationForm.patchValue({ tooltip: control.tooltip, label: control.label, customClass: control.customClass ?? '', value: control.value, column: control.column, style: control.style, }); const operationFormGroup = control.operations.map((operation) => this.formBuilder.group(operation)); const operationFormArray = this.formBuilder.array(operationFormGroup); this.aswEditCalculationForm.setControl('operations', operationFormArray); } get operations() { return this.aswEditCalculationForm.get('operations'); } createOperations() { return this.formBuilder.group({ id: [], label: [], value: [], operationValue: ['', [Validators.required]], control: [''] }); } onNoClick() { this.dialogRef.close(); } addNewOperation() { this.operations.push(this.createOperations()); } removeOperation(index) { this.operations.removeAt(index); } onSubmit() { if (this.aswEditCalculationForm.invalid) { return; } this.aswEditCalculationForm.value.controlType = this.data.control.controlType; this.aswEditCalculationForm.value.placeholder = this.data.control.placeholder; this.aswEditCalculationForm.value.operations.forEach((operation) => { operation.id = operation.control.guid; operation.label = operation.control.label; operation.value = operation.control.value; }); this.dialogRef.close(this.aswEditCalculationForm.value); } onOperationChange(event, operation) { if (event.value === 'x̄') { operation.controls.label.setErrors(null); } else { operation.controls.label.setValidators(Validators.required); } } onOperatorChange(event, operator) { this.data.numberControls.forEach((operation) => { if (event.value === operation.label) { operator.value.id = operation.guid; operator.value.control = operation; } }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculationDialog, deps: [{ token: i1.FormBuilder }, { token: i2.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.11", type: AswCalculationDialog, selector: "asw-calculation-dialog", ngImport: i0, template: "<h4 mat-dialog-title>Edit Property</h4>\r\n<form [formGroup]=\"aswEditCalculationForm\" (ngSubmit)=\"onSubmit()\">\r\n <mat-dialog-content class=\"mat-typography\">\r\n <div class=\"asw-full-width\"><br>\r\n <div class=\"row\">\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Label</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"label\"\r\n placeholder=\"Enter label\"\r\n matTooltip=\"Enter label\"\r\n formControlName=\"label\" required>\r\n <mat-error class=\"asw-mat-error\" *ngFor=\"let validation of constants.accountValidationMessages.label\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"aswEditCalculationForm.get('label')?.hasError(validation.type) && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)\">\r\n {{validation.message}}\r\n </mat-error>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Tooltip</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"tooltip\"\r\n placeholder=\"Enter tooltip\"\r\n matTooltip=\"Enter tooltip\"\r\n formControlName=\"tooltip\">\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n <div class=\"row\">\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Custom CSS Class</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"customClass\"\r\n placeholder=\"Custom CSS Class\"\r\n matTooltip=\"Custom CSS Class\"\r\n formControlName=\"customClass\">\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Calculation Style</mat-label>\r\n <mat-select formControlName=\"style\" matTooltip=\"Select textbox style\">\r\n <mat-option value=\"legacy\">Legacy</mat-option>\r\n <mat-option value=\"standard\">Standard</mat-option>\r\n <mat-option value=\"fill\">Fill</mat-option>\r\n <mat-option value=\"outline\">Outline</mat-option> \r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n <div class=\"row\">\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Value</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"value\"\r\n placeholder=\"Enter value\"\r\n matTooltip=\"Enter value\"\r\n formControlName=\"value\"> \r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Column Size</mat-label>\r\n <mat-select formControlName=\"column\" matTooltip=\"Select column size\">\r\n <mat-option *ngFor=\"let column of constants.columns\" [value]=\"column.value\">\r\n {{column.label}}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n <ng-container formArrayName=\"operations\">\r\n <div class=\"row\" \r\n *ngFor=\"let op of operations.controls; let index = index; let last=last;\" \r\n [formGroupName]=\"index\">\r\n <div class=\"col-md-4\" *ngIf=\"index!=0\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Operation {{index+1}}</mat-label>\r\n <mat-select formControlName=\"operationValue\" \r\n (selectionChange)=\"onOperationChange($event, op)\"\r\n matTooltip=\"Select operation {{index+1}}\" required>\r\n <mat-option *ngFor=\"let operation of constants.operations\" [value]=\"operation.value\">\r\n {{operation.label}}\r\n </mat-option>\r\n </mat-select>\r\n <mat-error class=\"asw-mat-error\" *ngFor=\"let validation of constants.accountValidationMessages.operationValue\">\r\n <ng-container class=\"asw-mat-error\" *ngIf=\"operations.controls[index].get('operationValue')?.hasError(validation.type) && (operations.controls[index].get('operationValue')?.dirty || operations.controls[index].get('operationValue')?.touched)\">\r\n {{validation.message}}\r\n </ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-4\" *ngIf=\"operations.controls[index].value.operationValue != 'x\u0304'\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Operator {{index+1}}</mat-label>\r\n <mat-select formControlName=\"label\"\r\n (selectionChange)=\"onOperatorChange($event, op)\"\r\n matTooltip=\"Select operator {{index+1}}\" required>\r\n <mat-option *ngFor=\"let control of data.numberControls\" [value]=\"control.label\">\r\n {{control.label}}\r\n </mat-option>\r\n </mat-select>\r\n <mat-error class=\"asw-mat-error\" *ngFor=\"let validation of constants.accountValidationMessages.control\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"operations.controls[index].get('control')?.hasError(validation.type) && (operations.controls[index].get('control')?.dirty || operations.controls[index].get('control')?.touched)\">\r\n {{validation.message}}\r\n </mat-error>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-2\">\r\n <button mat-icon-button *ngIf=\"last\"\r\n type=\"button\" \r\n matTooltip=\"Add\" \r\n [matTooltipPosition]=\"'below'\"\r\n (click)=\"addNewOperation()\">\r\n <mat-icon>add</mat-icon>\r\n </button>\r\n <button mat-icon-button *ngIf=\"index != 0\"\r\n type=\"button\" \r\n matTooltip=\"Delete\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"removeOperation(index)\">\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n </div>\r\n </div> \r\n </ng-container> \r\n </div>\r\n </mat-dialog-content>\r\n <mat-dialog-actions align=\"end\">\r\n <button type=\"button\"\r\n class=\"btn btn-danger mr-2 me-2 mb-1\"\r\n (click)=\"onNoClick()\">\r\n No\r\n </button>\r\n <button type=\"submit\"\r\n class=\"btn btn-primary mb-1\"\r\n cdkFocusInitial>\r\n Yes\r\n </button>\r\n </mat-dialog-actions>\r\n</form>\r\n\r\n", dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i1.FormGroupName, selector: "[formGroupName]", inputs: ["formGroupName"] }, { kind: "directive", type: i1.FormArrayName, selector: "[formArrayName]", inputs: ["formArrayName"] }, { kind: "directive", type: i4.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i5.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "component", type: i6.MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "component", type: i7.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "directive", type: i2.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i2.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i2.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "directive", type: i8.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: i9.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i10.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculationDialog, decorators: [{ type: Component, args: [{ selector: 'asw-calculation-dialog', template: "<h4 mat-dialog-title>Edit Property</h4>\r\n<form [formGroup]=\"aswEditCalculationForm\" (ngSubmit)=\"onSubmit()\">\r\n <mat-dialog-content class=\"mat-typography\">\r\n <div class=\"asw-full-width\"><br>\r\n <div class=\"row\">\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Label</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"label\"\r\n placeholder=\"Enter label\"\r\n matTooltip=\"Enter label\"\r\n formControlName=\"label\" required>\r\n <mat-error class=\"asw-mat-error\" *ngFor=\"let validation of constants.accountValidationMessages.label\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"aswEditCalculationForm.get('label')?.hasError(validation.type) && (aswEditCalculationForm.get('label')?.dirty || aswEditCalculationForm.get('label')?.touched)\">\r\n {{validation.message}}\r\n </mat-error>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Tooltip</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"tooltip\"\r\n placeholder=\"Enter tooltip\"\r\n matTooltip=\"Enter tooltip\"\r\n formControlName=\"tooltip\">\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n <div class=\"row\">\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Custom CSS Class</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"customClass\"\r\n placeholder=\"Custom CSS Class\"\r\n matTooltip=\"Custom CSS Class\"\r\n formControlName=\"customClass\">\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Calculation Style</mat-label>\r\n <mat-select formControlName=\"style\" matTooltip=\"Select textbox style\">\r\n <mat-option value=\"legacy\">Legacy</mat-option>\r\n <mat-option value=\"standard\">Standard</mat-option>\r\n <mat-option value=\"fill\">Fill</mat-option>\r\n <mat-option value=\"outline\">Outline</mat-option> \r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n <div class=\"row\">\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Value</mat-label>\r\n <input matInput type=\"text\"\r\n name=\"value\"\r\n placeholder=\"Enter value\"\r\n matTooltip=\"Enter value\"\r\n formControlName=\"value\"> \r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-6\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Column Size</mat-label>\r\n <mat-select formControlName=\"column\" matTooltip=\"Select column size\">\r\n <mat-option *ngFor=\"let column of constants.columns\" [value]=\"column.value\">\r\n {{column.label}}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n <ng-container formArrayName=\"operations\">\r\n <div class=\"row\" \r\n *ngFor=\"let op of operations.controls; let index = index; let last=last;\" \r\n [formGroupName]=\"index\">\r\n <div class=\"col-md-4\" *ngIf=\"index!=0\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Operation {{index+1}}</mat-label>\r\n <mat-select formControlName=\"operationValue\" \r\n (selectionChange)=\"onOperationChange($event, op)\"\r\n matTooltip=\"Select operation {{index+1}}\" required>\r\n <mat-option *ngFor=\"let operation of constants.operations\" [value]=\"operation.value\">\r\n {{operation.label}}\r\n </mat-option>\r\n </mat-select>\r\n <mat-error class=\"asw-mat-error\" *ngFor=\"let validation of constants.accountValidationMessages.operationValue\">\r\n <ng-container class=\"asw-mat-error\" *ngIf=\"operations.controls[index].get('operationValue')?.hasError(validation.type) && (operations.controls[index].get('operationValue')?.dirty || operations.controls[index].get('operationValue')?.touched)\">\r\n {{validation.message}}\r\n </ng-container>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-4\" *ngIf=\"operations.controls[index].value.operationValue != 'x\u0304'\">\r\n <mat-form-field appearance=\"outline\" class=\"asw-mat-form-field\">\r\n <mat-label>Operator {{index+1}}</mat-label>\r\n <mat-select formControlName=\"label\"\r\n (selectionChange)=\"onOperatorChange($event, op)\"\r\n matTooltip=\"Select operator {{index+1}}\" required>\r\n <mat-option *ngFor=\"let control of data.numberControls\" [value]=\"control.label\">\r\n {{control.label}}\r\n </mat-option>\r\n </mat-select>\r\n <mat-error class=\"asw-mat-error\" *ngFor=\"let validation of constants.accountValidationMessages.control\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"operations.controls[index].get('control')?.hasError(validation.type) && (operations.controls[index].get('control')?.dirty || operations.controls[index].get('control')?.touched)\">\r\n {{validation.message}}\r\n </mat-error>\r\n </mat-error>\r\n </mat-form-field>\r\n </div>\r\n <div class=\"col-md-2\">\r\n <button mat-icon-button *ngIf=\"last\"\r\n type=\"button\" \r\n matTooltip=\"Add\" \r\n [matTooltipPosition]=\"'below'\"\r\n (click)=\"addNewOperation()\">\r\n <mat-icon>add</mat-icon>\r\n </button>\r\n <button mat-icon-button *ngIf=\"index != 0\"\r\n type=\"button\" \r\n matTooltip=\"Delete\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"removeOperation(index)\">\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n </div>\r\n </div> \r\n </ng-container> \r\n </div>\r\n </mat-dialog-content>\r\n <mat-dialog-actions align=\"end\">\r\n <button type=\"button\"\r\n class=\"btn btn-danger mr-2 me-2 mb-1\"\r\n (click)=\"onNoClick()\">\r\n No\r\n </button>\r\n <button type=\"submit\"\r\n class=\"btn btn-primary mb-1\"\r\n cdkFocusInitial>\r\n Yes\r\n </button>\r\n </mat-dialog-actions>\r\n</form>\r\n\r\n" }] }], ctorParameters: () => [{ type: i1.FormBuilder }, { type: i2.MatDialogRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA] }] }] }); /** * @license * Copyright ASW (A Software World) All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file */ class AswCalculation { dialog; constants = Constants; /** * Calculation control */ control = null; formControls = []; /** * Calculation control index to help update or delete button from drop area */ controlIndex; isPreviewTemplate = false; calculationUpdateEvent = new EventEmitter(); calculationDeleteEvent = new EventEmitter(); aswModelChange = new EventEmitter(); duplicateControl = new EventEmitter(); constructor(dialog) { this.dialog = dialog; } deleteCalculationDialog(control, controlIndex) { const dialogRef = this.dialog.open(AswConfirmDialog, { width: '350px', data: { name: control.controlType, message: this.constants.messages.waringMessage } }); dialogRef.afterClosed().subscribe(result => { if (result !== undefined) { this.calculationDeleteEvent.emit(controlIndex); } }); } editCalculationDialog(control, formControls, controlIndex) { const numberControls = formControls.filter(x => x.controlType === 'number'); if (!numberControls.length) { control.operations = []; } if (!control.operations.length) { numberControls.forEach((x, index) => { control.operations.push(this.setControloperations(x, index)); }); } else { control.operations.map((operation, index) => { const numberControl = numberControls.find(element => element.guid === operation.id); if (numberControl) { const updatedOperation = { id: numberControl.guid, label: numberControl.label, value: numberControl.value, operationValue: operation.operationValue, control: numberControl }; control.operations.splice(index, 1, updatedOperation); } }); } const dialogRef = this.dialog.open(AswCalculationDialog, { disableClose: true, width: '80%', minWidth: '70vw', data: { control, numberControls } }); dialogRef.afterClosed().subscribe(result => { if (result !== undefined) { result.value = ObjectUtils.calculateValue(result.operations).toString(); this.calculationUpdateEvent.emit({ control: result, index: controlIndex }); } }); } setControloperations(control, index) { const operation = { id: control.guid, label: control.label, value: control.value, operationValue: index === 0 ? '' : '+', control }; return operation; } onChange(control) { this.aswModelChange.emit(control); } duplicateCalculationControl(control) { this.duplicateControl.emit(control); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculation, deps: [{ token: i2.MatDialog }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.11", type: AswCalculation, selector: "asw-calculation", inputs: { control: "control", formControls: "formControls", controlIndex: "controlIndex", isPreviewTemplate: "isPreviewTemplate" }, outputs: { calculationUpdateEvent: "calculationUpdateEvent", calculationDeleteEvent: "calculationDeleteEvent", aswModelChange: "aswModelChange", duplicateControl: "duplicateControl" }, ngImport: i0, template: "<ng-container *ngIf=\"control as control\">\r\n <mat-form-field [appearance]=\"control.style\" class=\"asw-mat-form-field {{control.customClass}}\">\r\n <mat-label>{{control.label}}</mat-label>\r\n <input matInput type=\"text\"\r\n [placeholder]=\"control.placeholder\"\r\n [(ngModel)]=\"control.value\"\r\n #input=\"ngModel\"\r\n (ngModelChange)=\"onChange(control)\"\r\n [matTooltip]=\"control.tooltip\" [disabled]=\"true\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"input.invalid && (input.dirty || input.touched)\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"input?.errors?.required\">\r\n {{control.label}} is required\r\n </mat-error>\r\n </mat-error>\r\n </mat-form-field>\r\n <ng-template [ngIf]=\"isPreviewTemplate\">\r\n <div class=\"row mb-2\">\r\n <div class=\"col-md-12\">\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Duplicate\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"duplicateCalculationControl(control)\">\r\n <mat-icon>content_copy</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Edit\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"editCalculationDialog(control, formControls, controlIndex)\">\r\n <mat-icon>edit</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Delete\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"deleteCalculationDialog(control, controlIndex)\">\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n </div> \r\n </div>\r\n </ng-template>\r\n</ng-container>", dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i4.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i5.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i8.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: i9.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i10.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculation, decorators: [{ type: Component, args: [{ selector: 'asw-calculation', template: "<ng-container *ngIf=\"control as control\">\r\n <mat-form-field [appearance]=\"control.style\" class=\"asw-mat-form-field {{control.customClass}}\">\r\n <mat-label>{{control.label}}</mat-label>\r\n <input matInput type=\"text\"\r\n [placeholder]=\"control.placeholder\"\r\n [(ngModel)]=\"control.value\"\r\n #input=\"ngModel\"\r\n (ngModelChange)=\"onChange(control)\"\r\n [matTooltip]=\"control.tooltip\" [disabled]=\"true\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"input.invalid && (input.dirty || input.touched)\">\r\n <mat-error class=\"asw-mat-error\" *ngIf=\"input?.errors?.required\">\r\n {{control.label}} is required\r\n </mat-error>\r\n </mat-error>\r\n </mat-form-field>\r\n <ng-template [ngIf]=\"isPreviewTemplate\">\r\n <div class=\"row mb-2\">\r\n <div class=\"col-md-12\">\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Duplicate\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"duplicateCalculationControl(control)\">\r\n <mat-icon>content_copy</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Edit\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"editCalculationDialog(control, formControls, controlIndex)\">\r\n <mat-icon>edit</mat-icon>\r\n </button>\r\n <button mat-icon-button \r\n type=\"button\" \r\n matTooltip=\"Delete\" \r\n [matTooltipPosition]=\"'below'\" \r\n (click)=\"deleteCalculationDialog(control, controlIndex)\">\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n </div> \r\n </div>\r\n </ng-template>\r\n</ng-container>" }] }], ctorParameters: () => [{ type: i2.MatDialog }], propDecorators: { control: [{ type: Input }], formControls: [{ type: Input }], controlIndex: [{ type: Input }], isPreviewTemplate: [{ type: Input }], calculationUpdateEvent: [{ type: Output }], calculationDeleteEvent: [{ type: Output }], aswModelChange: [{ type: Output }], duplicateControl: [{ type: Output }] } }); /** * @license * Copyright ASW (A Software World) All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file */ class AswCalculationModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.11", ngImport: i0, type: AswCalculationModule, declarations: [AswCalculation, AswCalculationDialog], imports: [CommonModule, FormsModule, ReactiveFormsModule, MatInputModule, MatSelectModule, MatDialogModule, MatSlideToggleModule, MatTooltipModule, MatDividerModule, MatIconModule, AswConfirmDialogModule, MatButtonModule], exports: [AswCalculation, AswCalculationDialog] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculationModule, imports: [CommonModule, FormsModule, ReactiveFormsModule, MatInputModule, MatSelectModule, MatDialogModule, MatSlideToggleModule, MatTooltipModule, MatDividerModule, MatIconModule, AswConfirmDialogModule, MatButtonModule] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.11", ngImport: i0, type: AswCalculationModule, decorators: [{ type: NgModule, args: [{ imports: [ CommonModule, FormsModule, ReactiveFormsModule, MatInputModule, MatSelectModule, MatDialogModule, MatSlideToggleModule, MatTooltipModule, MatDividerModule, MatIconModule, AswConfirmDialogModule, MatButtonModule ], declarations: [ AswCalculation, AswCalculationDialog ], exports: [ AswCalculation, AswCalculationDialog ] }] }] }); /** * @license * Copyright ASW (A Software World) All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file */ /** * Generated bundle index. Do not edit. */ export { AswCalculation, AswCalculationDialog, AswCalculationModule }; //# sourceMappingURL=asoftwareworld-form-builder-form-control-calculation.mjs.map