From 5fe750cb519c88a5fd6c55a93670354b78b806dc Mon Sep 17 00:00:00 2001 From: xuegao Date: Tue, 6 Aug 2019 13:03:53 +0200 Subject: 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 --- ui-react/src/api/LoopActionService.js | 74 ++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 27 deletions(-) (limited to 'ui-react/src/api/LoopActionService.js') 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); + }); + } +} -- cgit 1.2.3-korg