mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-04 21:06:20 +02:00
clean up backend
This commit is contained in:
parent
198d13de4c
commit
165b6e48f1
@ -36,11 +36,6 @@ const (
|
||||
tplProjectsView templates.TplName = "repo/projects/view"
|
||||
)
|
||||
|
||||
type projectColumnInfo struct {
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// MustEnableRepoProjects check if repo projects are enabled in settings
|
||||
func MustEnableRepoProjects(ctx *context.Context) {
|
||||
if unit.TypeProjects.UnitGlobalDisabled() {
|
||||
@ -465,96 +460,39 @@ func UpdateIssueProject(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
result := map[string]any{"ok": true}
|
||||
if projectID > 0 {
|
||||
project, err := project_model.GetProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectByID", err)
|
||||
return
|
||||
}
|
||||
columns, err := project.GetColumns(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectColumns", err)
|
||||
return
|
||||
}
|
||||
cols := make([]projectColumnInfo, 0, len(columns))
|
||||
for _, c := range columns {
|
||||
cols = append(cols, projectColumnInfo{ID: c.ID, Title: c.Title})
|
||||
}
|
||||
// The issue was assigned to the default column
|
||||
var selectedColumnID int64
|
||||
if len(issues) > 0 {
|
||||
selectedColumnID, err = issues[0].ProjectColumnID(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("ProjectColumnID", err)
|
||||
return
|
||||
}
|
||||
if selectedColumnID == 0 {
|
||||
defaultColumn, err := project.MustDefaultColumn(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("MustDefaultColumn", err)
|
||||
return
|
||||
}
|
||||
selectedColumnID = defaultColumn.ID
|
||||
}
|
||||
}
|
||||
result["columns"] = cols
|
||||
result["selected_column_id"] = selectedColumnID
|
||||
} else {
|
||||
result["columns"] = []projectColumnInfo{}
|
||||
result["selected_column_id"] = 0
|
||||
}
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
||||
// UpdateIssueProjectColumn moves an issue to a different column within its current project
|
||||
func UpdateIssueProjectColumn(ctx *context.Context) {
|
||||
issueID := ctx.FormInt64("issue_id")
|
||||
columnID := ctx.FormInt64("id")
|
||||
|
||||
issue, err := issues_model.GetIssueByID(ctx, issueID)
|
||||
if err != nil {
|
||||
if issues_model.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
ctx.ServerError("GetIssueByID", err)
|
||||
// UpdateIssueProjectSetColumn moves an issue to a different column within its current project
|
||||
func UpdateIssueProjectSetColumn(ctx *context.Context) {
|
||||
issues := getActionIssues(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if issue.RepoID != ctx.Repo.Repository.ID {
|
||||
|
||||
if err := issues.LoadProjects(ctx); err != nil {
|
||||
ctx.ServerError("LoadProjects", err)
|
||||
return
|
||||
}
|
||||
|
||||
column, err := project_model.GetColumn(ctx, ctx.FormInt64("id"))
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
if err := issue.LoadProject(ctx); err != nil {
|
||||
ctx.ServerError("LoadProject", err)
|
||||
return
|
||||
}
|
||||
if issue.Project == nil {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
column, err := project_model.GetColumn(ctx, columnID)
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectColumnNotExist(err) {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
} else if err != nil {
|
||||
ctx.ServerError("GetColumn", err)
|
||||
return
|
||||
}
|
||||
if column.ProjectID != issue.Project.ID {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
}
|
||||
|
||||
if err := project_service.MoveIssuesOnProjectColumn(ctx, ctx.Doer, column, map[int64]int64{0: issue.ID}); err != nil {
|
||||
ctx.ServerError("MoveIssuesOnProjectColumn", err)
|
||||
return
|
||||
for _, issue := range issues {
|
||||
if column.ProjectID != issue.Project.ID {
|
||||
continue
|
||||
}
|
||||
if err := project_service.MoveIssuesOnProjectColumn(ctx, ctx.Doer, column, map[int64]int64{0 /*sorting=0*/ : issue.ID}); err != nil {
|
||||
ctx.ServerError("MoveIssuesOnProjectColumn", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSONOK()
|
||||
}
|
||||
|
||||
|
||||
@ -1354,7 +1354,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel)
|
||||
m.Post("/milestone", reqRepoIssuesOrPullsWriter, repo.UpdateIssueMilestone)
|
||||
m.Post("/projects", reqRepoIssuesOrPullsWriter, reqRepoProjectsReader, repo.UpdateIssueProject)
|
||||
m.Post("/projects/column", reqRepoIssuesOrPullsWriter, reqRepoProjectsReader, repo.UpdateIssueProjectColumn)
|
||||
m.Post("/projects/set-column", reqRepoIssuesOrPullsWriter, reqRepoProjectsWriter, repo.UpdateIssueProjectSetColumn)
|
||||
m.Post("/assignee", reqRepoIssuesOrPullsWriter, repo.UpdateIssueAssignee)
|
||||
m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus)
|
||||
m.Post("/delete", reqRepoAdmin, repo.BatchDeleteIssues)
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
{{if $pageMeta.CanModifyIssueOrPull}}
|
||||
<div class="issue-sidebar-combo" id="sidebar-project-column"
|
||||
data-selection-mode="single" data-update-algo="all"
|
||||
data-update-url="{{$pageMeta.RepoLink}}/issues/projects/column?issue_id={{$pageMeta.Issue.ID}}">
|
||||
<input class="combo-value" name="column_id" type="hidden" value="{{$selectedColumn.ID}}">
|
||||
data-update-url="{{$pageMeta.RepoLink}}/issues/projects/set-column?issue_ids={{$pageMeta.Issue.ID}}">
|
||||
<input class="combo-value" type="hidden" value="{{$selectedColumn.ID}}">
|
||||
<div class="ui dropdown selection fluid">
|
||||
<div class="text">{{$selectedColumn.Title}}</div>{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||
<div class="menu">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user