blob: ac4b23fcb07b76c6d3d436e37e6b00fa205c06ab [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>
76import { requiredIf } from 'vuelidate/lib/validators';
77
78import BVToastMixin from '@/components/Mixins/BVToastMixin';
79import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
80import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
81
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080082import FormFile from '@/components/Global/FormFile';
83import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
84
85export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060086 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080087 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
88 props: {
89 isPageDisabled: {
90 required: true,
91 type: Boolean,
92 default: false,
93 },
Derick Montague71114fe2021-05-06 18:17:34 -050094 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080095 required: true,
96 type: Boolean,
97 },
98 },
99 data() {
100 return {
101 loading,
102 isWorkstationSelected: true,
103 file: null,
104 tftpFileAddress: null,
105 isServerPowerOffRequired:
106 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
107 };
108 },
109 computed: {
110 isTftpUploadAvailable() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800111 return this.$store.getters['firmware/isTftpUploadAvailable'];
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800112 },
113 },
114 watch: {
115 isWorkstationSelected: function () {
116 this.$v.$reset();
117 this.file = null;
118 this.tftpFileAddress = null;
119 },
120 },
121 validations() {
122 return {
123 file: {
124 required: requiredIf(function () {
125 return this.isWorkstationSelected;
126 }),
127 },
128 tftpFileAddress: {
129 required: requiredIf(function () {
130 return !this.isWorkstationSelected;
131 }),
132 },
133 };
134 },
135 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800136 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800137 },
138 methods: {
139 updateFirmware() {
140 this.startLoader();
141 const timerId = setTimeout(() => {
142 this.endLoader();
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800143 this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), {
144 title: this.$t('pageFirmware.toast.verifyUpdate'),
145 refreshAction: true,
146 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800147 }, 360000);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800148 this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), {
149 title: this.$t('pageFirmware.toast.updateStarted'),
150 timestamp: true,
151 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800152 if (this.isWorkstationSelected) {
153 this.dispatchWorkstationUpload(timerId);
154 } else {
155 this.dispatchTftpUpload(timerId);
156 }
157 },
158 dispatchWorkstationUpload(timerId) {
159 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800160 .dispatch('firmware/uploadFirmware', this.file)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800161 .catch(({ message }) => {
162 this.endLoader();
163 this.errorToast(message);
164 clearTimeout(timerId);
165 });
166 },
167 dispatchTftpUpload(timerId) {
168 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800169 .dispatch('firmware/uploadFirmwareTFTP', this.tftpFileAddress)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800170 .catch(({ message }) => {
171 this.endLoader();
172 this.errorToast(message);
173 clearTimeout(timerId);
174 });
175 },
176 onSubmitUpload() {
177 this.$v.$touch();
178 if (this.$v.$invalid) return;
179 this.$bvModal.show('modal-update-firmware');
180 },
181 onFileUpload(file) {
182 this.file = file;
183 this.$v.file.$touch();
184 },
185 },
186};
187</script>