1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Rename boardview type -> template type

This commit is contained in:
Lunny Xiao
2024-03-30 21:01:51 +08:00
parent ecdc683cc1
commit 311a82ff72
9 changed files with 90 additions and 90 deletions

View File

@@ -1,45 +0,0 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package project
type (
// BoardViewType is used to represent a project column type
BoardViewType uint8
// BoardConfig is used to identify the type of board that is being created
BoardConfig struct {
BoardType BoardViewType
Translation string
}
)
const (
// BoardViewTypeNone is a project board view type that has no predefined columns
BoardViewTypeNone BoardViewType = iota
// BoardViewTypeBasicKanban is a project board view type that has basic predefined columns
BoardViewTypeBasicKanban
// BoardViewTypeBugTriage is a project board view type that has predefined columns suited to hunting down bugs
BoardViewTypeBugTriage
)
// GetBoardViewConfig retrieves the types of configurations project boards could have
func GetBoardViewConfig() []BoardConfig {
return []BoardConfig{
{BoardViewTypeNone, "repo.projects.type.none"},
{BoardViewTypeBasicKanban, "repo.projects.type.basic_kanban"},
{BoardViewTypeBugTriage, "repo.projects.type.bug_triage"},
}
}
// IsBoardViewTypeValid checks if the project board type is valid
func IsBoardViewTypeValid(p BoardViewType) bool {
switch p {
case BoardViewTypeNone, BoardViewTypeBasicKanban, BoardViewTypeBugTriage:
return true
default:
return false
}
}

View File

