summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/BackendModule.vue
blob: 39daedb699b192e011d29d642fce33b2fcbf1da7 (plain) (blame)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<i18n>
{
  "en": {
    "addBackendBtn": "Add Backend",
    "backendId": "id",
    "backendName": "name",
    "backends": "Backends",
    "backendType": "type",
    "checkConnection": "Check one connection | Check {0} connections",
    "deleteAreYouSure": "Are you sure you want to delete this backend? | Are you sure you want to delete those backends?",
    "id": "ID",
    "name": "Name",
    "removeBackend": "Remove one backend | Remove {0} backends",
    "type": "Type"
  },
  "de": {
    "addBackendBtn": "Backend hinzufügen",
    "backends": "Backends",
    "backendId": "id",
    "backendName": "name",
    "backendType": "typ",
    "checkConnection": "Überprüfe eine Verbindung | Überprüfe {0} Verbindungen",
    "deleteAreYouSure": "Sind Sie sicher, dass sie dieses Backend Löschen wollen? | Sind sie sicher, dass sie diese Backends Löschen wollen?",
    "id": "ID",
    "name": "Name",
    "removeBackend": "Entferne ein Backend | Entferne {0} Backends",
    "type": "Type"
  }
}
</i18n>

<template>
  <v-container fill-height>
    <v-layout>
      <v-flex xl10 offset-xl1 lg12>
      <v-card class="tabbar-card">
        <v-tabs :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor"
          v-model="tab"
          grow
          hide-slider
        >
          <v-tab>
            <v-icon class="tabbar-tabicon">cloud</v-icon>{{ $t('backends') }}
          </v-tab>
        </v-tabs>
      </v-card>
      <v-tabs-items v-model="tab">
        <v-tab-item>
          <v-subheader>{{ $t('backends') }}</v-subheader>

            <v-card>
              <data-table v-model="selectedBackends" :headers="headers" :items="backends" @dblclick="$store.commit('backends/editBackend', $event.id)">
                <div slot="action" slot-scope="row" style="text-align: right">
                  <v-btn flat icon :loading="row.item.loading"
                    :disabled="row.item.loading"
                    :color="row.item.connection"
                    @click.stop="checkConnection(row.item)"
                  ><v-icon>cached</v-icon></v-btn>
                  <v-btn flat icon color="primary" @click.stop="$store.commit('backends/editSync', row.item.id)"><v-icon>settings_ethernet</v-icon></v-btn>
                  <v-btn flat icon color="primary" @click.stop="$store.commit('backends/editBackend', row.item.id)"><v-icon>edit</v-icon></v-btn>
                </div>
              </data-table>
            </v-card>

            <div class="text-xs-right">
              <v-btn color="primary" flat @click="checkConnections(selectedBackends)" :disabled="selectedBackends.length === 0">
                <v-icon left>cached</v-icon>{{ $tc('checkConnection', selectedBackends.length, [selectedBackends.length]) }}
              </v-btn>
              <v-btn color="error" flat @click="$store.commit('backends/setDialog', true)" :disabled="selectedBackends.length === 0">
                <v-icon left>remove_circle_outline</v-icon>{{ $tc('removeBackend', selectedBackends.length, [selectedBackends.length]) }}
              </v-btn>
              <v-btn color="success" flat @click="$store.commit('backends/editBackend', 0)">
                <v-icon left>add_circle_outline</v-icon>{{ $t('addBackendBtn') }}
              </v-btn>
            </div>

        </v-tab-item>
      </v-tabs-items>
      </v-flex>
    </v-layout>

    <v-dialog
      :value="$store.state.backends.dialog"
      @input="$store.commit('backends/setDialog', $event)"
      max-width="500px"
      scrollable
    >
      <v-card>
        <v-card-title class="elevation-3">
          <div>
            <div class="headline">{{ $tc('removeBackend', selectedBackends.length, [selectedBackends.length]) }}</div>
          </div>
        </v-card-title>
        <v-card-text>
          {{ $tc('deleteAreYouSure', selectedBackends.length) }}
            <template v-for="item in selectedBackends">
              <div class="grey--text" :key="item.id">[{{ item.id }}] {{ item.name }} ({{ item.type }})</div>
            </template>
        </v-card-text>
        <v-divider></v-divider>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn flat="flat" @click="$store.commit('backends/setDialog', false)">{{ $t('cancel') }}</v-btn>
          <v-btn color="error" @click="$store.commit('backends/setDialog', false); deleteSelectedBackends()">{{ $t('delete') }}</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
    <backend-module-edit :backendId="$store.state.backends.backendId"/>
    <backend-module-sync :backendId="$store.state.backends.backendId"/>
  </v-container>
</template>

<script>
import BackendModuleEdit from '@/components/BackendModuleEdit'
import BackendModuleSync from '@/components/BackendModuleSync'
import DataTable from '@/components/DataTable'
import { mapState, mapGetters } from 'vuex'

export default {
  name: 'BackendModule',
  components: {
    BackendModuleEdit,
    BackendModuleSync,
    DataTable
  },
  data () {
    return {
      dialog: false,
      backendName: '',
      backendId: '',
      backendType: '',
      edit: false,
      selectedBackends: [],
      tab: 0,
      headers: [
        { text: this.$t('id'), key: 'id' },
        { text: this.$t('name'), key: 'name' },
        { text: this.$t('type'), key: 'type' },
        { key: 'action' }
      ]
    }
  },
  methods: {
    checkConnection (item) {
      // Set to start the loading animation.
      item.loading = true
      // Test the credential connection.
      this.$http.post('/api/backends/' + item.id + '/connection', {
        headers: {
          'Cache-Control': 'no-cache'
        }
      }).then(response => {
        if (response.data.success) {
          // Set the button color to green if success.
          item.connection = 'success'
        } else {
          // Set the button color to red if error.
          item.connection = 'error'
          this.$snackbar({ color: 'error', text: response.data.error })
        }
        // Set item.loading = false to end the loading animation.
        item.loading = false
      })
    },
    checkConnections (items) {
      const tmp = this
      items.forEach(function (item) {
        tmp.checkConnection(item)
      })
    },
    async deleteSelectedBackends () {
      // Filter selected array to get a list of ids.
      await this.$http.post('/api/backends/delete', {
        id: this.selectedBackends.map(x => x.id)
      })
      this.$store.dispatch('backends/loadData')
    }
  },
  computed: {
    ...mapGetters(['tabsDark', 'tabsColor', 'tabsSliderColor']),
    ...mapState('backends', ['backends'])
  },
  created () {
    this.$store.dispatch('backends/loadData')
  }
}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>