diff options
author | SurenNeware <sneware9@in.ibm.com> | 2020-07-17 12:43:18 +0300 |
---|---|---|
committer | Derick Montague <derick.montague@ibm.com> | 2020-07-27 22:17:52 +0300 |
commit | a2c99829a713e8411bda20091765ee972cd4d8b9 (patch) | |
tree | f5eabc30b7bb8ceb3f19364c884b2e02e3fb6249 /src/views | |
parent | 47998e745aa315aeaa4c4abef478cf898de71d95 (diff) | |
download | webui-vue-a2c99829a713e8411bda20091765ee972cd4d8b9.tar.xz |
Add code to refactor the server LED component
-Resolved issue with toast notification appearing on page load.
Signed-off-by: Suren Neware <sneware9@in.ibm.com>
Change-Id: I03e76951bf9e4f92eb6a6a6fcffa09ef1be2f811
Diffstat (limited to 'src/views')
-rw-r--r-- | src/views/Control/ServerLed/ServerLed.vue | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/views/Control/ServerLed/ServerLed.vue b/src/views/Control/ServerLed/ServerLed.vue index 5b99e07c..f2e31fce 100644 --- a/src/views/Control/ServerLed/ServerLed.vue +++ b/src/views/Control/ServerLed/ServerLed.vue @@ -6,13 +6,14 @@ <page-section :section-title="$t('pageServerLed.serverLedTitle')"> <b-form-group :label="$t('pageServerLed.serverLedSubTitle')"> <b-form-checkbox - v-model="indicatorLED" + v-model="indicatorLed" name="check-button" value="Lit" unchecked-value="Off" switch + @change="changeLedValue" > - <span v-if="indicatorLED !== 'Off' && indicatorLED"> + <span v-if="indicatorLed && indicatorLed !== 'Off'"> {{ $t('global.status.on') }} </span> <span v-else> @@ -30,7 +31,6 @@ import PageTitle from '@/components/Global/PageTitle'; import PageSection from '@/components/Global/PageSection'; import BVToastMixin from '@/components/Mixins/BVToastMixin'; - import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; export default { @@ -38,17 +38,12 @@ export default { components: { PageTitle, PageSection }, mixins: [LoadingBarMixin, BVToastMixin], computed: { - indicatorLED: { + indicatorLed: { get() { return this.$store.getters['serverLed/getIndicatorValue']; }, set(newValue) { - if (newValue) { - this.$store - .dispatch('serverLed/saveIndicatorLedValue', newValue) - .then(message => this.successToast(message)) - .catch(({ message }) => this.errorToast(message)); - } + return newValue; } } }, @@ -61,6 +56,21 @@ export default { beforeRouteLeave(to, from, next) { this.hideLoader(); next(); + }, + methods: { + changeLedValue(indicatorLed) { + this.$store + .dispatch('serverLed/saveIndicatorLedValue', indicatorLed) + .then(message => this.successToast(message)) + .catch(({ message }) => { + this.errorToast(message); + if (indicatorLed === 'Off') { + this.indicatorLed === 'Lit'; + } else { + this.indicatorLed === 'Off'; + } + }); + } } }; </script> |