2022-06-08 22:56:17 +02:00
|
|
|
RED.runtime = (function() {
|
|
|
|
let state = ""
|
2022-06-27 19:06:53 +02:00
|
|
|
let settings = {ui: false, enabled: false};
|
2022-06-08 22:56:17 +02:00
|
|
|
const STOPPED = "stopped"
|
|
|
|
const STARTED = "started"
|
|
|
|
return {
|
|
|
|
init: function() {
|
|
|
|
// refresh the current runtime status from server
|
2022-06-27 19:06:53 +02:00
|
|
|
settings = Object.assign({}, settings, RED.settings.runtimeState);
|
2022-06-08 22:56:17 +02:00
|
|
|
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
|
2022-06-27 19:06:53 +02:00
|
|
|
if(settings.enabled === true && settings.ui === true) {
|
2022-06-08 22:56:17 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})()
|