summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/ConfiguratorModule.vue
blob: 0d625e9149d45fac7b94e708f12d7e3781a27570 (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<i18n>
{
  "en": {
    "id": "ID",
    "name": "Name",
    "description": "Description",
    "entries": "Entries",
    "configs": "Configs",
    "deleteConfigs": "Delete one config | Delete {0} configs",
    "createConfig": "Create config",
    "deleteEntries": "Delete one entry | Delete {0} entries",
    "createEntry": "Create entry",
    "successSetAsDefault": "Successfully set config as default.",
    "defaultConfig": "Default Config"
  },
  "de": {
    "id": "ID",
    "name": "Name",
    "description": "Beschreibung",
    "entries": "Einträge",
    "configs": "Konfigurationen",
    "deleteConfigs": "Eine Konfiguration löschen | {0} Konfigurationen löschen",
    "createConfig": "Konfiguration erstellen",
    "deleteEntries": "Einen Eintrag löschen | {0} Einträge löschen",
    "createEntry": "Eintrag erstellen",
    "successSetAsDefault": "Konfiguration erfolgreich als Standard gesetzt.",
    "defaultConfig": "Standard Konfiguration"
  }
}
</i18n>

<template>
  <v-container fill-height>
    <v-layout>
      <v-flex xl10 offset-xl1 lg12>
        <v-card class="tabbar-card">
          <v-tabs v-model="tabs" grow :dark="tabsDark" :background-color="tabsColor" :slider-color="tabsSliderColor">
              <v-tab><v-icon class="tabbar-tabicon">list</v-icon>{{ $t('configs') }}</v-tab>
              <v-tab><v-icon class="tabbar-tabicon">code</v-icon>{{ $t('entries') }}</v-tab>
          </v-tabs>
        </v-card>
        <v-tabs-items v-model="tabs" style="padding-bottom: 20px" touchless>
          <v-tab-item :transition="false" :reverse-transition="false">
            <v-subheader>{{ $t('configs') }}</v-subheader>
            <v-card>
              <data-table v-model="selectedConfigs" :headers="configHeaders" :items="configs" min-width="800px" @dblclick="editConfig($event)">
                <div slot="actions" slot-scope="row" style="display: flex; justify-content: flex-end; align-items: center">
                  <v-tooltip top v-if="row.item.isDefault">
                    <template #activator="{ on }">
                      <v-icon v-on="on" color="success" style="width: 36px">flag</v-icon>
                    </template>
                    <span>{{ $t('defaultConfig') }}</span>
                  </v-tooltip>
                  <v-btn v-else icon @click.stop="setAsDefault(row.item.id)">
                    <v-icon style="opacity: 0.2">outlined_flag</v-icon>
                  </v-btn>
                  <v-btn text small @click.stop="assignConfig(row.item)" class="mx-2">
                    <span class="mr-1">{{ row.item.groupCount }}</span><v-icon small>category</v-icon>
                    <span class="mx-1">/</span>
                    <span class="mr-1">{{ row.item.clientCount }}</span><v-icon small>computer</v-icon>
                  </v-btn>
                  <v-btn text icon @click.stop="editConfig(row.item)"><v-icon color="primary">edit</v-icon></v-btn>
                </div>
              </data-table>
            </v-card>
            <div class="text-right">
              <v-btn text color="error" @click="deleteSelectedConfigs" :disabled="selectedConfigs.length === 0" class="ma-2">
                <v-icon left>delete</v-icon>{{ $tc('deleteConfigs', selectedConfigs.length, [selectedConfigs.length]) }}
              </v-btn>
              <v-btn text color="success" @click="createConfig" class="ma-2">
                <v-icon left>create</v-icon>{{ $t('createConfig') }}
              </v-btn>
            </div>
          </v-tab-item>
          <v-tab-item :transition="false" :reverse-transition="false">
            <v-subheader>{{ $t('entries') }}</v-subheader>
            <v-card>
              <data-table v-model="selectedEntries" :headers="entryHeaders" :items="entries" min-width="600px" @dblclick="editEntry($event)">
                <div slot="actions" slot-scope="row" style="text-align: right">
                  <v-btn icon @click.stop="editEntry(row.item)"><v-icon color="primary">edit</v-icon></v-btn>
                </div>
              </data-table>
            </v-card>
            <div class="text-right">
              <v-btn text color="error" @click="deleteSelectedEntries" :disabled="selectedEntries.length === 0" class="ma-2">
                <v-icon left>delete</v-icon>{{ $tc('deleteEntries', selectedEntries.length, [selectedEntries.length]) }}
              </v-btn>
              <v-btn text color="success" @click="createEntry" class="ma-2">
                <v-icon left>create</v-icon>{{ $t('createEntry') }}
              </v-btn>
            </div>
          </v-tab-item>
        </v-tabs-items>
      </v-flex>
    </v-layout>
    <v-dialog
      :value="dialog.show"
      @input="setDialog({ show: $event })"
      :max-width="dialogWidthMap[dialog.type]"
      scrollable
      :persistent="dialog.type !== 'delete'"
      :fullscreen="$vuetify.breakpoint.smAndDown"
    >
      <configurator-module-delete v-if="dialog.type === 'delete'" />
      <configurator-module-config v-else-if="dialog.type === 'config'"/>
      <configurator-module-entry v-else-if="dialog.type === 'entry'" />
      <configurator-module-assign v-else-if="dialog.type === 'assign'" />
    </v-dialog>
  </v-container>
</template>

<script>
import DataTable from '@/components/DataTable'
import ConfiguratorModuleDelete from '@/components/ConfiguratorModuleDelete'
import ConfiguratorModuleConfig from '@/components/ConfiguratorModuleConfig'
import ConfiguratorModuleEntry from '@/components/ConfiguratorModuleEntry'
import ConfiguratorModuleAssign from '@/components/ConfiguratorModuleAssign'
import { mapState, mapGetters, mapMutations } from 'vuex'

export default {
  name: 'ConfiguratorModule',
  components: {
    DataTable,
    ConfiguratorModuleDelete,
    ConfiguratorModuleConfig,
    ConfiguratorModuleEntry,
    ConfiguratorModuleAssign
  },
  data () {
    return {
      tabs: 0,
      selectedConfigs: [],
      selectedEntries: [],
      dialogWidthMap: {
        'delete': '500px',
        'assign': '600px',
        'config': '1200px',
        'entry': '1200px'
      }
    }
  },
  computed: {
    ...mapGetters(['tabsDark', 'tabsColor', 'tabsSliderColor']),
    ...mapState('configurator', ['configs', 'entries', 'dialog']),
    configHeaders () {
      return [
        { key: 'id', text: this.$t('id'), width: '50px' },
        { key: 'name', text: this.$t('name'), width: '220px' },
        { key: 'description', text: this.$t('description') },
        { key: 'actions', width: '210px' }
      ]
    },
    entryHeaders () {
      return [
        { key: 'id', text: this.$t('id'), width: '50px' },
        { key: 'name', text: this.$t('name') },
        { key: 'actions', width: '60px' }
      ]
    }
  },
  watch: {
    configs () { this.selectedConfigs = [] },
    entries () { this.selectedEntries = [] }
  },
  methods: {
    ...mapMutations('configurator', ['setDialog']),
    deleteSelectedConfigs () {
      this.setDialog({ show: true, type: 'delete', info: { itemType: 'configs', selected: this.selectedConfigs } })
    },
    deleteSelectedEntries () {
      this.setDialog({ show: true, type: 'delete', info: { itemType: 'entries', selected: this.selectedEntries } })
    },
    createConfig () {
      this.setDialog({ show: true, type: 'config', info: {} })
    },
    createEntry () {
      this.setDialog({ show: true, type: 'entry', info: {} })
    },
    assignConfig (item) {
      this.setDialog({ show: true, type: 'assign', info: item })
    },
    editConfig (item) {
      this.setDialog({ show: true, type: 'config', info: item })
    },
    editEntry (item) {
      this.setDialog({ show: true, type: 'entry', info: item })
    },
    async setAsDefault (id) {
      await this.$http.put('/api/ipxeconfigs/' + id + '/default')
      this.$snackbar({ text: this.$t('successSetAsDefault'), color: 'success', timeout: 2000 })
      this.$store.dispatch('configurator/loadData')
    }
  },
  created () {
    this.$store.dispatch('configurator/loadData')
    this.$store.dispatch('groups/loadGroupList')
    this.$store.dispatch('groups/loadClientList')
  }
}
</script>

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