blob: a9e327dd87005ce032db862e9e9e209fa73bfd74 [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">
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -08005 <!-- Workstation Upload -->
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +05306 <b-form-group
7 :label="$t('pageFirmware.form.updateFirmware.imageFile')"
8 label-for="image-file"
jason westoverd36ac8a2025-11-03 20:58:59 -06009 class="mb-3"
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053010 >
11 <form-file
12 id="image-file"
13 :disabled="isPageDisabled"
14 :state="getValidationState(v$.file)"
15 aria-describedby="image-file-help-block"
16 @input="onFileUpload($event)"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080017 >
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053018 <template #invalid>
19 <b-form-invalid-feedback role="alert">
20 {{ $t('global.form.required') }}
21 </b-form-invalid-feedback>
22 </template>
23 </form-file>
24 </b-form-group>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080025
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080026 <b-btn
27 data-test-id="firmware-button-startUpdate"
28 type="submit"
29 variant="primary"
30 :disabled="isPageDisabled"
31 >
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080032 {{ $t('pageFirmware.form.updateFirmware.startUpdate') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080033 </b-btn>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080034 </b-form>
35 </div>
36
37 <!-- Modals -->
jason westoverd36ac8a2025-11-03 20:58:59 -060038 <modal-update-firmware v-model="showUpdateModal" @ok="updateFirmware" />
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080039 </div>
40</template>
41
42<script>
Nikhil Ashokabc49e092024-06-11 12:19:11 +053043import { required } from 'vuelidate/lib/validators';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080044
45import BVToastMixin from '@/components/Mixins/BVToastMixin';
46import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
47import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070048import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080049
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080050import FormFile from '@/components/Global/FormFile';
51import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
Surya Vde23ea22024-07-11 15:19:46 +053052import { useI18n } from 'vue-i18n';
53import i18n from '@/i18n';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080054
55export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060056 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080057 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
58 props: {
59 isPageDisabled: {
60 required: true,
61 type: Boolean,
62 default: false,
63 },
Derick Montague71114fe2021-05-06 18:17:34 -050064 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080065 required: true,
66 type: Boolean,
67 },
68 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -070069 setup() {
70 return {
Surya Venkatesan00355b62024-09-12 13:00:05 +053071 v$: useVuelidate(),
Ed Tanous7d6b44c2024-03-23 14:56:34 -070072 };
73 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080074 data() {
75 return {
Surya Vde23ea22024-07-11 15:19:46 +053076 $t: useI18n().t,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080077 loading,
jason westoverd36ac8a2025-11-03 20:58:59 -060078 showUpdateModal: false,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080079 file: null,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080080 isServerPowerOffRequired:
81 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
82 };
83 },
Surya Venkatesan00355b62024-09-12 13:00:05 +053084 validations: {
85 file: {
86 required,
87 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080088 },
89 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080090 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080091 },
92 methods: {
93 updateFirmware() {
94 this.startLoader();
95 const timerId = setTimeout(() => {
96 this.endLoader();
Surya Vde23ea22024-07-11 15:19:46 +053097 this.infoToast(
98 i18n.global.t('pageFirmware.toast.verifyUpdateMessage'),
99 {
100 title: i18n.global.t('pageFirmware.toast.verifyUpdate'),
101 refreshAction: true,
102 },
103 );
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800104 }, 360000);
Surya Vde23ea22024-07-11 15:19:46 +0530105 this.infoToast(i18n.global.t('pageFirmware.toast.updateStartedMessage'), {
106 title: i18n.global.t('pageFirmware.toast.updateStarted'),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800107 timestamp: true,
108 });
Nikhil Ashokabc49e092024-06-11 12:19:11 +0530109 this.dispatchWorkstationUpload(timerId);
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800110 },
111 dispatchWorkstationUpload(timerId) {
112 this.$store
Leo Xue2c716a2024-07-29 05:54:18 +0300113 .dispatch('firmware/uploadFirmware', {
114 image: this.file,
115 })
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800116 .catch(({ message }) => {
117 this.endLoader();
118 this.errorToast(message);
119 clearTimeout(timerId);
120 });
121 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800122 onSubmitUpload() {
Surya Venkatesan00355b62024-09-12 13:00:05 +0530123 this.v$.$touch();
124 if (this.v$.$invalid) return;
jason westoverd36ac8a2025-11-03 20:58:59 -0600125 this.showUpdateModal = true;
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800126 },
127 onFileUpload(file) {
128 this.file = file;
Surya Venkatesan00355b62024-09-12 13:00:05 +0530129 this.v$.file.$touch();
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800130 },
131 },
132};
133</script>