blob: 2b9a616acb401a8174e419b3851094cddec71bbe [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"
9 >
10 <form-file
11 id="image-file"
12 :disabled="isPageDisabled"
13 :state="getValidationState(v$.file)"
14 aria-describedby="image-file-help-block"
15 @input="onFileUpload($event)"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080016 >
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053017 <template #invalid>
18 <b-form-invalid-feedback role="alert">
19 {{ $t('global.form.required') }}
20 </b-form-invalid-feedback>
21 </template>
22 </form-file>
23 </b-form-group>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080024
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080025 <b-btn
26 data-test-id="firmware-button-startUpdate"
27 type="submit"
28 variant="primary"
29 :disabled="isPageDisabled"
30 >
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080031 {{ $t('pageFirmware.form.updateFirmware.startUpdate') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080032 </b-btn>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080033 </b-form>
34 </div>
35
36 <!-- Modals -->
37 <modal-update-firmware @ok="updateFirmware" />
38 </div>
39</template>
40
41<script>
Nikhil Ashokabc49e092024-06-11 12:19:11 +053042import { required } from 'vuelidate/lib/validators';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080043
44import BVToastMixin from '@/components/Mixins/BVToastMixin';
45import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
46import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070047import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080048
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080049import FormFile from '@/components/Global/FormFile';
50import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
Surya Vde23ea22024-07-11 15:19:46 +053051import { useI18n } from 'vue-i18n';
52import i18n from '@/i18n';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080053
54export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060055 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080056 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
57 props: {
58 isPageDisabled: {
59 required: true,
60 type: Boolean,
61 default: false,
62 },
Derick Montague71114fe2021-05-06 18:17:34 -050063 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080064 required: true,
65 type: Boolean,
66 },
67 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -070068 setup() {
69 return {
Surya Venkatesan00355b62024-09-12 13:00:05 +053070 v$: useVuelidate(),
Ed Tanous7d6b44c2024-03-23 14:56:34 -070071 };
72 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080073 data() {
74 return {
Surya Vde23ea22024-07-11 15:19:46 +053075 $t: useI18n().t,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080076 loading,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080077 file: null,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080078 isServerPowerOffRequired:
79 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
80 };
81 },
Surya Venkatesan00355b62024-09-12 13:00:05 +053082 validations: {
83 file: {
84 required,
85 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080086 },
87 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080088 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080089 },
90 methods: {
91 updateFirmware() {
92 this.startLoader();
93 const timerId = setTimeout(() => {
94 this.endLoader();
Surya Vde23ea22024-07-11 15:19:46 +053095 this.infoToast(
96 i18n.global.t('pageFirmware.toast.verifyUpdateMessage'),
97 {
98 title: i18n.global.t('pageFirmware.toast.verifyUpdate'),
99 refreshAction: true,
100 },
101 );
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800102 }, 360000);
Surya Vde23ea22024-07-11 15:19:46 +0530103 this.infoToast(i18n.global.t('pageFirmware.toast.updateStartedMessage'), {
104 title: i18n.global.t('pageFirmware.toast.updateStarted'),
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800105 timestamp: true,
106 });
Nikhil Ashokabc49e092024-06-11 12:19:11 +0530107 this.dispatchWorkstationUpload(timerId);
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800108 },
109 dispatchWorkstationUpload(timerId) {
110 this.$store
Leo Xue2c716a2024-07-29 05:54:18 +0300111 .dispatch('firmware/uploadFirmware', {
112 image: this.file,
113 })
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800114 .catch(({ message }) => {
115 this.endLoader();
116 this.errorToast(message);
117 clearTimeout(timerId);
118 });
119 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800120 onSubmitUpload() {
Surya Venkatesan00355b62024-09-12 13:00:05 +0530121 this.v$.$touch();
122 if (this.v$.$invalid) return;
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800123 this.$bvModal.show('modal-update-firmware');
124 },
125 onFileUpload(file) {
126 this.file = file;
Surya Venkatesan00355b62024-09-12 13:00:05 +0530127 this.v$.file.$touch();
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800128 },
129 },
130};
131</script>