Kanban colored boards (#16647)

Add a column Color in ProjectBoard and color picker in new / edit project board form.
This commit is contained in:
Romain 2021-09-29 22:53:12 +02:00 committed by GitHub
parent ba1fdbcfdb
commit ecfac78f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 187 additions and 31 deletions

View File

@ -344,6 +344,8 @@ var migrations = []Migration{
NewMigration("Add Branch Protection Unprotected Files Column", addBranchProtectionUnprotectedFilesColumn), NewMigration("Add Branch Protection Unprotected Files Column", addBranchProtectionUnprotectedFilesColumn),
// v195 -> v196 // v195 -> v196
NewMigration("Add table commit_status_index", addTableCommitStatusIndex), NewMigration("Add table commit_status_index", addTableCommitStatusIndex),
// v196 -> v197
NewMigration("Add Color to ProjectBoard table", addColorColToProjectBoard),
} }
// GetCurrentDBVersion returns the current db version // GetCurrentDBVersion returns the current db version

22
models/migrations/v196.go Normal file
View File

@ -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
}

View File

@ -5,6 +5,9 @@
package models package models
import ( import (
"fmt"
"regexp"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -32,12 +35,16 @@ const (
ProjectBoardTypeBugTriage 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 // ProjectBoard is used to represent boards on a project
type ProjectBoard struct { type ProjectBoard struct {
ID int64 `xorm:"pk autoincr"` ID int64 `xorm:"pk autoincr"`
Title string Title string
Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board 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"` Sorting int8 `xorm:"NOT NULL DEFAULT 0"`
Color string `xorm:"VARCHAR(7)"`
ProjectID int64 `xorm:"INDEX NOT NULL"` ProjectID int64 `xorm:"INDEX NOT NULL"`
CreatorID int64 `xorm:"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 // NewProjectBoard adds a new project board to a given project
func NewProjectBoard(board *ProjectBoard) error { 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) _, err := db.GetEngine(db.DefaultContext).Insert(board)
return err return err
} }
@ -178,6 +189,11 @@ func updateProjectBoard(e db.Engine, board *ProjectBoard) error {
fieldToUpdate = append(fieldToUpdate, "title") 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) _, err := e.ID(board.ID).Cols(fieldToUpdate...).Update(board)
return err return err

View File

@ -96,6 +96,7 @@ error = Error
error404 = The page you are trying to reach either <strong>does not exist</strong> or <strong>you are not authorized</strong> to view it. error404 = The page you are trying to reach either <strong>does not exist</strong> or <strong>you are not authorized</strong> to view it.
never = Never never = Never
color = Color
[error] [error]
occurred = An error has occurred occurred = An error has occurred
@ -977,7 +978,6 @@ commit_graph = Commit Graph
commit_graph.select = Select branches commit_graph.select = Select branches
commit_graph.hide_pr_refs = Hide Pull Requests commit_graph.hide_pr_refs = Hide Pull Requests
commit_graph.monochrome = Mono commit_graph.monochrome = Mono
commit_graph.color = Color
blame = Blame blame = Blame
normal_view = Normal View normal_view = Normal View
line = line line = line
@ -1793,7 +1793,6 @@ settings.slack_username = Username
settings.slack_icon_url = Icon URL settings.slack_icon_url = Icon URL
settings.discord_username = Username settings.discord_username = Username
settings.discord_icon_url = Icon URL settings.discord_icon_url = Icon URL
settings.slack_color = Color
settings.event_desc = Trigger On: settings.event_desc = Trigger On:
settings.event_push_only = Push Events settings.event_push_only = Push Events
settings.event_send_everything = All Events settings.event_send_everything = All Events

View File

@ -444,6 +444,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
if err := models.NewProjectBoard(&models.ProjectBoard{ if err := models.NewProjectBoard(&models.ProjectBoard{
ProjectID: project.ID, ProjectID: project.ID,
Title: form.Title, Title: form.Title,
Color: form.Color,
CreatorID: ctx.User.ID, CreatorID: ctx.User.ID,
}); err != nil { }); err != nil {
ctx.ServerError("NewProjectBoard", err) ctx.ServerError("NewProjectBoard", err)
@ -513,6 +514,8 @@ func EditProjectBoard(ctx *context.Context) {
board.Title = form.Title board.Title = form.Title
} }
board.Color = form.Color
if form.Sorting != 0 { if form.Sorting != 0 {
board.Sorting = form.Sorting board.Sorting = form.Sorting
} }

View File

@ -499,6 +499,7 @@ type UserCreateProjectForm struct {
type EditProjectBoardForm struct { type EditProjectBoardForm struct {
Title string `binding:"Required;MaxSize(100)"` Title string `binding:"Required;MaxSize(100)"`
Sorting int8 Sorting int8
Color string `binding:"MaxSize(7)"`
} }
// _____ .__.__ __ // _____ .__.__ __

View File

@ -47,7 +47,7 @@
</div> </div>
</div> </div>
<button id="flow-color-monochrome" class="ui labelled icon button{{if eq .Mode "monochrome"}} active{{end}}" title="{{.i18n.Tr "repo.commit_graph.monochrome"}}">{{svg "material-invert-colors" 16 "mr-2"}}{{.i18n.Tr "repo.commit_graph.monochrome"}}</button> <button id="flow-color-monochrome" class="ui labelled icon button{{if eq .Mode "monochrome"}} active{{end}}" title="{{.i18n.Tr "repo.commit_graph.monochrome"}}">{{svg "material-invert-colors" 16 "mr-2"}}{{.i18n.Tr "repo.commit_graph.monochrome"}}</button>
<button id="flow-color-colored" class="ui labelled icon button{{if ne .Mode "monochrome"}} active{{end}}" title="{{.i18n.Tr "repo.commit_graph.color"}}">{{svg "material-palette" 16 "mr-2"}}{{.i18n.Tr "repo.commit_graph.color"}}</button> <button id="flow-color-colored" class="ui labelled icon button{{if ne .Mode "monochrome"}} active{{end}}" title="{{.i18n.Tr "color"}}">{{svg "material-palette" 16 "mr-2"}}{{.i18n.Tr "color"}}</button>
</div> </div>
</h2> </h2>
<div class="ui dividing"></div> <div class="ui dividing"></div>

View File

@ -11,7 +11,7 @@
<a class="ui green button show-modal item" href="{{$.RepoLink}}/issues/new?project={{$.Project.ID}}">{{.i18n.Tr "repo.issues.new"}}</a> <a class="ui green button show-modal item" href="{{$.RepoLink}}/issues/new?project={{$.Project.ID}}">{{.i18n.Tr "repo.issues.new"}}</a>
<a class="ui green button show-modal item" data-modal="#new-board-item">{{.i18n.Tr "new_project_board"}}</a> <a class="ui green button show-modal item" data-modal="#new-board-item">{{.i18n.Tr "new_project_board"}}</a>
{{end}} {{end}}
<div class="ui small modal" id="new-board-item"> <div class="ui small modal new-board-modal" id="new-board-item">
<div class="header"> <div class="header">
{{$.i18n.Tr "repo.projects.board.new"}} {{$.i18n.Tr "repo.projects.board.new"}}
</div> </div>
@ -22,6 +22,16 @@
<input class="new-board" id="new_board" name="title" required> <input class="new-board" id="new_board" name="title" required>
</div> </div>
<div class="field color-field">
<label for="new_board_color">{{$.i18n.Tr "color"}}</label>
<div class="color picker column">
<input class="color-picker" maxlength="7" placeholder="#c320f6" id="new_board_color_picker" name="color">
<div class="column precolors">
{{template "repo/issue/label_precolors"}}
</div>
</div>
</div>
<div class="text right actions"> <div class="text right actions">
<div class="ui cancel button">{{$.i18n.Tr "settings.cancel"}}</div> <div class="ui cancel button">{{$.i18n.Tr "settings.cancel"}}</div>
<button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui green button" id="new_board_submit">{{$.i18n.Tr "repo.projects.board.new_submit"}}</button> <button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}" class="ui green button" id="new_board_submit">{{$.i18n.Tr "repo.projects.board.new_submit"}}</button>
@ -70,7 +80,7 @@
<div class="board"> <div class="board">
{{ range $board := .Boards }} {{ range $board := .Boards }}
<div class="ui segment board-column" data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}"> <div class="ui segment board-column" style="background: {{.Color}}!important;" data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}">
<div class="board-column-header df ac sb"> <div class="board-column-header df ac sb">
<div class="ui large label board-label py-2">{{.Title}}</div> <div class="ui large label board-label py-2">{{.Title}}</div>
{{if and $.CanWriteProjects (not $.Repository.IsArchived) $.PageIsProjects (ne .ID 0)}} {{if and $.CanWriteProjects (not $.Repository.IsArchived) $.PageIsProjects (ne .ID 0)}}
@ -105,6 +115,16 @@
<input class="project-board-title" id="new_board_title" name="title" value="{{.Title}}" required> <input class="project-board-title" id="new_board_title" name="title" value="{{.Title}}" required>
</div> </div>
<div class="field color-field">
<label for="new_board_color">{{$.i18n.Tr "color"}}</label>
<div class="color picker column">
<input class="color-picker" maxlength="7" placeholder="#c320f6" id="new_board_color" name="color" value="{{.Color}}">
<div class="column precolors">
{{template "repo/issue/label_precolors"}}
</div>
</div>
</div>
<div class="text right actions"> <div class="text right actions">
<div class="ui cancel button">{{$.i18n.Tr "settings.cancel"}}</div> <div class="ui cancel button">{{$.i18n.Tr "settings.cancel"}}</div>
<button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}" class="ui red button">{{$.i18n.Tr "repo.projects.board.edit"}}</button> <button data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}" class="ui red button">{{$.i18n.Tr "repo.projects.board.edit"}}</button>

View File

@ -20,7 +20,7 @@
<input id="icon_url" name="icon_url" value="{{.SlackHook.IconURL}}" placeholder="e.g. https://example.com/img/favicon.png"> <input id="icon_url" name="icon_url" value="{{.SlackHook.IconURL}}" placeholder="e.g. https://example.com/img/favicon.png">
</div> </div>
<div class="field"> <div class="field">
<label for="color">{{.i18n.Tr "repo.settings.slack_color"}}</label> <label for="color">{{.i18n.Tr "color"}}</label>
<input id="color" name="color" value="{{.SlackHook.Color}}" placeholder="e.g. #dd4b39, good, warning, danger"> <input id="color" name="color" value="{{.SlackHook.Color}}" placeholder="e.g. #dd4b39, good, warning, danger">
</div> </div>
{{template "repo/settings/webhook/settings" .}} {{template "repo/settings/webhook/settings" .}}

View File

@ -23,7 +23,7 @@ export default async function initProject() {
if (parseInt($(column).data('sorting')) !== i) { if (parseInt($(column).data('sorting')) !== i) {
$.ajax({ $.ajax({
url: $(column).data('url'), url: $(column).data('url'),
data: JSON.stringify({sorting: i}), data: JSON.stringify({sorting: i, color: rgbToHex($(column).css('backgroundColor'))}),
headers: { headers: {
'X-Csrf-Token': csrf, 'X-Csrf-Token': csrf,
'X-Remote': true, 'X-Remote': true,
@ -62,10 +62,17 @@ export default async function initProject() {
} }
$('.edit-project-board').each(function () { $('.edit-project-board').each(function () {
const projectTitleLabel = $(this).closest('.board-column-header').find('.board-label'); const projectHeader = $(this).closest('.board-column-header');
const projectTitleLabel = projectHeader.find('.board-label');
const projectTitleInput = $(this).find( const projectTitleInput = $(this).find(
'.content > .form > .field > .project-board-title', '.content > .form > .field > .project-board-title',
); );
const projectColorInput = $(this).find('.content > .form > .field #new_board_color');
const boardColumn = $(this).closest('.board-column');
if (boardColumn.css('backgroundColor')) {
setLabelColor(projectHeader, rgbToHex(boardColumn.css('backgroundColor')));
}
$(this) $(this)
.find('.content > .form > .actions > .red') .find('.content > .form > .actions > .red')
@ -74,7 +81,7 @@ export default async function initProject() {
$.ajax({ $.ajax({
url: $(this).data('url'), url: $(this).data('url'),
data: JSON.stringify({title: projectTitleInput.val()}), data: JSON.stringify({title: projectTitleInput.val(), color: projectColorInput.val()}),
headers: { headers: {
'X-Csrf-Token': csrf, 'X-Csrf-Token': csrf,
'X-Remote': true, 'X-Remote': true,
@ -84,6 +91,10 @@ export default async function initProject() {
}).done(() => { }).done(() => {
projectTitleLabel.text(projectTitleInput.val()); projectTitleLabel.text(projectTitleInput.val());
projectTitleInput.closest('form').removeClass('dirty'); projectTitleInput.closest('form').removeClass('dirty');
if (projectColorInput.val()) {
setLabelColor(projectHeader, projectColorInput.val());
}
boardColumn.attr('style', `background: ${projectColorInput.val()}!important`);
$('.ui.modal').modal('hide'); $('.ui.modal').modal('hide');
}); });
}); });
@ -127,10 +138,11 @@ export default async function initProject() {
e.preventDefault(); e.preventDefault();
const boardTitle = $('#new_board'); const boardTitle = $('#new_board');
const projectColorInput = $('#new_board_color_picker');
$.ajax({ $.ajax({
url: $(this).data('url'), url: $(this).data('url'),
data: JSON.stringify({title: boardTitle.val()}), data: JSON.stringify({title: boardTitle.val(), color: projectColorInput.val()}),
headers: { headers: {
'X-Csrf-Token': csrf, 'X-Csrf-Token': csrf,
'X-Remote': true, 'X-Remote': true,
@ -143,3 +155,34 @@ export default async function initProject() {
}); });
}); });
} }
function setLabelColor(label, color) {
const red = getRelativeColor(parseInt(color.substr(1, 2), 16));
const green = getRelativeColor(parseInt(color.substr(3, 2), 16));
const blue = getRelativeColor(parseInt(color.substr(5, 2), 16));
const luminance = 0.2126 * red + 0.7152 * green + 0.0722 * blue;
if (luminance > 0.179) {
label.removeClass('light-label').addClass('dark-label');
} else {
label.removeClass('dark-label').addClass('light-label');
}
}
/**
* Inspired by W3C recommandation https://www.w3.org/TR/WCAG20/#relativeluminancedef
*/
function getRelativeColor(color) {
color /= 255;
return color <= 0.03928 ? color / 12.92 : ((color + 0.055) / 1.055) ** 2.4;
}
function rgbToHex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return `#${hex(rgb[1])}${hex(rgb[2])}${hex(rgb[3])}`;
}
function hex(x) {
const hexDigits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
return Number.isNaN(x) ? '00' : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}

View File

@ -159,13 +159,8 @@ function initLabelEdit() {
$newLabelPanel.hide(); $newLabelPanel.hide();
}); });
createColorPicker($('.color-picker')); initColorPicker();
$('.precolors .color').on('click', function () {
const color_hex = $(this).data('color-hex');
$('.color-picker').val(color_hex);
$('.minicolors-swatch-color').css('background-color', color_hex);
});
$('.edit-label-button').on('click', function () { $('.edit-label-button').on('click', function () {
$('.edit-label .color-picker').minicolors('value', $(this).data('color')); $('.edit-label .color-picker').minicolors('value', $(this).data('color'));
$('#label-modal-id').val($(this).data('id')); $('#label-modal-id').val($(this).data('id'));
@ -182,6 +177,16 @@ function initLabelEdit() {
}); });
} }
function initColorPicker() {
createColorPicker($('.color-picker'));
$('.precolors .color').on('click', function () {
const color_hex = $(this).data('color-hex');
$('.color-picker').val(color_hex);
$('.minicolors-swatch-color').css('background-color', color_hex);
});
}
function updateIssuesMeta(url, action, issueIds, elementId) { function updateIssuesMeta(url, action, issueIds, elementId) {
return new Promise(((resolve) => { return new Promise(((resolve) => {
$.ajax({ $.ajax({
@ -2753,6 +2758,10 @@ $(document).ready(async () => {
}); });
$('.show-modal.button').on('click', function () { $('.show-modal.button').on('click', function () {
$($(this).data('modal')).modal('show'); $($(this).data('modal')).modal('show');
const colorPickers = $($(this).data('modal')).find('.color-picker');
if (colorPickers.length > 0) {
initColorPicker();
}
}); });
$('.delete-post.button').on('click', function () { $('.delete-post.button').on('click', function () {
const $this = $(this); const $this = $(this);

View File

@ -114,6 +114,8 @@
--color-placeholder-text: #aaa; --color-placeholder-text: #aaa;
--color-editor-line-highlight: var(--color-primary-light-6); --color-editor-line-highlight: var(--color-primary-light-6);
--color-project-board-bg: var(--color-secondary-light-4); --color-project-board-bg: var(--color-secondary-light-4);
--color-project-board-dark-label: #555555;
--color-project-board-light-label: #a6aab5;
--color-caret: var(--color-text-dark); --color-caret: var(--color-text-dark);
--color-reaction-bg: #0000000a; --color-reaction-bg: #0000000a;
--color-reaction-active-bg: var(--color-primary-alpha-20); --color-reaction-active-bg: var(--color-primary-alpha-20);
@ -2090,3 +2092,16 @@ table th[data-sortt-desc] {
margin-top: -.5em; margin-top: -.5em;
margin-bottom: -.5em; margin-bottom: -.5em;
} }
.precolors {
padding-left: 0;
padding-right: 0;
margin: 3px 10px auto;
width: 120px;
.color {
float: left;
width: 15px;
height: 15px;
}
}

View File

@ -2696,19 +2696,6 @@
width: 15px; width: 15px;
height: 15px; height: 15px;
} }
.precolors {
padding-left: 0;
padding-right: 0;
margin: 3px 10px auto;
width: 120px;
.color {
float: left;
width: 15px;
height: 15px;
}
}
} }
} }

View File

@ -23,6 +23,21 @@
.board-column-header { .board-column-header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
&.dark-label {
color: var(--color-project-board-dark-label) !important;
.board-label {
color: var(--color-project-board-dark-label) !important;
}
}
&.light-label {
color: var(--color-project-board-light-label) !important;
.board-label {
color: var(--color-project-board-light-label) !important;
}
}
} }
.board-label { .board-label {
@ -81,3 +96,27 @@
.card-ghost * { .card-ghost * {
opacity: 0; opacity: 0;
} }
.color-field .minicolors.minicolors-theme-default {
display: block;
.minicolors-input {
height: 38px;
padding-left: 2rem;
}
.minicolors-swatch {
top: 10px;
}
}
.edit-project-board,
.new-board-modal {
.color.picker.column {
display: flex;
.minicolors {
flex: 1;
}
}
}