summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/GroupModuleClientList.vue
blob: 35819d5093972003a44d5ad7a2afa75921ab5742 (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
<i18n>
{
  "en": {
    "id": "ID",
    "name": "Name",
    "ip": "IP Address",
    "mac": "MAC Address",
    "uuid": "UUID",
    "removeClients": "Remove one client | Remove {0} clients",
    "addClients": "Add clients",
    "deleteClients": "Delete one client | Delete {0} clients",
    "createClient": "Create client"
  },
  "de": {
    "id": "ID",
    "name": "Name",
    "ip": "IP Adresse",
    "mac": "MAC Adresse",
    "uuid": "UUID",
    "removeClients": "Entferne einen Clienten | Entferne {0} Clienten",
    "addClients": "Füge Clienten hinzu",
    "deleteClients": "Lösche einen Clienten | Lösche {0} Clienten",
    "createClient": "Client erstellen"
  }
}
</i18n>

<template>
  <div>
    <v-card>
      <component-search-table v-model="selected" :headers="headers" :items="clients" select-all :loading="loading">
        <template slot="items" slot-scope="row">
          <tr :style="row.color" @click="row.data.selected = !row.data.selected" @dblclick="loadClient(row.data.item)">
            <td class="narrow-td">
              <v-checkbox
                color="primary"
                v-model="row.data.selected"
                hide-details
              ></v-checkbox>
            </td>
            <td class="narrow-td">{{ row.data.item.id }}</td>
            <td>{{ row.data.item.name }}</td>
            <td>{{ row.data.item.ip }}</td>
            <td>{{ row.data.item.mac }}</td>
            <td>{{ row.data.item.uuid }}</td>
            <td class="narrow-td">
              <v-btn class="next-arrow" icon @click.stop="loadClient(row.data.item)"><v-icon>keyboard_arrow_right</v-icon></v-btn>
            </td>
          </tr>
        </template>
      </component-search-table>
    </v-card>
    <div v-if="tabIndex === 0" class="text-xs-right">
      <v-btn flat color="error" @click="deleteSelected" :disabled="selected.length === 0">
        <v-icon left>delete</v-icon>{{ $tc('deleteClients', selected.length, [selected.length]) }}
      </v-btn>
      <v-btn flat color="success" @click="newClient"><v-icon left>create</v-icon>{{ $t('createClient') }}</v-btn>
    </div>
    <div v-else class="text-xs-right">
        <v-btn flat color="error" @click="removeSelected" :disabled="selected.length === 0">
          <v-icon left>remove_circle_outline</v-icon>{{ $tc('removeClients', selected.length, [selected.length]) }}
        </v-btn>
        <v-btn flat color="success" @click="addExisting"><v-icon left>add_circle_outline</v-icon>{{ $t('addClients') }}</v-btn>
      </div>
  </div>
</template>

<script>
import ComponentSearchTable from '@/components/ComponentSearchTable'
import { mapMutations } from 'vuex'

export default {
  name: 'GroupModuleClientList',
  props: ['tabIndex', 'groupId', 'clients'],
  components: {
    ComponentSearchTable
  },
  data () {
    return {
      selected: []
    }
  },
  computed: {
    headers () {
      return [
        { text: this.$t('id'), value: 'id' },
        { text: this.$t('name'), value: 'name' },
        { text: this.$t('ip'), value: 'ip' },
        { text: this.$t('mac'), value: 'mac' },
        { text: this.$t('uuid'), value: 'uuid' },
        { sortable: false }
      ]
    },
    loading () {
      return this.$store.state.groups.tabChain[this.tabIndex].loading
    }
  },
  watch: {
    clients () {
      this.selected = []
    }
  },
  methods: {
    ...mapMutations('groups', ['setActiveTab', 'setTab', 'setDialog']),
    loadClient (item) {
      this.$store.dispatch('groups/loadClient', { id: item.id, name: item.name, tabIndex: this.tabIndex + 1, switchTab: true })
    },
    newClient () {
      this.setTab({ index: 1, item: { id: 'create', tabType: 'client' } })
      this.setActiveTab(1)
    },
    deleteSelected () {
      this.setDialog({ show: true, info: { action: 'delete', type: 'client', selected: this.selected } })
    },
    removeSelected () {
      this.setDialog({ show: true, info: { action: 'remove', type: 'client', selected: this.selected, tabIndex: this.tabIndex } })
    },
    addExisting () {
      this.setDialog({ show: true, info: { action: 'add', type: 'client', selected: this.selected, tabIndex: this.tabIndex } })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.narrow-td {
  width: 10px;
}

.next-arrow {
  margin-left: 20px;
  margin-right: -10px;
}
</style>