Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | <b-row> |
| 5 | <b-col md="8" xl="6"> |
| 6 | <alert variant="info" class="mb-4"> |
| 7 | <span> |
| 8 | {{ $t('pageDateTimeSettings.alert.message') }} |
| 9 | <b-link to="/profile-settings"> |
| 10 | {{ $t('pageDateTimeSettings.alert.link') }}</b-link |
| 11 | > |
| 12 | </span> |
| 13 | </alert> |
| 14 | </b-col> |
| 15 | </b-row> |
| 16 | <page-section> |
| 17 | <b-row> |
| 18 | <b-col lg="3"> |
| 19 | <dl> |
| 20 | <dt>{{ $t('pageDateTimeSettings.form.date') }}</dt> |
| 21 | <dd v-if="bmcTime">{{ bmcTime | formatDate }}</dd> |
| 22 | <dd v-else>--</dd> |
| 23 | </dl> |
| 24 | </b-col> |
| 25 | <b-col lg="3"> |
| 26 | <dl> |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 27 | <dt>{{ $t('pageDateTimeSettings.form.time.label') }}</dt> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 28 | <dd v-if="bmcTime">{{ bmcTime | formatTime }}</dd> |
| 29 | <dd v-else>--</dd> |
| 30 | </dl> |
| 31 | </b-col> |
| 32 | </b-row> |
| 33 | </page-section> |
| 34 | <page-section :section-title="$t('pageDateTimeSettings.configureSettings')"> |
| 35 | <b-form novalidate @submit.prevent="submitForm"> |
Mateusz Gapski | 471f2e0 | 2020-07-27 14:43:26 +0200 | [diff] [blame] | 36 | <b-form-group |
| 37 | label="Configure date and time" |
| 38 | :disabled="loading" |
| 39 | label-sr-only |
| 40 | > |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 41 | <b-form-radio |
| 42 | v-model="form.configurationSelected" |
| 43 | value="manual" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 44 | data-test-id="dateTimeSettings-radio-configureManual" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 45 | @change="onChangeConfigType" |
| 46 | > |
| 47 | {{ $t('pageDateTimeSettings.form.manual') }} |
| 48 | </b-form-radio> |
| 49 | <b-row class="mt-3 ml-3"> |
| 50 | <b-col sm="6" lg="4" xl="3"> |
| 51 | <b-form-group |
| 52 | :label="$t('pageDateTimeSettings.form.date')" |
| 53 | label-for="input-manual-date" |
| 54 | > |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 55 | <b-form-text id="date-format-help">YYYY-MM-DD</b-form-text> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 56 | <b-input-group> |
| 57 | <b-form-input |
| 58 | id="input-manual-date" |
| 59 | v-model="form.manual.date" |
| 60 | :state="getValidationState($v.form.manual.date)" |
| 61 | :disabled="form.configurationSelected === 'ntp'" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 62 | data-test-id="dateTimeSettings-input-manualDate" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 63 | class="form-control-with-button" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 64 | @blur="$v.form.manual.date.$touch()" |
| 65 | /> |
| 66 | <b-form-invalid-feedback role="alert"> |
| 67 | <div v-if="!$v.form.manual.date.pattern"> |
| 68 | {{ $t('global.form.invalidFormat') }} |
| 69 | </div> |
Dixsie Wolmers | 6aa9cf7 | 2020-07-20 07:46:32 -0500 | [diff] [blame] | 70 | <div v-if="!$v.form.manual.date.required"> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 71 | {{ $t('global.form.fieldRequired') }} |
| 72 | </div> |
| 73 | </b-form-invalid-feedback> |
| 74 | <b-form-datepicker |
| 75 | v-model="form.manual.date" |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 76 | class="btn-datepicker btn-icon-only" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 77 | button-only |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 78 | right |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 79 | :hide-header="true" |
| 80 | :locale="locale" |
| 81 | :label-help=" |
| 82 | $t('global.calendar.useCursorKeysToNavigateCalendarDates') |
| 83 | " |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 84 | :title="$t('global.calendar.selectDate')" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 85 | :disabled="form.configurationSelected === 'ntp'" |
| 86 | button-variant="link" |
| 87 | aria-controls="input-manual-date" |
| 88 | > |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 89 | <template #button-content> |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 90 | <icon-calendar /> |
Dixsie Wolmers | e9116eb | 2020-11-18 19:38:18 -0600 | [diff] [blame^] | 91 | <span class="sr-only"> |
| 92 | {{ $t('global.calendar.selectDate') }} |
| 93 | </span> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 94 | </template> |
| 95 | </b-form-datepicker> |
| 96 | </b-input-group> |
| 97 | </b-form-group> |
| 98 | </b-col> |
| 99 | <b-col sm="6" lg="4" xl="3"> |
| 100 | <b-form-group |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 101 | :label=" |
| 102 | $t('pageDateTimeSettings.form.time.timezone', { timezone }) |
| 103 | " |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 104 | label-for="input-manual-time" |
| 105 | > |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 106 | <b-form-text id="time-format-help">HH:MM</b-form-text> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 107 | <b-input-group> |
| 108 | <b-form-input |
| 109 | id="input-manual-time" |
| 110 | v-model="form.manual.time" |
| 111 | :state="getValidationState($v.form.manual.time)" |
| 112 | :disabled="form.configurationSelected === 'ntp'" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 113 | data-test-id="dateTimeSettings-input-manualTime" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 114 | @blur="$v.form.manual.time.$touch()" |
| 115 | /> |
| 116 | <b-form-invalid-feedback role="alert"> |
| 117 | <div v-if="!$v.form.manual.time.pattern"> |
| 118 | {{ $t('global.form.invalidFormat') }} |
| 119 | </div> |
| 120 | <div v-if="!$v.form.manual.time.required"> |
| 121 | {{ $t('global.form.fieldRequired') }} |
| 122 | </div> |
| 123 | </b-form-invalid-feedback> |
| 124 | </b-input-group> |
| 125 | </b-form-group> |
| 126 | </b-col> |
| 127 | </b-row> |
| 128 | <b-form-radio |
| 129 | v-model="form.configurationSelected" |
| 130 | value="ntp" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 131 | data-test-id="dateTimeSettings-radio-configureNTP" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 132 | @change="onChangeConfigType" |
| 133 | > |
| 134 | NTP |
| 135 | </b-form-radio> |
| 136 | <b-row class="mt-3 ml-3"> |
| 137 | <b-col sm="6" lg="4" xl="3"> |
| 138 | <b-form-group |
| 139 | :label="$t('pageDateTimeSettings.form.ntpServers.server1')" |
| 140 | label-for="input-ntp-1" |
| 141 | > |
| 142 | <b-input-group> |
| 143 | <b-form-input |
| 144 | id="input-ntp-1" |
| 145 | v-model="form.ntp.firstAddress" |
| 146 | :state="getValidationState($v.form.ntp.firstAddress)" |
| 147 | :disabled="form.configurationSelected === 'manual'" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 148 | data-test-id="dateTimeSettings-input-ntpServer1" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 149 | @blur="$v.form.ntp.firstAddress.$touch()" |
| 150 | /> |
| 151 | <b-form-invalid-feedback role="alert"> |
| 152 | <div v-if="!$v.form.ntp.firstAddress.required"> |
| 153 | {{ $t('global.form.fieldRequired') }} |
| 154 | </div> |
| 155 | </b-form-invalid-feedback> |
| 156 | </b-input-group> |
| 157 | </b-form-group> |
| 158 | </b-col> |
| 159 | <b-col sm="6" lg="4" xl="3"> |
| 160 | <b-form-group |
| 161 | :label="$t('pageDateTimeSettings.form.ntpServers.server2')" |
| 162 | label-for="input-ntp-2" |
| 163 | > |
| 164 | <b-input-group> |
| 165 | <b-form-input |
| 166 | id="input-ntp-2" |
| 167 | v-model="form.ntp.secondAddress" |
| 168 | :disabled="form.configurationSelected === 'manual'" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 169 | data-test-id="dateTimeSettings-input-ntpServer2" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 170 | @blur="$v.form.ntp.secondAddress.$touch()" |
| 171 | /> |
| 172 | </b-input-group> |
| 173 | </b-form-group> |
| 174 | </b-col> |
| 175 | <b-col sm="6" lg="4" xl="3"> |
| 176 | <b-form-group |
| 177 | :label="$t('pageDateTimeSettings.form.ntpServers.server3')" |
| 178 | label-for="input-ntp-3" |
| 179 | > |
| 180 | <b-input-group> |
| 181 | <b-form-input |
| 182 | id="input-ntp-3" |
| 183 | v-model="form.ntp.thirdAddress" |
| 184 | :disabled="form.configurationSelected === 'manual'" |
Sukanya Pandey | f7c3937 | 2020-07-17 16:53:07 +0530 | [diff] [blame] | 185 | data-test-id="dateTimeSettings-input-ntpServer3" |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 186 | @blur="$v.form.ntp.thirdAddress.$touch()" |
| 187 | /> |
| 188 | </b-input-group> |
| 189 | </b-form-group> |
| 190 | </b-col> |
| 191 | </b-row> |
Mateusz Gapski | 471f2e0 | 2020-07-27 14:43:26 +0200 | [diff] [blame] | 192 | <b-button |
| 193 | variant="primary" |
| 194 | type="submit" |
| 195 | data-test-id="dateTimeSettings-button-saveSettings" |
| 196 | > |
| 197 | {{ $t('global.action.saveSettings') }} |
| 198 | </b-button> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 199 | </b-form-group> |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 200 | </b-form> |
| 201 | </page-section> |
| 202 | </b-container> |
| 203 | </template> |
| 204 | |
| 205 | <script> |
| 206 | import Alert from '@/components/Global/Alert'; |
| 207 | import IconCalendar from '@carbon/icons-vue/es/calendar/20'; |
| 208 | import PageTitle from '@/components/Global/PageTitle'; |
| 209 | import PageSection from '@/components/Global/PageSection'; |
| 210 | |
| 211 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 212 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 213 | import LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin'; |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 214 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 215 | |
| 216 | import { mapState } from 'vuex'; |
| 217 | import { requiredIf, helpers } from 'vuelidate/lib/validators'; |
| 218 | |
| 219 | const isoDateRegex = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/; |
| 220 | const isoTimeRegex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/; |
| 221 | |
| 222 | export default { |
| 223 | name: 'DateTimeSettings', |
| 224 | components: { Alert, IconCalendar, PageTitle, PageSection }, |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 225 | mixins: [ |
| 226 | BVToastMixin, |
| 227 | LoadingBarMixin, |
| 228 | LocalTimezoneLabelMixin, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 229 | VuelidateMixin, |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 230 | ], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 231 | beforeRouteLeave(to, from, next) { |
| 232 | this.hideLoader(); |
| 233 | next(); |
| 234 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 235 | data() { |
| 236 | return { |
| 237 | locale: this.$store.getters['global/languagePreference'], |
| 238 | form: { |
| 239 | configurationSelected: '', |
| 240 | manual: { |
| 241 | date: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 242 | time: '', |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 243 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 244 | ntp: { firstAddress: '', secondAddress: '', thirdAddress: '' }, |
| 245 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 246 | }; |
| 247 | }, |
| 248 | validations() { |
| 249 | return { |
| 250 | form: { |
| 251 | manual: { |
| 252 | date: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 253 | required: requiredIf(function () { |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 254 | return this.form.configurationSelected === 'manual'; |
| 255 | }), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 256 | pattern: helpers.regex('pattern', isoDateRegex), |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 257 | }, |
| 258 | time: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 259 | required: requiredIf(function () { |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 260 | return this.form.configurationSelected === 'manual'; |
| 261 | }), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 262 | pattern: helpers.regex('pattern', isoTimeRegex), |
| 263 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 264 | }, |
| 265 | ntp: { |
| 266 | firstAddress: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 267 | required: requiredIf(function () { |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 268 | return this.form.configurationSelected === 'ntp'; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 269 | }), |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 270 | }, |
| 271 | secondAddress: {}, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 272 | thirdAddress: {}, |
| 273 | }, |
| 274 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 275 | }; |
| 276 | }, |
| 277 | computed: { |
| 278 | ...mapState('dateTime', ['ntpServers', 'isNtpProtocolEnabled']), |
| 279 | bmcTime() { |
| 280 | return this.$store.getters['global/bmcTime']; |
Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 281 | }, |
| 282 | isUtcDisplay() { |
| 283 | return this.$store.getters['global/isUtcDisplay']; |
| 284 | }, |
| 285 | timezone() { |
| 286 | if (this.isUtcDisplay) { |
| 287 | return 'UTC'; |
| 288 | } |
| 289 | return this.localOffset(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 290 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 291 | }, |
| 292 | watch: { |
| 293 | ntpServers() { |
| 294 | this.setNtpValues(); |
| 295 | }, |
| 296 | manualDate() { |
| 297 | this.emitChange(); |
Sukanya Pandey | ce33f21 | 2020-08-28 13:13:05 +0530 | [diff] [blame] | 298 | }, |
| 299 | bmcTime() { |
| 300 | this.form.manual.date = this.$options.filters.formatDate( |
| 301 | this.$store.getters['global/bmcTime'] |
| 302 | ); |
| 303 | this.form.manual.time = this.$options.filters |
| 304 | .formatTime(this.$store.getters['global/bmcTime']) |
| 305 | .slice(0, 5); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 306 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 307 | }, |
| 308 | created() { |
| 309 | this.startLoader(); |
| 310 | Promise.all([ |
| 311 | this.$store.dispatch('global/getBmcTime'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 312 | this.$store.dispatch('dateTime/getNtpData'), |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 313 | ]).finally(() => this.endLoader()); |
| 314 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 315 | methods: { |
| 316 | emitChange() { |
| 317 | if (this.$v.$invalid) return; |
| 318 | this.$v.$reset(); //reset to re-validate on blur |
| 319 | this.$emit('change', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 320 | manualDate: this.manualDate ? new Date(this.manualDate) : null, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 321 | }); |
| 322 | }, |
| 323 | setNtpValues() { |
| 324 | this.form.configurationSelected = this.isNtpProtocolEnabled |
| 325 | ? 'ntp' |
| 326 | : 'manual'; |
| 327 | this.form.ntp.firstAddress = this.ntpServers[0] || ''; |
| 328 | this.form.ntp.secondAddress = this.ntpServers[1] || ''; |
| 329 | this.form.ntp.thirdAddress = this.ntpServers[2] || ''; |
| 330 | }, |
| 331 | onChangeConfigType() { |
| 332 | this.$v.form.$reset(); |
| 333 | this.setNtpValues(); |
| 334 | }, |
| 335 | submitForm() { |
| 336 | this.$v.$touch(); |
| 337 | if (this.$v.$invalid) return; |
| 338 | this.startLoader(); |
| 339 | |
| 340 | let dateTimeForm = {}; |
| 341 | let ntpFirstAddress; |
| 342 | let ntpSecondAddress; |
| 343 | let ntpThirdAddress; |
| 344 | let isNTPEnabled = this.form.configurationSelected === 'ntp'; |
| 345 | |
| 346 | if (!isNTPEnabled) { |
Sukanya Pandey | b5c161b | 2020-07-30 21:56:03 +0530 | [diff] [blame] | 347 | const isUtcDisplay = this.$store.getters['global/isUtcDisplay']; |
| 348 | let date; |
| 349 | |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 350 | dateTimeForm.ntpProtocolEnabled = false; |
Sukanya Pandey | b5c161b | 2020-07-30 21:56:03 +0530 | [diff] [blame] | 351 | |
| 352 | if (isUtcDisplay) { |
| 353 | // Create UTC Date |
| 354 | date = this.getUtcDate(this.form.manual.date, this.form.manual.time); |
| 355 | } else { |
| 356 | // Create local Date |
| 357 | date = new Date(`${this.form.manual.date} ${this.form.manual.time}`); |
| 358 | } |
| 359 | |
| 360 | dateTimeForm.updatedDateTime = date.toISOString(); |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 361 | } else { |
| 362 | ntpFirstAddress = this.form.ntp.firstAddress; |
| 363 | ntpSecondAddress = this.form.ntp.secondAddress; |
| 364 | ntpThirdAddress = this.form.ntp.thirdAddress; |
| 365 | dateTimeForm.ntpProtocolEnabled = true; |
| 366 | dateTimeForm.ntpServersArray = [ |
| 367 | ntpFirstAddress, |
| 368 | ntpSecondAddress, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 369 | ntpThirdAddress, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 370 | ]; |
| 371 | } |
| 372 | |
| 373 | this.$store |
| 374 | .dispatch('dateTime/updateDateTimeSettings', dateTimeForm) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 375 | .then((success) => { |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 376 | this.successToast(success); |
| 377 | if (!isNTPEnabled) return; |
| 378 | // Shift address up if second address is empty |
| 379 | // to avoid refreshing after delay when updating NTP |
| 380 | if (ntpSecondAddress === '' && ntpThirdAddress !== '') { |
| 381 | this.form.ntp.secondAddress = ntpThirdAddress; |
| 382 | this.form.ntp.thirdAddress = ''; |
| 383 | } |
| 384 | }) |
Dixsie Wolmers | ecd45a8 | 2020-07-14 17:07:26 -0500 | [diff] [blame] | 385 | .then(() => { |
| 386 | this.$store.dispatch('global/getBmcTime'); |
| 387 | }) |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 388 | .catch(({ message }) => this.errorToast(message)) |
| 389 | .finally(() => { |
| 390 | this.$v.form.$reset(); |
| 391 | this.endLoader(); |
| 392 | }); |
Sukanya Pandey | b5c161b | 2020-07-30 21:56:03 +0530 | [diff] [blame] | 393 | }, |
| 394 | getUtcDate(date, time) { |
| 395 | // Split user input string values to create |
| 396 | // a UTC Date object |
| 397 | const datesArray = date.split('-'); |
| 398 | const timeArray = time.split(':'); |
| 399 | let utcDate = Date.UTC( |
| 400 | datesArray[0], // User input year |
Sukanya Pandey | 5a70596 | 2020-08-05 00:52:28 +0530 | [diff] [blame] | 401 | //UTC expects zero-index month value 0-11 (January-December) |
| 402 | //for reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC#Parameters |
| 403 | parseInt(datesArray[1]) - 1, // User input month |
Sukanya Pandey | b5c161b | 2020-07-30 21:56:03 +0530 | [diff] [blame] | 404 | datesArray[2], // User input day |
| 405 | timeArray[0], // User input hour |
| 406 | timeArray[1] // User input minute |
| 407 | ); |
| 408 | return new Date(utcDate); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 409 | }, |
| 410 | }, |
Dixsie Wolmers | 739e459 | 2020-06-05 07:00:06 -0500 | [diff] [blame] | 411 | }; |
| 412 | </script> |