You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
9.4 KiB
267 lines
9.4 KiB
9 months ago
|
import { $t, axios, Environment, Tools } from 'platform-core';
|
||
|
import { PlaceHolder } from '@/utils/PlaceHolder';
|
||
|
import { AutoCompletionManager } from '@/views/shared/AutoCompletionManager';
|
||
|
import { UserDefinedFunctionsManager } from '@/views/shared/UserDefinedFunctionsManager';
|
||
|
|
||
|
const autoCompletionManager = new AutoCompletionManager();
|
||
|
const userDefinedFunctionsManager = new UserDefinedFunctionsManager();
|
||
|
|
||
|
class ObjectProperties {
|
||
|
public static getToolbarAction(parameter: any) {
|
||
|
return {
|
||
|
extend: 'add',
|
||
|
name: 'objectProperties',
|
||
|
label: $t('io.sc.engine.rule.core.enums.ProcessorType.OBJECT_PROPERTIES'),
|
||
|
icon: 'bi-card-list',
|
||
|
enableIf: (args: any) => {
|
||
|
const valueType = parameter.valueType;
|
||
|
return (
|
||
|
valueType !== 'java.lang.Boolean' &&
|
||
|
valueType !== 'java.lang.Long' &&
|
||
|
valueType !== 'java.lang.Float' &&
|
||
|
valueType !== 'Float' &&
|
||
|
valueType !== 'java.math.BigDecimal' &&
|
||
|
valueType !== 'java.lang.String' &&
|
||
|
valueType !== 'java.util.Date' &&
|
||
|
valueType !== 'io.sc.engine.rule.core.classes.ResourceAbstract' &&
|
||
|
valueType !== 'io.sc.engine.rule.core.classes.RuleResult' &&
|
||
|
valueType !== 'io.sc.engine.rule.core.classes.SingleRuleResult' &&
|
||
|
!valueType.startsWith('List') &&
|
||
|
!valueType.startsWith('Map')
|
||
|
);
|
||
|
},
|
||
|
afterClick: (args: any) => {
|
||
|
args.grid.getEditorForm().setFieldValue('type', 'OBJECT_PROPERTIES');
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public static format(row: any) {
|
||
|
let str = '';
|
||
|
if (row.objectCondition) {
|
||
|
str += `<div class='py-2'>When ` + PlaceHolder.replace(row.objectCondition) + ' Then</div>';
|
||
|
}
|
||
|
const objs = Tools.json2Object(row.objectProperties);
|
||
|
if (objs) {
|
||
|
str += `<div class='border border-b-0 overflow-auto' style='max-height:100px'>`;
|
||
|
str += `<table width='100%' height='100%'>`;
|
||
|
objs.forEach((obj: any) => {
|
||
|
str += '<tr>';
|
||
|
str += ` <td width='30%'>` + obj.name + `</td>`;
|
||
|
str += ` <td width='70%'><span>` + ('' + PlaceHolder.replace(obj.expression)) + '</span></td>';
|
||
|
str += '</tr>';
|
||
|
});
|
||
|
str += '</table>';
|
||
|
str += `</div>`;
|
||
|
}
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
public static getEditorFields(properties: any) {
|
||
|
return [
|
||
|
{
|
||
|
colSpan: 5,
|
||
|
name: 'objectCondition',
|
||
|
label: $t('re.resources.designer.processor.grid.entity.objectCondition'),
|
||
|
type: 'w-code-mirror',
|
||
|
lang: 'java',
|
||
|
rows: 3,
|
||
|
lineWrap: true,
|
||
|
lineBreak: false,
|
||
|
autoCompletion: autoCompletionManager.autoCompletion(),
|
||
|
userDefinedFunctions: userDefinedFunctionsManager.userDefinedFunctions(),
|
||
|
showIf: (args: any) => {
|
||
|
return 'OBJECT_PROPERTIES' === args.form.getFieldValue('type');
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
colSpan: 5,
|
||
|
name: 'objectProperties',
|
||
|
label: $t('re.resources.designer.processor.grid.entity.objectProperties'),
|
||
|
showIf: (args: any) => {
|
||
|
return 'OBJECT_PROPERTIES' === args.form.getFieldValue('type');
|
||
|
},
|
||
|
type: 'w-grid',
|
||
|
title: $t('re.resources.designer.processor.grid.entity.objectProperties'),
|
||
|
height: 400,
|
||
|
autoFetchData: false,
|
||
|
dbClickOperation: 'edit',
|
||
|
dense: true,
|
||
|
draggable: 'local',
|
||
|
pageable: false,
|
||
|
configButton: false,
|
||
|
toolbarConfigure: { noIcon: false },
|
||
|
toolbarActions: [
|
||
|
'separator',
|
||
|
{
|
||
|
name: 'autoMatch',
|
||
|
label: $t('autoMatch'),
|
||
|
icon: 'bi-link-45deg',
|
||
|
click: (args: any) => {
|
||
|
const grid = properties.gridRef.getEditorForm().getFieldComponent('objectProperties');
|
||
|
const localData = grid.getRows();
|
||
|
const objectProperties: any[] = [];
|
||
|
localData.forEach((item: any) => {
|
||
|
objectProperties.push({
|
||
|
code: item.code,
|
||
|
name: item.name,
|
||
|
expression: item.expression,
|
||
|
});
|
||
|
});
|
||
|
properties.objectPropertiesMatcherDialogRef.open(objectProperties);
|
||
|
},
|
||
|
},
|
||
|
'edit',
|
||
|
{
|
||
|
extend: 'remove',
|
||
|
click: (args: any) => {
|
||
|
const grid = properties.gridRef.getEditorForm().getFieldComponent('objectProperties');
|
||
|
const selecteds: any[] = args.selecteds;
|
||
|
selecteds.forEach((selected) => {
|
||
|
selected.expression = '';
|
||
|
grid.updateLocalData(selected);
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
'separator',
|
||
|
{
|
||
|
extend: 'remove',
|
||
|
name: 'removeAll',
|
||
|
label: $t('removeAll'),
|
||
|
icon: 'bi-trash3',
|
||
|
enableIf: () => {
|
||
|
return true;
|
||
|
},
|
||
|
click: (args) => {
|
||
|
const grid = properties.gridRef.getEditorForm().getFieldComponent('objectProperties');
|
||
|
const rows: any[] = grid.getRows();
|
||
|
rows.forEach((row) => {
|
||
|
row.expression = '';
|
||
|
});
|
||
|
grid.setLocalData(rows);
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
primaryKey: 'code',
|
||
|
columns: [
|
||
|
{ name: 'code', label: 'code', hidden: true },
|
||
|
{
|
||
|
width: 300,
|
||
|
name: 'name',
|
||
|
label: $t('propertyName'),
|
||
|
align: 'left',
|
||
|
sortable: false,
|
||
|
format: (value: any, row: any) => {
|
||
|
if (row.expression) {
|
||
|
const expression = row.expression.replace(/\$\{(.+?)\.(.+?)\}/g, '$2');
|
||
|
if (expression.trim() !== value.trim()) {
|
||
|
return `<span class='text-red-500'>` + value + '</span>';
|
||
|
}
|
||
|
}
|
||
|
return value;
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
width: '100%',
|
||
|
name: 'expression',
|
||
|
label: $t('expression'),
|
||
|
sortable: false,
|
||
|
format: (value: any) => {
|
||
|
return PlaceHolder.replace(value);
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
editor: {
|
||
|
dialog: {
|
||
|
width: '800px',
|
||
|
},
|
||
|
form: {
|
||
|
colsNum: 1,
|
||
|
fields: [
|
||
|
{ name: 'code', label: 'code', showIf: false },
|
||
|
{
|
||
|
name: 'expression',
|
||
|
label: $t('expression'),
|
||
|
type: 'w-code-mirror',
|
||
|
lang: 'java',
|
||
|
rows: 3,
|
||
|
lineWrap: true,
|
||
|
lineBreak: false,
|
||
|
placeholder: true,
|
||
|
autoCompletion: autoCompletionManager.autoCompletion(),
|
||
|
userDefinedFunctions: userDefinedFunctionsManager.userDefinedFunctions(),
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
onBeforeEditorDataSubmit: (args: any) => {
|
||
|
const grid = properties.gridRef.getEditorForm().getFieldComponent('objectProperties');
|
||
|
const form = grid.getEditorForm();
|
||
|
if ('edit' == form.getStatus()) {
|
||
|
grid.updateLocalData(args.data);
|
||
|
args.callback(false);
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public static getViewerFields(properties) {
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
public static beforeEditorDataSubmit(args: any) {
|
||
|
const form = args.grid.getEditorForm();
|
||
|
const grid = form.getFieldComponent('objectProperties');
|
||
|
const localData: any[] = grid.getRows();
|
||
|
const objectProperties: any[] = [];
|
||
|
localData.forEach((item) => {
|
||
|
objectProperties.push({
|
||
|
code: item.code,
|
||
|
name: item.name,
|
||
|
expression: item.expression,
|
||
|
});
|
||
|
});
|
||
|
args.data.objectProperties = Tools.object2Json(objectProperties);
|
||
|
}
|
||
|
|
||
|
public static afterEditorOpen(args: any) {
|
||
|
if (args.type === 'parameter') {
|
||
|
autoCompletionManager.load(Environment.apiContextPath('/api/re/common/listParameterAndValueTypeByParameterId/' + args.parameter.id));
|
||
|
} else if (args.type === 'indicator') {
|
||
|
autoCompletionManager.load(Environment.apiContextPath('/api/re/common/listParameterAndValueTypeByIndicatorId/' + args.indicator.id));
|
||
|
}
|
||
|
userDefinedFunctionsManager.load();
|
||
|
|
||
|
const form = args.grid.getEditorForm();
|
||
|
const row = args.data;
|
||
|
if ('add' == form.getStatus()) {
|
||
|
let listObejctPropertiesUrl = '';
|
||
|
if (args.type === 'parameter') {
|
||
|
listObejctPropertiesUrl = '/api/re/model/parameter/listObejctPropertiesByParameterId/' + args.parameter.id;
|
||
|
} else if (args.type === 'indicator') {
|
||
|
listObejctPropertiesUrl = '/api/re/indicator/listObejctPropertiesByIndicatorId/' + args.indicator.id;
|
||
|
}
|
||
|
axios.get(Environment.apiContextPath(listObejctPropertiesUrl)).then((response) => {
|
||
|
const properties = response.data;
|
||
|
const grid = form.getFieldComponent('objectProperties');
|
||
|
grid?.setLocalData(properties);
|
||
|
});
|
||
|
} else if ('edit' == form.getStatus()) {
|
||
|
let listObejctPropertiesUrl = '';
|
||
|
if (args.type === 'parameter') {
|
||
|
listObejctPropertiesUrl = '/api/re/model/parameter/processor/listObejctPropertiesByProcessorId/' + row.id;
|
||
|
} else if (args.type === 'indicator') {
|
||
|
listObejctPropertiesUrl = '/api/re/indicator/processor/listObejctPropertiesByProcessorId/' + row.id;
|
||
|
}
|
||
|
axios.get(Environment.apiContextPath(listObejctPropertiesUrl)).then((response) => {
|
||
|
const properties = response.data;
|
||
|
const grid = form.getFieldComponent('objectProperties');
|
||
|
grid?.setLocalData(properties);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export { ObjectProperties };
|