1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/packages/node_modules/@node-red/editor-client/src/js/runtime.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

RED.runtime = (function() {
let state = ""
let settings = {ui: false, enabled: false};
const STOPPED = "stopped"
const STARTED = "started"
return {
init: function() {
// refresh the current runtime status from server
settings = Object.assign({}, settings, RED.settings.runtimeState);
RED.runtime.requestState()
// {id:"flows-run-state", started: false, state: "stopped", retain:true}
RED.comms.subscribe("notification/flows-run-state",function(topic,msg) {
RED.events.emit("flows-run-state",msg);
RED.runtime.updateState(msg.state);
});
},
get state() {
return state
},
get started() {
return state === STARTED
},
get states() {
return { STOPPED, STARTED }
},
updateState: function(newState) {
state = newState;
// disable pointer events on node buttons (e.g. inject/debug nodes)
$(".red-ui-flow-node-button").toggleClass("red-ui-flow-node-button-stopped", state === STOPPED)
// show/hide Start/Stop based on current state
if(settings.enabled === true && settings.ui === true) {
RED.menu.setVisible("deploymenu-item-runtime-stop", state === STARTED)
RED.menu.setVisible("deploymenu-item-runtime-start", state === STOPPED)
}
},
requestState: function(callback) {
$.ajax({
headers: {
"Accept":"application/json"
},
cache: false,
url: 'flows/state',
success: function(data) {
RED.runtime.updateState(data.state)
if(callback) {
callback(data.state)
}
}
});
}
}
})()