summaryrefslogtreecommitdiff
path: root/src/views/_sila/Settings/TransferInfo/Snmp.vue
blob: ef9e18ac05f7baba74ffc6d219ea6aa4d1598127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
  <page-section :section-title="$t('pageTransfer.snmp.snmpTitle')">
    <b-row>
      <b-col>
        <div class="text-right">
          <b-button
            variant="primary"
            :disabled="loading || isNotAdmin"
            @click="initAddModal()"
          >
            <icon-add />
            {{ $t('global.action.add') }}
          </b-button>
        </div>
        <b-table
          responsive="md"
          hover
          :busy="loading"
          :fields="fields"
          :items="subscribers"
          :empty-text="$t('global.table.emptyMessage')"
          show-empty
        >
          <!-- table actions column -->
          <template #cell(actions)="{ item }">
            <table-row-action
              v-for="(action, index) in item.actions"
              :key="index"
              :value="action.value"
              :enabled="action.enabled"
              :title="action.title"
              @click-table-action="onTableAction($event, item)"
            >
              <template #icon>
                <icon-trashcan
                  v-if="action.value === 'delete'"
                  :data-test-id="`snmp-tableRowAction-delete-${index}`"
                />
              </template>
            </table-row-action>
          </template>
        </b-table>
      </b-col>
    </b-row>
  </page-section>
</template>

<script>
import PageSection from '@/components/_sila/Global/PageSection';
import BVToastMixin from '@/components/_sila/Mixins/BVToastMixin';
import TableRowAction from '@/components/_sila/Global/TableRowAction';
import LoadingBarMixin, {
  loading,
} from '@/components/_sila/Mixins/LoadingBarMixin';

import IconAdd from '@carbon/icons-vue/es/add--alt/20';
import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';

export default {
  name: 'Snmp',
  components: {
    IconAdd,
    IconTrashcan,
    PageSection,
    TableRowAction,
  },
  mixins: [BVToastMixin, LoadingBarMixin],

  data() {
    return {
      loading,
      actions: [
        {
          value: 'delete',
          title: this.$t('global.action.delete'),
        },
      ],
      fields: [
        {
          key: 'host',
          label: this.$t('pageTransfer.snmp.host'),
        },
        {
          key: 'port',
          label: this.$t('pageTransfer.snmp.port'),
        },
        { key: 'actions', label: '', tdClass: 'text-right' },
      ],
    };
  },
  computed: {
    subscribers() {
      return this.$store.getters['snmpStore/subscribers'].map((subscriber) => {
        return {
          ...subscriber,
          actions: [
            {
              value: 'delete',
              title: this.$t('pageTransfer.snmp.delSubscriber'),
            },
          ],
        };
      });
    },
    isNotAdmin() {
      return (
        this.$store.getters['authentication/role'] === 'ReadOnly' ||
        this.$store.getters['authentication/role'] === 'Operator'
      );
    },
  },

  created() {
    this.startLoader();
    this.$store.dispatch('snmpStore/getSubscribers').finally(() => {
      this.endLoader();
    });
  },

  methods: {
    onTableAction($event, { Id }) {
      if ($event === 'delete') {
        this.deleteSubscriber(Id);
      }
    },
    deleteSubscriber(index) {
      this.startLoader();
      this.$store
        .dispatch('snmpStore/deleteSubscriber', index)
        .then((success) => this.successToast(success))
        .catch(({ message }) => this.errorToast(message))
        .finally(() => this.endLoader());
    },
    initAddModal() {
      this.$bvModal.show('modal-snmp');
    },
  },
};
</script>