blob: 73118c85ce10d0d01ed8c08f4a20d57c68ae52c8 [file] [log] [blame]
Dixsie Wolmersbb81d552020-02-26 19:52:28 -06001<template>
2 <b-container fluid="xl">
Sandeepa Singhf67f7692021-07-19 18:04:18 +05303 <page-title :description="$t('pageNetwork.pageDescription')" />
Dixsie Wolmersc4b87572021-10-07 16:15:50 -05004 <!-- Global settings for all interfaces -->
5 <network-global-settings />
6 <!-- Interface tabs -->
jason westoverd36ac8a2025-11-03 20:58:59 -06007 <page-section v-if="ethernetData && ethernetData.length">
Dixsie Wolmersbb81d552020-02-26 19:52:28 -06008 <b-row>
Dixsie Wolmersc4b87572021-10-07 16:15:50 -05009 <b-col>
10 <b-card no-body>
11 <b-tabs
jason westoverd36ac8a2025-11-03 20:58:59 -060012 :key="tabsRenderKey"
13 v-model:index="tabIndex"
14 active-nav-item-class="fw-bold"
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050015 card
16 content-class="mt-3"
jason westoverd36ac8a2025-11-03 20:58:59 -060017 :lazy="false"
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060018 >
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050019 <b-tab
jason westoverd36ac8a2025-11-03 20:58:59 -060020 v-for="data in ethernetData"
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050021 :key="data.Id"
22 :title="data.Id"
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050023 >
24 <!-- Interface settings -->
25 <network-interface-settings :tab-index="tabIndex" />
26 <!-- IPV4 table -->
27 <table-ipv-4 :tab-index="tabIndex" />
Sean Zhangdb47b7e2024-06-12 10:28:41 +030028 <!-- IPV6 table -->
29 <table-ipv-6 :tab-index="tabIndex" />
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050030 <!-- Static DNS table -->
31 <table-dns :tab-index="tabIndex" />
32 </b-tab>
33 </b-tabs>
34 </b-card>
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060035 </b-col>
36 </b-row>
37 </page-section>
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050038 <!-- Modals -->
39 <modal-ipv4 :default-gateway="defaultGateway" @ok="saveIpv4Address" />
Sean Zhangdb47b7e2024-06-12 10:28:41 +030040 <modal-ipv6 @ok="saveIpv6Address" />
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050041 <modal-dns @ok="saveDnsAddress" />
jason westoverd36ac8a2025-11-03 20:58:59 -060042 <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 Zhangdb47b7e2024-06-12 10:28:41 +030052 <modal-default-gateway
jason westoverd36ac8a2025-11-03 20:58:59 -060053 v-model="showDefaultGatewayModal"
Sean Zhangdb47b7e2024-06-12 10:28:41 +030054 :default-gateway="ipv6DefaultGateway"
55 @ok="saveSettings"
56 />
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060057 </b-container>
58</template>
59
60<script>
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060061import BVToastMixin from '@/components/Mixins/BVToastMixin';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050062import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin';
Yoshie Muranakad73f4962020-12-09 08:52:23 -080063import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060064import ModalMacAddress from './ModalMacAddress.vue';
Sean Zhangdb47b7e2024-06-12 10:28:41 +030065import ModalDefaultGateway from './ModalDefaultGateway.vue';
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060066import ModalHostname from './ModalHostname.vue';
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050067import ModalIpv4 from './ModalIpv4.vue';
Sean Zhangdb47b7e2024-06-12 10:28:41 +030068import ModalIpv6 from './ModalIpv6.vue';
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050069import ModalDns from './ModalDns.vue';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050070import NetworkGlobalSettings from './NetworkGlobalSettings.vue';
71import NetworkInterfaceSettings from './NetworkInterfaceSettings.vue';
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060072import PageSection from '@/components/Global/PageSection';
73import PageTitle from '@/components/Global/PageTitle';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050074import TableIpv4 from './TableIpv4.vue';
Sean Zhangdb47b7e2024-06-12 10:28:41 +030075import TableIpv6 from './TableIpv6.vue';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050076import TableDns from './TableDns.vue';
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060077import { mapState } from 'vuex';
Surya Vde23ea22024-07-11 15:19:46 +053078import { useI18n } from 'vue-i18n';
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060079
80export default {
Sandeepa Singhf67f7692021-07-19 18:04:18 +053081 name: 'Network',
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060082 components: {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060083 ModalHostname,
84 ModalMacAddress,
Sean Zhangdb47b7e2024-06-12 10:28:41 +030085 ModalDefaultGateway,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050086 ModalIpv4,
Sean Zhangdb47b7e2024-06-12 10:28:41 +030087 ModalIpv6,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050088 ModalDns,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050089 NetworkGlobalSettings,
90 NetworkInterfaceSettings,
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060091 PageSection,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050092 PageTitle,
93 TableDns,
94 TableIpv4,
Sean Zhangdb47b7e2024-06-12 10:28:41 +030095 TableIpv6,
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060096 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050097 mixins: [BVToastMixin, DataFormatterMixin, LoadingBarMixin],
Derick Montague602e98a2020-10-21 16:20:00 -050098 beforeRouteLeave(to, from, next) {
99 this.hideLoader();
100 next();
101 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600102 data() {
103 return {
Surya Vde23ea22024-07-11 15:19:46 +0530104 $t: useI18n().t,
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600105 currentHostname: '',
106 currentMacAddress: '',
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500107 defaultGateway: '',
Sean Zhangdb47b7e2024-06-12 10:28:41 +0300108 ipv6DefaultGateway: '',
Yoshie Muranakad73f4962020-12-09 08:52:23 -0800109 loading,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500110 tabIndex: 0,
jason westoverd36ac8a2025-11-03 20:58:59 -0600111 tabsReady: false,
112 tabsRenderKey: 0,
113 showHostnameModal: false,
114 showDefaultGatewayModal: false,
115 showMacAddressModal: false,
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600116 };
117 },
118 computed: {
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500119 ...mapState('network', ['ethernetData']),
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600120 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500121 watch: {
122 ethernetData() {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600123 this.getModalInfo();
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500124 },
jason westoverd36ac8a2025-11-03 20:58:59 -0600125 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 Wolmersb34349d2021-11-02 22:06:35 -0500133 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600134 created() {
135 this.startLoader();
jason westoverd36ac8a2025-11-03 20:58:59 -0600136 const eventBus = require('@/eventBus').default;
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500137 const globalSettings = new Promise((resolve) => {
jason westoverd36ac8a2025-11-03 20:58:59 -0600138 eventBus.$once('network-global-settings-complete', resolve);
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500139 });
140 const interfaceSettings = new Promise((resolve) => {
jason westoverd36ac8a2025-11-03 20:58:59 -0600141 eventBus.$once('network-interface-settings-complete', resolve);
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500142 });
143 const networkTableDns = new Promise((resolve) => {
jason westoverd36ac8a2025-11-03 20:58:59 -0600144 eventBus.$once('network-table-dns-complete', resolve);
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500145 });
146 const networkTableIpv4 = new Promise((resolve) => {
jason westoverd36ac8a2025-11-03 20:58:59 -0600147 eventBus.$once('network-table-ipv4-complete', resolve);
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500148 });
Sean Zhangdb47b7e2024-06-12 10:28:41 +0300149 const networkTableIpv6 = new Promise((resolve) => {
jason westoverd36ac8a2025-11-03 20:58:59 -0600150 eventBus.$once('network-table-ipv6-complete', resolve);
Sean Zhangdb47b7e2024-06-12 10:28:41 +0300151 });
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500152 // 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 Zhangdb47b7e2024-06-12 10:28:41 +0300160 networkTableIpv6,
jason westoverd36ac8a2025-11-03 20:58:59 -0600161 ])
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 Wolmersbb81d552020-02-26 19:52:28 -0600177 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600178 methods: {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600179 getModalInfo() {
jason westoverd36ac8a2025-11-03 20:58:59 -0600180 const settingsArray =
181 this.$store.getters['network/globalNetworkSettings'];
182 const settings = Array.isArray(settingsArray)
183 ? settingsArray[this.tabIndex]
184 : undefined;
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600185
jason westoverd36ac8a2025-11-03 20:58:59 -0600186 if (!settings) return;
187 this.defaultGateway = settings.defaultGateway;
188 this.currentHostname = settings.hostname;
189 this.currentMacAddress = settings.macAddress;
190 this.ipv6DefaultGateway = settings.ipv6DefaultGateway;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500191 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500192 getTabIndex(selectedIndex) {
193 this.tabIndex = selectedIndex;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500194 this.$store.dispatch('network/setSelectedTabIndex', this.tabIndex);
195 this.$store.dispatch(
196 'network/setSelectedTabId',
Ed Tanous81323992024-02-27 11:26:24 -0800197 this.ethernetData[selectedIndex].Id,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500198 );
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600199 this.getModalInfo();
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500200 },
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 Zhangdb47b7e2024-06-12 10:28:41 +0300209 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 Wolmersb34349d2021-11-02 22:06:35 -0500217 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 Montague602e98a2020-10-21 16:20:00 -0500224 },
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600225 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 Montague602e98a2020-10-21 16:20:00 -0500233 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600234};
235</script>