Skip to content

Commit

Permalink
Input actions, rework copy mechanism and cleanup some stuff (#40)
Browse files Browse the repository at this point in the history
* Lay the foundation for actions with input in frontend
This involved cleaning up some things, and especially rewriting the copy process

* Add actions with inputs to the front-end

* Some minor cosmetic changes

* Update dependencies

* Fix linting

* Add actions with input to backend

* Cleanup part 1

* Cleanup part 2

* Final remainder cleanup
Mainly renaming almost everything json-specific to the more general term "serialization"

* Improve style
  • Loading branch information
bewee authored Feb 7, 2021
1 parent 1ade436 commit 0717ba1
Show file tree
Hide file tree
Showing 16 changed files with 801 additions and 489 deletions.
2 changes: 1 addition & 1 deletion classes/arithmetic/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
card.setTooltipText('Comparison');
card.addParameter('left', {accepts: 'evaluable', text: 'x'});
card.addParameter('right', {accepts: 'evaluable', text: 'y'});
card.addInput('cmp', 'string', {enum: ['=', '>', '<', '>=', '<=', '!='], venum: ['=', '>', '<', '≥', '≤', '≠']});
card.addInput('cmp', {type: 'string', enum: ['=', '>', '<', '>=', '<=', '!='], venum: ['=', '>', '<', '≥', '≤', '≠']});
card.setText(`%p %i %p`, 'left', 'cmp', 'right');
card.addAbility('evaluable');
}
Expand Down
2 changes: 1 addition & 1 deletion classes/comment/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
constructor(handler) {
const block = handler.addBlock(null, ['Basics']);
block.setTooltipText('Comments');
block.addInput('text', 'string', {placeholder: 'Put your comment here'});
block.addInput('text', {type: 'string', placeholder: 'Put your comment here'});
block.setText('// %i', 'text');
block.setAttribute('comment', 'true');
block.addAbility('header');
Expand Down
8 changes: 4 additions & 4 deletions classes/constant/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
const card = handler.addCard('boolean', ['Constants']);
card.setTooltipText('True/False');
card.addAbility('evaluable');
card.addInput('value', 'boolean', {value: true});
card.addInput('value', {type: 'boolean', value: true});
card.setText('%i', 'value');
}
{
const card = handler.addCard('number', ['Constants']);
card.setTooltipText('Number');
card.addAbility('evaluable');
card.addInput('value', 'number', {placeholder: 'number'});
card.addInput('value', {type: 'number', placeholder: 'number'});
card.setText('%i', 'value');
}
{
const card = handler.addCard('string', ['Constants']);
card.setTooltipText('Text');
card.addAbility('evaluable');
card.addInput('value', 'string', {placeholder: 'text'});
card.addInput('value', {type: 'string', placeholder: 'text'});
card.setText('%i', 'value');
}
{
const card = handler.addCard('null', ['Constants']);
card.setTooltipText('None');
card.addAbility('evaluable');
card.setText('none');
card.setJSONAttribute('value', null);
card.addInternalAttribute('value', null);
}
}

Expand Down
132 changes: 72 additions & 60 deletions classes/controlflow/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,80 @@
block.setText('Wait %p seconds', 'time');
}
{
const setText = (block) => {
let ps = '';
const args = [];
for (let i = 1; i <= Object.keys(block.parameters).length; i++) {
ps += ' \n%p\n%d\n';
args.push(`program${i}`);
const delbttn = document.createElement('BUTTON');
delbttn.innerHTML = 'x';
delbttn.addEventListener('mousedown', (ev) => {
ev.stopPropagation();
});
delbttn.addEventListener('click', () => {
handler.editor.changes();
for (let j = i; j < Object.keys(block.parameters).length; j++) {
block.parameters[`program${j}`] = block.parameters[`program${j+1}`];
block.parameters[`program${j}`].name = `program${j}`;
block.parameters[`program${j}`].setText(`Program ${j}`);
}
delete block.parameters[`program${Object.keys(block.parameters).length}`];
setText(block);
});
args.push(delbttn);
const load_block = handler.addLoadBlock('async', (copy) => {
copy.updateInternalAttribute('programCount', 2);
let i = 3;
for (; `program${i}` in copy.getCachedSerialization(); i++) {
this.addProgram(copy);
const maxid = {i: handler.editor.nextId};
copy.getParameter(`program${i}`).loadFromSerialization(copy.getCachedSerialization()[`program${i}`], maxid);
handler.editor.nextId = Math.max(handler.editor.nextId, maxid.i);
}
const addbttn = document.createElement('BUTTON');
addbttn.innerHTML = '+';
addbttn.addEventListener('mousedown', (ev) => {
ev.stopPropagation();
});
addbttn.addEventListener('click', () => {
handler.editor.changes();
const i = Object.keys(block.parameters).length+1;
block.addParameter(`program${i}`, {accepts: 'executable[]', text: `Program ${i}`});
setText(block, addbttn);
});
block.setText(`Execute in parallel\n${ps} \n%d`, ...args, addbttn);
};
const block = handler.addBlock('async', ['Controlflow']);
block.addParameter('program1', {accepts: 'executable[]', text: 'Program 1'});
block.copyFromJSON = ((json, maxid) => {
maxid.i = Math.max(maxid.i, json.id);
const copy = block.copy();
copy.setAttribute('macro-block-no', json.id);
copy.className = copy.className.split(' ').includes('macrocard') ? 'macroblock macrocard placed' : 'macroblock placed';
let i = 2;
while (`program${i}` in json) {
copy.addParameter(`program${i}`, {accepts: 'executable[]', text: `Program ${i}`});
i++;
}
for (const parname in copy.parameters) {
copy.parameters[parname].copyFromJSON(json[parname], maxid);
}
setText(copy);
return copy;
}).bind(block);
const oldcopy = block.copy;
block.copy = () => {
const copy = oldcopy.call(block);
setText(copy);
return copy;
};
setText(block);
this.setupAsyncBlock(copy);
});
load_block.addInternalAttribute('programCount', 0);
this.addProgram(load_block);
this.addProgram(load_block);
load_block.addInput('add', {
type: 'button',
text: '+',
onClick: (block, _ev) => {
this.addProgram(block);
block.changes();
},
});
const block = handler.addBlock('async', ['Controlflow'], load_block);
this.setupAsyncBlock(block);
}
}

