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'; 31 32export default { 33 name: 'PowerRestorePolicy', 34 components: { PageTitle }, 35 mixins: [VuelidateMixin, BVToastMixin, LoadingBarMixin], 36 beforeRouteLeave(to, from, next) { 37 this.hideLoader(); 38 next(); 39 }, 40 setup() { 41 return { 42 v$: useVuelidate(), 43 }; 44 }, 45 data() { 46 return { 47 policyValue: null, 48 options: [], 49 }; 50 }, 51 computed: { 52 powerRestorePolicies() { 53 return this.$store.getters['powerPolicy/powerRestorePolicies']; 54 }, 55 currentPowerRestorePolicy: { 56 get() { 57 return this.$store.getters['powerPolicy/powerRestoreCurrentPolicy']; 58 }, 59 set(policy) { 60 this.policyValue = policy; 61 }, 62 }, 63 }, 64 created() { 65 this.startLoader(); 66 this.renderPowerRestoreSettings(); 67 }, 68 methods: { 69 renderPowerRestoreSettings() { 70 Promise.all([ 71 this.$store.dispatch('powerPolicy/getPowerRestorePolicies'), 72 this.$store.dispatch('powerPolicy/getPowerRestoreCurrentPolicy'), 73 ]).finally(() => { 74 this.options.length = 0; 75 this.powerRestorePolicies.map((item) => { 76 this.options.push({ 77 text: this.$t(`pagePowerRestorePolicy.policiesDesc.${item.state}`), 78 value: `${item.state}`, 79 }); 80 }); 81 this.endLoader(); 82 }); 83 }, 84 submitForm() { 85 this.startLoader(); 86 this.$store 87 .dispatch( 88 'powerPolicy/setPowerRestorePolicy', 89 this.policyValue || this.currentPowerRestorePolicy, 90 ) 91 .then((message) => this.successToast(message)) 92 .catch(({ message }) => this.errorToast(message)) 93 .finally(() => { 94 this.renderPowerRestoreSettings(); 95 }); 96 }, 97 }, 98}; 99</script> 100