blob: 04b28a5c80a59d1244f092c7c3c89aa109f85565 [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>
67 <alert
Derick Montague71114fe2021-05-06 18:17:34 -050068 v-if="isServerPowerOffRequired && !isServerOff"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080069 variant="warning"
70 :small="true"
71 class="mt-4"
72 >
73 <p class="col-form-label">
74 {{
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080075 $t('pageFirmware.alert.serverMustBePoweredOffToUpdateFirmware')
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080076 }}
77 </p>
78 </alert>
79 </b-form>
80 </div>
81
82 <!-- Modals -->
83 <modal-update-firmware @ok="updateFirmware" />
84 </div>
85</template>
86
87<script>
88import { requiredIf } from 'vuelidate/lib/validators';
89
90import BVToastMixin from '@/components/Mixins/BVToastMixin';
91import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
92import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
93
94import Alert from '@/components/Global/Alert';
95import FormFile from '@/components/Global/FormFile';
96import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
97
98export default {
99 components: { Alert, FormFile, ModalUpdateFirmware },
100 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
101 props: {
102 isPageDisabled: {
103 required: true,
104 type: Boolean,
105 default: false,
106 },
Derick Montague71114fe2021-05-06 18:17:34 -0500107 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800108 required: true,
109 type: Boolean,
110 },
111 },
112 data() {
113 return {
114 loading,
115 isWorkstationSelected: true,
116 file: null,
117 tftpFileAddress: null,
118 isServerPowerOffRequired:
119 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
120 };
121 },
122 computed: {
123 isTftpUploadAvailable() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800124 return this.$store.getters['firmware/isTftpUploadAvailable'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800125 },
126 },
127 watch: {
128 isWorkstationSelected: function () {
129 this.$v.$reset();
130 this.file = null;
131 this.tftpFileAddress = null;
132 },
133 },
134 validations() {
135 return {
136 file: {
137 required: requiredIf(function () {
138 return this.isWorkstationSelected;
139 }),
140 },
141 tftpFileAddress: {
142 required: requiredIf(function () {
143 return !this.isWorkstationSelected;
144 }),
145 },
146 };
147 },
148 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800149 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800150 },
151 methods: {
152 updateFirmware() {
153 this.startLoader();
154 const timerId = setTimeout(() => {
155 this.endLoader();
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800156 this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), {
157 title: this.$t('pageFirmware.toast.verifyUpdate'),
158 refreshAction: true,
159 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800160 }, 360000);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800161 this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), {
162 title: this.$t('pageFirmware.toast.updateStarted'),
163 timestamp: true,
164 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800165 if (this.isWorkstationSelected) {
166 this.dispatchWorkstationUpload(timerId);
167 } else {
168 this.dispatchTftpUpload(timerId);
169 }
170 },
171 dispatchWorkstationUpload(timerId) {
172 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800173 .dispatch('firmware/uploadFirmware', this.file)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800174 .catch(({ message }) => {
175 this.endLoader();
176 this.errorToast(message);
177 clearTimeout(timerId);
178 });
179 },
180 dispatchTftpUpload(timerId) {
181 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800182 .dispatch('firmware/uploadFirmwareTFTP', this.tftpFileAddress)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800183 .catch(({ message }) => {
184 this.endLoader();
185 this.errorToast(message);
186 clearTimeout(timerId);
187 });
188 },
189 onSubmitUpload() {
190 this.$v.$touch();
191 if (this.$v.$invalid) return;
192 this.$bvModal.show('modal-update-firmware');
193 },
194 onFileUpload(file) {
195 this.file = file;
196 this.$v.file.$touch();
197 },
198 },
199};
200</script>