diff options
author | Romain <romdum@users.noreply.github.com> | 2021-09-29 22:53:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-29 22:53:12 +0200 |
commit | ecfac78f6ef2cc01e4397c1a92b9a59b7ff0b2ff (patch) | |
tree | 161b9c6fcae7bbda0a827f565fdcc07cadd756ee /models/project_board.go | |
parent | ba1fdbcfdb26ce7088a7eab0175e224e5325ef72 (diff) | |
download | gitea-ecfac78f6ef2cc01e4397c1a92b9a59b7ff0b2ff.tar.gz gitea-ecfac78f6ef2cc01e4397c1a92b9a59b7ff0b2ff.zip |
Kanban colored boards (#16647)
Add a column Color in ProjectBoard and color picker in new / edit project board form.
Diffstat (limited to 'models/project_board.go')
-rw-r--r-- | models/project_board.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/models/project_board.go b/models/project_board.go index 6a35868511..e6c9f03386 100644 --- a/models/project_board.go +++ b/models/project_board.go @@ -5,6 +5,9 @@ package models import ( + "fmt" + "regexp" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" @@ -32,12 +35,16 @@ const ( ProjectBoardTypeBugTriage ) +// BoardColorPattern is a regexp witch can validate BoardColor +var BoardColorPattern = regexp.MustCompile("^#[0-9a-fA-F]{6}$") + // ProjectBoard is used to represent boards on a project type ProjectBoard struct { ID int64 `xorm:"pk autoincr"` Title string - Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board - Sorting int8 `xorm:"NOT NULL DEFAULT 0"` + Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board + Sorting int8 `xorm:"NOT NULL DEFAULT 0"` + Color string `xorm:"VARCHAR(7)"` ProjectID int64 `xorm:"INDEX NOT NULL"` CreatorID int64 `xorm:"NOT NULL"` @@ -100,6 +107,10 @@ func createBoardsForProjectsType(sess *xorm.Session, project *Project) error { // NewProjectBoard adds a new project board to a given project func NewProjectBoard(board *ProjectBoard) error { + if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) { + return fmt.Errorf("bad color code: %s", board.Color) + } + _, err := db.GetEngine(db.DefaultContext).Insert(board) return err } @@ -178,6 +189,11 @@ func updateProjectBoard(e db.Engine, board *ProjectBoard) error { fieldToUpdate = append(fieldToUpdate, "title") } + if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) { + return fmt.Errorf("bad color code: %s", board.Color) + } + fieldToUpdate = append(fieldToUpdate, "color") + _, err := e.ID(board.ID).Cols(fieldToUpdate...).Update(board) return err |