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