summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/DashboardPage.vue
blob: 4f7dc033c206c70128a48c93cd9abfd400b008ef (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": {
    "title": "Boot Selection Server",
    "user": "User",
    "settings": "Settings",
    "logout": "Logout"
  },
  "de": {
    "title": "Boot Auswahl Server",
    "user": "Benutzer",
    "settings": "Einstellungen",
    "logout": "Abmelden"
  }
}
</i18n>

<template>
  <v-app :dark="settings.dark" :class="{ 'no-animation': settings.noAnimations }">

    <v-navigation-drawer
      class="drawer non-selectable"
      persistent
      :mini-variant="desktop && drawerMini"
      :clipped="settings.clipped && desktop"
      v-model="drawerOpen"
      fixed
      width="250"
      app
    >
      <div class="drawer-header grey darken-4 hidden-lg-and-up"><img src="@/assets/logo.svg" /></div>
      <div v-for="category in categories" :key="category.name">
        <div class="dashboard-category text--secondary">{{ desktop && drawerMini ? '' : $t('$dashboardCategories.' + category.name) }}</div>
        <v-list>
          <v-list-tile ripple v-for="module in category.modules" :key="module.name" :to="{ name: module.name }">
            <v-list-tile-action>
              <v-icon v-html="module.icon"></v-icon>
            </v-list-tile-action>
            <v-list-tile-content>
              <v-list-tile-title v-text="$t('$dashboardModules.' + module.name)"></v-list-tile-title>
            </v-list-tile-content>
          </v-list-tile>
        </v-list>
        <v-divider></v-divider>
      </div>
    </v-navigation-drawer>

    <v-toolbar :height="$vuetify.breakpoint.smAndDown ? 56 : 64" dark app :clipped-left="settings.clipped" class="non-selectable" style="z-index: 10;" id="topbar">
      <v-toolbar-side-icon class="drawer-icon" @click.stop="toggleDrawer"></v-toolbar-side-icon>
      <div class="logo"><img class="non-draggable hidden-md-and-down" src="@/assets/logo.svg" /></div>
      <v-spacer></v-spacer>
      <v-btn v-if="devMode" icon @click="$store.commit('saveSetting', { name: 'locale', value: settings.locale === 'en' ? 'de' : 'en' })"><v-icon>language</v-icon></v-btn>
      <v-btn icon @click="$store.commit('saveSetting', { name: 'dark', value: !settings.dark })"><v-icon>invert_colors</v-icon></v-btn>
      <notifications-alerts style="margin-right: 16px"></notifications-alerts>
      <v-toolbar-items>
        <v-menu offset-y attach>
          <v-btn class="user-button" flat slot="activator" style="text-transform: none;">
            <v-icon left>account_circle</v-icon>
            <v-flex>
              {{ user.name }}
              <v-spacer></v-spacer>
              <v-subheader class="user-subheader">{{ user.username }}</v-subheader>
            </v-flex>
          </v-btn>
          <v-list>
            <v-list-tile to="/dashboard/account" active-class="">
              <v-icon class="user-menu-icon">perm_identity</v-icon>
              <v-list-tile-title>{{ $t('user') }}</v-list-tile-title>
            </v-list-tile>
            <v-list-tile to="/dashboard/settings" active-class="">
              <v-icon class="user-menu-icon">settings</v-icon>
              <v-list-tile-title>{{ $t('settings') }}</v-list-tile-title>
            </v-list-tile>
            <v-list-tile @click="logout">
              <v-icon class="user-menu-icon">power_settings_new</v-icon>
              <v-list-tile-title>{{ $t('logout') }}</v-list-tile-title>
            </v-list-tile>
          </v-list>
        </v-menu>
      </v-toolbar-items>
    </v-toolbar>

    <v-content>
      <router-view />
    </v-content>
    <back-to-top-button></back-to-top-button>
    <notifications-snackbars></notifications-snackbars>
  </v-app>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'
import BackToTopButton from '@/components/BackToTopButton'
import NotificationsAlerts from '@/components/NotificationsAlerts'
import NotificationsSnackbars from '@/components/NotificationsSnackbars'
import AccountModule from '@/components/AccountModule'
import SettingsModule from '@/components/SettingsModule'
import dashboardCategories from '@/config/dashboard'

export default {
  name: 'DashboardPage',
  routes () {
    return [
      { path: 'account', component: AccountModule },
      { path: 'settings', component: SettingsModule }
    ]
  },
  components: {
    BackToTopButton,
    NotificationsAlerts,
    NotificationsSnackbars
  },
  data () {
    return {
      categories: dashboardCategories,
      drawerMini: localStorage.getItem('drawerMini') === 'true',
      drawerOpen: localStorage.getItem('drawerOpen') !== 'false'
    }
  },
  computed: {
    ...mapState(['settings']),
    ...mapGetters(['user']),
    mini () { return this.settings.mini },
    desktop () { return this.$vuetify.breakpoint.lgAndUp },
    devMode () { return localStorage.getItem('dev') === 'true' }
  },
  watch: {
    mini (value) {
      if (value) {
        this.drawerMini = !this.drawerOpen
        this.drawerOpen = true
      } else {
        this.drawerOpen = !this.drawerMini
        this.drawerMini = false
      }
    },
    drawerMini (value) { localStorage.setItem('drawerMini', value) },
    drawerOpen (value) { localStorage.setItem('drawerOpen', value) }
  },
  methods: {
    ...mapMutations(['setLoginRedirect']),
    toggleDrawer () {
      if (this.settings.mini && this.desktop) this.drawerMini = !this.drawerMini
      else this.drawerOpen = !this.drawerOpen
    },
    logout () {
      this.$http.post('/api/authentication/logout').then(response => {
        this.setLoginRedirect(this.$route.fullPath)
        this.$router.push('/login')
        this.$socket.close()
      })
    }
  },
  created () {
    if (this.settings.mini && this.desktop) this.drawerOpen = true
    this.$store.dispatch('loadUser')
  }
}
</script>

<style scoped>

.dashboard-category {
  padding: 16px 0 0 32px;
}

.logo {
  height: 100%;
  overflow: hidden;
}

.logo > img {
  margin-top: -160px;
  margin-left: 20px;
  height: 400px;
}

.drawer {
  z-index: 11;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
}

.drawer-header > img {
  height: 60%;
}

.user-button {
  min-width: 160px;
}

.user-menu-icon {
  margin-right: 8px;
}

.user-subheader {
  height: unset;
  justify-content: center;
  font-size: 8pt;
}

</style>