summaryrefslogtreecommitdiff
path: root/src/views/Control/ServerLed/ServerLed.vue
blob: 72726babaa01672aa0178ce3ec0b1a726693cfc6 (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
<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="indicatorLedActiveState"
              data-test-id="serverLed-checkbox-switchIndicatorLed"
              name="check-button"
              switch
              @change="changeLedValue"
            >
              <span v-if="indicatorLedActiveState">
                {{ $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],
  beforeRouteLeave(to, from, next) {
    this.hideLoader();
    next();
  },
  computed: {
    indicatorLedActiveState: {
      get() {
        return this.$store.getters['serverLed/getIndicatorLedActiveState'];
      },
      set(newValue) {
        return newValue;
      },
    },
  },
  created() {
    this.startLoader();
    this.$store
      .dispatch('serverLed/getIndicatorLedActiveState')
      .finally(() => this.endLoader());
  },
  methods: {
    changeLedValue(indicatorLedActiveState) {
      this.$store
        .dispatch(
          'serverLed/saveIndicatorLedActiveState',
          indicatorLedActiveState
        )
        .then((message) => this.successToast(message))
        .catch(({ message }) => this.errorToast(message));
    },
  },
};
</script>