summaryrefslogtreecommitdiffstats
path: root/ui-react/src/api/LoopActionService.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui-react/src/api/LoopActionService.js')
-rw-r--r--ui-react/src/api/LoopActionService.js74
1 files changed, 47 insertions, 27 deletions
diff --git a/ui-react/src/api/LoopActionService.js b/ui-react/src/api/LoopActionService.js
index 9ce8ff0a9..6e45ce4b9 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);
+ });
+ }
+}