Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 3 | <page-title :description="$t('pageNetworkSettings.pageDescription')" /> |
| 4 | <page-section :section-title="$t('pageNetworkSettings.interface')"> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 5 | <b-row> |
| 6 | <b-col lg="3"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 7 | <b-form-group |
| 8 | label-for="interface-select" |
| 9 | :label="$t('pageNetworkSettings.form.networkInterface')" |
| 10 | > |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 11 | <b-form-select |
| 12 | id="interface-select" |
| 13 | v-model="selectedInterfaceIndex" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 14 | data-test-id="networkSettings-select-interface" |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 15 | :options="interfaceSelectOptions" |
| 16 | @change="selectInterface" |
| 17 | > |
| 18 | </b-form-select> |
| 19 | </b-form-group> |
| 20 | </b-col> |
| 21 | </b-row> |
| 22 | </page-section> |
| 23 | <b-form novalidate @submit.prevent="submitForm"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 24 | <page-section :section-title="$t('pageNetworkSettings.system')"> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 25 | <b-row> |
| 26 | <b-col lg="3"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 27 | <b-form-group |
| 28 | :label="$t('pageNetworkSettings.form.defaultGateway')" |
| 29 | label-for="default-gateway" |
| 30 | > |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 31 | <b-form-input |
| 32 | id="default-gateway" |
| 33 | v-model.trim="form.gateway" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 34 | data-test-id="networkSettings-input-gateway" |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 35 | type="text" |
| 36 | :readonly="dhcpEnabled" |
| 37 | :state="getValidationState($v.form.gateway)" |
| 38 | @change="$v.form.gateway.$touch()" |
| 39 | /> |
| 40 | <b-form-invalid-feedback role="alert"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 41 | <div v-if="!$v.form.gateway.required"> |
| 42 | {{ $t('global.form.fieldRequired') }} |
| 43 | </div> |
| 44 | <div v-if="!$v.form.gateway.validateAddress"> |
| 45 | {{ $t('global.form.invalidFormat') }} |
| 46 | </div> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 47 | </b-form-invalid-feedback> |
| 48 | </b-form-group> |
| 49 | </b-col> |
| 50 | <b-col lg="3"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 51 | <b-form-group |
| 52 | :label="$t('pageNetworkSettings.form.hostname')" |
| 53 | label-for="hostname-field" |
| 54 | > |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 55 | <b-form-input |
| 56 | id="hostname-field" |
| 57 | v-model.trim="form.hostname" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 58 | data-test-id="networkSettings-input-hostname" |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 59 | type="text" |
| 60 | :state="getValidationState($v.form.hostname)" |
| 61 | @change="$v.form.hostname.$touch()" |
| 62 | /> |
| 63 | <b-form-invalid-feedback role="alert"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 64 | <div v-if="!$v.form.hostname.required"> |
| 65 | {{ $t('global.form.fieldRequired') }} |
| 66 | </div> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 67 | <div v-if="!$v.form.hostname.validateHostname"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 68 | {{ |
| 69 | $t('global.form.lengthMustBeBetween', { min: 1, max: 64 }) |
| 70 | }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 71 | </div> |
| 72 | </b-form-invalid-feedback> |
| 73 | </b-form-group> |
| 74 | </b-col> |
| 75 | <b-col lg="3"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 76 | <b-form-group |
| 77 | :label="$t('pageNetworkSettings.form.macAddress')" |
| 78 | label-for="mac-address" |
| 79 | > |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 80 | <b-form-input |
| 81 | id="mac-address" |
| 82 | v-model.trim="form.macAddress" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 83 | data-test-id="networkSettings-input-macAddress" |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 84 | type="text" |
| 85 | :state="getValidationState($v.form.macAddress)" |
| 86 | @change="$v.form.macAddress.$touch()" |
| 87 | /> |
| 88 | <b-form-invalid-feedback role="alert"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 89 | <div v-if="!$v.form.macAddress.required"> |
| 90 | {{ $t('global.form.fieldRequired') }} |
| 91 | </div> |
| 92 | <div v-if="!$v.form.macAddress.validateMacAddress"> |
| 93 | {{ $t('global.form.invalidFormat') }} |
| 94 | </div> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 95 | </b-form-invalid-feedback> |
| 96 | </b-form-group> |
| 97 | </b-col> |
| 98 | </b-row> |
| 99 | </page-section> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 100 | <page-section :section-title="$t('pageNetworkSettings.staticIpv4')"> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 101 | <b-row> |
| 102 | <b-col lg="9" class="mb-3"> |
| 103 | <b-table |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 104 | responsive="md" |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 105 | :fields="ipv4StaticTableFields" |
| 106 | :items="form.ipv4StaticTableItems" |
| 107 | class="mb-0" |
| 108 | > |
| 109 | <template v-slot:cell(Address)="{ item, index }"> |
| 110 | <b-form-input |
| 111 | v-model.trim="item.Address" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 112 | :data-test-id="`networkSettings-input-staticIpv4-${index}`" |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 113 | :aria-label=" |
| 114 | $t('pageNetworkSettings.ariaLabel.staticIpv4AddressRow') + |
| 115 | ' ' + |
| 116 | (index + 1) |
| 117 | " |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 118 | :readonly="dhcpEnabled" |
| 119 | :state=" |
| 120 | getValidationState( |
| 121 | $v.form.ipv4StaticTableItems.$each.$iter[index].Address |
| 122 | ) |
| 123 | " |
| 124 | @change=" |
| 125 | $v.form.ipv4StaticTableItems.$each.$iter[ |
| 126 | index |
| 127 | ].Address.$touch() |
| 128 | " |
| 129 | /> |
| 130 | <b-form-invalid-feedback role="alert"> |
| 131 | <div |
| 132 | v-if=" |
| 133 | !$v.form.ipv4StaticTableItems.$each.$iter[index].Address |
| 134 | .required |
| 135 | " |
| 136 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 137 | {{ $t('global.form.fieldRequired') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 138 | </div> |
| 139 | <div |
| 140 | v-if=" |
| 141 | !$v.form.ipv4StaticTableItems.$each.$iter[index].Address |
| 142 | .validateAddress |
| 143 | " |
| 144 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 145 | {{ $t('global.form.invalidFormat') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 146 | </div> |
| 147 | </b-form-invalid-feedback> |
| 148 | </template> |
| 149 | <template v-slot:cell(SubnetMask)="{ item, index }"> |
| 150 | <b-form-input |
| 151 | v-model.trim="item.SubnetMask" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 152 | :data-test-id="`networkSettings-input-subnetMask-${index}`" |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 153 | :aria-label=" |
| 154 | $t('pageNetworkSettings.ariaLabel.staticIpv4SubnetRow') + |
| 155 | ' ' + |
| 156 | (index + 1) |
| 157 | " |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 158 | :readonly="dhcpEnabled" |
| 159 | :state=" |
| 160 | getValidationState( |
| 161 | $v.form.ipv4StaticTableItems.$each.$iter[index].SubnetMask |
| 162 | ) |
| 163 | " |
| 164 | @change=" |
| 165 | $v.form.ipv4StaticTableItems.$each.$iter[ |
| 166 | index |
| 167 | ].SubnetMask.$touch() |
| 168 | " |
| 169 | /> |
| 170 | <b-form-invalid-feedback role="alert"> |
| 171 | <div |
| 172 | v-if=" |
| 173 | !$v.form.ipv4StaticTableItems.$each.$iter[index] |
| 174 | .SubnetMask.required |
| 175 | " |
| 176 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 177 | {{ $t('global.form.fieldRequired') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 178 | </div> |
| 179 | <div |
| 180 | v-if=" |
| 181 | !$v.form.ipv4StaticTableItems.$each.$iter[index] |
| 182 | .SubnetMask.validateAddress |
| 183 | " |
| 184 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 185 | {{ $t('global.form.invalidFormat') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 186 | </div> |
| 187 | </b-form-invalid-feedback> |
| 188 | </template> |
| 189 | <template v-slot:cell(actions)="{ item, index }"> |
| 190 | <table-row-action |
| 191 | v-for="(action, actionIndex) in item.actions" |
| 192 | :key="actionIndex" |
| 193 | :value="action.value" |
| 194 | :title="action.title" |
| 195 | @click:tableAction="onDeleteIpv4StaticTableRow($event, index)" |
| 196 | > |
| 197 | <template v-slot:icon> |
| 198 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 199 | </template> |
| 200 | </table-row-action> |
| 201 | </template> |
| 202 | </b-table> |
| 203 | <b-button variant="link" @click="addIpv4StaticTableRow"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 204 | <icon-add /> |
| 205 | {{ $t('pageNetworkSettings.table.addStaticIpv4Address') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 206 | </b-button> |
| 207 | </b-col> |
| 208 | </b-row> |
| 209 | </page-section> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 210 | <page-section :section-title="$t('pageNetworkSettings.staticDns')"> |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 211 | <b-row> |
| 212 | <b-col lg="4" class="mb-3"> |
| 213 | <b-table |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 214 | responsive |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 215 | :fields="dnsTableFields" |
| 216 | :items="form.dnsStaticTableItems" |
| 217 | class="mb-0" |
| 218 | > |
| 219 | <template v-slot:cell(address)="{ item, index }"> |
| 220 | <b-form-input |
| 221 | v-model.trim="item.address" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 222 | :data-test-id="`networkSettings-input-dnsAddress-${index}`" |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 223 | :aria-label=" |
| 224 | $t('pageNetworkSettings.ariaLabel.staticDnsRow') + |
| 225 | ' ' + |
| 226 | (index + 1) |
| 227 | " |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 228 | :readonly="dhcpEnabled" |
| 229 | :state=" |
| 230 | getValidationState( |
| 231 | $v.form.dnsStaticTableItems.$each.$iter[index].address |
| 232 | ) |
| 233 | " |
| 234 | @change=" |
| 235 | $v.form.dnsStaticTableItems.$each.$iter[ |
| 236 | index |
| 237 | ].address.$touch() |
| 238 | " |
| 239 | /> |
| 240 | <b-form-invalid-feedback role="alert"> |
| 241 | <div |
| 242 | v-if=" |
| 243 | !$v.form.dnsStaticTableItems.$each.$iter[index].address |
| 244 | .required |
| 245 | " |
| 246 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 247 | {{ $t('global.form.fieldRequired') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 248 | </div> |
| 249 | <div |
| 250 | v-if=" |
| 251 | !$v.form.dnsStaticTableItems.$each.$iter[index].address |
| 252 | .validateAddress |
| 253 | " |
| 254 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 255 | {{ $t('global.form.invalidFormat') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 256 | </div> |
| 257 | </b-form-invalid-feedback> |
| 258 | </template> |
| 259 | <template v-slot:cell(actions)="{ item, index }"> |
| 260 | <table-row-action |
| 261 | v-for="(action, actionIndex) in item.actions" |
| 262 | :key="actionIndex" |
| 263 | :value="action.value" |
| 264 | :title="action.title" |
| 265 | @click:tableAction="onDeleteDnsTableRow($event, index)" |
| 266 | > |
| 267 | <template v-slot:icon> |
| 268 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 269 | </template> |
| 270 | </table-row-action> |
| 271 | </template> |
| 272 | </b-table> |
| 273 | <b-button variant="link" @click="addDnsTableRow"> |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 274 | <icon-add /> {{ $t('pageNetworkSettings.table.addDns') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 275 | </b-button> |
| 276 | </b-col> |
| 277 | </b-row> |
| 278 | </page-section> |
| 279 | <b-button |
| 280 | variant="primary" |
| 281 | type="submit" |
Dixsie Wolmers | 55888a1 | 2020-07-01 11:21:47 -0500 | [diff] [blame] | 282 | data-test-id="networkSettings-button-saveNetworkSettings" |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 283 | :disabled="!$v.form.$anyDirty || $v.form.$invalid" |
| 284 | > |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 285 | {{ $t('global.action.saveSettings') }} |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 286 | </b-button> |
| 287 | </b-form> |
| 288 | </b-container> |
| 289 | </template> |
| 290 | |
| 291 | <script> |
| 292 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 293 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 294 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 295 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 296 | import PageSection from '@/components/Global/PageSection'; |
| 297 | import PageTitle from '@/components/Global/PageTitle'; |
| 298 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 299 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin'; |
| 300 | import { mapState } from 'vuex'; |
| 301 | import { required, helpers } from 'vuelidate/lib/validators'; |
| 302 | |
| 303 | // IP address, gateway and subnet pattern |
| 304 | const validateAddress = helpers.regex( |
| 305 | 'validateAddress', |
| 306 | /^(?=.*[^.]$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.?){4}$/ |
| 307 | ); |
| 308 | // Hostname pattern |
| 309 | const validateHostname = helpers.regex('validateHostname', /^\S{0,64}$/); |
| 310 | // MAC address pattern |
| 311 | const validateMacAddress = helpers.regex( |
| 312 | 'validateMacAddress', |
| 313 | /^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})){2}$/ |
| 314 | ); |
| 315 | |
| 316 | export default { |
| 317 | name: 'NetworkSettings', |
| 318 | components: { |
| 319 | PageTitle, |
| 320 | PageSection, |
| 321 | TableRowAction, |
| 322 | IconTrashcan, |
| 323 | IconAdd |
| 324 | }, |
| 325 | mixins: [BVToastMixin, VuelidateMixin, LoadingBarMixin], |
| 326 | data() { |
| 327 | return { |
| 328 | dhcpEnabled: null, |
| 329 | ipv4Configuration: '', |
| 330 | ipv4StaticTableFields: [ |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 331 | { |
| 332 | key: 'Address', |
| 333 | label: this.$t('pageNetworkSettings.table.ipAddress') |
| 334 | }, |
| 335 | { |
| 336 | key: 'SubnetMask', |
| 337 | label: this.$t('pageNetworkSettings.table.subnet') |
| 338 | }, |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 339 | { key: 'actions', label: '', tdClass: 'text-right' } |
| 340 | ], |
| 341 | dnsTableFields: [ |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 342 | { |
| 343 | key: 'address', |
| 344 | label: this.$t('pageNetworkSettings.table.ipAddress') |
| 345 | }, |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 346 | { key: 'actions', label: '', tdClass: 'text-right' } |
| 347 | ], |
| 348 | selectedInterfaceIndex: 0, |
| 349 | selectedInterface: {}, |
| 350 | form: { |
| 351 | gateway: '', |
| 352 | hostname: '', |
| 353 | macAddress: '', |
| 354 | ipv4StaticTableItems: [], |
| 355 | dnsStaticTableItems: [] |
| 356 | } |
| 357 | }; |
| 358 | }, |
| 359 | validations() { |
| 360 | return { |
| 361 | form: { |
| 362 | gateway: { required, validateAddress }, |
| 363 | hostname: { required, validateHostname }, |
| 364 | ipv4StaticTableItems: { |
| 365 | $each: { |
| 366 | Address: { |
| 367 | required, |
| 368 | validateAddress |
| 369 | }, |
| 370 | SubnetMask: { |
| 371 | required, |
| 372 | validateAddress |
| 373 | } |
| 374 | } |
| 375 | }, |
| 376 | macAddress: { required, validateMacAddress }, |
| 377 | dnsStaticTableItems: { |
| 378 | $each: { |
| 379 | address: { |
| 380 | required, |
| 381 | validateAddress |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | }; |
| 387 | }, |
| 388 | computed: { |
| 389 | ...mapState('networkSettings', [ |
| 390 | 'ethernetData', |
| 391 | 'interfaceOptions', |
| 392 | 'defaultGateway' |
| 393 | ]), |
| 394 | interfaceSelectOptions() { |
| 395 | return this.interfaceOptions.map((option, index) => { |
| 396 | return { |
| 397 | text: option, |
| 398 | value: index |
| 399 | }; |
| 400 | }); |
| 401 | } |
| 402 | }, |
| 403 | watch: { |
| 404 | ethernetData: function() { |
| 405 | this.selectInterface(); |
| 406 | } |
| 407 | }, |
| 408 | created() { |
| 409 | this.startLoader(); |
| 410 | this.$store |
| 411 | .dispatch('networkSettings/getEthernetData') |
| 412 | .finally(() => this.endLoader()); |
| 413 | }, |
| 414 | beforeRouteLeave(to, from, next) { |
| 415 | this.hideLoader(); |
| 416 | next(); |
| 417 | }, |
| 418 | methods: { |
| 419 | selectInterface() { |
| 420 | this.selectedInterface = this.ethernetData[this.selectedInterfaceIndex]; |
| 421 | this.getIpv4StaticTableItems(); |
| 422 | this.getDnsStaticTableItems(); |
| 423 | this.getInterfaceSettings(); |
| 424 | }, |
| 425 | getInterfaceSettings() { |
| 426 | this.form.gateway = this.defaultGateway; |
| 427 | this.form.hostname = this.selectedInterface.HostName; |
| 428 | this.form.macAddress = this.selectedInterface.MACAddress; |
| 429 | this.dhcpEnabled = this.selectedInterface.DHCPv4.DHCPEnabled; |
| 430 | }, |
| 431 | getDnsStaticTableItems() { |
| 432 | const dns = this.selectedInterface.StaticNameServers || []; |
| 433 | this.form.dnsStaticTableItems = dns.map(server => { |
| 434 | return { |
| 435 | address: server, |
| 436 | actions: [ |
| 437 | { |
| 438 | value: 'delete', |
| 439 | enabled: this.dhcpEnabled, |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 440 | title: this.$t('pageNetworkSettings.table.deleteDns') |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 441 | } |
| 442 | ] |
| 443 | }; |
| 444 | }); |
| 445 | }, |
| 446 | addDnsTableRow() { |
| 447 | this.$v.form.dnsStaticTableItems.$touch(); |
| 448 | this.form.dnsStaticTableItems.push({ |
| 449 | address: '', |
| 450 | actions: [ |
| 451 | { |
| 452 | value: 'delete', |
| 453 | enabled: this.dhcpEnabled, |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 454 | title: this.$t('pageNetworkSettings.table.deleteDns') |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 455 | } |
| 456 | ] |
| 457 | }); |
| 458 | }, |
| 459 | deleteDnsTableRow(index) { |
| 460 | this.$v.form.dnsStaticTableItems.$touch(); |
| 461 | this.form.dnsStaticTableItems.splice(index, 1); |
| 462 | }, |
| 463 | onDeleteDnsTableRow(action, row) { |
| 464 | this.deleteDnsTableRow(row); |
| 465 | }, |
| 466 | getIpv4StaticTableItems() { |
| 467 | const addresses = this.selectedInterface.IPv4StaticAddresses || []; |
| 468 | this.form.ipv4StaticTableItems = addresses.map(ipv4 => { |
| 469 | return { |
| 470 | Address: ipv4.Address, |
| 471 | SubnetMask: ipv4.SubnetMask, |
| 472 | actions: [ |
| 473 | { |
| 474 | value: 'delete', |
| 475 | enabled: this.dhcpEnabled, |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 476 | title: this.$t('pageNetworkSettings.table.deleteStaticIpv4') |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 477 | } |
| 478 | ] |
| 479 | }; |
| 480 | }); |
| 481 | }, |
| 482 | addIpv4StaticTableRow() { |
| 483 | this.$v.form.ipv4StaticTableItems.$touch(); |
| 484 | this.form.ipv4StaticTableItems.push({ |
| 485 | Address: '', |
| 486 | SubnetMask: '', |
| 487 | actions: [ |
| 488 | { |
| 489 | value: 'delete', |
| 490 | enabled: this.dhcpEnabled, |
Dixsie Wolmers | e3c9c09 | 2020-05-20 23:27:56 -0500 | [diff] [blame] | 491 | title: this.$t('pageNetworkSettings.table.deleteStaticIpv4') |
Dixsie Wolmers | bb81d55 | 2020-02-26 19:52:28 -0600 | [diff] [blame] | 492 | } |
| 493 | ] |
| 494 | }); |
| 495 | }, |
| 496 | deleteIpv4StaticTableRow(index) { |
| 497 | this.$v.form.ipv4StaticTableItems.$touch(); |
| 498 | this.form.ipv4StaticTableItems.splice(index, 1); |
| 499 | }, |
| 500 | onDeleteIpv4StaticTableRow(action, row) { |
| 501 | this.deleteIpv4StaticTableRow(row); |
| 502 | }, |
| 503 | submitForm() { |
| 504 | this.startLoader(); |
| 505 | let networkInterfaceSelected = this.selectedInterface; |
| 506 | let selectedInterfaceIndex = this.selectedInterfaceIndex; |
| 507 | let interfaceId = networkInterfaceSelected.Id; |
| 508 | let isDhcpEnabled = networkInterfaceSelected.DHCPv4.DHCPEnabled; |
| 509 | let macAddress = this.form.macAddress; |
| 510 | let hostname = this.form.hostname; |
| 511 | let networkSettingsForm = { |
| 512 | interfaceId, |
| 513 | hostname, |
| 514 | macAddress, |
| 515 | selectedInterfaceIndex, |
| 516 | isDhcpEnabled |
| 517 | }; |
| 518 | networkSettingsForm.staticIpv4 = this.form.ipv4StaticTableItems.map( |
| 519 | updateIpv4 => { |
| 520 | delete updateIpv4.actions; |
| 521 | updateIpv4.Gateway = this.form.gateway; |
| 522 | return updateIpv4; |
| 523 | } |
| 524 | ); |
| 525 | networkSettingsForm.staticNameServers = this.form.dnsStaticTableItems.map( |
| 526 | updateDns => { |
| 527 | return updateDns.address; |
| 528 | } |
| 529 | ); |
| 530 | this.$store |
| 531 | .dispatch( |
| 532 | 'networkSettings/updateInterfaceSettings', |
| 533 | networkSettingsForm |
| 534 | ) |
| 535 | .then(success => { |
| 536 | this.successToast(success); |
| 537 | }) |
| 538 | .catch(({ message }) => this.errorToast(message)) |
| 539 | .finally(() => { |
| 540 | this.$v.form.$reset(); |
| 541 | this.endLoader(); |
| 542 | }); |
| 543 | } |
| 544 | } |
| 545 | }; |
| 546 | </script> |