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

<template>
  <v-container fill-height>
    <v-layout>
      <v-flex xl10 offset-xl1 lg12>
        <v-card class="tabbar-card non-selectable" style="display: flex; justify-content: space-between" :color="tabsColor">
          <v-tabs :value="activeTab" @change="setActiveTab" :dark="tabsDark" :color="tabsColor" :slider-color="tabsSliderColor" style="overflow-x: hidden;">
            <template v-for="(item, index) in tabChain">
              <v-icon v-if="item.id > 0 || item.id === 'create'" :key="'arrow' + index">keyboard_arrow_right</v-icon>
              <v-tab ripple :key="'tab' + index">
                <v-icon v-if="item.tabType === 'group' && item.id === 0">home</v-icon>
                <v-icon v-if="item.tabType === 'client'" class="tabbar-tabicon">computer</v-icon>
                <div v-if="item.id > 0 || item.id === 'create'" class="tab-text">{{ item.name ? item.name : item.id !== 'create' ? item.id : ' . . . . . . . . . . ' }}</div>
              </v-tab>
            </template>
          </v-tabs>
          <v-btn icon :loading="reloading" @click="reload"><v-icon>refresh</v-icon></v-btn>
        </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" lazy>
            <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>
      </v-flex>
    </v-layout>
    <group-module-dialog />
  </v-container>
</template>

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

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

<style scoped>
.tab-text {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>