flaschengeist-frontend/src/router/index.js

193 lines
4.9 KiB
JavaScript
Raw Normal View History

2019-12-20 13:01:36 +00:00
import Vue from 'vue'
import VueRouter from 'vue-router'
2020-01-14 21:01:24 +00:00
import FinanzerView from '@/views/FinanzerView'
import Login from '@/views/Login'
import store from '@/store/index'
2020-01-17 00:01:10 +00:00
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'
2020-01-18 11:49:49 +00:00
import ServiceManagement from '../components/vorstand/ServiceManagement'
2020-02-16 19:35:13 +00:00
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";
2020-03-03 21:29:32 +00:00
import UserManager from "@/components/vorstand/UserManager";
2019-12-20 13:01:36 +00:00
Vue.use(VueRouter)
const routes = [
2020-03-04 22:10:18 +00:00
{
path: '/cookies',
name: 'cookies',
},
2020-02-27 20:54:28 +00:00
{
path: '/pricelist',
name: 'priceListNoLogin',
component: PriceListView
2020-02-27 20:54:28 +00:00
},
2019-12-20 13:01:36 +00:00
{
2020-01-14 21:01:24 +00:00
path: '/login',
name: 'login',
2019-12-21 07:20:25 +00:00
component: Login
2019-12-20 13:01:36 +00:00
},
2019-12-21 07:20:25 +00:00
{
2020-01-17 00:01:10 +00:00
path: '/main',
name: 'main',
component: MainView,
children: [
{
path: 'management',
name: 'management',
components: { nav: ManagementNavigation, default: BarView},
children: [
{
path: 'servicemanagement',
component: ServiceManagement
2020-03-03 21:29:32 +00:00
},
{
path: 'usermanager',
component: UserManager
}
]
},
2020-01-17 00:01:10 +00:00
{
path: 'user',
name: 'user',
components: { nav: UserNavigation, default: UserView },
2020-01-17 00:01:10 +00:00
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
2020-01-17 00:01:10 +00:00
}
]
},
{
path: 'bar',
name: 'bar',
components: { nav: BarNavigation, default: BarView },
2020-01-17 00:01:10 +00:00
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: [
2020-01-18 11:49:49 +00:00
{
path: 'pricelist',
name: 'gastroPricelist',
component: PriceList
}
]
2020-01-17 00:01:10 +00:00
}
]
2019-12-21 07:20:25 +00:00
},
{
path: '*',
redirect: {
2020-01-14 21:01:24 +00:00
name: 'login'
2019-12-21 07:20:25 +00:00
}
2020-01-14 21:01:24 +00:00
}
2019-12-20 13:01:36 +00:00
]
const router = new VueRouter({
2019-12-21 07:20:25 +00:00
mode: 'history',
base: process.env.BASE_URL,
2019-12-20 13:01:36 +00:00
routes
})
2019-12-21 07:20:25 +00:00
router.beforeEach((to, from, next) => {
2020-01-14 21:01:24 +00:00
store.dispatch('fetchAccessToken')
2020-01-17 00:01:10 +00:00
if (to.fullPath.includes('/main')) {
if (to.fullPath.includes('/main/finanzer')) {
if (!store.state.login.user.group.includes('moneymaster')) {
next('/login')
}
}
2020-01-17 00:01:10 +00:00
if (to.fullPath.includes('/main/bar')) {
if (!store.state.login.user.group.includes('bar')) {
next('/login')
}
}
2020-01-17 00:01:10 +00:00
if (to.fullPath.includes('/main/user')) {
if (!store.state.login.user.group.includes('user')) {
next('/login')
}
}
if (!store.state.login.user.accessToken) {
2019-12-21 07:20:25 +00:00
next('/login')
}
}
if (to.fullPath === '/login') {
if (store.state.login.user.accessToken) {
if (store.state.login.user.group.includes('moneymaster')) {
2020-02-27 21:19:31 +00:00
next('/main/finanzer/overview')
} else if (store.state.login.user.group.includes('bar')) {
2020-01-17 00:01:10 +00:00
next('/main/bar/geruecht')
} else if (store.state.login.user.group.includes('user')) {
next('/main/user/add')
2020-03-04 20:12:08 +00:00
} else if (store.state.login.user.group.includes('extern')) {
next('/main')
}
2019-12-21 07:20:25 +00:00
}
}
2020-01-14 21:01:24 +00:00
next()
})
2019-12-21 07:20:25 +00:00
2019-12-20 13:01:36 +00:00
export default router