blob: 2abbcd7a7f0b7fe74128e7bb3ab03463c2f596b7 [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 -->
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -06007 <page-section v-show="ethernetData">
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
12 active-nav-item-class="font-weight-bold"
13 card
14 content-class="mt-3"
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060015 >
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050016 <b-tab
17 v-for="(data, index) in ethernetData"
18 :key="data.Id"
19 :title="data.Id"
20 @click="getTabIndex(index)"
21 >
22 <!-- Interface settings -->
23 <network-interface-settings :tab-index="tabIndex" />
24 <!-- IPV4 table -->
25 <table-ipv-4 :tab-index="tabIndex" />
26 <!-- Static DNS table -->
27 <table-dns :tab-index="tabIndex" />
28 </b-tab>
29 </b-tabs>
30 </b-card>
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060031 </b-col>
32 </b-row>
33 </page-section>
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050034 <!-- Modals -->
35 <modal-ipv4 :default-gateway="defaultGateway" @ok="saveIpv4Address" />
36 <modal-dns @ok="saveDnsAddress" />
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060037 <modal-hostname :hostname="currentHostname" @ok="saveSettings" />
38 <modal-mac-address :mac-address="currentMacAddress" @ok="saveSettings" />
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060039 </b-container>
40</template>
41
42<script>
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060043import BVToastMixin from '@/components/Mixins/BVToastMixin';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050044import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin';
Yoshie Muranakad73f4962020-12-09 08:52:23 -080045import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060046import ModalMacAddress from './ModalMacAddress.vue';
47import ModalHostname from './ModalHostname.vue';
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050048import ModalIpv4 from './ModalIpv4.vue';
49import ModalDns from './ModalDns.vue';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050050import NetworkGlobalSettings from './NetworkGlobalSettings.vue';
51import NetworkInterfaceSettings from './NetworkInterfaceSettings.vue';
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060052import PageSection from '@/components/Global/PageSection';
53import PageTitle from '@/components/Global/PageTitle';
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050054import TableIpv4 from './TableIpv4.vue';
55import TableDns from './TableDns.vue';
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060056import { mapState } from 'vuex';
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060057
58export default {
Sandeepa Singhf67f7692021-07-19 18:04:18 +053059 name: 'Network',
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060060 components: {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060061 ModalHostname,
62 ModalMacAddress,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050063 ModalIpv4,
64 ModalDns,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050065 NetworkGlobalSettings,
66 NetworkInterfaceSettings,
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060067 PageSection,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050068 PageTitle,
69 TableDns,
70 TableIpv4,
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060071 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050072 mixins: [BVToastMixin, DataFormatterMixin, LoadingBarMixin],
Derick Montague602e98a2020-10-21 16:20:00 -050073 beforeRouteLeave(to, from, next) {
74 this.hideLoader();
75 next();
76 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060077 data() {
78 return {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060079 currentHostname: '',
80 currentMacAddress: '',
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050081 defaultGateway: '',
Yoshie Muranakad73f4962020-12-09 08:52:23 -080082 loading,
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050083 tabIndex: 0,
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060084 };
85 },
86 computed: {
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050087 ...mapState('network', ['ethernetData']),
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060088 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050089 watch: {
90 ethernetData() {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -060091 this.getModalInfo();
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050092 },
93 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -060094 created() {
95 this.startLoader();
Dixsie Wolmersc4b87572021-10-07 16:15:50 -050096 const globalSettings = new Promise((resolve) => {
97 this.$root.$on('network-global-settings-complete', () => resolve());
98 });
99 const interfaceSettings = new Promise((resolve) => {
100 this.$root.$on('network-interface-settings-complete', () => resolve());
101 });
102 const networkTableDns = new Promise((resolve) => {
103 this.$root.$on('network-table-dns-complete', () => resolve());
104 });
105 const networkTableIpv4 = new Promise((resolve) => {
106 this.$root.$on('network-table-ipv4-complete', () => resolve());
107 });
108 // Combine all child component Promises to indicate
109 // when page data load complete
110 Promise.all([
111 this.$store.dispatch('network/getEthernetData'),
112 globalSettings,
113 interfaceSettings,
114 networkTableDns,
115 networkTableIpv4,
116 ]).finally(() => this.endLoader());
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600117 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600118 methods: {
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600119 getModalInfo() {
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500120 this.defaultGateway = this.$store.getters[
121 'network/globalNetworkSettings'
122 ][this.tabIndex].defaultGateway;
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600123
124 this.currentHostname = this.$store.getters[
125 'network/globalNetworkSettings'
126 ][this.tabIndex].hostname;
127
128 this.currentMacAddress = this.$store.getters[
129 'network/globalNetworkSettings'
130 ][this.tabIndex].macAddress;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500131 },
Dixsie Wolmersc4b87572021-10-07 16:15:50 -0500132 getTabIndex(selectedIndex) {
133 this.tabIndex = selectedIndex;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500134 this.$store.dispatch('network/setSelectedTabIndex', this.tabIndex);
135 this.$store.dispatch(
136 'network/setSelectedTabId',
137 this.ethernetData[selectedIndex].Id
138 );
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600139 this.getModalInfo();
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500140 },
141 saveIpv4Address(modalFormData) {
142 this.startLoader();
143 this.$store
144 .dispatch('network/saveIpv4Address', modalFormData)
145 .then((message) => this.successToast(message))
146 .catch(({ message }) => this.errorToast(message))
147 .finally(() => this.endLoader());
148 },
149 saveDnsAddress(modalFormData) {
150 this.startLoader();
151 this.$store
152 .dispatch('network/saveDnsAddress', modalFormData)
153 .then((message) => this.successToast(message))
154 .catch(({ message }) => this.errorToast(message))
155 .finally(() => this.endLoader());
Derick Montague602e98a2020-10-21 16:20:00 -0500156 },
Dixsie Wolmers12dc20c2021-12-03 14:29:26 -0600157 saveSettings(modalFormData) {
158 this.startLoader();
159 this.$store
160 .dispatch('network/saveSettings', modalFormData)
161 .then((message) => this.successToast(message))
162 .catch(({ message }) => this.errorToast(message))
163 .finally(() => this.endLoader());
164 },
Derick Montague602e98a2020-10-21 16:20:00 -0500165 },
Dixsie Wolmersbb81d552020-02-26 19:52:28 -0600166};
167</script>