From e4b1a5d2db528c844b01f46cd17eea342d121343 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 14 Mar 2024 09:41:55 +0100 Subject: [PATCH] feat(views): create default 4 default view for projects --- pkg/models/project.go | 5 +++++ pkg/models/project_view.go | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/pkg/models/project.go b/pkg/models/project.go index 878c3e1a0..5e36e76bb 100644 --- a/pkg/models/project.go +++ b/pkg/models/project.go @@ -789,6 +789,11 @@ func CreateProject(s *xorm.Session, project *Project, auth web.Auth, createBackl } } + err = CreateDefaultViewsForProject(s, project, auth) + if err != nil { + return + } + return events.Dispatch(&ProjectCreatedEvent{ Project: project, Doer: doer, diff --git a/pkg/models/project_view.go b/pkg/models/project_view.go index 02b633f5e..2767e7723 100644 --- a/pkg/models/project_view.go +++ b/pkg/models/project_view.go @@ -206,3 +206,47 @@ func GetProjectViewByID(s *xorm.Session, id int64) (view *ProjectView, err error return } + +func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth) (err error) { + list := &ProjectView{ + ProjectID: project.ID, + Title: "List", + ViewKind: ProjectViewKindList, + Position: 100, + } + err = list.Create(s, a) + if err != nil { + return + } + + gantt := &ProjectView{ + ProjectID: project.ID, + Title: "Gantt", + ViewKind: ProjectViewKindGantt, + Position: 200, + } + err = gantt.Create(s, a) + if err != nil { + return + } + + table := &ProjectView{ + ProjectID: project.ID, + Title: "Table", + ViewKind: ProjectViewKindTable, + Position: 300, + } + err = table.Create(s, a) + if err != nil { + return + } + + kanban := &ProjectView{ + ProjectID: project.ID, + Title: "Kanban", + ViewKind: ProjectViewKindKanban, + Position: 400, + } + err = kanban.Create(s, a) + return +}