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