blob: abb25fc46ec47fb01861c00a1ae71e23b1232c2b [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 -->
Nikhil Ashoka2d65f4a2024-06-11 12:19:11 +05306 <template>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -08007 <b-form-group
Yoshie Muranaka33d755f2021-02-18 15:24:14 -08008 :label="$t('pageFirmware.form.updateFirmware.imageFile')"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -08009 label-for="image-file"
10 >
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080011 <form-file
12 id="image-file"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080013 :disabled="isPageDisabled"
Surya Venkatesan52ed8852024-09-12 13:00:05 +053014 :state="getValidationState(v$.file)"
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080015 aria-describedby="image-file-help-block"
16 @input="onFileUpload($event)"
17 >
18 <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>
25 </template>
26
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080027 <b-btn
28 data-test-id="firmware-button-startUpdate"
29 type="submit"
30 variant="primary"
31 :disabled="isPageDisabled"
32 >
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080033 {{ $t('pageFirmware.form.updateFirmware.startUpdate') }}
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080034 </b-btn>
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080035 </b-form>
36 </div>
37
38 <!-- Modals -->
39 <modal-update-firmware @ok="updateFirmware" />
40 </div>
41</template>
42
43<script>
Nikhil Ashoka2d65f4a2024-06-11 12:19:11 +053044import { required } from 'vuelidate/lib/validators';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080045
46import BVToastMixin from '@/components/Mixins/BVToastMixin';
47import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
48import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous9c729792024-03-23 14:56:34 -070049import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080050
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080051import FormFile from '@/components/Global/FormFile';
52import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
Surya V603cfbf2024-07-11 15:19:46 +053053import { useI18n } from 'vue-i18n';
54import i18n from '@/i18n';
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080055
56export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060057 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080058 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
59 props: {
60 isPageDisabled: {
61 required: true,
62 type: Boolean,
63 default: false,
64 },
Derick Montague71114fe2021-05-06 18:17:34 -050065 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080066 required: true,
67 type: Boolean,
68 },
69 },
Ed Tanous9c729792024-03-23 14:56:34 -070070 setup() {
71 return {
Surya Venkatesan52ed8852024-09-12 13:00:05 +053072 v$: useVuelidate(),
Ed Tanous9c729792024-03-23 14:56:34 -070073 };
74 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080075 data() {
76 return {
Surya V603cfbf2024-07-11 15:19:46 +053077 $t: useI18n().t,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080078 loading,
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 Venkatesan52ed8852024-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 V603cfbf2024-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 V603cfbf2024-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 Ashoka2d65f4a2024-06-11 12:19:11 +0530109 this.dispatchWorkstationUpload(timerId);
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800110 },
111 dispatchWorkstationUpload(timerId) {
112 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800113 .dispatch('firmware/uploadFirmware', this.file)
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 Venkatesan52ed8852024-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 Venkatesan52ed8852024-09-12 13:00:05 +0530127 this.v$.file.$touch();
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800128 },
129 },
130};
131</script>