summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/GroupModuleClientList.vue
blob: ef01ee32cd26aed38d6099c9605fc28d5185388d (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
<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>
    <data-table class="client-table" v-model="selected" :headers="headers" :items="clients" :loading="loading" @dblclick="loadClient($event)" min-width="1300px">
      <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>
    <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' },
        { key: 'name', text: this.$t('name') },
        { key: 'ip', text: this.$t('ip'), width: '120px' },
        { 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;
}

.client-table {
  position: relative;
}

.client-table::before {
  pointer-events: none;
  z-index: 3;
  box-shadow: inset 0px 0px 6px rgba(0,0,0,0.5);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  content: "";
}
</style>