UNPKG

awv3

Version:
96 lines (87 loc) 3.87 kB
import Plugin from '../../session/plugin'; import Dimension from '../dimension/'; import { buildFeaturePath } from '../../session/helpers'; import { Spacer, Group, Button, Input, Label, Selection, Checkbox, Dropdown, Console, Link } from '../../session/elements'; import { actions as connectionActions } from 'awv3/session/store/connections'; const resources = ['isometric'].reduce((prev, item) => ({ ...prev, [item]: require('!!url-loader!awv3-icons/32x32/' + item + '.png') }), { }); export default class Feature extends Plugin { constructor(session, args) { super(session, { type: 'Feature', icon: 'feature', resources, ...args }); this.dimension = new Dimension(this.session, { name: 'Dimensions', collapsed: true, closeable: false, parent: this.id }); this.dimension.afterSetCallback = () => { this.connection.execute('_O.OBJ_Recalc();'); } this.dependencies.push(this.dimension); } onEnabled() { let members = this.tree[this.feature].members; let header = new Group(this, { name: 'Name', margin: false, format: Group.Format.Rows, children: [ new Label(this, { value: 'Expression', header: true }), new Label(this, { value: 'Value', header: true }) ] }); this.addElement( new Group(this, { format: Group.Format.Table, children: [header, ...Object.keys(members).filter(key => members[key]).map(key => { let member = members[key]; let expression = new Input(this, { value: member.expression }); expression.observe(state => state.lastEvent, async event => { if (event.key === 'Enter') { let path = buildFeaturePath(this.tree, this.feature); let current = this.tree[this.feature].members[key].expression; let command = `${path}.OBJ_SetMemberExpr("${key}","${expression.value}");_C.GlobaleFunktionen.UseOnStartRecalc(_O);`; let reset = `${path}.OBJ_SetMemberExpr("${key}","${current}"); _C.GlobaleFunktionen.UseOnStartRecalc(_O);`; this.store.dispatch( connectionActions.message(this.connection.id, 'Reset', command, reset) ); let { context } = await this.connection.execute(command); } }); let memberValue = Array.isArray(member.value) ? `[${member.value.map(value => value.toFixed(1)).join(',')}]` : member.value; let value = new Input(this, { value: memberValue }); value.observe(state => state.lastEvent, async event => { if (event.key === 'Enter') { // ? } }); return new Group(this, { name: key, margin: false, format: Group.Format.Rows, children: [expression, value] }); })] }) ); this.addElement(new Spacer(this)); this.addElement(new Link(this, { value: this.dimension.id, collapsable: true })); this.dimension.enabled = true; } onDisabled() { this.dimension.enabled = false; this.destroyElements(); } }