summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/RegistrationModule.vue
blob: 8448dd442b2e8a801b405e8eba74f55614909b87 (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": {
    "hooks": "Registration hooks",
    "createHook": "Create hook"
  },
  "de": {
    "hooks": "Registrierungs Hooks ",
    "createHook": "Hook erstellen"
  }
}
</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 hide-slider :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor">
              <v-tab><v-icon class="tabbar-tabicon">extension</v-icon>{{ $t('hooks') }}</v-tab>
          </v-tabs>
        </v-card>
        <v-tabs-items v-model="tabs" style="padding-bottom: 20px">
          <v-tab-item>
            <v-subheader>{{ $t('hooks') }}</v-subheader>
            <v-card v-if="hooks.length > 0">
              <v-list two-line>
                <draggable :value="hooks" @input="setHooks($event)" :options="{ handle:'.handle' }">
                  <v-list-tile v-for="hook in hooks" :key="hook.id" @click.stop @dblclick="editHook(hook)">
                    <v-list-tile-action class="handle">
                      <v-icon>drag_handle</v-icon>
                    </v-list-tile-action>
                    <v-list-tile-content>
                      <v-list-tile-title>{{ hook.name }}<small class="type">{{ hook.type }}</small></v-list-tile-title>
                      <v-list-tile-sub-title>{{ hook.description }}</v-list-tile-sub-title>
                    </v-list-tile-content>
                    <v-icon v-if="hook.groups.length > 0">device_hub</v-icon>
                    <v-list-tile-action>
                      <v-btn @click="editHook(hook)" icon><v-icon color="primary">edit</v-icon></v-btn>
                    </v-list-tile-action>
                    <v-list-tile-action class="delete">
                      <v-btn @click="deleteHook(hook)" icon><v-icon color="error">delete</v-icon></v-btn>
                    </v-list-tile-action>
                  </v-list-tile>
                </draggable>
              </v-list>
            </v-card>
            <div class="text-xs-right">
              <v-btn flat color="success" @click="createHook"><v-icon left>create</v-icon>{{ $t('createHook') }}</v-btn>
            </div>
          </v-tab-item>
        </v-tabs-items>
      </v-flex>
    </v-layout>
    <v-dialog
      :value="dialog.show"
      @input="setDialog({ show: $event })"
      :max-width="dialog.type === 'delete' ? '500px' : '1200px'"
      scrollable
      :persistent="dialog.type !== 'delete'"
      :fullscreen="$vuetify.breakpoint.smAndDown"
    >
      <registration-module-delete v-show="dialog.type === 'delete'" />
      <registration-module-edit v-show="dialog.type === 'edit'"/>
    </v-dialog>
  </v-container>
</template>

<script>
import draggable from 'vuedraggable'
import RegistrationModuleDelete from '@/components/RegistrationModuleDelete'
import RegistrationModuleEdit from '@/components/RegistrationModuleEdit'
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'

export default {
  name: 'RegistrationModule',
  components: {
    draggable,
    RegistrationModuleDelete,
    RegistrationModuleEdit
  },
  data () {
    return {
      tabs: 0
    }
  },
  computed: {
    ...mapGetters(['tabsDark', 'tabsColor', 'tabsSliderColor']),
    ...mapState('registration', ['hooks', 'dialog'])
  },
  methods: {
    ...mapMutations('registration', ['setDialog']),
    ...mapActions('registration', ['setHooks']),
    deleteHook (hook) {
      this.setDialog({ show: true, type: 'delete', info: hook })
    },
    editHook (hook) {
      this.setDialog({ show: true, type: 'edit', info: hook })
    },
    createHook () {
      this.setDialog({ show: true, type: 'edit', info: {} })
    }
  },
  created () {
    this.$store.dispatch('groups/loadGroupList')
    this.$store.dispatch('registration/loadHooks')
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.handle {
  margin-left: 12px;
}
.delete {
  margin-right: 12px;
}
.type {
  margin-left: 24px;
}
.hook-info {
  display: flex;
  flex-direction: row;
  width: 100%;
}
.hook-info > .hook-type {
  min-width: 60px;
}
.hook-info > .hook-name {
  white-space: nowrap;
}
.hook-info > .hook-description {
  margin-left: 40px;
  overflow: hidden;
  white-space: nowrap;
}
</style>