summaryrefslogtreecommitdiff
path: root/src/views/_sila/Settings/TransferInfo/Syslog.vue
blob: 163a7f5baed0b53000b08984cdff4834f65601da (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
  <page-section :section-title="$t('pageTransfer.syslog.title')">
    <b-row class="mt-4 justify-content-end syslog-warning">
      <b-col xs="12" sm="12">
        <div class="switch-group">
          <label for="statusSwitch">{{
            $t('pageTransfer.syslog.status')
          }}</label>
          <b-form-checkbox
            id="statusSwitch"
            v-model="syslogStatus"
            data-test-id="checkbox-status"
            switch
            :disabled="loading || isNotAdmin"
          >
            <span v-if="syslogStatus">
              {{ $t('global.status.enabled') }}
            </span>
            <span v-else>{{ $t('global.status.disabled') }}</span>
          </b-form-checkbox>
        </div>
      </b-col>
      <b-col xs="12" sm="6">
        <b-form-group
          :label="$t('pageTransfer.syslog.ip')"
          label-for="syslog-ip"
        >
          <b-form-input
            id="syslog-ip"
            v-model="form.Address"
            :disabled="!syslogStatus || loading || isNotAdmin"
          /> </b-form-group
      ></b-col>
      <b-col xs="12" sm="6">
        <b-form-group
          :label="$t('pageTransfer.syslog.port')"
          label-for="syslog-port"
        >
          <b-form-input
            id="syslog-port"
            v-model="form.Port"
            type="number"
            :disabled="!syslogStatus || loading || isNotAdmin"
          />
        </b-form-group>
      </b-col>
      <b-col xs="4" class="d-flex justify-content-end align-items-start">
        <b-button
          variant="primary"
          :disabled="loading || isNotAdmin"
          @click="saveSyslog"
        >
          {{ $t('global.action.save') }}
        </b-button>
      </b-col>
    </b-row>
  </page-section>
</template>

<script>
import PageSection from '@/components/_sila/Global/PageSection';
import BVToastMixin from '@/components/_sila/Mixins/BVToastMixin';
import LoadingBarMixin, {
  loading,
} from '@/components/_sila/Mixins/LoadingBarMixin';

export default {
  name: 'Syslog',
  components: {
    PageSection,
  },
  mixins: [BVToastMixin, LoadingBarMixin],

  data() {
    return {
      loading,
      syslogStatus: false,
      form: {
        Address: null,
        Port: null,
      },
    };
  },
  computed: {
    settings() {
      return this.$store.getters['syslogStore/settings'];
    },
    isNotAdmin() {
      return (
        this.$store.getters['authentication/role'] === 'ReadOnly' ||
        this.$store.getters['authentication/role'] === 'Operator'
      );
    },
  },

  watch: {
    settings() {
      this.setForm();
    },
  },

  created() {
    this.startLoader();
    this.$store.dispatch('syslogStore/getSettings').finally(() => {
      this.setForm();
      this.endLoader();
    });
  },

  methods: {
    saveSyslog() {
      this.startLoader();
      if (!this.syslogStatus) {
        this.form = {
          Address: '',
          Port: 0,
        };
      }

      this.form.Port = +this.form.Port;
      this.$store
        .dispatch('syslogStore/saveSettings', this.form)
        .then((success) => this.successToast(success))
        .catch(({ message }) => this.errorToast(message))
        .finally(() => this.endLoader());
    },

    setForm() {
      if (!this.settings) {
        return;
      }

      if (!this.settings.Address && this.settings.Port === 0) {
        this.syslogStatus = false;
      } else {
        this.syslogStatus = true;
      }

      this.form.Address = this.settings.Address;
      this.form.Port = this.settings.Port || null;
    },
  },
};
</script>

<style lang="scss" scoped>
.switch-group {
  margin-bottom: 1.5rem;
}
.syslog-warning {
  width: 50%;
  @media (max-width: 1200px) {
    width: 75%;
  }
  @media (max-width: 576px) {
    width: 100%;
  }
}
</style>