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>
diff --git a/ui-react/src/api/LoopActionService.js b/ui-react/src/api/LoopActionService.js
index 9ce8ff0..6e45ce4 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{
+
+ 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);
+ });
+ }
-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 refreshStatus(cl_name) {
+ console.log("Refresh the status for closedloopName=" + cl_name);
- let options = {
- method: 'GET'
- };
- return sendRequest(svcUrl, svcAction, options);
+ 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);
+ });
+ }
}
-
-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();
-};
-
-export default loopActionService;
\ No newline at end of file