1
0

feat: default view setting (#2306)

This PR adds configuration of default project view in settings, which is used when the user has not visited the project and thus last view hasn't yet been saved in projects. Updates old settings and adds "First View" option with fallback.

Resolves https://kolaente.dev/vikunja/vikunja/issues/2153

Co-authored-by: Elscrux <nickposer2102@gmail.com>
Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/2306
Reviewed-by: konrad <k@knt.li>
Co-authored-by: Elscrux <elscrux@gmail.com>
Co-committed-by: Elscrux <elscrux@gmail.com>
This commit is contained in:
Elscrux
2024-06-02 08:15:53 +00:00
committed by konrad
parent a175214aa0
commit aac01c7a35
6 changed files with 53 additions and 6 deletions

View File

@ -8,6 +8,8 @@ import ProjectList from '@/components/project/views/ProjectList.vue'
import ProjectGantt from '@/components/project/views/ProjectGantt.vue'
import ProjectTable from '@/components/project/views/ProjectTable.vue'
import ProjectKanban from '@/components/project/views/ProjectKanban.vue'
import {useAuthStore} from '@/stores/auth'
import {DEFAULT_PROJECT_VIEW_SETTINGS} from '@/modelTypes/IProjectView'
const {
projectId,
@ -19,6 +21,7 @@ const {
const router = useRouter()
const projectStore = useProjectStore()
const authStore = useAuthStore()
const currentView = computed(() => {
const project = projectStore.projects[projectId]
@ -26,17 +29,27 @@ const currentView = computed(() => {
return project?.views.find(v => v.id === viewId)
})
function redirectToFirstViewIfNecessary() {
function redirectToDefaultViewIfNecessary() {
if (viewId === 0 || !projectStore.projects[projectId]?.views.find(v => v.id === viewId)) {
// Ideally, we would do that in the router redirect, but the projects (and therefore, the views)
// are not always loaded then.
const firstViewId = projectStore.projects[projectId]?.views[0].id
if (firstViewId) {
let view
if (authStore.settings.frontendSettings.defaultView !== DEFAULT_PROJECT_VIEW_SETTINGS.FIRST) {
view = projectStore.projects[projectId]?.views.find(v => v.viewKind === authStore.settings.frontendSettings.defaultView)
}
// Use the first view as fallback if the default view is not available
if (view === undefined && projectStore.projects[projectId]?.views?.length > 0) {
view = projectStore.projects[projectId]?.views[0]
}
if (view) {
router.replace({
name: 'project.view',
params: {
projectId,
viewId: firstViewId,
viewId: view.id,
},
})
}
@ -45,13 +58,13 @@ function redirectToFirstViewIfNecessary() {
watch(
() => viewId,
redirectToFirstViewIfNecessary,
redirectToDefaultViewIfNecessary,
{immediate: true},
)
watch(
() => projectStore.projects[projectId],
redirectToFirstViewIfNecessary,
redirectToDefaultViewIfNecessary,
)
// using a watcher instead of beforeEnter because beforeEnter is not called when only the viewId changes