blob: 702352f2dbb4d053b54c2b70ff671b4cae2d20e2 [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 >
24 <b-form-text id="image-file-help-block">
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080025 {{ $t('pageFirmware.form.updateFirmware.imageFileHelperText') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080026 </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 Muranaka33d755f2021-02-18 15:24:14 -080047 :label="$t('pageFirmware.form.updateFirmware.fileAddress')"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080048 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 Muranaka33d755f2021-02-18 15:24:14 -080069 {{ $t('pageFirmware.form.updateFirmware.startUpdate') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080070 </b-btn>
71 <alert
Derick Montague71114fe2021-05-06 18:17:34 -050072 v-if="isServerPowerOffRequired && !isServerOff"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080073 variant="warning"
74 :small="true"
75 class="mt-4"
76 >
77 <p class="col-form-label">
78 {{
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080079 $t('pageFirmware.alert.serverMustBePoweredOffToUpdateFirmware')
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080080 }}
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>
92import { requiredIf } from 'vuelidate/lib/validators';
93
94import BVToastMixin from '@/components/Mixins/BVToastMixin';
95import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
96import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
97
98import Alert from '@/components/Global/Alert';
99import FormFile from '@/components/Global/FormFile';
100import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
101
102export 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 Montague71114fe2021-05-06 18:17:34 -0500111 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800112 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 Muranaka33d755f2021-02-18 15:24:14 -0800128 return this.$store.getters['firmware/isTftpUploadAvailable'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800129 },
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 Muranaka33d755f2021-02-18 15:24:14 -0800153 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800154 },
155 methods: {
156 updateFirmware() {
157 this.startLoader();
158 const timerId = setTimeout(() => {
159 this.endLoader();
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800160 this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), {
161 title: this.$t('pageFirmware.toast.verifyUpdate'),
162 refreshAction: true,
163 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800164 }, 360000);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800165 this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), {
166 title: this.$t('pageFirmware.toast.updateStarted'),
167 timestamp: true,
168 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800169 if (this.isWorkstationSelected) {
170 this.dispatchWorkstationUpload(timerId);
171 } else {
172 this.dispatchTftpUpload(timerId);
173 }
174 },
175 dispatchWorkstationUpload(timerId) {
176 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800177 .dispatch('firmware/uploadFirmware', this.file)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800178 .catch(({ message }) => {
179 this.endLoader();
180 this.errorToast(message);
181 clearTimeout(timerId);
182 });
183 },
184 dispatchTftpUpload(timerId) {
185 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800186 .dispatch('firmware/uploadFirmwareTFTP', this.tftpFileAddress)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800187 .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>