flaschengeist-frontend/src/router/index.js

193 lines
4.9 KiB
JavaScript

import Vue from 'vue'
import VueRouter from 'vue-router'
import FinanzerView from '@/views/FinanzerView'
import Login from '@/views/Login'
import store from '@/store/index'
import GeruechteView from '../views/contents/GeruechteView'
import AddAmount from '../components/user/AddAmount'
import CreditOverview from '../components/user/CreditOverview'
import MainView from '../views/MainView'
import UserView from '../views/UserView'
import BarView from '../views/BarView'
import UserNavigation from '../components/user/UserNavigation'
import BarNavigation from '../components/baruser/BarNavigation'
import FinanzerNavigation from '../components/finanzer/FinanzerNavigation'
import Overview from '../components/finanzer/Overview'
import User from '../components/finanzer/User'
import ServiceManagement from '../components/vorstand/ServiceManagement'
import Config from '@/components/user/Config'
import Jobs from '@/components/user/Jobs'
import JobRequests from '@/components/user/JobRequests'
import PriceList from '@/components/pricelist/PriceList'
import ManagementNavigation from "@/components/vorstand/ManagementNavigation";
import GastroNavigation from "@/components/gastro/GastroNavigation";
import PriceListView from "@/views/contents/PriceListView";
import UserManager from "@/components/vorstand/UserManager";
Vue.use(VueRouter)
const routes = [
{
path: '/cookies',
name: 'cookies',
},
{
path: '/pricelist',
name: 'priceListNoLogin',
component: PriceListView
},
{
path: '/login',
name: 'login',
component: Login
},
{
path: '/main',
name: 'main',
component: MainView,
children: [
{
path: 'management',
name: 'management',
components: { nav: ManagementNavigation, default: BarView},
children: [
{
path: 'servicemanagement',
component: ServiceManagement
},
{
path: 'usermanager',
component: UserManager
}
]
},
{
path: 'user',
name: 'user',
components: { nav: UserNavigation, default: UserView },
children: [
{
path: 'add',
name: 'add',
component: AddAmount
},
{
path: 'overview',
name: 'userOverview',
component: CreditOverview
},
{
path: 'config',
name: 'userConfig',
component: Config
},
{
path: 'jobs',
name: 'userJobs',
component: Jobs
},
{
path: 'jobRequests',
name: 'jobRequests',
component: JobRequests
}
]
},
{
path: 'bar',
name: 'bar',
components: { nav: BarNavigation, default: BarView },
children: [
{
path: 'geruecht',
name: 'geruecht',
component: GeruechteView
}
]
},
{
path: 'finanzer',
name: 'finanzer',
components: { default: FinanzerView, nav: FinanzerNavigation },
children: [
{
path: 'overview',
component: Overview
},
{
path: 'user/:id',
name: 'activeUser',
props: true,
component: User
}
]
},
{
path: 'gastro',
name: 'gastro',
components: { nav: GastroNavigation, default: BarView},
children: [
{
path: 'pricelist',
name: 'gastroPricelist',
component: PriceList
}
]
}
]
},
{
path: '*',
redirect: {
name: 'login'
}
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
router.beforeEach((to, from, next) => {
store.dispatch('fetchAccessToken')
if (to.fullPath.includes('/main')) {
if (to.fullPath.includes('/main/finanzer')) {
if (!store.state.login.user.group.includes('moneymaster')) {
next('/login')
}
}
if (to.fullPath.includes('/main/bar')) {
if (!store.state.login.user.group.includes('bar')) {
next('/login')
}
}
if (to.fullPath.includes('/main/user')) {
if (!store.state.login.user.group.includes('user')) {
next('/login')
}
}
if (!store.state.login.user.accessToken) {
next('/login')
}
}
if (to.fullPath === '/login') {
if (store.state.login.user.accessToken) {
if (store.state.login.user.group.includes('moneymaster')) {
next('/main/finanzer/overview')
} else if (store.state.login.user.group.includes('bar')) {
next('/main/bar/geruecht')
} else if (store.state.login.user.group.includes('user')) {
next('/main/user/add')
} else if (store.state.login.user.group.includes('extern')) {
next('/main')
}
}
}
next()
})
export default router