Enable CA certificate upload

This patchset enables CA certificate type to be uploaded
in the GUI.

Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: I52953933f6fd3dbd363c42b887996942b99b358e
diff --git a/app/common/directives/certificate.js b/app/common/directives/certificate.js
index 63dc594..45b8c99 100644
--- a/app/common/directives/certificate.js
+++ b/app/common/directives/certificate.js
@@ -9,9 +9,32 @@
         'template': require('./certificate.html'),
         'scope': {'cert': '=', 'reload': '&'},
         'controller': [
-          '$scope', 'APIUtils', 'toastService',
-          function($scope, APIUtils, toastService) {
+          '$scope', 'APIUtils', 'toastService', 'Constants',
+          function($scope, APIUtils, toastService, Constants) {
             var certificateType = 'PEM';
+            var availableCertificateTypes = Constants.CERTIFICATE_TYPES;
+
+            /**
+             * This function is needed to map the backend Description to what
+             * should appear in the GUI. This is needed specifically for CA
+             * certificate types. The backend description for the certificate
+             * type is 'TrustStore Certificate', this function will make sure we
+             * display 'CA Certificate' on the frontend
+             * @param {string} : certificate Description property
+             * @returns {string} : certificate name that should appear on GUI
+             */
+            $scope.getCertificateName = function(certificateDescription) {
+              var matched =
+                  availableCertificateTypes.find(function(certificate) {
+                    return certificate.Description === certificateDescription;
+                  });
+              if (matched === undefined) {
+                return '';
+              } else {
+                return matched.name;
+              }
+            };
+
             $scope.replaceCertificate = function(certificate) {
               $scope.loading = true;
               if (certificate.file.name.split('.').pop() !==
@@ -35,14 +58,16 @@
                     function(data) {
                       $scope.loading = false;
                       toastService.success(
-                          certificate.Description + ' was replaced.');
+                          $scope.getCertificateName(certificate.Description) +
+                          ' was replaced.');
                       $scope.reload();
                     },
                     function(error) {
                       console.log(error);
                       $scope.loading = false;
                       toastService.error(
-                          'Unable to replace ' + certificate.Description);
+                          'Unable to replace ' +
+                          $scope.getCertificateName(certificate.Description));
                     });
               };
               reader.readAsBinaryString(file);