| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 1 | <template> |
| 2 | <page-section :section-title="$t('pageNetwork.ipv4')"> |
| Nikhil Ashoka | e8cb2c6 | 2023-01-04 15:45:20 +0530 | [diff] [blame] | 3 | <b-row class="mb-4"> |
| 4 | <b-col lg="2" md="6"> |
| 5 | <dl> |
| 6 | <dt>{{ $t('pageNetwork.dhcp') }}</dt> |
| 7 | <dd> |
| 8 | <b-form-checkbox |
| 9 | id="dhcpSwitch" |
| 10 | v-model="dhcpEnabledState" |
| 11 | data-test-id="networkSettings-switch-dhcpEnabled" |
| 12 | switch |
| 13 | @change="changeDhcpEnabledState" |
| 14 | > |
| 15 | <span v-if="dhcpEnabledState"> |
| 16 | {{ $t('global.status.enabled') }} |
| 17 | </span> |
| 18 | <span v-else>{{ $t('global.status.disabled') }}</span> |
| 19 | </b-form-checkbox> |
| 20 | </dd> |
| 21 | </dl> |
| 22 | </b-col> |
| 23 | </b-row> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 24 | <b-row> |
| 25 | <b-col> |
| 26 | <h3 class="h5"> |
| 27 | {{ $t('pageNetwork.ipv4Addresses') }} |
| 28 | </h3> |
| 29 | </b-col> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 30 | <b-col class="text-end"> |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 31 | <b-button variant="primary" @click="initAddIpv4Address()"> |
| 32 | <icon-add /> |
| 33 | {{ $t('pageNetwork.table.addIpv4Address') }} |
| 34 | </b-button> |
| 35 | </b-col> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 36 | </b-row> |
| 37 | <b-table |
| 38 | responsive="md" |
| 39 | hover |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 40 | thead-class="table-light" |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 41 | :fields="ipv4TableFields" |
| 42 | :items="form.ipv4TableItems" |
| 43 | :empty-text="$t('global.table.emptyMessage')" |
| 44 | class="mb-0" |
| 45 | show-empty |
| 46 | > |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 47 | <template #cell(actions)="{ item, index }"> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 48 | <table-row-action |
| Sivaprabu Ganesan | 2098359 | 2023-09-25 18:43:10 +0530 | [diff] [blame] | 49 | v-for="(action, actionIndex) in filteredActions(item)" |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 50 | :key="actionIndex" |
| 51 | :value="action.value" |
| 52 | :title="action.title" |
| 53 | :enabled="action.enabled" |
| 54 | @click-table-action="onIpv4TableAction(action, $event, index)" |
| 55 | > |
| 56 | <template #icon> |
| 57 | <icon-edit v-if="action.value === 'edit'" /> |
| 58 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 59 | </template> |
| 60 | </table-row-action> |
| 61 | </template> |
| 62 | </b-table> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 63 | <modal-ipv4 v-model="showAddIpv4" /> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 64 | </page-section> |
| 65 | </template> |
| 66 | |
| 67 | <script> |
| 68 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 69 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 70 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 71 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 72 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 73 | import PageSection from '@/components/Global/PageSection'; |
| 74 | import TableRowAction from '@/components/Global/TableRowAction'; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 75 | import ModalIpv4 from './ModalIpv4.vue'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 76 | import { mapState } from 'vuex'; |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 77 | import { useI18n } from 'vue-i18n'; |
| 78 | import i18n from '@/i18n'; |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 79 | import { useModal } from 'bootstrap-vue-next'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 80 | |
| 81 | export default { |
| 82 | name: 'Ipv4Table', |
| 83 | components: { |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 84 | IconAdd, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 85 | IconEdit, |
| 86 | IconTrashcan, |
| 87 | PageSection, |
| 88 | TableRowAction, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 89 | ModalIpv4, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 90 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 91 | mixins: [BVToastMixin, LoadingBarMixin], |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 92 | props: { |
| 93 | tabIndex: { |
| 94 | type: Number, |
| 95 | default: 0, |
| 96 | }, |
| 97 | }, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 98 | setup() { |
| 99 | const bvModal = useModal(); |
| 100 | return { bvModal }; |
| 101 | }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 102 | data() { |
| 103 | return { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 104 | $t: useI18n().t, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 105 | showAddIpv4: false, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 106 | form: { |
| 107 | ipv4TableItems: [], |
| 108 | }, |
| 109 | actions: [ |
| 110 | { |
| 111 | value: 'edit', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 112 | title: i18n.global.t('global.action.edit'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 113 | }, |
| 114 | { |
| 115 | value: 'delete', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 116 | title: i18n.global.t('global.action.delete'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 117 | }, |
| 118 | ], |
| 119 | ipv4TableFields: [ |
| 120 | { |
| 121 | key: 'Address', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 122 | label: i18n.global.t('pageNetwork.table.ipAddress'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 123 | }, |
| 124 | { |
| 125 | key: 'Gateway', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 126 | label: i18n.global.t('pageNetwork.table.gateway'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 127 | }, |
| 128 | { |
| 129 | key: 'SubnetMask', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 130 | label: i18n.global.t('pageNetwork.table.subnet'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 131 | }, |
| 132 | { |
| 133 | key: 'AddressOrigin', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 134 | label: i18n.global.t('pageNetwork.table.addressOrigin'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 135 | }, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 136 | { key: 'actions', label: '', tdClass: 'text-end' }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 137 | ], |
| 138 | }; |
| 139 | }, |
| 140 | computed: { |
| 141 | ...mapState('network', ['ethernetData']), |
| Nikhil Ashoka | e8cb2c6 | 2023-01-04 15:45:20 +0530 | [diff] [blame] | 142 | selectedInterface() { |
| 143 | return this.$store.getters['network/selectedInterfaceIndex']; |
| 144 | }, |
| 145 | dhcpEnabledState: { |
| 146 | get() { |
| 147 | return this.$store.getters['network/globalNetworkSettings'][ |
| 148 | this.selectedInterface |
| 149 | ].dhcpEnabled; |
| 150 | }, |
| 151 | set(newValue) { |
| 152 | return newValue; |
| 153 | }, |
| 154 | }, |
| Sivaprabu Ganesan | 2098359 | 2023-09-25 18:43:10 +0530 | [diff] [blame] | 155 | filteredActions() { |
| 156 | return (item) => { |
| 157 | if (item.AddressOrigin === 'DHCP') { |
| 158 | return item.actions.filter((action) => action.value !== 'delete'); |
| 159 | } else { |
| 160 | return item.actions; |
| 161 | } |
| 162 | }; |
| 163 | }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 164 | }, |
| 165 | watch: { |
| 166 | // Watch for change in tab index |
| 167 | tabIndex() { |
| 168 | this.getIpv4TableItems(); |
| 169 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 170 | ethernetData() { |
| 171 | this.getIpv4TableItems(); |
| 172 | }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 173 | }, |
| 174 | created() { |
| 175 | this.getIpv4TableItems(); |
| 176 | this.$store.dispatch('network/getEthernetData').finally(() => { |
| 177 | // Emit initial data fetch complete to parent component |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 178 | require('@/eventBus').default.$emit('network-table-ipv4-complete'); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 179 | }); |
| 180 | }, |
| 181 | methods: { |
| 182 | getIpv4TableItems() { |
| 183 | const index = this.tabIndex; |
| 184 | const addresses = this.ethernetData[index].IPv4Addresses || []; |
| 185 | this.form.ipv4TableItems = addresses.map((ipv4) => { |
| 186 | return { |
| 187 | Address: ipv4.Address, |
| 188 | SubnetMask: ipv4.SubnetMask, |
| 189 | Gateway: ipv4.Gateway, |
| 190 | AddressOrigin: ipv4.AddressOrigin, |
| 191 | actions: [ |
| 192 | { |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 193 | value: 'delete', |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 194 | title: i18n.global.t('pageNetwork.table.deleteIpv4'), |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 195 | }, |
| 196 | ], |
| 197 | }; |
| 198 | }); |
| 199 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 200 | onIpv4TableAction(action, $event, index) { |
| 201 | if ($event === 'delete') { |
| 202 | this.deleteIpv4TableRow(index); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 203 | } |
| 204 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 205 | deleteIpv4TableRow(index) { |
| 206 | this.form.ipv4TableItems.splice(index, 1); |
| 207 | const newIpv4Array = this.form.ipv4TableItems.map((ipv4) => { |
| 208 | const { Address, SubnetMask, Gateway } = ipv4; |
| 209 | return { |
| 210 | Address, |
| 211 | SubnetMask, |
| 212 | Gateway, |
| 213 | }; |
| 214 | }); |
| 215 | this.$store |
| 216 | .dispatch('network/editIpv4Address', newIpv4Array) |
| 217 | .then((message) => this.successToast(message)) |
| 218 | .catch(({ message }) => this.errorToast(message)); |
| 219 | }, |
| 220 | initAddIpv4Address() { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 221 | this.showAddIpv4 = true; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 222 | }, |
| Nikhil Ashoka | e8cb2c6 | 2023-01-04 15:45:20 +0530 | [diff] [blame] | 223 | changeDhcpEnabledState(state) { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 224 | const dhcpState = state |
| 225 | ? i18n.global.t('global.action.enable') |
| 226 | : i18n.global.t('global.action.disable'); |
| 227 | this.confirmDialog( |
| 228 | state |
| 229 | ? i18n.global.t('pageNetwork.modal.confirmEnableDhcp') |
| 230 | : i18n.global.t('pageNetwork.modal.confirmDisableDhcp'), |
| 231 | { |
| 232 | title: i18n.global.t('pageNetwork.modal.dhcpConfirmTitle', { |
| 233 | dhcpState, |
| 234 | }), |
| 235 | okTitle: dhcpState, |
| 236 | okVariant: 'danger', |
| 237 | cancelTitle: i18n.global.t('global.action.cancel'), |
| 238 | autoFocusButton: 'cancel', |
| 239 | }, |
| 240 | ).then((dhcpEnableConfirmed) => { |
| 241 | if (dhcpEnableConfirmed) { |
| 242 | this.$store |
| 243 | .dispatch('network/saveDhcpEnabledState', state) |
| 244 | .then((message) => this.successToast(message)) |
| 245 | .catch(({ message }) => this.errorToast(message)); |
| 246 | } else { |
| 247 | let onDhcpCancel = document.getElementById('dhcpSwitch'); |
| 248 | onDhcpCancel.checked = !state; |
| 249 | } |
| 250 | }); |
| 251 | }, |
| 252 | confirmDialog(message, options = {}) { |
| 253 | return this.$confirm({ message, ...options }); |
| Nikhil Ashoka | e8cb2c6 | 2023-01-04 15:45:20 +0530 | [diff] [blame] | 254 | }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 255 | }, |
| 256 | }; |
| 257 | </script> |