1<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')"> 8 <b-form-radio-group 9 v-model="currentPowerRestorePolicy" 10 :options="options" 11 name="power-restore-policy" 12 stacked 13 ></b-form-radio-group> 14 </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'; 28import { useVuelidate } from '@vuelidate/core'; 29 30import BVToastMixin from '@/components/Mixins/BVToastMixin'; 31import { useI18n } from 'vue-i18n'; 32import i18n from '@/i18n'; 33 34export default { 35 name: 'PowerRestorePolicy', 36 components: { PageTitle }, 37 mixins: [VuelidateMixin, BVToastMixin, LoadingBarMixin], 38 beforeRouteLeave(to, from, next) { 39 this.hideLoader(); 40 next(); 41 }, 42 setup() { 43 return { 44 v$: useVuelidate(), 45 }; 46 }, 47 data() { 48 return { 49 $t: useI18n().t, 50 policyValue: null, 51 options: [], 52 }; 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(); 69 this.renderPowerRestoreSettings(); 70 }, 71 methods: { 72 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({ 80 text: i18n.global.t( 81 `pagePowerRestorePolicy.policiesDesc.${item.state}`, 82 ), 83 value: `${item.state}`, 84 }); 85 }); 86 this.endLoader(); 87 }); 88 }, 89 submitForm() { 90 this.startLoader(); 91 this.$store 92 .dispatch( 93 'powerPolicy/setPowerRestorePolicy', 94 this.policyValue || this.currentPowerRestorePolicy, 95 ) 96 .then((message) => this.successToast(message)) 97 .catch(({ message }) => this.errorToast(message)) 98 .finally(() => { 99 this.renderPowerRestoreSettings(); 100 }); 101 }, 102 }, 103}; 104</script> 105