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