summaryrefslogtreecommitdiff
path: root/src/views/Control/ServerLed/ServerLed.vue
blob: f2e31fce1f4a637e76eabba612321171d22b3e17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
  <b-container fluid="xl">
    <page-title />
    <b-row>
      <b-col md="12">
        <page-section :section-title="$t('pageServerLed.serverLedTitle')">
          <b-form-group :label="$t('pageServerLed.serverLedSubTitle')">
            <b-form-checkbox
              v-model="indicatorLed"
              name="check-button"
              value="Lit"
              unchecked-value="Off"
              switch
              @change="changeLedValue"
            >
              <span v-if="indicatorLed && indicatorLed !== 'Off'">
                {{ $t('global.status.on') }}
              </span>
              <span v-else>
                {{ $t('global.status.off') }}
              </span>
            </b-form-checkbox>
          </b-form-group>
        </page-section>
      </b-col>
    </b-row>
  </b-container>
</template>

<script>
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 {
  name: 'ServerLed',
  components: { PageTitle, PageSection },
  mixins: [LoadingBarMixin, BVToastMixin],
  computed: {
    indicatorLed: {
      get() {
        return this.$store.getters['serverLed/getIndicatorValue'];
      },
      set(newValue) {
        return newValue;
      }
    }
  },
  created() {
    this.startLoader();
    this.$store
      .dispatch('serverLed/getIndicatorValue')
      .finally(() => this.endLoader());
  },
  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>