Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 1 | <template> |
| 2 | <div> |
| 3 | <div class="form-background p-3"> |
| 4 | <b-form @submit.prevent="onSubmitUpload"> |
| 5 | <b-form-group |
| 6 | v-if="isTftpUploadAvailable" |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 7 | :label="$t('pageFirmware.form.updateFirmware.fileSource')" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 8 | :disabled="isPageDisabled" |
| 9 | > |
| 10 | <b-form-radio v-model="isWorkstationSelected" :value="true"> |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 11 | {{ $t('pageFirmware.form.updateFirmware.workstation') }} |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 12 | </b-form-radio> |
| 13 | <b-form-radio v-model="isWorkstationSelected" :value="false"> |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 14 | {{ $t('pageFirmware.form.updateFirmware.tftpServer') }} |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 15 | </b-form-radio> |
| 16 | </b-form-group> |
| 17 | |
| 18 | <!-- Workstation Upload --> |
| 19 | <template v-if="isWorkstationSelected"> |
| 20 | <b-form-group |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 21 | :label="$t('pageFirmware.form.updateFirmware.imageFile')" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 22 | label-for="image-file" |
| 23 | > |
| 24 | <b-form-text id="image-file-help-block"> |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 25 | {{ $t('pageFirmware.form.updateFirmware.imageFileHelperText') }} |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 26 | </b-form-text> |
| 27 | <form-file |
| 28 | id="image-file" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 29 | :disabled="isPageDisabled" |
| 30 | :state="getValidationState($v.file)" |
| 31 | aria-describedby="image-file-help-block" |
| 32 | @input="onFileUpload($event)" |
| 33 | > |
| 34 | <template #invalid> |
| 35 | <b-form-invalid-feedback role="alert"> |
| 36 | {{ $t('global.form.required') }} |
| 37 | </b-form-invalid-feedback> |
| 38 | </template> |
| 39 | </form-file> |
| 40 | </b-form-group> |
| 41 | </template> |
| 42 | |
| 43 | <!-- TFTP Server Upload --> |
| 44 | <template v-else> |
| 45 | <b-form-group |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 46 | :label="$t('pageFirmware.form.updateFirmware.fileAddress')" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 47 | label-for="tftp-address" |
| 48 | > |
| 49 | <b-form-input |
| 50 | id="tftp-address" |
| 51 | v-model="tftpFileAddress" |
| 52 | type="text" |
| 53 | :state="getValidationState($v.tftpFileAddress)" |
| 54 | :disabled="isPageDisabled" |
| 55 | @input="$v.tftpFileAddress.$touch()" |
| 56 | /> |
| 57 | <b-form-invalid-feedback role="alert"> |
| 58 | {{ $t('global.form.fieldRequired') }} |
| 59 | </b-form-invalid-feedback> |
| 60 | </b-form-group> |
| 61 | </template> |
| 62 | <b-btn |
| 63 | data-test-id="firmware-button-startUpdate" |
| 64 | type="submit" |
| 65 | variant="primary" |
| 66 | :disabled="isPageDisabled" |
| 67 | > |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 68 | {{ $t('pageFirmware.form.updateFirmware.startUpdate') }} |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 69 | </b-btn> |
| 70 | <alert |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 71 | v-if="isServerPowerOffRequired && !isServerOff" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 72 | variant="warning" |
| 73 | :small="true" |
| 74 | class="mt-4" |
| 75 | > |
| 76 | <p class="col-form-label"> |
| 77 | {{ |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 78 | $t('pageFirmware.alert.serverMustBePoweredOffToUpdateFirmware') |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 79 | }} |
| 80 | </p> |
| 81 | </alert> |
| 82 | </b-form> |
| 83 | </div> |
| 84 | |
| 85 | <!-- Modals --> |
| 86 | <modal-update-firmware @ok="updateFirmware" /> |
| 87 | </div> |
| 88 | </template> |
| 89 | |
| 90 | <script> |
| 91 | import { requiredIf } from 'vuelidate/lib/validators'; |
| 92 | |
| 93 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 94 | import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin'; |
| 95 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 96 | |
| 97 | import Alert from '@/components/Global/Alert'; |
| 98 | import FormFile from '@/components/Global/FormFile'; |
| 99 | import ModalUpdateFirmware from './FirmwareModalUpdateFirmware'; |
| 100 | |
| 101 | export default { |
| 102 | components: { Alert, FormFile, ModalUpdateFirmware }, |
| 103 | mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin], |
| 104 | props: { |
| 105 | isPageDisabled: { |
| 106 | required: true, |
| 107 | type: Boolean, |
| 108 | default: false, |
| 109 | }, |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 110 | isServerOff: { |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 111 | required: true, |
| 112 | type: Boolean, |
| 113 | }, |
| 114 | }, |
| 115 | data() { |
| 116 | return { |
| 117 | loading, |
| 118 | isWorkstationSelected: true, |
| 119 | file: null, |
| 120 | tftpFileAddress: null, |
| 121 | isServerPowerOffRequired: |
| 122 | process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true', |
| 123 | }; |
| 124 | }, |
| 125 | computed: { |
| 126 | isTftpUploadAvailable() { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 127 | return this.$store.getters['firmware/isTftpUploadAvailable']; |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 128 | }, |
| 129 | }, |
| 130 | watch: { |
| 131 | isWorkstationSelected: function () { |
| 132 | this.$v.$reset(); |
| 133 | this.file = null; |
| 134 | this.tftpFileAddress = null; |
| 135 | }, |
| 136 | }, |
| 137 | validations() { |
| 138 | return { |
| 139 | file: { |
| 140 | required: requiredIf(function () { |
| 141 | return this.isWorkstationSelected; |
| 142 | }), |
| 143 | }, |
| 144 | tftpFileAddress: { |
| 145 | required: requiredIf(function () { |
| 146 | return !this.isWorkstationSelected; |
| 147 | }), |
| 148 | }, |
| 149 | }; |
| 150 | }, |
| 151 | created() { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 152 | this.$store.dispatch('firmware/getUpdateServiceSettings'); |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 153 | }, |
| 154 | methods: { |
| 155 | updateFirmware() { |
| 156 | this.startLoader(); |
| 157 | const timerId = setTimeout(() => { |
| 158 | this.endLoader(); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 159 | this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), { |
| 160 | title: this.$t('pageFirmware.toast.verifyUpdate'), |
| 161 | refreshAction: true, |
| 162 | }); |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 163 | }, 360000); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 164 | this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), { |
| 165 | title: this.$t('pageFirmware.toast.updateStarted'), |
| 166 | timestamp: true, |
| 167 | }); |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 168 | if (this.isWorkstationSelected) { |
| 169 | this.dispatchWorkstationUpload(timerId); |
| 170 | } else { |
| 171 | this.dispatchTftpUpload(timerId); |
| 172 | } |
| 173 | }, |
| 174 | dispatchWorkstationUpload(timerId) { |
| 175 | this.$store |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 176 | .dispatch('firmware/uploadFirmware', this.file) |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 177 | .catch(({ message }) => { |
| 178 | this.endLoader(); |
| 179 | this.errorToast(message); |
| 180 | clearTimeout(timerId); |
| 181 | }); |
| 182 | }, |
| 183 | dispatchTftpUpload(timerId) { |
| 184 | this.$store |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 185 | .dispatch('firmware/uploadFirmwareTFTP', this.tftpFileAddress) |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 186 | .catch(({ message }) => { |
| 187 | this.endLoader(); |
| 188 | this.errorToast(message); |
| 189 | clearTimeout(timerId); |
| 190 | }); |
| 191 | }, |
| 192 | onSubmitUpload() { |
| 193 | this.$v.$touch(); |
| 194 | if (this.$v.$invalid) return; |
| 195 | this.$bvModal.show('modal-update-firmware'); |
| 196 | }, |
| 197 | onFileUpload(file) { |
| 198 | this.file = file; |
| 199 | this.$v.file.$touch(); |
| 200 | }, |
| 201 | }, |
| 202 | }; |
| 203 | </script> |