Add DumpsStore API calls

Ties in API requests to the Dumps page and adds ability to:
- Create new System or BMC dump
- Delete single or multiple BMC dumps. Uses ClearLog service to
  delete all and DELETE request for single dump deletion

Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: Iae928fa3b8fab00e549c33c0ab914a4b04de0f40
diff --git a/src/env/components/Dumps/Dumps.vue b/src/env/components/Dumps/Dumps.vue
index eba90b7..3bf5579 100644
--- a/src/env/components/Dumps/Dumps.vue
+++ b/src/env/components/Dumps/Dumps.vue
@@ -3,14 +3,14 @@
     <page-title />
     <b-row>
       <b-col sm="6" lg="5" xl="4">
-        <page-section :section-title="$t('pageDumps.newDump')">
+        <page-section :section-title="$t('pageDumps.initiateDump')">
           <dumps-form />
         </page-section>
       </b-col>
     </b-row>
     <b-row>
       <b-col xl="10">
-        <page-section :section-title="$t('pageDumps.dumpHistory')">
+        <page-section :section-title="$t('pageDumps.dumpsAvailableOnBmc')">
           <b-row class="align-items-start">
             <b-col sm="8" xl="6" class="d-sm-flex align-items-end">
               <search
@@ -41,6 +41,7 @@
             hover
             sort-icon-left
             no-sort-reset
+            sort-desc
             selectable
             no-select-on-click
             responsive="md"
@@ -121,6 +122,7 @@
   tableHeaderCheckboxModel,
   tableHeaderCheckboxIndeterminate,
 } from '@/components/Mixins/BVTableSelectableMixin';
+import BVToastMixin from '@/components/Mixins/BVToastMixin';
 import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
 import SearchFilterMixin, {
   searchFilter,
@@ -141,6 +143,7 @@
   },
   mixins: [
     BVTableSelectableMixin,
+    BVToastMixin,
     LoadingBarMixin,
     SearchFilterMixin,
     TableFilterMixin,
@@ -202,7 +205,7 @@
   },
   computed: {
     dumps() {
-      return this.$store.getters['dumps/allDumps'];
+      return this.$store.getters['dumps/bmcDumps'];
     },
     tableItems() {
       return this.dumps.map((item) => {
@@ -246,7 +249,7 @@
       this.filterStartDate = fromDate;
       this.filterEndDate = toDate;
     },
-    onTableRowAction(action) {
+    onTableRowAction(action, dump) {
       if (action === 'delete') {
         this.$bvModal
           .msgBoxConfirm(this.$tc('pageDumps.modal.deleteDumpConfirmation'), {
@@ -255,7 +258,19 @@
             cancelTitle: this.$t('global.action.cancel'),
           })
           .then((deleteConfrimed) => {
-            if (deleteConfrimed); // delete dump
+            if (deleteConfrimed) {
+              this.$store
+                .dispatch('dumps/deleteDumps', [dump])
+                .then((messages) => {
+                  messages.forEach(({ type, message }) => {
+                    if (type === 'success') {
+                      this.successToast(message);
+                    } else if (type === 'error') {
+                      this.errorToast(message);
+                    }
+                  });
+                });
+            }
           });
       }
     },
@@ -280,7 +295,26 @@
             }
           )
           .then((deleteConfrimed) => {
-            if (deleteConfrimed); // delete dump
+            if (deleteConfrimed) {
+              if (this.selectedRows.length === this.dumps.length) {
+                this.$store
+                  .dispatch('dumps/deleteAllDumps')
+                  .then((success) => this.successToast(success))
+                  .catch(({ message }) => this.errorToast(message));
+              } else {
+                this.$store
+                  .dispatch('dumps/deleteDumps', this.selectedRows)
+                  .then((messages) => {
+                    messages.forEach(({ type, message }) => {
+                      if (type === 'success') {
+                        this.successToast(message);
+                      } else if (type === 'error') {
+                        this.errorToast(message);
+                      }
+                    });
+                  });
+              }
+            }
           });
       }
     },
diff --git a/src/env/components/Dumps/DumpsForm.vue b/src/env/components/Dumps/DumpsForm.vue
index ed81b3a..9dc8bcb 100644
--- a/src/env/components/Dumps/DumpsForm.vue
+++ b/src/env/components/Dumps/DumpsForm.vue
@@ -21,20 +21,28 @@
           {{ $t('global.form.required') }}
         </b-form-invalid-feedback>
       </b-form-group>
