Clamp react ui to use url pathname dynamically instead of hardcoded prefix for callin...
[clamp.git] / ui-react / src / api / TemplateService.js
index 615a87e..08436f2 100644 (file)
  */
 
 export default class TemplateService {
-       static getTemplateNames() {
-               return fetch('/restservices/clds/v2/templates/names', { method: 'GET', credentials: 'same-origin' })
-                       .then(function (response) {
-                               console.debug("GetTemplateNames response received: ", response.status);
-                               if (response.ok) {
-                                       return response.json();
-                               } else {
-                                       console.error("GetTemplateNames query failed");
-                                       return {};
-                               }
-                       })
-                       .catch(function (error) {
-                               console.error("GetTemplateNames error received", error);
-                               return {};
-                       });
-       }
 
-       static getBlueprintMicroServiceTemplates() {
-           return fetch('restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', })
+        static getLoopNames() {
+                return fetch(window.location.pathname + 'restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' })
+                        .then(function (response) {
+                                console.debug("getLoopNames response received: ", response.status);
+                                if (response.ok) {
+                                        return response.json();
+                                } else {
+                                        console.error("getLoopNames query failed");
+                                        return {};
+                                }
+                        })
+                        .catch(function (error) {
+                                console.error("getLoopNames error received", error);
+                                return {};
+                        });
+        }
+
+       static getAllLoopTemplates() {
+           return fetch(window.location.pathname + 'restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', })
                .then(function (response) {
-                   console.debug("getBlueprintMicroServiceTemplates response received: ", response.status);
+                   console.debug("getAllLoopTemplates response received: ", response.status);
                    if (response.ok) {
                        return response.json();
                    } else {
-                       console.error("getBlueprintMicroServiceTemplates query failed");
+                       console.error("getAllLoopTemplates query failed");
                        return {};
                    }
                })
                .catch(function (error) {
-                   console.error("getBlueprintMicroServiceTemplates error received", error);
+                   console.error("getAllLoopTemplates error received", error);
                    return {};
                });
            }
 
-       static getBlueprintMicroServiceTemplate(templateName) {
-               return fetch('/restservices/clds/v2/templates/' + templateName + ' /svgRepresentation', { method: 'GET', credentials: 'same-origin', })
-                       .then(function (response) {
-                       console.debug("getBlueprintMicroServiceTemplate response received: ", response.status);
-                       if (response.ok) {
-                               return response.text();
-                       } else {
-                               console.error("getBlueprintMicroServiceTemplates query failed");
-                               return {};
-                       }
-               })
-               .catch(function (error) {
-                       console.error("getBlueprintMicroServiceTemplate error received", error);
-                       return {};
-               });
-       }
-       
        static getDictionary() {
-           return fetch('restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', })
+           return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', })
              .then(function (response) {
                console.debug("getDictionary response received: ", response.status);
                if (response.ok) {
@@ -90,7 +74,7 @@ export default class TemplateService {
          }
 
          static getDictionaryElements(dictionaryName) {
-           return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
+           return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + dictionaryName, {
              method: 'GET',
              headers: {
                "Content-Type": "application/json",
@@ -114,7 +98,7 @@ export default class TemplateService {
 
          static insDictionary(jsonData) {
            console.log("dictionaryName is", jsonData.name)
-           return fetch('/restservices/clds/v2/dictionary/', {
+           return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/', {
              method: 'PUT',
              credentials: 'same-origin',
              headers: {
@@ -140,7 +124,7 @@ export default class TemplateService {
 
          static insDictionaryElements(jsonData) {
            console.log("dictionaryName is", jsonData.name)
-           return fetch('/restservices/clds/v2/dictionary/' + jsonData.name, {
+           return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + jsonData.name, {
              method: 'PUT',
              credentials: 'same-origin',
              headers: {
@@ -166,7 +150,7 @@ export default class TemplateService {
 
          static deleteDictionary(dictionaryName) {
            console.log("inside templaemenu service", dictionaryName)
-           return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
+           return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + dictionaryName, {
              method: 'DELETE',
              headers: {
                "Content-Type": "application/json",
@@ -189,7 +173,7 @@ export default class TemplateService {
          }
 
          static deleteDictionaryElements(dictionaryData) {
-           return fetch('restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName , {
+           return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName , {
              method: 'DELETE',
              headers: {
                "Content-Type": "application/json",