blob: e78234b0127242f0a853d573af22d95edbf87d3f [file] [log] [blame]
Dixsie Wolmersc4b87572021-10-07 16:15:50 -05001<template>
2 <page-section :section-title="$t('pageNetwork.staticDns')">
3 <b-row>
4 <b-col lg="6">
jason westoverd36ac8a2025-11-03 20:58:59 -06005 <div class="text-end">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -05006 <b-button variant="primary" @click="initDnsModal()">
7 <icon-add />
8 {{ $t('pageNetwork.table.addDnsAddress') }}
9 </b-button>
10 </div>
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050011 <b-table
12 responsive="md"
13 hover
jason westoverd36ac8a2025-11-03 20:58:59 -060014 thead-class="table-light"
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050015 :fields="dnsTableFields"
16 :items="form.dnsStaticTableItems"
17 :empty-text="$t('global.table.emptyMessage')"
18 class="mb-0"
19 show-empty
20 >
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050021 <template #cell(actions)="{ item, index }">
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050022 <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 westoverd36ac8a2025-11-03 20:58:59 -060040 <modal-dns v-model="showDnsModal" />
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050041</template>
42
43<script>
44import BVToastMixin from '@/components/Mixins/BVToastMixin';
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050045import IconAdd from '@carbon/icons-vue/es/add--alt/20';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050046import IconEdit from '@carbon/icons-vue/es/edit/20';
47import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
48import PageSection from '@/components/Global/PageSection';
49import TableRowAction from '@/components/Global/TableRowAction';
jason westoverd36ac8a2025-11-03 20:58:59 -060050import ModalDns from './ModalDns.vue';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050051import { mapState } from 'vuex';
Surya Vde23ea22024-07-11 15:19:46 +053052import { useI18n } from 'vue-i18n';
Surya Venkatesan4626aec2024-09-19 15:06:49 +053053import i18n from '@/i18n';
jason westoverd36ac8a2025-11-03 20:58:59 -060054import { useModal } from 'bootstrap-vue-next';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050055
56export default {
57 name: 'DNSTable',
58 components: {
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050059 IconAdd,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050060 IconEdit,
61 IconTrashcan,
62 PageSection,
63 TableRowAction,
jason westoverd36ac8a2025-11-03 20:58:59 -060064 ModalDns,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050065 },
66 mixins: [BVToastMixin],
67 props: {
68 tabIndex: {
69 type: Number,
70 default: 0,
71 },
72 },
jason westoverd36ac8a2025-11-03 20:58:59 -060073 setup() {
74 const bvModal = useModal();
75 return { bvModal };
76 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050077 data() {
78 return {
Surya Vde23ea22024-07-11 15:19:46 +053079 $t: useI18n().t,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050080 form: {
81 dnsStaticTableItems: [],
82 },
jason westoverd36ac8a2025-11-03 20:58:59 -060083 showDnsModal: false,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050084 actions: [
85 {
86 value: 'edit',
Surya Vde23ea22024-07-11 15:19:46 +053087 title: 'global.action.edit',
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050088 },
89 {
90 value: 'delete',
Surya Vde23ea22024-07-11 15:19:46 +053091 title: 'global.action.delete',
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050092 },
93 ],
94 dnsTableFields: [
95 {
96 key: 'address',
Surya Venkatesan4626aec2024-09-19 15:06:49 +053097 label: i18n.global.t('pageNetwork.table.ipAddress'),
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050098 },
jason westoverd36ac8a2025-11-03 20:58:59 -060099 { key: 'actions', label: '', tdClass: 'text-end' },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500100 ],
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 Wolmersb34349d2021-11-02 22:06:35 -0500111 ethernetData() {
112 this.getStaticDnsItems();
113 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500114 },
115 created() {
116 this.getStaticDnsItems();
117 this.$store.dispatch('network/getEthernetData').finally(() => {
118 // Emit initial data fetch complete to parent component
jason westoverd36ac8a2025-11-03 20:58:59 -0600119 require('@/eventBus').default.$emit('network-table-dns-complete');
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500120 });
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 Wolmersc4b87572021-10-07 16:15:50 -0500131 value: 'delete',
Surya Vde23ea22024-07-11 15:19:46 +0530132 title: 'pageNetwork.table.deleteDns',
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500133 },
134 ],
135 };
136 });
137 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500138 onDnsTableAction(action, $event, index) {
139 if ($event === 'delete') {
140 this.deleteDnsTableRow(index);
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500141 }
142 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500143 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 westoverd36ac8a2025-11-03 20:58:59 -0600154 this.showDnsModal = true;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500155 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500156 },
157};
158</script>