UNPKG

@lcap/asl

Version:

NetEase Application Specific Language

170 lines 5.76 kB
"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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnumItem = void 0; const decorators_1 = require("../decorators"); const __1 = require(".."); const data_1 = require("../../service/data"); /** * 枚举项 */ class EnumItem extends __1.Vertex { /** * @param source 需要合并的部分参数 */ constructor(source) { super(); /** * 概念类型 */ this.level = __1.LEVEL_ENUM.enumItem; /** * Id */ this.id = undefined; /** * 值 */ this.value = undefined; /** * 名称 */ this.label = undefined; /** * 枚举 Id */ this.enumId = undefined; /** * 父级引用 */ this.root = undefined; source && this.assign(source); } /** * 添加枚举项 */ async create(none, actionOptions) { __1.config.defaultApp?.emit('saving'); const body = this.toJSON(); __1.utils.logger.debug('添加枚举项', body); const result = await data_1.enumPropertyService.create({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'EnumItem.create', operationDesc: actionOptions?.actionDesc || `添加枚举项"${this.label}"`, }, body, }); this.deepPick(result, ['id']); this.root.dataNode.service.emit('dataTypesChange'); this.root.dataNode.service.emit('enumsChange'); this.root.dataNode.service.emit('vertexIdToNameChange', this.id, this.label); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); return this; } /** * 删除枚举项 */ async delete(none, actionOptions) { __1.config.defaultApp?.emit('saving'); if (this.id) { await data_1.enumPropertyService.delete({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'EnumItem.delete', operationDesc: actionOptions?.actionDesc || `删除枚举项"${this.label}"`, }, query: { id: this.id, }, }); } const index = this.root.enumItemList.indexOf(this); ~index && this.root.enumItemList.splice(index, 1); this.destroy(); this.root.dataNode.service.emit('dataTypesChange'); this.root.dataNode.service.emit('enumsChange'); 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(); body._posIndex = this.root.enumItemList.indexOf(this); await data_1.enumPropertyService.update({ headers: { appId: __1.config.defaultApp?.id, operationAction: actionOptions?.actionName || 'EnumItem.update', operationDesc: actionOptions?.actionDesc || `修改枚举项"${this.name}"`, }, body, }); await then?.(); await __1.config.defaultApp?.history.load(); __1.config.defaultApp?.emit('saved'); return this; } /** * 设置枚举项值 * @param value */ async setValue(value) { this.assign({ value }); await this.update(undefined, { actionDesc: '设置枚举项值', }); this.root.dataNode.service.emit('dataTypesChange'); this.root.dataNode.service.emit('enumsChange'); this.root.dataNode.service.emit('vertexIdToNameChange', this.id, this.value); } /** * 设置枚举项标题 * @param value */ async setLabel(label) { this.assign({ label }); await this.update(undefined, { actionDesc: '设置枚举项标题', }); this.root.dataNode.service.emit('dataTypesChange'); this.root.dataNode.service.emit('enumsChange'); this.root.dataNode.service.emit('vertexIdToNameChange', this.id, this.value); } } __decorate([ decorators_1.immutable() ], EnumItem.prototype, "level", void 0); __decorate([ decorators_1.immutable() ], EnumItem.prototype, "id", void 0); __decorate([ decorators_1.immutable() ], EnumItem.prototype, "value", void 0); __decorate([ decorators_1.immutable() ], EnumItem.prototype, "label", void 0); __decorate([ decorators_1.immutable() ], EnumItem.prototype, "enumId", void 0); __decorate([ decorators_1.circular(), decorators_1.immutable() ], EnumItem.prototype, "root", void 0); __decorate([ decorators_1.action('添加枚举项') ], EnumItem.prototype, "create", null); __decorate([ decorators_1.action('删除枚举项') ], EnumItem.prototype, "delete", null); exports.EnumItem = EnumItem; exports.default = EnumItem; //# sourceMappingURL=EnumItem.js.map