From ecfac78f6ef2cc01e4397c1a92b9a59b7ff0b2ff Mon Sep 17 00:00:00 2001 From: Romain Date: Wed, 29 Sep 2021 22:53:12 +0200 Subject: [PATCH] Kanban colored boards (#16647) Add a column Color in ProjectBoard and color picker in new / edit project board form. --- models/migrations/migrations.go | 2 + models/migrations/v196.go | 22 ++++++++++ models/project_board.go | 20 ++++++++- options/locale/locale_en-US.ini | 3 +- routers/web/repo/projects.go | 3 ++ services/forms/repo_form.go | 1 + templates/repo/graph.tmpl | 2 +- templates/repo/projects/view.tmpl | 24 +++++++++- templates/repo/settings/webhook/slack.tmpl | 2 +- web_src/js/features/projects.js | 51 ++++++++++++++++++++-- web_src/js/index.js | 21 ++++++--- web_src/less/_base.less | 15 +++++++ web_src/less/_repository.less | 13 ------ web_src/less/features/projects.less | 39 +++++++++++++++++ 14 files changed, 187 insertions(+), 31 deletions(-) create mode 100644 models/migrations/v196.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 753ca063d..33b094e48 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 000000000..c0332c7bb --- /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 6a3586851..e6c9f0338 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 diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e6a29a5c8..028c25a76 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -96,6 +96,7 @@ error = Error error404 = The page you are trying to reach either does not exist or you are not authorized to view it. never = Never +color = Color [error] occurred = An error has occurred @@ -977,7 +978,6 @@ commit_graph = Commit Graph commit_graph.select = Select branches commit_graph.hide_pr_refs = Hide Pull Requests commit_graph.monochrome = Mono -commit_graph.color = Color blame = Blame normal_view = Normal View line = line @@ -1793,7 +1793,6 @@ settings.slack_username = Username settings.slack_icon_url = Icon URL settings.discord_username = Username settings.discord_icon_url = Icon URL -settings.slack_color = Color settings.event_desc = Trigger On: settings.event_push_only = Push Events settings.event_send_everything = All Events diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 556656e5b..2490efc92 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -444,6 +444,7 @@ func AddBoardToProjectPost(ctx *context.Context) { if err := models.NewProjectBoard(&models.ProjectBoard{ ProjectID: project.ID, Title: form.Title, + Color: form.Color, CreatorID: ctx.User.ID, }); err != nil { ctx.ServerError("NewProjectBoard", err) @@ -513,6 +514,8 @@ func EditProjectBoard(ctx *context.Context) { board.Title = form.Title } + board.Color = form.Color + if form.Sorting != 0 { board.Sorting = form.Sorting } diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 1210d5dfc..7c61be5e2 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -499,6 +499,7 @@ type UserCreateProjectForm struct { type EditProjectBoardForm struct { Title string `binding:"Required;MaxSize(100)"` Sorting int8 + Color string `binding:"MaxSize(7)"` } // _____ .__.__ __ diff --git a/templates/repo/graph.tmpl b/templates/repo/graph.tmpl index e3b5cd387..963bf0449 100644 --- a/templates/repo/graph.tmpl +++ b/templates/repo/graph.tmpl @@ -47,7 +47,7 @@ - +
diff --git a/templates/repo/projects/view.tmpl b/templates/repo/projects/view.tmpl index 9d08462b1..082f4d8eb 100644 --- a/templates/repo/projects/view.tmpl +++ b/templates/repo/projects/view.tmpl @@ -11,7 +11,7 @@ {{.i18n.Tr "repo.issues.new"}} {{.i18n.Tr "new_project_board"}} {{end}} -