blob: 554d1d458cb1bdb411df218ec9530d1cd6332b06 [file] [log] [blame]
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -08001<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 Muranaka33d755f2021-02-18 15:24:14 -08007 :label="$t('pageFirmware.form.updateFirmware.fileSource')"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -08008 :disabled="isPageDisabled"
9 >
10 <b-form-radio v-model="isWorkstationSelected" :value="true">
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080011 {{ $t('pageFirmware.form.updateFirmware.workstation') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080012 </b-form-radio>
13 <b-form-radio v-model="isWorkstationSelected" :value="false">
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080014 {{ $t('pageFirmware.form.updateFirmware.tftpServer') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080015 </b-form-radio>
16 </b-form-group>
17
18 <!-- Workstation Upload -->
19 <template v-if="isWorkstationSelected">
20 <b-form-group
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080021 :label="$t('pageFirmware.form.updateFirmware.imageFile')"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080022 label-for="image-file"
23 >
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080024 <form-file
25 id="image-file"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080026 :disabled="isPageDisabled"
27 :state="getValidationState($v.file)"
28 aria-describedby="image-file-help-block"
29 @input="onFileUpload($event)"
30 >
31 <template #invalid>
32 <b-form-invalid-feedback role="alert">
33 {{ $t('global.form.required') }}
34 </b-form-invalid-feedback>
35 </template>
36 </form-file>
37 </b-form-group>
38 </template>
39
40 <!-- TFTP Server Upload -->
41 <template v-else>
42 <b-form-group
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080043 :label="$t('pageFirmware.form.updateFirmware.fileAddress')"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080044 label-for="tftp-address"
45 >
46 <b-form-input
47 id="tftp-address"
48 v-model="tftpFileAddress"
49 type="text"
50 :state="getValidationState($v.tftpFileAddress)"
51 :disabled="isPageDisabled"
52 @input="$v.tftpFileAddress.$touch()"
53 />
54 <b-form-invalid-feedback role="alert">
55 {{ $t('global.form.fieldRequired') }}
56 </b-form-invalid-feedback>
57 </b-form-group>
58 </template>
59 <b-btn
60 data-test-id="firmware-button-startUpdate"
61 type="submit"
62 variant="primary"
63 :disabled="isPageDisabled"
64 >
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080065 {{ $t('pageFirmware.form.updateFirmware.startUpdate') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080066 </b-btn>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080067 </b-form>
68 </div>
69
70 <!-- Modals -->
71 <modal-update-firmware @ok="updateFirmware" />
72 </div>
73</template>
74
75<script>
Ed Tanous9c729792024-03-23 14:56:34 -070076import { requiredIf } from '@vuelidate/validators';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080077
78import BVToastMixin from '@/components/Mixins/BVToastMixin';
79import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
80import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous9c729792024-03-23 14:56:34 -070081import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080082
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080083import FormFile from '@/components/Global/FormFile';
84import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
85
86export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060087 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080088 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
89 props: {
90 isPageDisabled: {
91 required: true,
92 type: Boolean,
93 default: false,
94 },
Derick Montague71114fe2021-05-06 18:17:34 -050095 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080096 required: true,
97 type: Boolean,
98 },
99 },
Ed Tanous9c729792024-03-23 14:56:34 -0700100 setup() {
101 return {
102 v$: useVuelidate(),
103 };
104 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800105 data() {
106 return {
107 loading,
108 isWorkstationSelected: true,
109 file: null,
110 tftpFileAddress: null,
111 isServerPowerOffRequired:
112 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
113 };
114 },
115 computed: {
116 isTftpUploadAvailable() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800117 return this.$store.getters['firmware/isTftpUploadAvailable'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800118 },
119 },
120 watch: {
121 isWorkstationSelected: function () {
122 this.$v.$reset();
123 this.file = null;
124 this.tftpFileAddress = null;
125 },
126 },
127 validations() {
128 return {
129 file: {
130 required: requiredIf(function () {
131 return this.isWorkstationSelected;
132 }),
133 },
134 tftpFileAddress: {
135 required: requiredIf(function () {
136 return !this.isWorkstationSelected;
137 }),
138 },
139 };
140 },
141 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800142 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800143 },
144 methods: {
145 updateFirmware() {
146 this.startLoader();
147 const timerId = setTimeout(() => {
148 this.endLoader();
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800149 this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), {
150 title: this.$t('pageFirmware.toast.verifyUpdate'),
151 refreshAction: true,
152 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800153 }, 360000);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800154 this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), {
155 title: this.$t('pageFirmware.toast.updateStarted'),
156 timestamp: true,
157 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800158 if (this.isWorkstationSelected) {
159 this.dispatchWorkstationUpload(timerId);
160 } else {
161 this.dispatchTftpUpload(timerId);
162 }
163 },
164 dispatchWorkstationUpload(timerId) {
165 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800166 .dispatch('firmware/uploadFirmware', this.file)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800167 .catch(({ message }) => {
168 this.endLoader();
169 this.errorToast(message);
170 clearTimeout(timerId);
171 });
172 },
173 dispatchTftpUpload(timerId) {
174 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800175 .dispatch('firmware/uploadFirmwareTFTP', this.tftpFileAddress)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800176 .catch(({ message }) => {
177 this.endLoader();
178 this.errorToast(message);
179 clearTimeout(timerId);
180 });
181 },
182 onSubmitUpload() {
183 this.$v.$touch();
184 if (this.$v.$invalid) return;
185 this.$bvModal.show('modal-update-firmware');
186 },
187 onFileUpload(file) {
188 this.file = file;
189 this.$v.file.$touch();
190 },
191 },
192};
193</script>