blob: 4c302df60a0a6c8eab153a921ef9da31eb787bc3 [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 Ashokabc49e092024-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"
14 :state="getValidationState($v.file)"
15 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 Ashokabc49e092024-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';
49
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080050import FormFile from '@/components/Global/FormFile';
51import ModalUpdateFirmware from './FirmwareModalUpdateFirmware';
52
53export default {
Kenneth Fullbright19b2cfb2022-02-21 16:27:32 -060054 components: { FormFile, ModalUpdateFirmware },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080055 mixins: [BVToastMixin, LoadingBarMixin, VuelidateMixin],
56 props: {
57 isPageDisabled: {
58 required: true,
59 type: Boolean,
60 default: false,
61 },
Derick Montague71114fe2021-05-06 18:17:34 -050062 isServerOff: {
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080063 required: true,
64 type: Boolean,
65 },
66 },
67 data() {
68 return {
69 loading,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080070 file: null,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080071 isServerPowerOffRequired:
72 process.env.VUE_APP_SERVER_OFF_REQUIRED === 'true',
73 };
74 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080075 validations() {
76 return {
77 file: {
Nikhil Ashokabc49e092024-06-11 12:19:11 +053078 required,
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080079 },
80 };
81 },
82 created() {
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080083 this.$store.dispatch('firmware/getUpdateServiceSettings');
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080084 },
85 methods: {
86 updateFirmware() {
87 this.startLoader();
88 const timerId = setTimeout(() => {
89 this.endLoader();
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080090 this.infoToast(this.$t('pageFirmware.toast.verifyUpdateMessage'), {
91 title: this.$t('pageFirmware.toast.verifyUpdate'),
92 refreshAction: true,
93 });
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -080094 }, 360000);
Yoshie Muranaka33d755f2021-02-18 15:24:14 -080095 this.infoToast(this.$t('pageFirmware.toast.updateStartedMessage'), {
96 title: this.$t('pageFirmware.toast.updateStarted'),
97 timestamp: true,
98 });
Nikhil Ashokabc49e092024-06-11 12:19:11 +053099 this.dispatchWorkstationUpload(timerId);
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800100 },
101 dispatchWorkstationUpload(timerId) {
102 this.$store
Yoshie Muranaka33d755f2021-02-18 15:24:14 -0800103 .dispatch('firmware/uploadFirmware', this.file)
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800104 .catch(({ message }) => {
105 this.endLoader();
106 this.errorToast(message);
107 clearTimeout(timerId);
108 });
109 },
Yoshie Muranaka7bc85e42021-02-11 09:59:13 -0800110 onSubmitUpload() {
111 this.$v.$touch();
112 if (this.$v.$invalid) return;
113 this.$bvModal.show('modal-update-firmware');
114 },
115 onFileUpload(file) {
116 this.file = file;
117 this.$v.file.$touch();
118 },
119 },
120};
121</script>