summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/GroupModuleClientList.vue
blob: e73a3fb8d5733a1757388900f1b520eea8a3fda7 (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
<i18n>
{
  "en": {
    "id": "ID",
    "name": "Name",
    "ip": "IP Address",
    "mac": "MAC Address",
    "uuid": "UUID",
    "wakeClients": "Wake one client up | Wake {0} clients up",
    "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",
    "wakeClients": "Einen Client aufwecken | {0} Clients aufwecken",
    "removeClients": "Einen Client entfernen | {0} Clients entfernen",
    "addClients": "Clients hinzufügen",
    "deleteClients": "Einen Client löschen | {0} Clients löschen",
    "createClient": "Client erstellen"
  }
}
</i18n>

<template>
  <div>
    <v-divider></v-divider>
    <data-table v-model="selected" :headers="headers" :items="clients" :loading="loading" @dblclick="loadClient($event)" min-width="1300px" copy-button>
      <div slot="actions" slot-scope="row" style="text-align: right">
        <v-btn icon @click.stop @mousedown="loadClient(row.item)" style="margin: 0"><v-icon>keyboard_arrow_right</v-icon></v-btn>
      </div>
    </data-table>
    <v-divider></v-divider>
    <div class="text-xs-right">
      <v-btn flat color="primary" @click="wake" :disabled="selected.length === 0">
        <v-icon left>notifications_active</v-icon>{{ $tc('wakeClients', selected.length, [selected.length]) }}
      </v-btn>
      <template v-if="tabIndex === 0">
        <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>
      </template>
      <template v-else>
        <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>
      </template>
    </div>
  </div>
</template>

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

export default {
  name: 'GroupModuleClientList',
  props: ['tabIndex', 'groupId', 'clients'],
  components: {
    DataTable
  },
  data () {
    return {
      selected: []
    }
  },
  computed: {
    headers () {
      return [
        { key: 'id', text: this.$t('id'), width: '50px', sortType: 'number' },
        { key: 'name', text: this.$t('name') },
        { key: 'ip', text: this.$t('ip'), width: '120px', sortType: 'ipv4' },
        { key: 'mac', text: this.$t('mac'), width: '160px' },
        { key: 'uuid', text: this.$t('uuid'), width: '300px' },
        { key: 'actions', width: '60px' }
      ]
    },
    loading () {
      return this.$store.state.groups.tabChain[this.tabIndex].loading
    }
  },
  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 } })
    },
    wake () {
      this.setDialog({ show: true, info: { action: 'wake', 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>