blob: 348540a28cb50495133124dfe618d91b81d87f09 [file] [log] [blame]
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05301<template>
2 <b-container fluid="xl">
3 <page-title :description="$t('pagePowerRestorePolicy.description')" />
4
5 <b-row>
6 <b-col sm="8" md="6" xl="12">
7 <b-form-group :label="$t('pagePowerRestorePolicy.powerPoliciesLabel')">
Kenneth Fullbright80a87852022-01-07 13:12:30 -06008 <b-form-radio-group
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05309 v-model="currentPowerRestorePolicy"
Kenneth Fullbright80a87852022-01-07 13:12:30 -060010 :options="options"
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053011 name="power-restore-policy"
Nikhil Ashoka07368132024-05-09 14:02:19 +053012 stacked
Kenneth Fullbright80a87852022-01-07 13:12:30 -060013 ></b-form-radio-group>
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053014 </b-form-group>
15 </b-col>
16 </b-row>
17
18 <b-button variant="primary" type="submit" @click="submitForm">
19 {{ $t('global.action.saveSettings') }}
20 </b-button>
21 </b-container>
22</template>
23
24<script>
25import PageTitle from '@/components/Global/PageTitle';
26import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
27import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous9c729792024-03-23 14:56:34 -070028import { useVuelidate } from '@vuelidate/core';
29
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053030import BVToastMixin from '@/components/Mixins/BVToastMixin';
Surya V603cfbf2024-07-11 15:19:46 +053031import { useI18n } from 'vue-i18n';
32import i18n from '@/i18n';
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053033
34export default {
35 name: 'PowerRestorePolicy',
36 components: { PageTitle },
37 mixins: [VuelidateMixin, BVToastMixin, LoadingBarMixin],
38 beforeRouteLeave(to, from, next) {
39 this.hideLoader();
40 next();
41 },
Ed Tanous9c729792024-03-23 14:56:34 -070042 setup() {
43 return {
44 v$: useVuelidate(),
45 };
46 },
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053047 data() {
48 return {
Surya V603cfbf2024-07-11 15:19:46 +053049 $t: useI18n().t,
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053050 policyValue: null,
Kenneth Fullbright80a87852022-01-07 13:12:30 -060051 options: [],
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053052 };
53 },
54 computed: {
55 powerRestorePolicies() {
56 return this.$store.getters['powerPolicy/powerRestorePolicies'];
57 },
58 currentPowerRestorePolicy: {
59 get() {
60 return this.$store.getters['powerPolicy/powerRestoreCurrentPolicy'];
61 },
62 set(policy) {
63 this.policyValue = policy;
64 },
65 },
66 },
67 created() {
68 this.startLoader();
Kenneth Fullbright80a87852022-01-07 13:12:30 -060069 this.renderPowerRestoreSettings();
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053070 },
71 methods: {
Kenneth Fullbright80a87852022-01-07 13:12:30 -060072 renderPowerRestoreSettings() {
73 Promise.all([
74 this.$store.dispatch('powerPolicy/getPowerRestorePolicies'),
75 this.$store.dispatch('powerPolicy/getPowerRestoreCurrentPolicy'),
76 ]).finally(() => {
77 this.options.length = 0;
78 this.powerRestorePolicies.map((item) => {
79 this.options.push({
Surya V603cfbf2024-07-11 15:19:46 +053080 text: i18n.global.t(
81 `pagePowerRestorePolicy.policiesDesc.${item.state}`,
82 ),
Kenneth Fullbright80a87852022-01-07 13:12:30 -060083 value: `${item.state}`,
84 });
85 });
86 this.endLoader();
87 });
88 },
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053089 submitForm() {
90 this.startLoader();
91 this.$store
92 .dispatch(
93 'powerPolicy/setPowerRestorePolicy',
Ed Tanous81323992024-02-27 11:26:24 -080094 this.policyValue || this.currentPowerRestorePolicy,
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053095 )
96 .then((message) => this.successToast(message))
97 .catch(({ message }) => this.errorToast(message))
Kenneth Fullbright80a87852022-01-07 13:12:30 -060098 .finally(() => {
99 this.renderPowerRestoreSettings();
100 });
Sukanya Pandeybe6858c2020-12-16 20:08:01 +0530101 },
102 },
103};
104</script>