@lcap/asl
Version:
NetEase Application Specific Language
252 lines • 9.92 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProcessComponentVariable = void 0;
const decorators_1 = require("../decorators");
const __1 = require("..");
const dataTypeUtils_1 = require("../data/dataTypeUtils");
const basicTypes_1 = require("../data/basicTypes");
const common_1 = require("../../service/common");
const process_1 = __importDefault(require("../../service/process"));
/**
* 流程组件局部变量
*/
class ProcessComponentVariable extends __1.Variable {
/**
* @param source 需要合并的部分参数
*/
constructor(source) {
super();
/**
* 概念类型
*/
this.level = __1.LEVEL_ENUM.processComponentVariable;
/**
* 流程组件 Id
*/
this.parentId = undefined;
/**
* 流程组件
*/
this.processComponent = undefined;
/**
* 默认值
* 按 JSON string 处理
* - string: 666 -> '666'
* - string: true -> 'true'
* - number: 666 -> 666
* - boolean: true -> true
*/
this.defaultValue = undefined;
source && this.assign(source);
}
genCode() {
return `ID_${this.processComponent.process.id}.ID_${this.processComponent.id}.ID_${this.id}`;
}
/**
* 添加流程组件局部变量
*/
async create(none, actionOptions) {
__1.config.defaultApp?.emit('saving');
this.assign({ loading: true, editing: false });
const body = this.toJSON();
const result = await process_1.default.addProcessVal({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'ProcessComponentVariable.create',
operationDesc: actionOptions?.actionDesc || `添加流程组件"${this.processComponent.name}"局部变量"${this.name}"`,
},
body,
});
this.assign(ProcessComponentVariable.from(result, this.processComponent));
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 删除流程组件局部变量
*/
async delete(none, actionOptions) {
if (this.id) {
__1.config.defaultApp?.emit('saving');
this.assign({ loading: true });
const body = this.toJSON();
await process_1.default.deleteProcessVal({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'ProcessComponentVariable.delete',
operationDesc: actionOptions?.actionDesc || `删除流程组件"${this.processComponent.name}"局部变量"${this.name}"`,
},
body,
});
const index = this.processComponent.variables.indexOf(this);
~index && this.processComponent.variables.splice(index, 1);
this.destroy();
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
}
}
/**
* 修改流程组件局部变量
*/
async update(none, actionOptions, then) {
__1.config.defaultApp?.emit('saving');
const body = this.toJSON();
const result = await process_1.default.updateProcessVal({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'ProcessComponentVariable.update',
operationDesc: actionOptions?.actionDesc || `修改流程组件"${this.processComponent.name}"局部变量"${this.name}"`,
},
body,
});
this.assign(ProcessComponentVariable.from(result, this.processComponent));
await then?.();
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 设置流程组件局部变量名称
* @param name 名称
*/
async setName(name) {
const oldName = this.name;
this.assign({ name });
await this.update(undefined, {
actionDesc: `设置流程组件"${this.processComponent.name}"的局部变量"${oldName}"的名称为"${name}"`,
});
}
/**
* 设置流程组件局部变量描述
* @param description 描述
*/
async setDescription(description) {
this.assign({ description });
await this.update(undefined, {
actionDesc: `设置流程组件"${this.processComponent.name}"的局部变量"${this.name}"的描述为"${description}"`,
});
}
/**
* 设置流程组件局部变量的数据类型
* @param $ref 数据类型
*/
async setDataType(schema) {
// 用于update失败后还原数据
const originalData = {
schema: Object.assign({}, this.schema),
defaultValue: this.defaultValue,
};
Object.assign(this.schema, {
$ref: undefined,
type: undefined,
format: undefined,
typeInstantiation: undefined,
});
Object.assign(this.schema, schema);
this.assign({ defaultValue: basicTypes_1.getBasicTypeDefaultValue() });
try {
await this.update(undefined, {
actionDesc: `设置流程组件"${this.processComponent.name}"的局部变量"${this.name}"的数据类型为"${this.schema.typeKey}"`,
});
this.genSchemaChildren();
this.processComponent.process.checkType();
}
catch (err) {
this.assign(originalData);
__1.config.defaultApp?.emit('saved');
throw err;
}
}
/**
* 设置流程组件局部变量是否为列表
* @param isArray
*/
async setAsList(isArray) {
this.schema.isArray = isArray;
this.assign({ defaultValue: basicTypes_1.getBasicTypeDefaultValue() });
await this.update(undefined, {
actionDesc: `设置流程组件"${this.processComponent.name}"的局部变量"${this.name}"${isArray ? '为' : '不为'}列表`,
});
this.genSchemaChildren();
}
/**
* 设置流程组件局部变量的默认值
* @param defaultValue 默认值
*/
async setDefaultValue(defaultValue) {
this.assign({ defaultValue });
await this.update(undefined, {
actionDesc: `设置流程组件"${this.processComponent.name}"的局部变量"${this.name}"的默认值为"${defaultValue}"`,
});
}
/**
* 查找schema 顶点被引用的流程顶点列表
*/
async getSchemaUsage() {
if (this.schema) {
const schemaId = this.schema.type === 'genericType' ? this.id : this.schema.id;
const result = await common_1.schemaService.getSchemaUsage({
query: {
schemaId,
valSource: 'process_component_variable',
},
});
return result;
}
}
/**
* 从后端 JSON 生成规范的 ProcessComponentVariable 对象
*/
static from(source, processComponent) {
dataTypeUtils_1.convert2RefType(source.schema);
source.processComponent = processComponent;
source.parentId = processComponent.id;
source.code = `ID_${processComponent.process.id}.ID_${processComponent.id}.ID_${source.id}`;
const processComponentVariable = new ProcessComponentVariable(source);
processComponentVariable.genSchemaChildren();
return processComponentVariable;
}
}
__decorate([
decorators_1.immutable()
], ProcessComponentVariable.prototype, "level", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponentVariable.prototype, "parentId", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], ProcessComponentVariable.prototype, "processComponent", void 0);
__decorate([
decorators_1.action('添加流程组件局部变量')
], ProcessComponentVariable.prototype, "create", null);
__decorate([
decorators_1.action('删除流程组件局部变量')
], ProcessComponentVariable.prototype, "delete", null);
__decorate([
decorators_1.action('设置流程组件局部变量名称')
], ProcessComponentVariable.prototype, "setName", null);
__decorate([
decorators_1.action('设置流程组件局部变量描述')
], ProcessComponentVariable.prototype, "setDescription", null);
__decorate([
decorators_1.action('设置流程组件局部变量的数据类型')
], ProcessComponentVariable.prototype, "setDataType", null);
__decorate([
decorators_1.action('设置流程组件局部变量是否为列表')
], ProcessComponentVariable.prototype, "setAsList", null);
__decorate([
decorators_1.action('设置流程组件局部变量的默认值')
], ProcessComponentVariable.prototype, "setDefaultValue", null);
exports.ProcessComponentVariable = ProcessComponentVariable;
exports.default = ProcessComponentVariable;
//# sourceMappingURL=ProcessComponentVariable.js.map