|
|
|
@ -36,9 +36,14 @@ import { EntityDebugSettingsPanelComponent } from '@home/components/entity/debug |
|
|
|
import { CalculatedFieldsService } from '@core/http/calculated-fields.service'; |
|
|
|
import { catchError, filter, switchMap, tap } from 'rxjs/operators'; |
|
|
|
import { |
|
|
|
ArgumentType, |
|
|
|
CalculatedField, |
|
|
|
CalculatedFieldArgument, |
|
|
|
CalculatedFieldEventArguments, |
|
|
|
CalculatedFieldDebugDialogData, |
|
|
|
CalculatedFieldDialogData, |
|
|
|
CalculatedFieldRollingValueArgumentAutocomplete, |
|
|
|
CalculatedFieldSingleValueArgumentAutocomplete, |
|
|
|
CalculatedFieldTestScriptDialogData, |
|
|
|
} from '@shared/models/calculated-field.models'; |
|
|
|
import { |
|
|
|
@ -48,6 +53,7 @@ import { |
|
|
|
} from './components/public-api'; |
|
|
|
import { ImportExportService } from '@shared/import-export/import-export.service'; |
|
|
|
import { isObject } from '@core/utils'; |
|
|
|
import { TbEditorCompleter } from '@shared/models/ace/completion.models'; |
|
|
|
|
|
|
|
export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedField, PageLink> { |
|
|
|
|
|
|
|
@ -58,7 +64,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
readonly tenantId = getCurrentAuthUser(this.store).tenantId; |
|
|
|
additionalDebugActionConfig = { |
|
|
|
title: this.translate.instant('calculated-fields.see-debug-events'), |
|
|
|
action: (calculatedField: CalculatedField) => this.openDebugDialog.call(this, calculatedField), |
|
|
|
action: (calculatedField: CalculatedField) => this.openDebugEventsDialog.call(this, calculatedField), |
|
|
|
}; |
|
|
|
|
|
|
|
constructor(private calculatedFieldsService: CalculatedFieldsService, |
|
|
|
@ -122,7 +128,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
name: this.translate.instant('entity-view.events'), |
|
|
|
icon: 'history', |
|
|
|
isEnabled: () => true, |
|
|
|
onAction: (_, entity) => this.openDebugDialog(entity), |
|
|
|
onAction: (_, entity) => this.openDebugEventsDialog(entity), |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: '', |
|
|
|
@ -149,7 +155,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
const { debugSettings = {}, id } = calculatedField; |
|
|
|
const additionalActionConfig = { |
|
|
|
...this.additionalDebugActionConfig, |
|
|
|
action: () => this.openDebugDialog(calculatedField) |
|
|
|
action: () => this.openDebugEventsDialog(calculatedField) |
|
|
|
}; |
|
|
|
const { viewContainerRef } = this.getTable(); |
|
|
|
if ($event) { |
|
|
|
@ -211,14 +217,15 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
entityName: this.entityName, |
|
|
|
additionalDebugActionConfig: this.additionalDebugActionConfig, |
|
|
|
getTestScriptDialogFn: this.getTestScriptDialog.bind(this), |
|
|
|
isDirty |
|
|
|
isDirty, |
|
|
|
getArgumentsEditorCompleterFn: this.getArgumentsEditorCompleter, |
|
|
|
}, |
|
|
|
enterAnimationDuration: isDirty ? 0 : null, |
|
|
|
}) |
|
|
|
.afterClosed(); |
|
|
|
} |
|
|
|
|
|
|
|
private openDebugDialog(calculatedField: CalculatedField): void { |
|
|
|
private openDebugEventsDialog(calculatedField: CalculatedField): void { |
|
|
|
this.dialog.open<CalculatedFieldDebugDialogComponent, CalculatedFieldDebugDialogData, null>(CalculatedFieldDebugDialogComponent, { |
|
|
|
disableClose: true, |
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
|
|
|
@ -267,7 +274,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
).subscribe(() => this.updateData()); |
|
|
|
} |
|
|
|
|
|
|
|
private getTestScriptDialog(calculatedField: CalculatedField, argumentsObj?: Record<string, unknown>, openCalculatedFieldEdit = true): Observable<string> { |
|
|
|
private getTestScriptDialog(calculatedField: CalculatedField, argumentsObj?: CalculatedFieldEventArguments, openCalculatedFieldEdit = true): Observable<string> { |
|
|
|
const resultArguments = Object.keys(calculatedField.configuration.arguments).reduce((acc, key) => { |
|
|
|
acc[key] = isObject(argumentsObj) && argumentsObj.hasOwnProperty(key) ? argumentsObj[key] : ''; |
|
|
|
return acc; |
|
|
|
@ -279,6 +286,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
data: { |
|
|
|
arguments: resultArguments, |
|
|
|
expression: calculatedField.configuration.expression, |
|
|
|
argumentsEditorCompleter: this.getArgumentsEditorCompleter(calculatedField.configuration.arguments), |
|
|
|
openCalculatedFieldEdit |
|
|
|
} |
|
|
|
}).afterClosed() |
|
|
|
@ -291,4 +299,13 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie |
|
|
|
}), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private getArgumentsEditorCompleter(argumentsObj: Record<string, CalculatedFieldArgument>): TbEditorCompleter { |
|
|
|
return new TbEditorCompleter(Object.keys(argumentsObj).reduce((acc, key) => { |
|
|
|
acc[key] = argumentsObj[key].refEntityKey.type === ArgumentType.Rolling |
|
|
|
? CalculatedFieldRollingValueArgumentAutocomplete |
|
|
|
: CalculatedFieldSingleValueArgumentAutocomplete; |
|
|
|
return acc; |
|
|
|
}, {})) |
|
|
|
} |
|
|
|
} |
|
|
|
|