diff options
author | xuegao <xg353y@intl.att.com> | 2019-08-06 13:03:53 +0200 |
---|---|---|
committer | xuegao <xg353y@intl.att.com> | 2019-08-08 09:35:53 +0200 |
commit | 5fe750cb519c88a5fd6c55a93670354b78b806dc (patch) | |
tree | 88975cb5316b58ecde1fe7834e44fb7b141e6c24 /ui-react/src/api | |
parent | 6cfa53edcefa8472ccbd3c2d3c075392e769f071 (diff) |
Rework action itmes
Rework the submit, stop, restart, delete, undeploy and refresh status
actions.
Issue-ID: CLAMP-441,CLAMP-442,CLAMP-443,CLAMP-444,CLAMP-446,CLAMP-448
Change-Id: I38aed3a06fdcdf0f53fc9b8f8d2d9072f0932d55
Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'ui-react/src/api')
-rw-r--r-- | ui-react/src/api/LoopActionService.js | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/ui-react/src/api/LoopActionService.js b/ui-react/src/api/LoopActionService.js index 9ce8ff0a..6e45ce4b 100644 --- a/ui-react/src/api/LoopActionService.js +++ b/ui-react/src/api/LoopActionService.js @@ -20,35 +20,55 @@ * =================================================================== * */ -const loopActionService = { - submit -}; +export default class LoopActionService{ -function submit(uiAction) { - const cl_name = ""; - console.log("clActionServices perform action: " + uiAction + " closedloopName=" - + cl_name); - const svcAction = uiAction.toLowerCase(); - const svcUrl = "/restservices/clds/v2/loop/" + svcAction + "/" + cl_name; + static performAction(cl_name, uiAction) { + console.log("LoopActionService perform action: " + uiAction + " closedloopName=" + cl_name); + const svcAction = uiAction.toLowerCase(); + return fetch("/restservices/clds/v2/loop/" + svcAction + "/" + cl_name, { + method: 'PUT', + credentials: 'same-origin', + }) + .then(function (response) { + if (response.ok) { + return response.json(); + } else { + return Promise.reject("Perform action failed with code:" + response.status); + } + }) + .then(function (data) { + alert("Action Successful: " + uiAction); + return data; + }) + .catch(function(error) { + console.log("Action Failure: " + uiAction); + return Promise.reject(error); + }); + } - let options = { - method: 'GET' - }; - return sendRequest(svcUrl, svcAction, options); -} - -function sendRequest(svcUrl, svcAction) { - fetch(svcUrl, options) - .then( - response => { - alertService.alertMessage("Action Successful: " + svcAction, 1) - }).error(error => { - alertService.alertMessage("Action Failure: " + svcAction, 2); - return Promise.reject(error); - }); - return response.json(); -}; + static refreshStatus(cl_name) { + console.log("Refresh the status for closedloopName=" + cl_name); -export default loopActionService;
\ No newline at end of file + return fetch("/restservices/clds/v2/loop/getstatus/" + cl_name, { + method: 'GET', + credentials: 'same-origin', + }) + .then(function (response) { + if (response.ok) { + return response.json(); + } else { + return Promise.reject("Refresh status failed with code:" + response.status); + } + }) + .then(function (data) { + console.info ("Refresh status Successful"); + return data; + }) + .catch(function(error) { + console.info ("Refresh status failed:", error); + return Promise.reject(error); + }); + } +} |