@@ -83,15 +83,15 @@ func IsCardTypeValid(p CardType) bool {
} }
} }
func createColumnsForProjectsBoradViewType(ctx context.Context, project *Project) error { func createDefaultColumnsForProject(ctx context.Context, project *Project) error {
var items []string var items []string
switch project.BoardViewType { switch project.TemplateType {
case BoardViewTypeBugTriage: case TemplateTypeBugTriage:
items = setting.Project.ProjectBoardBugTriageType items = setting.Project.ProjectBoardBugTriageType
case BoardViewTypeBasicKanban: case TemplateTypeBasicKanban:
items = setting.Project.ProjectBoardBasicKanbanType items = setting.Project.ProjectBoardBasicKanbanType
case BoardViewTypeNone: case TemplateTypeNone:
fallthrough fallthrough
default: default:
return nil return nil

View File

@@ -83,18 +83,18 @@ func (err ErrProjectColumnNotExist) Unwrap() error {
// Project represents a project // Project represents a project
type Project struct { type Project struct {
ID int64 `xorm:"pk autoincr"` ID int64 `xorm:"pk autoincr"`
Title string `xorm:"INDEX NOT NULL"` Title string `xorm:"INDEX NOT NULL"`
Description string `xorm:"TEXT"` Description string `xorm:"TEXT"`
OwnerID int64 `xorm:"INDEX"` OwnerID int64 `xorm:"INDEX"`
Owner *user_model.User `xorm:"-"` Owner *user_model.User `xorm:"-"`
RepoID int64 `xorm:"INDEX"` RepoID int64 `xorm:"INDEX"`
Repo *repo_model.Repository `xorm:"-"` Repo *repo_model.Repository `xorm:"-"`
CreatorID int64 `xorm:"NOT NULL"` CreatorID int64 `xorm:"NOT NULL"`
IsClosed bool `xorm:"INDEX"` IsClosed bool `xorm:"INDEX"`
BoardViewType BoardViewType `xorm:"'board_type'"` TemplateType TemplateType `xorm:"'board_type'"`
CardType CardType CardType CardType
Type Type Type Type
RenderedContent template.HTML `xorm:"-"` RenderedContent template.HTML `xorm:"-"`
@@ -229,8 +229,8 @@ func GetSearchOrderByBySortType(sortType string) db.SearchOrderBy {
// NewProject creates a new Project // NewProject creates a new Project
func NewProject(ctx context.Context, p *Project) error { func NewProject(ctx context.Context, p *Project) error {
if !IsBoardViewTypeValid(p.BoardViewType) { if !IsTemplateTypeValid(p.TemplateType) {
p.BoardViewType = BoardViewTypeNone p.TemplateType = TemplateTypeNone
} }
if !IsCardTypeValid(p.CardType) { if !IsCardTypeValid(p.CardType) {
@@ -252,7 +252,7 @@ func NewProject(ctx context.Context, p *Project) error {
} }
} }
return createColumnsForProjectsBoradViewType(ctx, p) return createDefaultColumnsForProject(ctx, p)
}) })
} }

View File

@@ -51,13 +51,13 @@ func TestProject(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
project := &Project{ project := &Project{
Type: TypeRepository, Type: TypeRepository,
BoardViewType: BoardViewTypeBasicKanban, TemplateType: TemplateTypeBasicKanban,
CardType: CardTypeTextOnly, CardType: CardTypeTextOnly,
Title: "New Project", Title: "New Project",
RepoID: 1, RepoID: 1,
CreatedUnix: timeutil.TimeStampNow(), CreatedUnix: timeutil.TimeStampNow(),
CreatorID: 2, CreatorID: 2,
} }
assert.NoError(t, NewProject(db.DefaultContext, project)) assert.NoError(t, NewProject(db.DefaultContext, project))

View File

@@ -0,0 +1,45 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package project
type (
// TemplateType is used to represent a project template type
TemplateType uint8
// TemplateConfig is used to identify the template type of project that is being created
TemplateConfig struct {
TemplateType TemplateType
Translation string
}
)
const (
// TemplateTypeNone is a project template type that has no predefined columns
TemplateTypeNone TemplateType = iota
// TemplateTypeBasicKanban is a project template type that has basic predefined columns
TemplateTypeBasicKanban
// TemplateTypeBugTriage is a project template type that has predefined columns suited to hunting down bugs
TemplateTypeBugTriage
)
// GetTemplateConfigs retrieves the template configs of configurations project boards could have
func GetTemplateConfigs() []TemplateConfig {
return []TemplateConfig{
{TemplateTypeNone, "repo.projects.type.none"},
{TemplateTypeBasicKanban, "repo.projects.type.basic_kanban"},
{TemplateTypeBugTriage, "repo.projects.type.bug_triage"},
}
}
// IsTemplateTypeValid checks if the project board type is valid
func IsTemplateTypeValid(p TemplateType) bool {
switch p {
case TemplateTypeNone, TemplateTypeBasicKanban, TemplateTypeBugTriage:
return true
default:
return false
}
}

View File

@@ -141,7 +141,7 @@ func canWriteProjects(ctx *context.Context) bool {
// RenderNewProject render creating a project page // RenderNewProject render creating a project page
func RenderNewProject(ctx *context.Context) { func RenderNewProject(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.new") ctx.Data["Title"] = ctx.Tr("repo.projects.new")
ctx.Data["BoardTypes"] = project_model.GetBoardViewConfig() ctx.Data["TemplateConfigs"] = project_model.GetTemplateConfigs()
ctx.Data["CardTypes"] = project_model.GetCardConfig() ctx.Data["CardTypes"] = project_model.GetCardConfig()
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
ctx.Data["PageIsViewProjects"] = true ctx.Data["PageIsViewProjects"] = true
@@ -170,12 +170,12 @@ func NewProjectPost(ctx *context.Context) {
} }
newProject := project_model.Project{ newProject := project_model.Project{
OwnerID: ctx.ContextUser.ID, OwnerID: ctx.ContextUser.ID,
Title: form.Title, Title: form.Title,
Description: form.Content, Description: form.Content,
CreatorID: ctx.Doer.ID, CreatorID: ctx.Doer.ID,
BoardViewType: form.BoardType, TemplateType: form.BoardType,
CardType: form.CardType, CardType: form.CardType,
} }
if ctx.ContextUser.IsOrganization() { if ctx.ContextUser.IsOrganization() {

View File

@@ -132,7 +132,7 @@ func Projects(ctx *context.Context) {
// RenderNewProject render creating a project page // RenderNewProject render creating a project page
func RenderNewProject(ctx *context.Context) { func RenderNewProject(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.new") ctx.Data["Title"] = ctx.Tr("repo.projects.new")
ctx.Data["BoardTypes"] = project_model.GetBoardViewConfig() ctx.Data["TemplateConfigs"] = project_model.GetTemplateConfigs()
ctx.Data["CardTypes"] = project_model.GetCardConfig() ctx.Data["CardTypes"] = project_model.GetCardConfig()
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
ctx.Data["CancelLink"] = ctx.Repo.Repository.Link() + "/projects" ctx.Data["CancelLink"] = ctx.Repo.Repository.Link() + "/projects"
@@ -150,13 +150,13 @@ func NewProjectPost(ctx *context.Context) {
} }
if err := project_model.NewProject(ctx, &project_model.Project{ if err := project_model.NewProject(ctx, &project_model.Project{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
Title: form.Title, Title: form.Title,
Description: form.Content, Description: form.Content,
CreatorID: ctx.Doer.ID, CreatorID: ctx.Doer.ID,
BoardViewType: form.BoardType, TemplateType: form.BoardType,
CardType: form.CardType, CardType: form.CardType,
Type: project_model.TypeRepository, Type: project_model.TypeRepository,
}); err != nil { }); err != nil {
ctx.ServerError("NewProject", err) ctx.ServerError("NewProject", err)
return return

View File

@@ -508,7 +508,7 @@ func (i IssueLockForm) HasValidReason() bool {
type CreateProjectForm struct { type CreateProjectForm struct {
Title string `binding:"Required;MaxSize(100)"` Title string `binding:"Required;MaxSize(100)"`
Content string Content string
BoardType project_model.BoardViewType BoardType project_model.TemplateType // NOTE: don't change the name except you know what you are doing
CardType project_model.CardType CardType project_model.CardType
} }
@@ -517,7 +517,7 @@ type CreateProjectForm struct {
type UserCreateProjectForm struct { type UserCreateProjectForm struct {
Title string `binding:"Required;MaxSize(100)"` Title string `binding:"Required;MaxSize(100)"`
Content string Content string
BoardType project_model.BoardViewType BoardType project_model.TemplateType
CardType project_model.CardType CardType project_model.CardType
UID int64 `binding:"Required"` UID int64 `binding:"Required"`
} }

View File

@@ -28,7 +28,7 @@
<input type="hidden" name="board_type" value="{{.type}}"> <input type="hidden" name="board_type" value="{{.type}}">
<div class="default text">{{ctx.Locale.Tr "repo.projects.template.desc_helper"}}</div> <div class="default text">{{ctx.Locale.Tr "repo.projects.template.desc_helper"}}</div>
<div class="menu"> <div class="menu">
{{range $element := .BoardTypes}} {{range $element := .TemplateConfigs}}
<div class="item" data-id="{{$element.BoardType}}" data-value="{{$element.BoardType}}">{{ctx.Locale.Tr $element.Translation}}</div> <div class="item" data-id="{{$element.BoardType}}" data-value="{{$element.BoardType}}">{{ctx.Locale.Tr $element.Translation}}</div>
{{end}} {{end}}
</div> </div>