Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 1 | <template> |
| 2 | <page-section :section-title="$t('pageNetwork.staticDns')"> |
| 3 | <b-row> |
| 4 | <b-col lg="6"> |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 5 | <div class="text-right"> |
| 6 | <b-button variant="primary" @click="initDnsModal()"> |
| 7 | <icon-add /> |
| 8 | {{ $t('pageNetwork.table.addDnsAddress') }} |
| 9 | </b-button> |
| 10 | </div> |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 11 | <b-table |
| 12 | responsive="md" |
| 13 | hover |
| 14 | :fields="dnsTableFields" |
| 15 | :items="form.dnsStaticTableItems" |
| 16 | :empty-text="$t('global.table.emptyMessage')" |
| 17 | class="mb-0" |
| 18 | show-empty |
| 19 | > |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 20 | <template #cell(actions)="{ item, index }"> |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 21 | <table-row-action |
| 22 | v-for="(action, actionIndex) in item.actions" |
| 23 | :key="actionIndex" |
| 24 | :value="action.value" |
| 25 | :title="action.title" |
| 26 | :enabled="action.enabled" |
| 27 | @click-table-action="onDnsTableAction(action, $event, index)" |
| 28 | > |
| 29 | <template #icon> |
| 30 | <icon-edit v-if="action.value === 'edit'" /> |
| 31 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 32 | </template> |
| 33 | </table-row-action> |
| 34 | </template> |
| 35 | </b-table> |
| 36 | </b-col> |
| 37 | </b-row> |
| 38 | </page-section> |
| 39 | </template> |
| 40 | |
| 41 | <script> |
| 42 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 43 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 44 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 45 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 46 | import PageSection from '@/components/Global/PageSection'; |
| 47 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 48 | import { mapState } from 'vuex'; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 49 | import { useI18n } from 'vue-i18n'; |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 50 | |
| 51 | export default { |
| 52 | name: 'DNSTable', |
| 53 | components: { |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 54 | IconAdd, |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 55 | IconEdit, |
| 56 | IconTrashcan, |
| 57 | PageSection, |
| 58 | TableRowAction, |
| 59 | }, |
| 60 | mixins: [BVToastMixin], |
| 61 | props: { |
| 62 | tabIndex: { |
| 63 | type: Number, |
| 64 | default: 0, |
| 65 | }, |
| 66 | }, |
| 67 | data() { |
| 68 | return { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 69 | $t: useI18n().t, |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 70 | form: { |
| 71 | dnsStaticTableItems: [], |
| 72 | }, |
| 73 | actions: [ |
| 74 | { |
| 75 | value: 'edit', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 76 | title: 'global.action.edit', |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 77 | }, |
| 78 | { |
| 79 | value: 'delete', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 80 | title: 'global.action.delete', |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 81 | }, |
| 82 | ], |
| 83 | dnsTableFields: [ |
| 84 | { |
| 85 | key: 'address', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 86 | label: 'pageNetwork.table.ipAddress', |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 87 | }, |
| 88 | { key: 'actions', label: '', tdClass: 'text-right' }, |
| 89 | ], |
| 90 | }; |
| 91 | }, |
| 92 | computed: { |
| 93 | ...mapState('network', ['ethernetData']), |
| 94 | }, |
| 95 | watch: { |
| 96 | // Watch for change in tab index |
| 97 | tabIndex() { |
| 98 | this.getStaticDnsItems(); |
| 99 | }, |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 100 | ethernetData() { |
| 101 | this.getStaticDnsItems(); |
| 102 | }, |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 103 | }, |
| 104 | created() { |
| 105 | this.getStaticDnsItems(); |
| 106 | this.$store.dispatch('network/getEthernetData').finally(() => { |
| 107 | // Emit initial data fetch complete to parent component |
| 108 | this.$root.$emit('network-table-dns-complete'); |
| 109 | }); |
| 110 | }, |
| 111 | methods: { |
| 112 | getStaticDnsItems() { |
| 113 | const index = this.tabIndex; |
| 114 | const dns = this.ethernetData[index].StaticNameServers || []; |
| 115 | this.form.dnsStaticTableItems = dns.map((server) => { |
| 116 | return { |
| 117 | address: server, |
| 118 | actions: [ |
| 119 | { |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 120 | value: 'delete', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 121 | title: 'pageNetwork.table.deleteDns', |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 122 | }, |
| 123 | ], |
| 124 | }; |
| 125 | }); |
| 126 | }, |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 127 | onDnsTableAction(action, $event, index) { |
| 128 | if ($event === 'delete') { |
| 129 | this.deleteDnsTableRow(index); |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 130 | } |
| 131 | }, |
Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 132 | deleteDnsTableRow(index) { |
| 133 | this.form.dnsStaticTableItems.splice(index, 1); |
| 134 | const newDnsArray = this.form.dnsStaticTableItems.map((dns) => { |
| 135 | return dns.address; |
| 136 | }); |
| 137 | this.$store |
| 138 | .dispatch('network/editDnsAddress', newDnsArray) |
| 139 | .then((message) => this.successToast(message)) |
| 140 | .catch(({ message }) => this.errorToast(message)); |
| 141 | }, |
| 142 | initDnsModal() { |
| 143 | this.$bvModal.show('modal-dns'); |
| 144 | }, |
Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 145 | }, |
| 146 | }; |
| 147 | </script> |