blob: 9f206296e131860caf35ffc1d3d0a69a3fa74849 [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"
Kenneth Fullbright80a87852022-01-07 13:12:30 -060012 ></b-form-radio-group>
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053013 </b-form-group>
14 </b-col>
15 </b-row>
16
17 <b-button variant="primary" type="submit" @click="submitForm">
18 {{ $t('global.action.saveSettings') }}
19 </b-button>
20 </b-container>
21</template>
22
23<script>
24import PageTitle from '@/components/Global/PageTitle';
25import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
26import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
27import BVToastMixin from '@/components/Mixins/BVToastMixin';
28
29export default {
30 name: 'PowerRestorePolicy',
31 components: { PageTitle },
32 mixins: [VuelidateMixin, BVToastMixin, LoadingBarMixin],
33 beforeRouteLeave(to, from, next) {
34 this.hideLoader();
35 next();
36 },
37 data() {
38 return {
39 policyValue: null,
Kenneth Fullbright80a87852022-01-07 13:12:30 -060040 options: [],
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053041 };
42 },
43 computed: {
44 powerRestorePolicies() {
45 return this.$store.getters['powerPolicy/powerRestorePolicies'];
46 },
47 currentPowerRestorePolicy: {
48 get() {
49 return this.$store.getters['powerPolicy/powerRestoreCurrentPolicy'];
50 },
51 set(policy) {
52 this.policyValue = policy;
53 },
54 },
55 },
56 created() {
57 this.startLoader();
Kenneth Fullbright80a87852022-01-07 13:12:30 -060058 this.renderPowerRestoreSettings();
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053059 },
60 methods: {
Kenneth Fullbright80a87852022-01-07 13:12:30 -060061 renderPowerRestoreSettings() {
62 Promise.all([
63 this.$store.dispatch('powerPolicy/getPowerRestorePolicies'),
64 this.$store.dispatch('powerPolicy/getPowerRestoreCurrentPolicy'),
65 ]).finally(() => {
66 this.options.length = 0;
67 this.powerRestorePolicies.map((item) => {
68 this.options.push({
69 text: this.$t(`pagePowerRestorePolicy.policiesDesc.${item.state}`),
70 value: `${item.state}`,
71 });
72 });
73 this.endLoader();
74 });
75 },
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053076 submitForm() {
77 this.startLoader();
78 this.$store
79 .dispatch(
80 'powerPolicy/setPowerRestorePolicy',
Ed Tanous81323992024-02-27 11:26:24 -080081 this.policyValue || this.currentPowerRestorePolicy,
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053082 )
83 .then((message) => this.successToast(message))
84 .catch(({ message }) => this.errorToast(message))
Kenneth Fullbright80a87852022-01-07 13:12:30 -060085 .finally(() => {
86 this.renderPowerRestoreSettings();
87 });
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053088 },
89 },
90};
91</script>