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"> |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 5 | <!-- Workstation Upload --> |
Nikhil Ashoka | bc49e09 | 2024-06-11 12:19:11 +0530 | [diff] [blame] | 6 | <template> |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 7 | <b-form-group |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 8 | :label="$t('pageFirmware.form.updateFirmware.imageFile')" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 9 | label-for="image-file" |
| 10 | > |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 11 | <form-file |
| 12 | id="image-file" |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 13 | :disabled="isPageDisabled" |
| 14 | :state="getValidationState($v.file)" |
| 15 | aria-describedby="image-file-help-block" |
| 16 | @input="onFileUpload($event)" |
| 17 | > |
| 18 | <template #invalid> |
| 19 | <b-form-invalid-feedback role="alert"> |
| 20 | {{ $t('global.form.required') }} |
| 21 | </b-form-invalid-feedback> |
| 22 | </template> |
| 23 | </form-file> |
| 24 | </b-form-group> |
| 25 | </template> |
| 26 | |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 27 | <b-btn |
| 28 | data-test-id="firmware-button-startUpdate" |
| 29 | type="submit" |
| 30 | variant="primary" |
| 31 | :disabled="isPageDisabled" |
| 32 | > |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 33 | {{ $t('pageFirmware.form.updateFirmware.startUpdate') }} |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 34 | </b-btn> |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 35 | </b-form> |
| 36 | </div> |
| 37 | |
| 38 | <!-- Modals --> |
| 39 | <modal-update-firmware @ok="updateFirmware" /> |
| 40 | </div> |
| 41 | </template> |
| 42 | |
| 43 | <script> |
Nikhil Ashoka | bc49e09 | 2024-06-11 12:19:11 +0530 | [diff] [blame] | 44 | import { required } from 'vuelidate/lib/validators'; |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 45 | |
| 46 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 47 | import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin'; |
| 48 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame^] | 49 | import { useVuelidate } from '@vuelidate/core'; |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 50 | |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 51 | import FormFile from '@/components/Global/FormFile'; |
| 52 | import ModalUpdateFirmware from './FirmwareModalUpdateFirmware'; |
| 53 | |
| 54 | export default { |
Kenneth Fullbright | 19b2cfb | 2022-02-21 16:27:32 -0600 | [diff] [blame] | 55 | components: { FormFile, ModalUpdateFirmware }, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 56 | mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin], |
| 57 | props: { |
| 58 | isPageDisabled: { |
| 59 | required: true, |
| 60 | type: Boolean, |
| 61 | default: false, |
| 62 | }, |
Derick Montague | 71114fe | 2021-05-06 18:17:34 -0500 | [diff] [blame] | 63 | isServerOff: { |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 64 | required: true, |
| 65 | type: Boolean, |
| 66 | }, |
| 67 | }, |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame^] | 68 | setup() { |
| 69 | return { |
| 70 | v$: useVuelidate(), |
| 71 | }; |
| 72 | }, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 73 | data() { |
| 74 | return { |
| 75 | loading, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 76 | file: null, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 77 | isServerPowerOffRequired: |
| 78 | process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true', |
| 79 | }; |
| 80 | }, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 81 | validations() { |
| 82 | return { |
| 83 | file: { |
Nikhil Ashoka | bc49e09 | 2024-06-11 12:19:11 +0530 | [diff] [blame] | 84 | required, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 85 | }, |
| 86 | }; |
| 87 | }, |
| 88 | created() { |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 89 | this.$store.dispatch('firmware/getUpdateServiceSettings'); |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 90 | }, |
| 91 | methods: { |
| 92 | updateFirmware() { |
| 93 | this.startLoader(); |
| 94 | const timerId = setTimeout(() => { |
| 95 | this.endLoader(); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 96 | this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), { |
| 97 | title: this.$t('pageFirmware.toast.verifyUpdate'), |
| 98 | refreshAction: true, |
| 99 | }); |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 100 | }, 360000); |
Yoshie Muranaka | 33d755f | 2021-02-18 15:24:14 -0800 | [diff] [blame] | 101 | this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), { |
| 102 | title: this.$t('pageFirmware.toast.updateStarted'), |
| 103 | timestamp: true, |
| 104 | }); |
Nikhil Ashoka | bc49e09 | 2024-06-11 12:19:11 +0530 | [diff] [blame] | 105 | this.dispatchWorkstationUpload(timerId); |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 106 | }, |
| 107 | dispatchWorkstationUpload(timerId) { |
| 108 | this.$store |
Leo Xu | e2c716a | 2024-07-29 05:54:18 +0300 | [diff] [blame] | 109 | .dispatch('firmware/uploadFirmware', { |
| 110 | image: this.file, |
| 111 | }) |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 112 | .catch(({ message }) => { |
| 113 | this.endLoader(); |
| 114 | this.errorToast(message); |
| 115 | clearTimeout(timerId); |
| 116 | }); |
| 117 | }, |
Yoshie Muranaka | 7bc85e4 | 2021-02-11 09:59:13 -0800 | [diff] [blame] | 118 | onSubmitUpload() { |
| 119 | this.$v.$touch(); |
| 120 | if (this.$v.$invalid) return; |
| 121 | this.$bvModal.show('modal-update-firmware'); |
| 122 | }, |
| 123 | onFileUpload(file) { |
| 124 | this.file = file; |
| 125 | this.$v.file.$touch(); |
| 126 | }, |
| 127 | }, |
| 128 | }; |
| 129 | </script> |