mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
|
RED.runtime = (function() {
|
||
|
let state = ""
|
||
|
let settings = {ui: true, enabled: true};
|
||
|
const STOPPED = "stopped"
|
||
|
const STARTED = "started"
|
||
|
return {
|
||
|
init: function() {
|
||
|
// refresh the current runtime status from server
|
||
|
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(!RED.settings.runtimeState || RED.settings.runtimeState.ui !== false) {
|
||
|
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)
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
})()
|