blob: dc3161b23af0e4bdfc79bc464c0db1d55df9591d [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';
Surya V603cfbf2024-07-11 15:19:46 +053085import { useI18n } from 'vue-i18n';
86import i18n from '@/i18n';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080087
88export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060089 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080090 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
91 props: {
92 isPageDisabled: {
93 required: true,
94 type: Boolean,
95 default: false,
96 },
Derick Montague71114fe2021-05-06 18:17:34 -050097 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080098 required: true,
99 type: Boolean,
100 },
101 },
Ed Tanous9c729792024-03-23 14:56:34 -0700102 setup() {
103 return {
Surya V603cfbf2024-07-11 15:19:46 +0530104 $v: useVuelidate(),
Ed Tanous9c729792024-03-23 14:56:34 -0700105 };
106 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800107 data() {
108 return {
Surya V603cfbf2024-07-11 15:19:46 +0530109 $t: useI18n().t,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800110 loading,
111 isWorkstationSelected: true,
112 file: null,
113 tftpFileAddress: null,
114 isServerPowerOffRequired:
115 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
116 };
117 },
118 computed: {
119 isTftpUploadAvailable() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800120 return this.$store.getters['firmware/isTftpUploadAvailable'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800121 },
122 },
123 watch: {
124 isWorkstationSelected: function () {
125 this.$v.$reset();
126 this.file = null;
127 this.tftpFileAddress = null;
128 },
129 },
130 validations() {
131 return {
132 file: {
133 required: requiredIf(function () {
134 return this.isWorkstationSelected;
135 }),
136 },
137 tftpFileAddress: {
138 required: requiredIf(function () {
139 return !this.isWorkstationSelected;
140 }),
141 },
142 };
143 },
144 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800145 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800146 },
147 methods: {
148 updateFirmware() {
149 this.startLoader();
150 const timerId = setTimeout(() => {
151 this.endLoader();
Surya V603cfbf2024-07-11 15:19:46 +0530152 this.infoToast(
153 i18n.global.t('pageFirmware.toast.verifyUpdateMessage'),
154 {
155 title: i18n.global.t('pageFirmware.toast.verifyUpdate'),
156 refreshAction: true,
157 },
158 );
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800159 }, 360000);
Surya V603cfbf2024-07-11 15:19:46 +0530160 this.infoToast(i18n.global.t('pageFirmware.toast.updateStartedMessage'), {
161 title: i18n.global.t('pageFirmware.toast.updateStarted'),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800162 timestamp: true,
163 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800164 if (this.isWorkstationSelected) {
165 this.dispatchWorkstationUpload(timerId);
166 } else {
167 this.dispatchTftpUpload(timerId);
168 }
169 },
170 dispatchWorkstationUpload(timerId) {
171 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800172 .dispatch('firmware/uploadFirmware', this.file)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800173 .catch(({ message }) => {
174 this.endLoader();
175 this.errorToast(message);
176 clearTimeout(timerId);
177 });
178 },
179 dispatchTftpUpload(timerId) {
180 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800181 .dispatch('firmware/uploadFirmwareTFTP', this.tftpFileAddress)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800182 .catch(({ message }) => {
183 this.endLoader();
184 this.errorToast(message);
185 clearTimeout(timerId);
186 });
187 },
188 onSubmitUpload() {
189 this.$v.$touch();
190 if (this.$v.$invalid) return;
191 this.$bvModal.show('modal-update-firmware');
192 },
193 onFileUpload(file) {
194 this.file = file;
195 this.$v.file.$touch();
196 },
197 },
198};
199</script>