+      <alert variant="info" class="mb-3" :show="selectedDumpType === 'system'">
+        {{ $t('pageDumps.form.systemDumpInfo') }}
+      </alert>
       <b-button variant="primary" type="submit" form="form-new-dump">
-        {{ $t('pageDumps.form.createNewDump') }}
+        {{ $t('pageDumps.form.initiateDump') }}
       </b-button>
     </b-form>
+    <modal-confirmation @ok="createSystemDump" />
   </div>
 </template>
 
 <script>
 import { required } from 'vuelidate/lib/validators';
 
+import ModalConfirmation from './DumpsModalConfirmation';
+import Alert from '@/components/Global/Alert';
+
 import BVToastMixin from '@/components/Mixins/BVToastMixin';
 import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
 
 export default {
+  components: { Alert, ModalConfirmation },
   mixins: [BVToastMixin, VuelidateMixin],
   data() {
     return {
@@ -54,7 +62,33 @@
     handleSubmit() {
       this.$v.$touch();
       if (this.$v.$invalid) return;
-      this.successToast(this.$t('pageDumps.toast.successStartDump'));
+      if (this.selectedDumpType === 'system') {
+        this.showConfirmationModal();
+      } else {
+        this.$store
+          .dispatch('dumps/createBmcDump')
+          .then(() =>
+            this.infoToast(
+              this.$t('pageDumps.toast.successStartBmcDump'),
+              this.$t('pageDumps.toast.successStartBmcDumpTitle')
+            )
+          )
+          .catch(({ message }) => this.errorToast(message));
+      }
+    },
+    showConfirmationModal() {
+      this.$bvModal.show('modal-confirmation');
+    },
+    createSystemDump() {
+      this.$store
+        .dispatch('dumps/createSystemDump')
+        .then(() =>
+          this.infoToast(
+            this.$t('pageDumps.toast.successStartSystemDump'),
+            this.$t('pageDumps.toast.successStartSystemDumpTitle')
+          )
+        )
+        .catch(({ message }) => this.errorToast(message));
     },
   },
 };
diff --git a/src/env/components/Dumps/DumpsModalConfirmation.vue b/src/env/components/Dumps/DumpsModalConfirmation.vue
new file mode 100644
index 0000000..f8e20cf
--- /dev/null
+++ b/src/env/components/Dumps/DumpsModalConfirmation.vue
@@ -0,0 +1,75 @@
+<template>
+  <b-modal
+    id="modal-confirmation"
+    ref="modal"
+    :title="$t('pageDumps.modal.initiateSystemDump')"
+    @hidden="resetForm"
+  >
+    <p>
+      <strong>
+        {{ $t('pageDumps.modal.initiateSystemDumpMessage1') }}
+      </strong>
+    </p>
+    <p>
+      {{ $t('pageDumps.modal.initiateSystemDumpMessage2') }}
+    </p>
+    <p>
+      <status-icon status="danger" />
+      {{ $t('pageDumps.modal.initiateSystemDumpMessage3') }}
+    </p>
+    <b-form-checkbox v-model="confirmed" @input="$v.confirmed.$touch()">
+      {{ $t('pageDumps.modal.initiateSystemDumpMessage4') }}
+    </b-form-checkbox>
+    <b-form-invalid-feedback
+      :state="getValidationState($v.confirmed)"
+      role="alert"
+    >
+      {{ $t('global.form.required') }}
+    </b-form-invalid-feedback>
+    <template #modal-footer="{ cancel }">
+      <b-button variant="secondary" @click="cancel()">
+        {{ $t('global.action.cancel') }}
+      </b-button>
+      <b-button variant="danger" @click="handleSubmit">
+        {{ $t('pageDumps.form.initiateDump') }}
+      </b-button>
+    </template>
+  </b-modal>
+</template>
+
+<script>
+import StatusIcon from '@/components/Global/StatusIcon';
+import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
+
+export default {
+  components: { StatusIcon },
+  mixins: [VuelidateMixin],
+  data() {
+    return {
+      confirmed: false,
+    };
+  },
+  validations: {
+    confirmed: {
+      mustBeTrue: (value) => value === true,
+    },
+  },
+  methods: {
+    closeModal() {
+      this.$nextTick(() => {
+        this.$refs.modal.hide();
+      });
+    },
+    handleSubmit() {
+      this.$v.$touch();
+      if (this.$v.$invalid) return;
+      this.$emit('ok');
+      this.closeModal();
+    },
+    resetForm() {
+      this.confirmed = false;
+      this.$v.$reset();
+    },
+  },
+};
+</script>