summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorRomain <romdum@users.noreply.github.com>2021-09-29 22:53:12 +0200
committerGitHub <noreply@github.com>2021-09-29 22:53:12 +0200
commitecfac78f6ef2cc01e4397c1a92b9a59b7ff0b2ff (patch)
tree161b9c6fcae7bbda0a827f565fdcc07cadd756ee /models
parentba1fdbcfdb26ce7088a7eab0175e224e5325ef72 (diff)
downloadgitea-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')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v196.go22
-rw-r--r--models/project_board.go20
3 files changed, 42 insertions, 2 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 753ca063d9..33b094e48c 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -344,6 +344,8 @@ var migrations = []Migration{
NewMigration("Add Branch Protection Unprotected Files Column", addBranchProtectionUnprotectedFilesColumn),
// v195 -> v196
NewMigration("Add table commit_status_index", addTableCommitStatusIndex),
+ // v196 -> v197
+ NewMigration("Add Color to ProjectBoard table", addColorColToProjectBoard),
}
// GetCurrentDBVersion returns the current db version
diff --git a/models/migrations/v196.go b/models/migrations/v196.go
new file mode 100644
index 0000000000..c0332c7bb4
--- /dev/null
+++ b/models/migrations/v196.go
@@ -0,0 +1,22 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "fmt"
+
+ "xorm.io/xorm"
+)
+
+func addColorColToProjectBoard(x *xorm.Engine) error {
+ type ProjectBoard struct {
+ Color string `xorm:"VARCHAR(7)"`
+ }
+
+ if err := x.Sync2(new(ProjectBoard)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+ return nil
+}
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