1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-15 14:44:41 +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
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
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
switch project.BoardViewType {
case BoardViewTypeBugTriage:
switch project.TemplateType {
case TemplateTypeBugTriage:
items = setting.Project.ProjectBoardBugTriageType
case BoardViewTypeBasicKanban:
case TemplateTypeBasicKanban:
items = setting.Project.ProjectBoardBasicKanbanType
case BoardViewTypeNone:
case TemplateTypeNone:
fallthrough
default:
return nil

View File

@ -83,18 +83,18 @@ func (err ErrProjectColumnNotExist) Unwrap() error {
// Project represents a project
type Project struct {
ID int64 `xorm:"pk autoincr"`
Title string `xorm:"INDEX NOT NULL"`
Description string `xorm:"TEXT"`
OwnerID int64 `xorm:"INDEX"`
Owner *user_model.User `xorm:"-"`
RepoID int64 `xorm:"INDEX"`
Repo *repo_model.Repository `xorm:"-"`
CreatorID int64 `xorm:"NOT NULL"`
IsClosed bool `xorm:"INDEX"`
BoardViewType BoardViewType `xorm:"'board_type'"`
CardType CardType
Type Type
ID int64 `xorm:"pk autoincr"`
Title string `xorm:"INDEX NOT NULL"`
Description string `xorm:"TEXT"`
OwnerID int64 `xorm:"INDEX"`
Owner *user_model.User `xorm:"-"`
RepoID int64 `xorm:"INDEX"`
Repo *repo_model.Repository `xorm:"-"`
CreatorID int64 `xorm:"NOT NULL"`
IsClosed bool `xorm:"INDEX"`
TemplateType TemplateType `xorm:"'board_type'"`
CardType CardType
Type Type
RenderedContent template.HTML `xorm:"-"`
@ -229,8 +229,8 @@ func GetSearchOrderByBySortType(sortType string) db.SearchOrderBy {
// NewProject creates a new Project
func NewProject(ctx context.Context, p *Project) error {
if !IsBoardViewTypeValid(p.BoardViewType) {
p.BoardViewType = BoardViewTypeNone
if !IsTemplateTypeValid(p.TemplateType) {
p.TemplateType = TemplateTypeNone
}
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())
project := &Project{
Type: TypeRepository,
BoardViewType: BoardViewTypeBasicKanban,
CardType: CardTypeTextOnly,
Title: "New Project",
RepoID: 1,
CreatedUnix: timeutil.TimeStampNow(),
CreatorID: 2,
Type: TypeRepository,
TemplateType: TemplateTypeBasicKanban,
CardType: CardTypeTextOnly,
Title: "New Project",
RepoID: 1,
CreatedUnix: timeutil.TimeStampNow(),
CreatorID: 2,
}
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
func RenderNewProject(ctx *context.Context) {
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["CanWriteProjects"] = canWriteProjects(ctx)
ctx.Data["PageIsViewProjects"] = true
@ -170,12 +170,12 @@ func NewProjectPost(ctx *context.Context) {
}
newProject := project_model.Project{
OwnerID: ctx.ContextUser.ID,
Title: form.Title,
Description: form.Content,
CreatorID: ctx.Doer.ID,
BoardViewType: form.BoardType,
CardType: form.CardType,
OwnerID: ctx.ContextUser.ID,
Title: form.Title,
Description: form.Content,
CreatorID: ctx.Doer.ID,
TemplateType: form.BoardType,
CardType: form.CardType,
}
if ctx.ContextUser.IsOrganization() {

View File

@ -132,7 +132,7 @@ func Projects(ctx *context.Context) {
// RenderNewProject render creating a project page
func RenderNewProject(ctx *context.Context) {
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["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
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{
RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
Description: form.Content,
CreatorID: ctx.Doer.ID,
BoardViewType: form.BoardType,
CardType: form.CardType,
Type: project_model.TypeRepository,
RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
Description: form.Content,
CreatorID: ctx.Doer.ID,
TemplateType: form.BoardType,
CardType: form.CardType,
Type: project_model.TypeRepository,
}); err != nil {
ctx.ServerError("NewProject", err)
return

View File

@ -508,7 +508,7 @@ func (i IssueLockForm) HasValidReason() bool {
type CreateProjectForm struct {
Title string `binding:"Required;MaxSize(100)"`
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
}
@ -517,7 +517,7 @@ type CreateProjectForm struct {
type UserCreateProjectForm struct {
Title string `binding:"Required;MaxSize(100)"`
Content string
BoardType project_model.BoardViewType
BoardType project_model.TemplateType
CardType project_model.CardType
UID int64 `binding:"Required"`
}

View File

@ -28,7 +28,7 @@
<input type="hidden" name="board_type" value="{{.type}}">
<div class="default text">{{ctx.Locale.Tr "repo.projects.template.desc_helper"}}</div>
<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>
{{end}}
</div>