|
|
@ -14,7 +14,7 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import { AfterViewInit, Component, Inject } from '@angular/core'; |
|
|
import { Component, DestroyRef, Inject } from '@angular/core'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { AppState } from '@core/core.state'; |
|
|
import { AppState } from '@core/core.state'; |
|
|
@ -28,6 +28,7 @@ import { |
|
|
CalculatedFieldType, |
|
|
CalculatedFieldType, |
|
|
CalculatedFieldTypeTranslations, |
|
|
CalculatedFieldTypeTranslations, |
|
|
getCalculatedFieldArgumentsEditorCompleter, |
|
|
getCalculatedFieldArgumentsEditorCompleter, |
|
|
|
|
|
getCalculatedFieldArgumentsHighlights, |
|
|
OutputType, |
|
|
OutputType, |
|
|
OutputTypeTranslations |
|
|
OutputTypeTranslations |
|
|
} from '@shared/models/calculated-field.models'; |
|
|
} from '@shared/models/calculated-field.models'; |
|
|
@ -37,13 +38,14 @@ import { EntityType } from '@shared/models/entity-type.models'; |
|
|
import { map, startWith } from 'rxjs/operators'; |
|
|
import { map, startWith } from 'rxjs/operators'; |
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|
|
import { ScriptLanguage } from '@shared/models/rule-node.models'; |
|
|
import { ScriptLanguage } from '@shared/models/rule-node.models'; |
|
|
|
|
|
import { CalculatedFieldsService } from '@core/http/calculated-fields.service'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'tb-calculated-field-dialog', |
|
|
selector: 'tb-calculated-field-dialog', |
|
|
templateUrl: './calculated-field-dialog.component.html', |
|
|
templateUrl: './calculated-field-dialog.component.html', |
|
|
styleUrls: ['./calculated-field-dialog.component.scss'], |
|
|
styleUrls: ['./calculated-field-dialog.component.scss'], |
|
|
}) |
|
|
}) |
|
|
export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFieldDialogComponent, CalculatedField> implements AfterViewInit { |
|
|
export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFieldDialogComponent, CalculatedField> { |
|
|
|
|
|
|
|
|
fieldFormGroup = this.fb.group({ |
|
|
fieldFormGroup = this.fb.group({ |
|
|
name: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex), Validators.maxLength(255)]], |
|
|
name: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex), Validators.maxLength(255)]], |
|
|
@ -73,6 +75,12 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi |
|
|
map(argumentsObj => getCalculatedFieldArgumentsEditorCompleter(argumentsObj)) |
|
|
map(argumentsObj => getCalculatedFieldArgumentsEditorCompleter(argumentsObj)) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
argumentsHighlightRules$ = this.configFormGroup.get('arguments').valueChanges |
|
|
|
|
|
.pipe( |
|
|
|
|
|
startWith(this.data.value?.configuration?.arguments ?? {}), |
|
|
|
|
|
map(argumentsObj => getCalculatedFieldArgumentsHighlights(argumentsObj)) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
additionalDebugActionConfig = this.data.value?.id ? { |
|
|
additionalDebugActionConfig = this.data.value?.id ? { |
|
|
...this.data.additionalDebugActionConfig, |
|
|
...this.data.additionalDebugActionConfig, |
|
|
action: () => this.data.additionalDebugActionConfig.action({ id: this.data.value.id, ...this.fromGroupValue }), |
|
|
action: () => this.data.additionalDebugActionConfig.action({ id: this.data.value.id, ...this.fromGroupValue }), |
|
|
@ -92,8 +100,11 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi |
|
|
protected router: Router, |
|
|
protected router: Router, |
|
|
@Inject(MAT_DIALOG_DATA) public data: CalculatedFieldDialogData, |
|
|
@Inject(MAT_DIALOG_DATA) public data: CalculatedFieldDialogData, |
|
|
protected dialogRef: MatDialogRef<CalculatedFieldDialogComponent, CalculatedField>, |
|
|
protected dialogRef: MatDialogRef<CalculatedFieldDialogComponent, CalculatedField>, |
|
|
|
|
|
private calculatedFieldsService: CalculatedFieldsService, |
|
|
|
|
|
private destroyRef: DestroyRef, |
|
|
private fb: FormBuilder) { |
|
|
private fb: FormBuilder) { |
|
|
super(store, router, dialogRef); |
|
|
super(store, router, dialogRef); |
|
|
|
|
|
this.observeIsLoading(); |
|
|
this.applyDialogData(); |
|
|
this.applyDialogData(); |
|
|
this.observeTypeChanges(); |
|
|
this.observeTypeChanges(); |
|
|
} |
|
|
} |
|
|
@ -112,19 +123,15 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi |
|
|
return { configuration: { ...restConfig, type, expression: configuration['expression'+type] }, ...rest, type } as CalculatedField; |
|
|
return { configuration: { ...restConfig, type, expression: configuration['expression'+type] }, ...rest, type } as CalculatedField; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngAfterViewInit(): void { |
|
|
|
|
|
if (this.data.isDirty) { |
|
|
|
|
|
this.fieldFormGroup.markAsDirty(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cancel(): void { |
|
|
cancel(): void { |
|
|
this.dialogRef.close(null); |
|
|
this.dialogRef.close(null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
add(): void { |
|
|
add(): void { |
|
|
if (this.fieldFormGroup.valid) { |
|
|
if (this.fieldFormGroup.valid) { |
|
|
this.dialogRef.close(this.fromGroupValue); |
|
|
this.calculatedFieldsService.saveCalculatedField({ entityId: this.data.entityId, ...(this.data.value ?? {}), ...this.fromGroupValue}) |
|
|
|
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
|
|
|
.subscribe(calculatedField => this.dialogRef.close(calculatedField)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -169,4 +176,19 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi |
|
|
this.configFormGroup.get('expressionSCRIPT').enable({emitEvent: false}); |
|
|
this.configFormGroup.get('expressionSCRIPT').enable({emitEvent: false}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private observeIsLoading(): void { |
|
|
|
|
|
this.isLoading$.pipe(takeUntilDestroyed()).subscribe(loading => { |
|
|
|
|
|
if (loading) { |
|
|
|
|
|
this.fieldFormGroup.disable({emitEvent: false}); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.fieldFormGroup.enable({emitEvent: false}); |
|
|
|
|
|
this.toggleScopeByOutputType(this.outputFormGroup.get('type').value); |
|
|
|
|
|
this.toggleKeyByCalculatedFieldType(this.fieldFormGroup.get('type').value); |
|
|
|
|
|
if (this.data.isDirty) { |
|
|
|
|
|
this.fieldFormGroup.markAsDirty(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|