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