| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| Sandeepa Singh | f67f769 | 2021-07-19 18:04:18 +0530 | [diff] [blame] | 3 | <page-title :description="$t('pageNetwork.pageDescription')" /> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 4 | <!-- Global settings for all interfaces --> |
| 5 | <network-global-settings /> |
| 6 | <!-- Interface tabs --> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 7 | <page-section v-if="ethernetData && ethernetData.length"> |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 8 | <b-row> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 9 | <b-col> |
| 10 | <b-card no-body> |
| 11 | <b-tabs |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 12 | :key="tabsRenderKey" |
| 13 | v-model:index="tabIndex" |
| 14 | active-nav-item-class="fw-bold" |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 15 | card |
| 16 | content-class="mt-3" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 17 | :lazy="false" |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 18 | > |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 19 | <b-tab |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 20 | v-for="data in ethernetData" |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 21 | :key="data.Id" |
| 22 | :title="data.Id" |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 23 | > |
| 24 | <!-- Interface settings --> |
| 25 | <network-interface-settings :tab-index="tabIndex" /> |
| 26 | <!-- IPV4 table --> |
| 27 | <table-ipv-4 :tab-index="tabIndex" /> |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 28 | <!-- IPV6 table --> |
| 29 | <table-ipv-6 :tab-index="tabIndex" /> |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 30 | <!-- Static DNS table --> |
| 31 | <table-dns :tab-index="tabIndex" /> |
| 32 | </b-tab> |
| 33 | </b-tabs> |
| 34 | </b-card> |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 35 | </b-col> |
| 36 | </b-row> |
| 37 | </page-section> |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 38 | <!-- Modals --> |
| 39 | <modal-ipv4 :default-gateway="defaultGateway" @ok="saveIpv4Address" /> |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 40 | <modal-ipv6 @ok="saveIpv6Address" /> |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 41 | <modal-dns @ok="saveDnsAddress" /> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 42 | <modal-hostname |
| 43 | v-model="showHostnameModal" |
| 44 | :hostname="currentHostname" |
| 45 | @ok="saveSettings" |
| 46 | /> |
| 47 | <modal-mac-address |
| 48 | v-model="showMacAddressModal" |
| 49 | :mac-address="currentMacAddress" |
| 50 | @ok="saveSettings" |
| 51 | /> |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 52 | <modal-default-gateway |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 53 | v-model="showDefaultGatewayModal" |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 54 | :default-gateway="ipv6DefaultGateway" |
| 55 | @ok="saveSettings" |
| 56 | /> |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 57 | </b-container> |
| 58 | </template> |
| 59 | |
| 60 | <script> |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 61 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 62 | import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin'; |
| Yoshie Muranaka | d73f496 | 2020-12-09 08:52:23 -0800 | [diff] [blame] | 63 | import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin'; |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 64 | import ModalMacAddress from './ModalMacAddress.vue'; |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 65 | import ModalDefaultGateway from './ModalDefaultGateway.vue'; |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 66 | import ModalHostname from './ModalHostname.vue'; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 67 | import ModalIpv4 from './ModalIpv4.vue'; |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 68 | import ModalIpv6 from './ModalIpv6.vue'; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 69 | import ModalDns from './ModalDns.vue'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 70 | import NetworkGlobalSettings from './NetworkGlobalSettings.vue'; |
| 71 | import NetworkInterfaceSettings from './NetworkInterfaceSettings.vue'; |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 72 | import PageSection from '@/components/Global/PageSection'; |
| 73 | import PageTitle from '@/components/Global/PageTitle'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 74 | import TableIpv4 from './TableIpv4.vue'; |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 75 | import TableIpv6 from './TableIpv6.vue'; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 76 | import TableDns from './TableDns.vue'; |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 77 | import { mapState } from 'vuex'; |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 78 | import { useI18n } from 'vue-i18n'; |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 79 | |
| 80 | export default { |
| Sandeepa Singh | f67f769 | 2021-07-19 18:04:18 +0530 | [diff] [blame] | 81 | name: 'Network', |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 82 | components: { |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 83 | ModalHostname, |
| 84 | ModalMacAddress, |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 85 | ModalDefaultGateway, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 86 | ModalIpv4, |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 87 | ModalIpv6, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 88 | ModalDns, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 89 | NetworkGlobalSettings, |
| 90 | NetworkInterfaceSettings, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 91 | PageSection, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 92 | PageTitle, |
| 93 | TableDns, |
| 94 | TableIpv4, |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 95 | TableIpv6, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 96 | }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 97 | mixins: [BVToastMixin, DataFormatterMixin, LoadingBarMixin], |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 98 | beforeRouteLeave(to, from, next) { |
| 99 | this.hideLoader(); |
| 100 | next(); |
| 101 | }, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 102 | data() { |
| 103 | return { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 104 | $t: useI18n().t, |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 105 | currentHostname: '', |
| 106 | currentMacAddress: '', |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 107 | defaultGateway: '', |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 108 | ipv6DefaultGateway: '', |
| Yoshie Muranaka | d73f496 | 2020-12-09 08:52:23 -0800 | [diff] [blame] | 109 | loading, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 110 | tabIndex: 0, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 111 | tabsReady: false, |
| 112 | tabsRenderKey: 0, |
| 113 | showHostnameModal: false, |
| 114 | showDefaultGatewayModal: false, |
| 115 | showMacAddressModal: false, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 116 | }; |
| 117 | }, |
| 118 | computed: { |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 119 | ...mapState('network', ['ethernetData']), |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 120 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 121 | watch: { |
| 122 | ethernetData() { |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 123 | this.getModalInfo(); |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 124 | }, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 125 | tabIndex(newIndex) { |
| 126 | this.$store.dispatch('network/setSelectedTabIndex', newIndex); |
| 127 | this.$store.dispatch( |
| 128 | 'network/setSelectedTabId', |
| 129 | this.ethernetData?.[newIndex]?.Id, |
| 130 | ); |
| 131 | this.getModalInfo(); |
| 132 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 133 | }, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 134 | created() { |
| 135 | this.startLoader(); |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 136 | const eventBus = require('@/eventBus').default; |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 137 | const globalSettings = new Promise((resolve) => { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 138 | eventBus.$once('network-global-settings-complete', resolve); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 139 | }); |
| 140 | const interfaceSettings = new Promise((resolve) => { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 141 | eventBus.$once('network-interface-settings-complete', resolve); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 142 | }); |
| 143 | const networkTableDns = new Promise((resolve) => { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 144 | eventBus.$once('network-table-dns-complete', resolve); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 145 | }); |
| 146 | const networkTableIpv4 = new Promise((resolve) => { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 147 | eventBus.$once('network-table-ipv4-complete', resolve); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 148 | }); |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 149 | const networkTableIpv6 = new Promise((resolve) => { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 150 | eventBus.$once('network-table-ipv6-complete', resolve); |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 151 | }); |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 152 | // Combine all child component Promises to indicate |
| 153 | // when page data load complete |
| 154 | Promise.all([ |
| 155 | this.$store.dispatch('network/getEthernetData'), |
| 156 | globalSettings, |
| 157 | interfaceSettings, |
| 158 | networkTableDns, |
| 159 | networkTableIpv4, |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 160 | networkTableIpv6, |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 161 | ]) |
| 162 | .then(() => { |
| 163 | // ensure first tab is selected and expanded (index 0). Force a change |
| 164 | // cycle to trigger BTabs to render the pane content immediately. |
| 165 | const count = this.ethernetData?.length || 0; |
| 166 | if (count > 0) { |
| 167 | // set initial selection directly to index 0 |
| 168 | this.tabIndex = 0; |
| 169 | this.$store.dispatch('network/setSelectedTabIndex', 0); |
| 170 | const firstId = this.ethernetData?.[0]?.Id; |
| 171 | if (firstId) |
| 172 | this.$store.dispatch('network/setSelectedTabId', firstId); |
| 173 | this.tabsRenderKey += 1; |
| 174 | } |
| 175 | }) |
| 176 | .finally(() => this.endLoader()); |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 177 | }, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 178 | methods: { |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 179 | getModalInfo() { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 180 | const settingsArray = |
| 181 | this.$store.getters['network/globalNetworkSettings']; |
| 182 | const settings = Array.isArray(settingsArray) |
| 183 | ? settingsArray[this.tabIndex] |
| 184 | : undefined; |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 185 | |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 186 | if (!settings) return; |
| 187 | this.defaultGateway = settings.defaultGateway; |
| 188 | this.currentHostname = settings.hostname; |
| 189 | this.currentMacAddress = settings.macAddress; |
| 190 | this.ipv6DefaultGateway = settings.ipv6DefaultGateway; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 191 | }, |
| Dixsie Wolmers | c4b8757 | 2021-10-07 16:15:50 -0500 | [diff] [blame] | 192 | getTabIndex(selectedIndex) { |
| 193 | this.tabIndex = selectedIndex; |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 194 | this.$store.dispatch('network/setSelectedTabIndex', this.tabIndex); |
| 195 | this.$store.dispatch( |
| 196 | 'network/setSelectedTabId', |
| Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 197 | this.ethernetData[selectedIndex].Id, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 198 | ); |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 199 | this.getModalInfo(); |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 200 | }, |
| 201 | saveIpv4Address(modalFormData) { |
| 202 | this.startLoader(); |
| 203 | this.$store |
| 204 | .dispatch('network/saveIpv4Address', modalFormData) |
| 205 | .then((message) => this.successToast(message)) |
| 206 | .catch(({ message }) => this.errorToast(message)) |
| 207 | .finally(() => this.endLoader()); |
| 208 | }, |
| Sean Zhang | db47b7e | 2024-06-12 10:28:41 +0300 | [diff] [blame] | 209 | saveIpv6Address(modalFormData) { |
| 210 | this.startLoader(); |
| 211 | this.$store |
| 212 | .dispatch('network/saveIpv6Address', modalFormData) |
| 213 | .then((message) => this.successToast(message)) |
| 214 | .catch(({ message }) => this.errorToast(message)) |
| 215 | .finally(() => this.endLoader()); |
| 216 | }, |
| Dixsie Wolmers | b34349d | 2021-11-02 22:06:35 -0500 | [diff] [blame] | 217 | saveDnsAddress(modalFormData) { |
| 218 | this.startLoader(); |
| 219 | this.$store |
| 220 | .dispatch('network/saveDnsAddress', modalFormData) |
| 221 | .then((message) => this.successToast(message)) |
| 222 | .catch(({ message }) => this.errorToast(message)) |
| 223 | .finally(() => this.endLoader()); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 224 | }, |
| Dixsie Wolmers | 12dc20c | 2021-12-03 14:29:26 -0600 | [diff] [blame] | 225 | saveSettings(modalFormData) { |
| 226 | this.startLoader(); |
| 227 | this.$store |
| 228 | .dispatch('network/saveSettings', modalFormData) |
| 229 | .then((message) => this.successToast(message)) |
| 230 | .catch(({ message }) => this.errorToast(message)) |
| 231 | .finally(() => this.endLoader()); |
| 232 | }, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 233 | }, |
| Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 234 | }; |
| 235 | </script> |