Add loading bar to SSL certificates page

- Return new Date() instead of null when calculating expiring
  time. Expired certificates banner is sometimes visible if
  the certificates are returned before the bmc time

Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: I3a2b8ac8a639f464856472013be14878151e7289
diff --git a/src/store/modules/AccessControl/SslCertificatesStore.js b/src/store/modules/AccessControl/SslCertificatesStore.js
index ef4afdb..71304b5 100644
--- a/src/store/modules/AccessControl/SslCertificatesStore.js
+++ b/src/store/modules/AccessControl/SslCertificatesStore.js
@@ -48,8 +48,8 @@
     }
   },
   actions: {
-    getCertificates({ commit }) {
-      api
+    async getCertificates({ commit }) {
+      return await api
         .get('/redfish/v1/CertificateService/CertificateLocations')
         .then(({ data: { Links: { Certificates } } }) =>
           Certificates.map(certificate => certificate['@odata.id'])
diff --git a/src/views/AccessControl/SslCertificates/SslCertificates.vue b/src/views/AccessControl/SslCertificates/SslCertificates.vue
index 6f74c81..7dcb4dd 100644
--- a/src/views/AccessControl/SslCertificates/SslCertificates.vue
+++ b/src/views/AccessControl/SslCertificates/SslCertificates.vue
@@ -100,6 +100,7 @@
 import Alert from '../../../components/Global/Alert';
 
 import BVToastMixin from '../../../components/Mixins/BVToastMixin';
+import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
 
 export default {
   name: 'SslCertificates',
@@ -114,7 +115,7 @@
     StatusIcon,
     TableRowAction
   },
-  mixins: [BVToastMixin],
+  mixins: [BVToastMixin, LoadingBarMixin],
   data() {
     return {
       modalCertificate: null,
@@ -195,9 +196,16 @@
       }, []);
     }
   },
-  created() {
-    this.$store.dispatch('sslCertificates/getCertificates');
-    this.$store.dispatch('global/getBmcTime');
+  async created() {
+    this.startLoader();
+    await this.$store.dispatch('global/getBmcTime');
+    this.$store
+      .dispatch('sslCertificates/getCertificates')
+      .finally(() => this.endLoader());
+  },
+  beforeRouteLeave(to, from, next) {
+    this.hideLoader();
+    next();
   },
   methods: {
     onTableRowAction(event, rowItem) {
@@ -242,12 +250,15 @@
       }
     },
     addNewCertificate(file, type) {
+      this.startLoader();
       this.$store
         .dispatch('sslCertificates/addNewCertificate', { file, type })
         .then(success => this.successToast(success))
-        .catch(({ message }) => this.errorToast(message));
+        .catch(({ message }) => this.errorToast(message))
+        .finally(() => this.endLoader());
     },
     replaceCertificate(file, type, location) {
+      this.startLoader();
       const reader = new FileReader();
       reader.readAsBinaryString(file);
       reader.onloadend = event => {
@@ -259,17 +270,20 @@
             location
           })
           .then(success => this.successToast(success))
-          .catch(({ message }) => this.errorToast(message));
+          .catch(({ message }) => this.errorToast(message))
+          .finally(() => this.endLoader());
       };
     },
     deleteCertificate({ type, location }) {
+      this.startLoader();
       this.$store
         .dispatch('sslCertificates/deleteCertificate', {
           type,
           location
         })
         .then(success => this.successToast(success))
-        .catch(({ message }) => this.errorToast(message));
+        .catch(({ message }) => this.errorToast(message))
+        .finally(() => this.endLoader());
     },
     getDaysUntilExpired(date) {
       if (this.bmcTime) {
@@ -278,7 +292,7 @@
         const oneDayInMs = 24 * 60 * 60 * 1000;
         return Math.round((validUntilMs - currentBmcTimeMs) / oneDayInMs);
       }
-      return null;
+      return new Date();
     },
     getIconStatus(date) {
       const daysUntilExpired = this.getDaysUntilExpired(date);