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