vikunja-frontend/src/router/index.ts

452 lines
11 KiB
TypeScript
Raw Normal View History

import { createRouter, createWebHistory, RouteLocation } from 'vue-router'
import {saveLastVisited} from '@/helpers/saveLastVisited'
import {store} from '@/store'
2021-11-14 21:33:53 +01:00
import {getListView} from '@/helpers/saveListView'
2020-06-17 22:15:59 +02:00
import HomeComponent from '../views/Home'
import NotFoundComponent from '../views/404'
import About from '../views/About'
2018-09-08 22:27:13 +02:00
// User Handling
2020-06-17 22:15:59 +02:00
import LoginComponent from '../views/user/Login'
import RegisterComponent from '../views/user/Register'
import OpenIdAuth from '../views/user/OpenIdAuth'
import DataExportDownload from '../views/user/DataExportDownload'
// Tasks
import ShowTasksInRangeComponent from '../views/tasks/ShowTasksInRange'
import LinkShareAuthComponent from '../views/sharing/LinkSharingAuth'
import ListNamespaces from '../views/namespaces/ListNamespaces'
2021-11-01 18:19:59 +01:00
import TaskDetailViewModal from '../views/tasks/TaskDetailViewModal'
// Team Handling
import ListTeamsComponent from '../views/teams/ListTeams'
// Label Handling
import ListLabelsComponent from '../views/labels/ListLabels'
import NewLabelComponent from '../views/labels/NewLabel'
// Migration
import MigrationComponent from '../views/migrator/Migrate'
import MigrateServiceComponent from '../views/migrator/MigrateService'
2021-11-14 21:33:53 +01:00
// List Views
2021-11-14 21:33:53 +01:00
import ListList from '../views/list/ListList'
import ListGantt from '../views/list/ListGantt'
import ListTable from '../views/list/ListTable'
import ListKanban from '../views/list/ListKanban'
2021-11-01 18:19:59 +01:00
// List Settings
import ListSettingEdit from '../views/list/settings/edit'
import ListSettingBackground from '../views/list/settings/background'
import ListSettingDuplicate from '../views/list/settings/duplicate'
import ListSettingShare from '../views/list/settings/share'
import ListSettingDelete from '../views/list/settings/delete'
import ListSettingArchive from '../views/list/settings/archive'
// Namespace Settings
import NamespaceSettingEdit from '../views/namespaces/settings/edit'
import NamespaceSettingShare from '../views/namespaces/settings/share'
import NamespaceSettingArchive from '../views/namespaces/settings/archive'
import NamespaceSettingDelete from '../views/namespaces/settings/delete'
// Saved Filters
import FilterNew from '@/views/filters/FilterNew'
import FilterEdit from '@/views/filters/FilterEdit'
import FilterDelete from '@/views/filters/FilterDelete'
2020-07-27 19:53:19 +02:00
const PasswordResetComponent = () => import('../views/user/PasswordReset')
const GetPasswordResetComponent = () => import('../views/user/RequestPasswordReset')
const UserSettingsComponent = () => import('../views/user/Settings')
const UserSettingsAvatarComponent = () => import('../views/user/settings/Avatar')
const UserSettingsCaldavComponent = () => import('../views/user/settings/Caldav')
const UserSettingsDataExportComponent = () => import('../views/user/settings/DataExport')
const UserSettingsDeletionComponent = () => import('../views/user/settings/Deletion')
const UserSettingsEmailUpdateComponent = () => import('../views/user/settings/EmailUpdate')
const UserSettingsGeneralComponent = () => import('../views/user/settings/General')
const UserSettingsPasswordUpdateComponent = () => import('../views/user/settings/PasswordUpdate')
const UserSettingsTOTPComponent = () => import('../views/user/settings/TOTP')
2018-09-08 23:33:23 +02:00
// List Handling
const NewListComponent = () => import('../views/list/NewList')
2018-09-11 19:20:07 +02:00
// Namespace Handling
const NewNamespaceComponent = () => import('../views/namespaces/NewNamespace')
2020-07-27 19:53:19 +02:00
const EditTeamComponent = () => import('../views/teams/EditTeam')
const NewTeamComponent = () => import('../views/teams/NewTeam')
2021-08-20 15:17:19 +02:00
const router = createRouter({
history: createWebHistory(),
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
scrollBehavior(to, from, savedPosition) {
2019-10-20 21:40:44 +02:00
// If the user is using their forward/backward keys to navigate, we want to restore the scroll view
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
if (savedPosition) {
2019-10-20 21:40:44 +02:00
return savedPosition
}
// Scroll to anchor should still work
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
if (to.hash) {
2021-08-20 15:17:19 +02:00
return {el: document.getElementById(to.hash.slice(1))}
2019-10-20 21:40:44 +02:00
}
// Otherwise just scroll to the top
2021-08-20 15:17:19 +02:00
return {left: 0, top: 0}
2019-10-20 21:40:44 +02:00
},
2019-03-07 20:48:40 +01:00
routes: [
{
path: '/',
name: 'home',
component: HomeComponent,
2019-03-07 20:48:40 +01:00
},
2020-03-02 20:30:49 +01:00
{
2021-08-20 15:17:19 +02:00
path: '/:pathMatch(.*)*',
name: 'not-found',
component: NotFoundComponent,
},
// if you omit the last `*`, the `/` character in params will be encoded when resolving or pushing
{
path: '/:pathMatch(.*)',
name: 'bad-not-found',
2020-03-02 20:30:49 +01:00
component: NotFoundComponent,
},
2019-03-07 20:48:40 +01:00
{
path: '/login',
name: 'user.login',
component: LoginComponent,
meta: {
title: 'user.auth.login',
},
2019-03-07 20:48:40 +01:00
},
{
path: '/get-password-reset',
name: 'user.password-reset.request',
component: GetPasswordResetComponent,
meta: {
title: 'user.auth.resetPassword',
},
2019-03-07 20:48:40 +01:00
},
{
path: '/password-reset',
name: 'user.password-reset.reset',
component: PasswordResetComponent,
meta: {
title: 'user.auth.resetPassword',
},
2019-03-07 20:48:40 +01:00
},
{
path: '/register',
name: 'user.register',
component: RegisterComponent,
meta: {
title: 'user.auth.register',
},
2019-03-07 20:48:40 +01:00
},
{
path: '/user/settings',
name: 'user.settings',
component: UserSettingsComponent,
redirect: {name: 'user.settings.general'},
children: [
{
path: '/user/settings/avatar',
name: 'user.settings.avatar',
component: UserSettingsAvatarComponent,
},
{
path: '/user/settings/caldav',
name: 'user.settings.caldav',
component: UserSettingsCaldavComponent,
},
{
path: '/user/settings/data-export',
name: 'user.settings.data-export',
component: UserSettingsDataExportComponent,
},
{
path: '/user/settings/deletion',
name: 'user.settings.deletion',
component: UserSettingsDeletionComponent,
},
{
path: '/user/settings/email-update',
name: 'user.settings.email-update',
component: UserSettingsEmailUpdateComponent,
},
{
path: '/user/settings/general',
name: 'user.settings.general',
component: UserSettingsGeneralComponent,
},
{
path: '/user/settings/password-update',
name: 'user.settings.password-update',
component: UserSettingsPasswordUpdateComponent,
},
{
path: '/user/settings/totp',
name: 'user.settings.totp',
component: UserSettingsTOTPComponent,
},
],
},
{
path: '/user/export/download',
name: 'user.export.download',
component: DataExportDownload,
},
{
path: '/share/:share/auth',
name: 'link-share.auth',
component: LinkShareAuthComponent,
},
{
path: '/namespaces',
name: 'namespaces.index',
component: ListNamespaces,
},
{
path: '/namespaces/new',
name: 'namespace.create',
2021-11-01 18:19:59 +01:00
component: NewNamespaceComponent,
meta: {
showAsModal: true,
},
},
2019-03-07 20:48:40 +01:00
{
path: '/namespaces/:id/settings/edit',
name: 'namespace.settings.edit',
2021-11-01 18:19:59 +01:00
component: NamespaceSettingEdit,
meta: {
showAsModal: true,
},
},
{
2021-11-30 16:58:15 +01:00
path: '/namespaces/:namespaceId/settings/share',
name: 'namespace.settings.share',
2021-11-01 18:19:59 +01:00
component: NamespaceSettingShare,
meta: {
showAsModal: true,
},
},
{
path: '/namespaces/:id/settings/archive',
name: 'namespace.settings.archive',
2021-11-01 18:19:59 +01:00
component: NamespaceSettingArchive,
meta: {
showAsModal: true,
},
},
{
path: '/namespaces/:id/settings/delete',
name: 'namespace.settings.delete',
2021-11-01 18:19:59 +01:00
component: NamespaceSettingDelete,
meta: {
showAsModal: true,
},
2019-03-07 20:48:40 +01:00
},
{
path: '/tasks/:id',
name: 'task.detail',
2021-11-01 18:19:59 +01:00
component: TaskDetailViewModal,
},
{
path: '/tasks/by/upcoming',
name: 'tasks.range',
component: ShowTasksInRangeComponent,
},
2021-11-01 18:19:59 +01:00
{
2021-11-17 18:04:53 +01:00
path: '/lists/new/:namespaceId/',
2021-11-01 18:19:59 +01:00
name: 'list.create',
component: NewListComponent,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/edit',
name: 'list.settings.edit',
2021-11-01 18:19:59 +01:00
component: ListSettingEdit,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/background',
name: 'list.settings.background',
2021-11-01 18:19:59 +01:00
component: ListSettingBackground,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/duplicate',
name: 'list.settings.duplicate',
2021-11-01 18:19:59 +01:00
component: ListSettingDuplicate,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/share',
name: 'list.settings.share',
2021-11-01 18:19:59 +01:00
component: ListSettingShare,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/delete',
name: 'list.settings.delete',
2021-11-01 18:19:59 +01:00
component: ListSettingDelete,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/archive',
name: 'list.settings.archive',
2021-11-01 18:19:59 +01:00
component: ListSettingArchive,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/edit',
name: 'filter.settings.edit',
2021-11-01 18:19:59 +01:00
component: FilterEdit,
meta: {
showAsModal: true,
},
},
{
path: '/lists/:listId/settings/delete',
name: 'filter.settings.delete',
2021-11-01 18:19:59 +01:00
component: FilterDelete,
meta: {
showAsModal: true,
},
},
2019-04-29 23:41:39 +02:00
{
Kanban (#118) Add error message when trying to create an invalid new task in a bucket Prevent creation of new buckets if the bucket title is empty Disable deleting a bucket if it's the last one Disable dragging tasks when they are being updated Fix transition when opening tasks Send the user to list view by default Show loading spinner when updating multiple tasks Add loading spinner when moving tasks Add loading animation when bucket is loading / updating etc Add bucket title edit Fix creating new buckets Add loading animation Add removing buckets Fix creating a new bucket after tasks were moved Fix warning about labels on tasks Fix labels on tasks not updating after retrieval from api Fix property width Add closing and mobile design Make the task detail popup look good Move list views Move task detail view in a popup Add link to tasks Add saving the new task position after it was moved Fix creating new bucket Fix creating a new task Cleanup Disable user selection for task cards Fix drag placeholder Add dragging style to task Add placeholder + change animation duration More cleanup Cleanup / docs Working of dragging and dropping tasks Adjust markup and styling for new library Change kanban library to something that works Add basic calculation of new positions Don't try to create empty tasks Add indicator if a task is done Add moving tasks between buckets Make empty buckets a little smaller Add gimmick for button description Fix color Fix scrolling bucket layout Add creating a new bucket Add hiding the task input field Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/118
2020-04-26 01:11:34 +02:00
path: '/lists/:listId',
name: 'list.index',
2021-11-14 21:33:53 +01:00
beforeEnter(to) {
// Redirect the user to list view by default
const savedListView = getListView(to.params.listId)
console.debug('Replaced list view with', savedListView)
return {
name: savedListView,
params: {listId: to.params.listId},
}
},
},
{
path: '/lists/:listId/list',
name: 'list.list',
component: ListList,
},
{
path: '/lists/:listId/gantt',
name: 'list.gantt',
component: ListGantt,
},
{
path: '/lists/:listId/table',
name: 'list.table',
component: ListTable,
},
{
path: '/lists/:listId/kanban',
name: 'list.kanban',
component: ListKanban,
2019-04-29 23:41:39 +02:00
},
2019-03-07 20:48:40 +01:00
{
path: '/teams',
name: 'teams.index',
component: ListTeamsComponent,
2019-03-07 20:48:40 +01:00
},
{
path: '/teams/new',
name: 'teams.create',
2021-11-01 18:19:59 +01:00
component: NewTeamComponent,
meta: {
showAsModal: true,
},
2019-03-07 20:48:40 +01:00
},
{
path: '/teams/:id/edit',
name: 'teams.edit',
component: EditTeamComponent,
2019-03-07 20:48:40 +01:00
},
{
path: '/labels',
name: 'labels.index',
component: ListLabelsComponent,
2019-09-09 19:55:43 +02:00
},
{
path: '/labels/new',
name: 'labels.create',
2021-11-01 18:19:59 +01:00
component: NewLabelComponent,
meta: {
showAsModal: true,
},
},
{
path: '/migrate',
name: 'migrate.start',
component: MigrationComponent,
},
{
2020-05-24 15:31:27 +02:00
path: '/migrate/:service',
name: 'migrate.service',
2020-05-24 15:31:27 +02:00
component: MigrateServiceComponent,
},
{
path: '/filters/new',
name: 'filters.create',
2021-11-01 18:19:59 +01:00
component: FilterNew,
meta: {
showAsModal: true,
},
},
{
path: '/auth/openid/:provider',
name: 'openid.auth',
component: OpenIdAuth,
},
{
path: '/about',
name: 'about',
component: About,
},
],
2021-08-20 15:17:19 +02:00
})
router.beforeEach((to) => {
return checkAuth(to)
})
function checkAuth(route: RouteLocation) {
const authUser = store.getters['auth/authUser']
const authLinkShare = store.getters['auth/authLinkShare']
if (authUser || authLinkShare) {
return
}
2021-08-20 15:17:19 +02:00
// Check if the user is already logged in and redirect them to the home page if not
if (
![
'user.login',
'user.password-reset.request',
'user.password-reset.reset',
'user.register',
'link-share.auth',
'openid.auth',
].includes(route.name as string) &&
localStorage.getItem('passwordResetToken') === null &&
localStorage.getItem('emailConfirmToken') === null
) {
saveLastVisited(route.name as string, route.params)
return {name: 'user.login'}
}
}
2021-08-20 15:17:19 +02:00
export default router