From 4f7e960578efba7411d6709a84a12c1bb652b233 Mon Sep 17 00:00:00 2001 From: Caldwell Date: Tue, 1 May 2018 16:54:29 -0400 Subject: [PATCH 1/2] Optionally split states into separate outputs --- package.json | 16 +++--------- state-machine.html | 62 +++++++++++++++++++++++++++++++++++----------- state-machine.js | 12 ++++++++- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 15dda49..035628f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name": "node-red-contrib-state-machine", - "version": "1.2.0", + "name": "node-red-contrib-state-machine-2", + "version": "1.2.1", "description": "A Node Red node for implementing a finite state machine.", "dependencies": { "javascript-state-machine": "3.*" }, "author": { - "name": "Dean Cording", + "name": "Blind Squirrel", "email": "dean@cording.id.au" }, "license": "MIT", @@ -18,17 +18,9 @@ "state", "transition" ], - "bugs": { - "url": "https://github.com/DeanCording/node-red-contrib-state-machine/issues" - }, - "homepage": "https://github.com/DeanCording/node-red-contrib-state-machine", - "repository": { - "type": "git", - "url": "https://github.com/DeanCording/node-red-contrib-state-machine.git" - }, "node-red": { "nodes": { - "state-machine": "state-machine.js" + "state-machine-2": "state-machine.js" } }, "devDependencies": { diff --git a/state-machine.html b/state-machine.html index 78f1266..a30b93e 100644 --- a/state-machine.html +++ b/state-machine.html @@ -37,13 +37,14 @@ statePropertyType: {value: "msg", required: true}, outputStateChangeOnly: {value: false}, throwException: {value: false}, + discreteOutputs: {value: false}, states: {value: ["start", "", "", ""], validate: function(states) { return (states.length > 0); } }, - transitions: {value: [{name:"", from: "", to: ""}, - {name:"", from: "", to: ""}, - {name:"", from: "", to: ""}], + transitions: {value: [{name:"", from: "", to: "", out: false}, + {name:"", from: "", to: "", out: false}, + {name:"", from: "", to: "", out: false}], validate: function(transitions) { return (transitions.length > 0) && (transitions.every(function(transition) { if (transition.name.length == 0) return false; @@ -53,10 +54,11 @@ return true; }, this)); } - } + }, + outputs: {value: 1} }, - inputs:1, - outputs:1, + inputs: 1, + outputs: 1, icon: "switch.png", label: function() { return this.name||"state machine"; @@ -65,8 +67,13 @@ return this.name?"node_label_italic":""; }, inputLabels: "trigger", - outputLabels: "state", + outputLabels: function(index) { + if(!this.discreteOutputs) return "state"; + + return this.states[index]; + }, oneditprepare: function() { + var node = this; if (!this.triggerPropertyType) { this.triggerPropertyType = 'msg'; @@ -86,13 +93,18 @@ typeField: $("#node-input-statePropertyType") }); + var outputCount = $("#node-input-outputDetails").val("{}"); var statesList = $("#node-input-states-container"); statesList.editableList({ addItem: function(container, i, state) { if (typeof state != "string") state = ""; - +/* + if (!state.hasOwnProperty('i')) { + state._i = Math.floor((0x99999-0x10000)*Math.random()).toString(); + } +*/ var stateField = $('',{type: "text", style:"margin-left: 5px;", class: 'node-input-state-value'}).appendTo(container).focus(); var label = $("