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