commit 28787717c693f291e97b9a0ec5ee9f1b1a6c4f8d
Author: Jan Pašek <janpasek97@gmail.com>
Date:   Fri Apr 2 17:13:37 2021 +0200

    Re #8475 - Created constants.js for Rest API endpoint definitions

diff --git a/static/index.html b/static/index.html
index f9504ca..68dd7b6 100644
--- a/static/index.html
+++ b/static/index.html
@@ -41,6 +41,7 @@
     <script src="/static/js/jquery-3.6.0.min.js"></script>
     <script src="/static/js/bootstrap.bundle.min.js"></script>
     <script src="/static/js/axios.min.js"></script>
+    <script src="/static/js/constants.js"></script>
     <script src="/static/js/utilities.js"></script>
     <script src="/static/js/components.js"></script>
     <script src="/static/js/index.js"></script>
diff --git a/static/js/components.js b/static/js/components.js
index cc6c0c3..c9a19fa 100644
--- a/static/js/components.js
+++ b/static/js/components.js
@@ -11,13 +11,13 @@ Vue.component("certificate-item",{
                     "   <div v-if='certificate.usage.SSL'>SSL/TLS</div>" +
                     "</td>"+
                     "<td class='align-middle'><button v-on:click='onCertificateDownload()'>Download certificate</button></td>"+
-                    "<td class='align-middle'><button>Download chain of trust</button></td>"+
-                    "<td class='align-middle'><button>Download chain root</button></td>"+
+                    "<td class='align-middle'><button v-on:click='onCertificateChainDownload()'>Download chain of trust</button></td>"+
+                    "<td class='align-middle'><button v-on:click='onCertificateRootDownload()'>Download chain root</button></td>"+
                 "</tr>",
         methods: {
             onCertificateDownload: function () {
                 var id = this.certificate.id;
-                axios.get("https://virtserver.swaggerhub.com/janpasek97/X509_management/1.0.0/api/certificates/" + id)
+                axios.get(API_URL + "certificates/" + id)
                     .then(function (response) {
                         if(response.data["success"]) {
                             download(id + ".crt", response.data["data"])
@@ -28,6 +28,34 @@ Vue.component("certificate-item",{
                     .catch(function (error) {
                         console.log(error);
                     });
+            },
+            onCertificateChainDownload: function () {
+                var id = this.certificate.id;
+                axios.get(API_URL + "certificates/" + id + "/chain")
+                    .then(function (response) {
+                        if(response.data["success"]) {
+                            download(id + "_chain.crt", response.data["data"])
+                        }
+                        else
+                            console.log("Error occurred while downloading the certificate's chain of trust") // TODO more action may be required
+                    })
+                    .catch(function (error) {
+                        console.log(error);
+                    });
+            },
+            onCertificateRootDownload: function () {
+                var id = this.certificate.id;
+                axios.get(API_URL + "certificates/" + id + "/root")
+                    .then(function (response) {
+                        if(response.data["success"]) {
+                            download(id + "_root.crt", response.data["data"])
+                        }
+                        else
+                            console.log("Error occurred while downloading the certificate's root CA") // TODO more action may be required
+                    })
+                    .catch(function (error) {
+                        console.log(error);
+                    });
             }
         }
     });
\ No newline at end of file
diff --git a/static/js/constants.js b/static/js/constants.js
new file mode 100644
index 0000000..e921905
--- /dev/null
+++ b/static/js/constants.js
@@ -0,0 +1 @@
+const API_URL = "https://virtserver.swaggerhub.com/janpasek97/X509_management/1.0.0/api/";
\ No newline at end of file
diff --git a/static/js/index.js b/static/js/index.js
index 1ed6fa9..586f109 100644
--- a/static/js/index.js
+++ b/static/js/index.js
@@ -6,7 +6,7 @@
         }
     });
 
-    axios.get("https://virtserver.swaggerhub.com/janpasek97/X509_management/1.0.0/api/certificates")
+    axios.get(API_URL + "certificates")
         .then(function (response) {
             if (response.data["success"])
                 response.data["data"].forEach(item => certificateListingApp.certificates.push(item))