addProgram(block) {
const id = block.getInternalAttribute('programCount')+1;
block.addParameter(`program${id}`, {accepts: 'executable[]', text: `Program ${id}`});
block.addInput(`delprogram${id}`, {
type: 'button',
text: 'x',
onClick: (block, _ev) => {
this.delProrgam(block, id);
block.changes();
},
});
block.updateInternalAttribute('programCount', id);
this.setTextForAsyncBlock(block);
}

delProrgam(block, i) {
block.setText('');
block.deleteParameter(`program${i}`);
block.deleteInput(`delprogram${i}`);
for (let j = i+1; j <= block.getInternalAttribute('programCount'); j++) {
block.updateParameter(`program${j}`, {text: `Program ${j-1}`});
block.renameParameter(`program${j}`, `program${j-1}`);
block.renameInput(`delprogram${j}`, `delprogram${j-1}`);
}
block.updateInternalAttribute('programCount', block.getInternalAttribute('programCount')-1);
this.setTextForAsyncBlock(block);
}

setupAsyncBlock(block) {
this.setTextForAsyncBlock(block);
block.revive();
}

setTextForAsyncBlock(block) {
const args = [];
let ps = '';
for (let i = 1; i <= block.getInternalAttribute('programCount'); i++) {
if (block.getInternalAttribute('programCount') <= 2) {
ps += ' \n%p\n';
args.push(`program${i}`);
} else {
ps += ' \n%p\n%i\n';
args.push(`program${i}`);
args.push(`delprogram${i}`);
}
}
block.setText(`Execute in parallel\n${ps} \n%i`, ...args, 'add');
}

}
Expand Down
2 changes: 1 addition & 1 deletion classes/gateway/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const card = handler.addCard('execution_reason', ['Gateway']);
card.setTooltipText('Reason for execution (e.g. "manual execution", "trigger nr 1", ...)');
card.addAbility('evaluable');
card.setText('Reason for execution', 'ev');
card.setText('Reason for execution');
}
}

Expand Down
2 changes: 1 addition & 1 deletion classes/log/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
constructor(handler) {
const block = handler.addBlock(null, ['Basics']);
block.setTooltipText('Log');
block.addInput('level', 'string', {enum: ['debug', 'info', 'warn', 'error', 'fatal'], venum: ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']});
block.addInput('level', {type: 'string', enum: ['debug', 'info', 'warn', 'error', 'fatal'], venum: ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']});
block.addParameter('title', {accepts: 'evaluable'});
block.addParameter('message', {accepts: 'evaluable'});
block.setText('Log %i %p: %p', 'level', 'title', 'message');
Expand Down
6 changes: 3 additions & 3 deletions classes/sun/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
card.setTooltipText('Sun trigger');
card.addAbility('trigger');
const sunevs_ = sunevs.map((x) => `sun_${x}`);
card.addInput('ev', 'string', {enum: sunevs_, venum: vsunevs});
card.addInput('ev', {type: 'string', enum: sunevs_, venum: vsunevs});
card.setText('%i', 'ev');
}
const g_beforeafter = handler.addGroup('sun_beforeafter', ['Date & Time']);
Expand All @@ -19,7 +19,7 @@
card.setTooltipText('Before sun event?');
card.addAbility('evaluable');
const sunevs_ = sunevs.map((x) => `sun_before_${x}`);
card.addInput('ev', 'string', {enum: sunevs_, venum: vsunevs});
card.addInput('ev', {type: 'string', enum: sunevs_, venum: vsunevs});
card.setText('Before %i ?', 'ev');
g_beforeafter.assign(card);
}
Expand All @@ -28,7 +28,7 @@
card.setTooltipText('After sun event?');
card.addAbility('evaluable');
const sunevs_ = sunevs.map((x) => `sun_after_${x}`);
card.addInput('ev', 'string', {enum: sunevs_, venum: vsunevs});
card.addInput('ev', {type: 'string', enum: sunevs_, venum: vsunevs});
card.setText('After %i ?', 'ev');
g_beforeafter.assign(card);
}
Expand Down
Loading

0 comments on commit 0717ba1

Please sign in to comment.