Rework start/stop api to use runtime-event notification message

This commit is contained in:
Nick O'Leary
2022-06-29 10:27:44 +01:00
parent 68c1e49f62
commit f33848e16b
11 changed files with 107 additions and 140 deletions

View File

@@ -69,7 +69,7 @@ RED.deploy = (function() {
{id:"deploymenu-item-node",toggle:"deploy-type",icon:"red/images/deploy-nodes.svg",label:RED._("deploy.modifiedNodes"),sublabel:RED._("deploy.modifiedNodesDesc"),onselect:function(s) { if(s){changeDeploymentType("nodes")}}},
null
]
if(RED.settings.runtimeState && RED.settings.runtimeState.ui === true) {
if (RED.settings.runtimeState && RED.settings.runtimeState.ui === true) {
mainMenuItems.push({id:"deploymenu-item-runtime-start", icon:"red/images/start.svg",label:"Start"/*RED._("deploy.startFlows")*/,sublabel:"Start Flows" /*RED._("deploy.startFlowsDesc")*/,onselect:"core:start-flows", visible:false})
mainMenuItems.push({id:"deploymenu-item-runtime-stop", icon:"red/images/stop.svg",label:"Stop"/*RED._("deploy.startFlows")*/,sublabel:"Stop Flows" /*RED._("deploy.startFlowsDesc")*/,onselect:"core:stop-flows", visible:false})
}
@@ -302,7 +302,6 @@ RED.deploy = (function() {
deployInflight = true
deployButtonSetBusy()
shadeShow()
RED.runtime.updateState(state)
$.ajax({
url:"flows/state",
type: "POST",
@@ -311,30 +310,23 @@ RED.deploy = (function() {
if (deployWasEnabled) {
$("#red-ui-header-button-deploy").removeClass("disabled")
}
RED.runtime.updateState((data && data.state) || "unknown")
RED.notify(RED._("stopstart.status.state_changed", data), "success")
}).fail(function(xhr,textStatus,err) {
if (deployWasEnabled) {
$("#red-ui-header-button-deploy").removeClass("disabled")
}
if (xhr.status === 401) {
RED.notify(RED._("notification.error", { message: RED._("stopstart.errors.notAuthorized") }), "error")
} else if (xhr.status === 404) {
RED.notify(RED._("notification.error", { message: RED._("stopstart.errors.notFound") }), "error")
} else if (xhr.status === 405) {
RED.notify(RED._("notification.error", { message: RED._("stopstart.errors.notAllowed") }), "error")
RED.notify(RED._("notification.error", { message: RED._("user.notAuthorized") }), "error")
} else if (xhr.responseText) {
const errorDetail = { message: err ? (err + "") : "" }
try {
errorDetail.message = JSON.parse(xhr.responseText).message
} finally {
} finally {
errorDetail.message = errorDetail.message || xhr.responseText
}
RED.notify(RED._("notification.error", errorDetail), "error")
} else {
RED.notify(RED._("notification.error", { message: RED._("stopstart.errors.noResponse") }), "error")
RED.notify(RED._("notification.error", { message: RED._("deploy.errors.noResponse") }), "error")
}
RED.runtime.requestState()
}).always(function() {
const delta = Math.max(0, 300 - (Date.now() - startTime))
setTimeout(function () {
@@ -514,13 +506,10 @@ RED.deploy = (function() {
deployButtonSetBusy();
const data = { flows: nns };
data.runtimeState = RED.runtime.state;
if (data.runtimeState === RED.runtime.states.STOPPED || force) {
data._rev = RED.nodes.version();
} else {
if (!force) {
data.rev = RED.nodes.version();
}
deployInflight = true;
shadeShow();
$.ajax({

View File

@@ -4877,7 +4877,7 @@ RED.view = (function() {
if (d._def.button) {
var buttonEnabled = isButtonEnabled(d);
this.__buttonGroup__.classList.toggle("red-ui-flow-node-button-disabled", !buttonEnabled);
if(RED.runtime && Object.hasOwn(RED.runtime,'started')) {
if (RED.runtime && Object.hasOwn(RED.runtime,'started')) {
this.__buttonGroup__.classList.toggle("red-ui-flow-node-button-stopped", !RED.runtime.started);
}