mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
[auth] Added auth guard
This commit is contained in:
1 parent
ef6369714b
commit
1e86dbbbb3
5 files changed
+44
-21
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
|
||||
import store from '@/store'
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
@@ -16,17 +17,20 @@ const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/auth/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/plugins/lib@auth/login/login.vue')
|
||||
component: () => import('@/plugins/lib@auth/login/login.vue'),
|
||||
meta: {requiresAuth: false}
|
||||
},
|
||||
{
|
||||
path: '/auth/forgot-password',
|
||||
name: 'Forgot password',
|
||||
component: () => import('@/plugins/lib@auth/forgot-password/forgot-password.vue')
|
||||
component: () => import('@/plugins/lib@auth/forgot-password/forgot-password.vue'),
|
||||
meta: {requiresAuth: false}
|
||||
},
|
||||
{
|
||||
path: '/auth/reset-password',
|
||||
name: 'Reset password',
|
||||
component: () => import('@/plugins/lib@auth/reset-password/reset-password.vue')
|
||||
component: () => import('@/plugins/lib@auth/reset-password/reset-password.vue'),
|
||||
meta: {requiresAuth: false}
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -45,50 +49,50 @@ const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/app/dashboard/tasks',
|
||||
name: 'Dashboard - Tasks',
|
||||
meta: { title: 'Tasks' },
|
||||
meta: { title: 'Tasks', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@dashboard/tasks/tasks.vue')
|
||||
},
|
||||
{
|
||||
path: '/app/dashboard/teams',
|
||||
name: 'Dashboard - Teams',
|
||||
meta: { title: 'Teams Overview' },
|
||||
meta: { title: 'Teams Overview', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@dashboard/teams/teams.vue')
|
||||
},
|
||||
{
|
||||
path: '/app/dashboard/projects',
|
||||
name: 'Dashboard - Projects',
|
||||
meta: { title: 'Projects overview' },
|
||||
meta: { title: 'Projects overview', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@dashboard/projects/projects.vue')
|
||||
},
|
||||
|
||||
{
|
||||
path: '/app/overview/unscheduled',
|
||||
name: 'Overview - Unscheduled tasks',
|
||||
meta: { title: 'Unscheduled tasks' },
|
||||
meta: { title: 'Unscheduled tasks', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@overview/tasks-unscheduled/tasks-unscheduled.vue')
|
||||
},
|
||||
{
|
||||
path: '/app/overview/ongoing',
|
||||
name: 'Overview - Ongoing tasks',
|
||||
meta: { title: 'Ongoing tasks' },
|
||||
meta: { title: 'Ongoing tasks', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@overview/tasks-ongoing/tasks-ongoing.vue')
|
||||
},
|
||||
{
|
||||
path: '/app/overview/teams',
|
||||
name: 'Overview - Teams',
|
||||
meta: { title: 'Teams' },
|
||||
meta: { title: 'Teams', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@overview/teams/teams.vue')
|
||||
},
|
||||
{
|
||||
path: '/app/dashboard/user',
|
||||
name: 'Dashboard - User',
|
||||
meta: { title: 'Profile' },
|
||||
meta: { title: 'Profile', requiresAuth: true },
|
||||
component: () => import('@/plugins/tm@profile/profile/my-profile.vue')
|
||||
},
|
||||
{
|
||||
path: '/app/search',
|
||||
name: 'Search',
|
||||
meta: { title: 'Search Results' },
|
||||
meta: { title: 'Search Results', requiresAuth: true },
|
||||
component: () => import('@/plugins/lib@search/search/search.vue')
|
||||
}
|
||||
]
|
||||
@@ -98,7 +102,8 @@ const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/:catchAll(.*)',
|
||||
name: '404',
|
||||
component: () => import('@/plugins/w@screen/404/404.vue')
|
||||
component: () => import('@/plugins/w@screen/404/404.vue'),
|
||||
meta: {requiresAuth: null}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -107,4 +112,22 @@ const router = createRouter({
|
||||
routes
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const isLoggedIn = store.getters['auth/isLoggedIn']
|
||||
|
||||
if (to.meta.requiresAuth === true) {
|
||||
if (isLoggedIn)
|
||||
return next()
|
||||
else
|
||||
return next({name: 'Login'})
|
||||
} else if (to.meta.requiresAuth === false) {
|
||||
if (!isLoggedIn)
|
||||
return next()
|
||||
else
|
||||
return next({name: 'Dashboard - Tasks'})
|
||||
} else {
|
||||
return next({name: 'Login'})
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -35,13 +35,12 @@ export default {
|
||||
splitDays() {
|
||||
const days = []
|
||||
const workingHours = {}
|
||||
const capacityPerDay = this.$store.getters['auth/user'].work_end - this.$store.getters['auth/user'].work_start
|
||||
|
||||
this.timelineData.tasks.forEach(task => {
|
||||
if (!workingHours[task.split])
|
||||
workingHours[task.split] = 0
|
||||
|
||||
if (task.nonWorking)
|
||||
if (task.nonWorking || task.subtask.is_finished)
|
||||
return
|
||||
|
||||
workingHours[task.split] += timelineUtils._getDifferenceInHours(task.end, task.start)
|
||||
@@ -52,7 +51,7 @@ export default {
|
||||
id: i + 1,
|
||||
fullname: `${this.filter.employee.name} ${this.filter.employee.surname}`,
|
||||
initials: this.filter.employee.name.charAt(0).toUpperCase() + this.filter.employee.surname.charAt(0).toUpperCase(),
|
||||
unscheduledTime: capacityPerDay - workingHours[i + 1],
|
||||
unscheduledTime: workingHours[i + 1],
|
||||
date: addDays(this.filter.start, i),
|
||||
isWeekend: timelineUtils.isWeekend(addDays(this.filter.start, i))
|
||||
})
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
label="Nenaplánované hodiny"
|
||||
v-model="time"
|
||||
variant="outlined"
|
||||
:disabled="true"
|
||||
></v-text-field>
|
||||
</v-row>
|
||||
</template>
|
||||
|
||||
@@ -37,7 +37,6 @@ export default {
|
||||
|
||||
this.filter.team.employees.forEach((employee, index) => {
|
||||
let workingHours = 0
|
||||
const capacityPerDay = employee.work_end - employee.work_start
|
||||
|
||||
this.timelineData.tasks.forEach(task => {
|
||||
if (task?.subtask?.employee_id == employee.id)
|
||||
@@ -49,7 +48,7 @@ export default {
|
||||
name: employee.name,
|
||||
fullname: `${employee.name} ${employee.surname}`,
|
||||
initials: employee.name.charAt(0).toUpperCase() + employee.surname.charAt(0).toUpperCase(),
|
||||
unscheduledTime: capacityPerDay - workingHours
|
||||
unscheduledTime: workingHours
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<v-dialog v-model="visible" max-width="750">
|
||||
<v-card>
|
||||
<div class="d-flex justify-space-between align-center">
|
||||
<h1>Ste si istý, že chcete {{ this.subtask.is_finished ? 'znovu otvoriť' : 'dokončiť' }} task, z masterTasku <b>{{ subtask?.master_task?.name || subtask.master_task }}</b>?</h1>
|
||||
<h1>Ste si istý, že chcete {{ subtask.is_finished ? 'znovu otvoriť' : 'dokončiť' }} task, z masterTasku <b>{{ subtask?.master_task?.name || subtask.master_task }}</b>?</h1>
|
||||
<v-icon
|
||||
@click.stop="visible = false"
|
||||
icon="mdi-close"
|
||||
@@ -36,12 +36,13 @@ export default {
|
||||
|
||||
async complete() {
|
||||
try {
|
||||
const tempSubtask = {...this.subtask, is_finished: !this.subtask.is_finished}
|
||||
const tempSubtask = {...this.subtask, is_finished: this.subtask.is_finished ? 0 : 1}
|
||||
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${tempSubtask.id}`, tempSubtask)
|
||||
|
||||
this.visible = false
|
||||
|
||||
this.$store.commit('tm/update_subtask', subtask)
|
||||
this.$store.dispatch('tm/loadMastertasks')
|
||||
this.$store.dispatch('tm/loadUnscheduledSubtasks')
|
||||
this.$store.dispatch('tm/loadOngoingSubtasks')
|
||||
this.$emit('on-subtask-edited', subtask)
|
||||
} catch (error) {
|
||||
this.$toast.error(error)
|
||||
|
||||
Reference in new issue
Block a user