summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/GroupModule.vue
blob: 4d4c7658598d1175d42e56c66110a0535aa2e2b1 (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
<i18n>
{
  "en": {
  },
  "de": {
  }
}
</i18n>

<template>
  <v-container fill-height>
    <v-layout>
      <v-flex class="tabs-wrapper" xl10 offset-xl1 lg12>
          <v-card>
            <v-tabs :value="activeTab" @input="setActiveTab" :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor">
              <template v-for="(item, index) in tabChain">
                <v-icon v-if="item.tabType !== 'home'" :key="'arrow' + index">keyboard_arrow_right</v-icon>
                <v-tab ripple :key="'tab' + index">
                  <v-icon v-if="item.tabType === 'home'">home</v-icon>
                  <v-icon v-if="item.tabType === 'client'" style="margin-right: 10px">computer</v-icon>
                  <template v-if="item.tabType !== 'home'">{{ item.name || item.id || ' . . . . . . . . . . ' }}</template>
                </v-tab>
              </template>
            </v-tabs>
          </v-card>
          <v-tabs-items :value="activeTab" @input="setActiveTab" touchless style="padding-bottom: 20px">
            <v-tab-item v-for="(item, index) in tabChain" :key="index">
              <group-module-home-view v-if="item.tabType === 'home'" :home="item" />
              <group-module-group-view v-if="item.tabType === 'group'" :group="item" :tabIndex="index" />
              <group-module-client-view v-if="item.tabType === 'client'" :client="item" :tabIndex="index" />
            </v-tab-item>
          </v-tabs-items>
          <router-view />
      </v-flex>
    </v-layout>
    <group-module-dialog />
  </v-container>
</template>

<script>
import GroupModuleHomeView from '@/components/GroupModuleHomeView'
import GroupModuleGroupView from '@/components/GroupModuleGroupView'
import GroupModuleClientView from '@/components/GroupModuleClientView'
import GroupModuleDialog from '@/components/GroupModuleDialog'
import { mapState, mapGetters, mapMutations } from 'vuex'

export default {
  name: 'GroupModule',
  routes () {
    return [
      { name: 'home', path: '' },
      { name: 'group', path: ':id' },
      { name: 'client', path: 'client/:id' }
    ]
  },
  components: {
    GroupModuleHomeView,
    GroupModuleGroupView,
    GroupModuleClientView,
    GroupModuleDialog
  },
  data () {
    return {
    }
  },
  computed: {
    ...mapGetters(['tabsDark', 'tabsColor', 'tabsSliderColor']),
    ...mapState('groups', ['tabChain', 'activeTab', 'groupList', 'clientList'])
  },
  watch: {
    activeTab (index) {
      this.$router.replace({
        name: 'GroupModule.' + this.tabChain[index].tabType,
        params: { id: this.tabChain[index].id || 'create', noReload: true }
      })
    }
  },
  methods: {
    ...mapMutations('groups', ['setActiveTab', 'setTab']),
    loadItem (routeName, id) {
      const type = routeName.replace('GroupModule.', '')
      if (id === 'create') {
        this.setTab({ index: 1, item: { tabType: type } })
        this.setActiveTab(1)
      } else {
        const action = type === 'group' ? 'loadGroup' : type === 'client' ? 'loadClient' : null
        if (action) this.$store.dispatch('groups/' + action, { id, tabIndex: 1, switchTab: true })
      }
    }
  },
  created () {
    if (this.groupList.length === 0 || this.clientList.length === 0) this.$store.dispatch('groups/loadLists')
    if (this.tabChain.length === 0) this.$store.dispatch('groups/loadHome')
    this.loadItem(this.$route.name, this.$route.params.id)
    if (this.tabChain[this.activeTab].tabType !== 'home') {
      this.$router.replace({
        name: 'GroupModule.' + this.tabChain[this.activeTab].tabType,
        params: { id: this.tabChain[this.activeTab].id, noReload: true }
      })
    }
  },
  beforeRouteUpdate (to, from, next) {
    if (!to.params.noReload) this.loadItem(to.name, to.params.id)
    next()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>