Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 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')"> |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 8 | <b-form-radio-group |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 9 | v-model="currentPowerRestorePolicy" |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 10 | :options="options" |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 11 | name="power-restore-policy" |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 12 | ></b-form-radio-group> |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 13 | </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> |
| 24 | import PageTitle from '@/components/Global/PageTitle'; |
| 25 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 26 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 27 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 28 | |
| 29 | export 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 Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 40 | options: [], |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 41 | }; |
| 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 Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 58 | this.renderPowerRestoreSettings(); |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 59 | }, |
| 60 | methods: { |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 61 | 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 Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 76 | submitForm() { |
| 77 | this.startLoader(); |
| 78 | this.$store |
| 79 | .dispatch( |
| 80 | 'powerPolicy/setPowerRestorePolicy', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 81 | this.policyValue || this.currentPowerRestorePolicy, |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 82 | ) |
| 83 | .then((message) => this.successToast(message)) |
| 84 | .catch(({ message }) => this.errorToast(message)) |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 85 | .finally(() => { |
| 86 | this.renderPowerRestoreSettings(); |
| 87 | }); |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 88 | }, |
| 89 | }, |
| 90 | }; |
| 91 | </script> |