From f30cc9faa93935f5afb7a38354e5381d5e8825bf Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 19 Apr 2023 23:28:28 +0900 Subject: [PATCH] Add unset default project column (#23531) Close: https://github.com/go-gitea/gitea/issues/23401 --- options/locale/locale_en-US.ini | 2 ++ routers/web/org/projects.go | 17 ++++++++++++++ routers/web/repo/projects.go | 17 ++++++++++++++ routers/web/web.go | 2 ++ templates/projects/view.tmpl | 27 +++++++++++++++++------ templates/repo/projects/view.tmpl | 29 ++++++++++++++++++------ web_src/js/features/repo-projects.js | 33 ++++++++++++++++++---------- 7 files changed, 102 insertions(+), 25 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 96e28fe87a..f168334d9d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1261,6 +1261,8 @@ projects.column.new_submit = "Create Column" projects.column.new = "New Column" projects.column.set_default = "Set Default" projects.column.set_default_desc = "Set this column as default for uncategorized issues and pulls" +projects.column.unset_default = "Unset Default" +projects.column.unset_default_desc = "Unset this column as default" projects.column.delete = "Delete Column" projects.column.deletion_desc = "Deleting a project column moves all related issues to 'Uncategorized'. Continue?" projects.column.color = "Color" diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index ed6a2e645f..37212179c9 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -610,6 +610,23 @@ func SetDefaultProjectBoard(ctx *context.Context) { }) } +// UnsetDefaultProjectBoard unset default board for uncategorized issues/pulls +func UnsetDefaultProjectBoard(ctx *context.Context) { + project, _ := CheckProjectBoardChangePermissions(ctx) + if ctx.Written() { + return + } + + if err := project_model.SetDefaultBoard(project.ID, 0); err != nil { + ctx.ServerError("SetDefaultBoard", err) + return + } + + ctx.JSON(http.StatusOK, map[string]interface{}{ + "ok": true, + }) +} + // MoveIssues moves or keeps issues in a column and sorts them inside that column func MoveIssues(ctx *context.Context) { if ctx.Doer == nil { diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index cef6893fbd..72f83f8b31 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -576,6 +576,23 @@ func SetDefaultProjectBoard(ctx *context.Context) { }) } +// UnSetDefaultProjectBoard unset default board for uncategorized issues/pulls +func UnSetDefaultProjectBoard(ctx *context.Context) { + project, _ := checkProjectBoardChangePermissions(ctx) + if ctx.Written() { + return + } + + if err := project_model.SetDefaultBoard(project.ID, 0); err != nil { + ctx.ServerError("SetDefaultBoard", err) + return + } + + ctx.JSON(http.StatusOK, map[string]interface{}{ + "ok": true, + }) +} + // MoveIssues moves or keeps issues in a column and sorts them inside that column func MoveIssues(ctx *context.Context) { if ctx.Doer == nil { diff --git a/routers/web/web.go b/routers/web/web.go index 30a8314691..8f0b0b1f45 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -936,6 +936,7 @@ func RegisterRoutes(m *web.Route) { m.Put("", web.Bind(forms.EditProjectBoardForm{}), org.EditProjectBoard) m.Delete("", org.DeleteProjectBoard) m.Post("/default", org.SetDefaultProjectBoard) + m.Post("/unsetdefault", org.UnsetDefaultProjectBoard) m.Post("/move", org.MoveIssues) }) @@ -1292,6 +1293,7 @@ func RegisterRoutes(m *web.Route) { m.Put("", web.Bind(forms.EditProjectBoardForm{}), repo.EditProjectBoard) m.Delete("", repo.DeleteProjectBoard) m.Post("/default", repo.SetDefaultProjectBoard) + m.Post("/unsetdefault", repo.UnSetDefaultProjectBoard) m.Post("/move", repo.MoveIssues) }) diff --git a/templates/projects/view.tmpl b/templates/projects/view.tmpl index 41bbb83f7b..338524d153 100644 --- a/templates/projects/view.tmpl +++ b/templates/projects/view.tmpl @@ -95,10 +95,25 @@ {{$.locale.Tr "repo.projects.column.edit"}} {{if not .Default}} - + {{svg "octicon-pin"}} {{$.locale.Tr "repo.projects.column.set_default"}} + {{else}} + + {{svg "octicon-pin"}} + {{$.locale.Tr "repo.projects.column.unset_default"}} + {{end}} {{svg "octicon-trash"}} @@ -134,18 +149,16 @@ - -