From 38d0f7459cc0238f7ac62dd112c551c3e67815bd Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 11:04:59 +0800 Subject: [PATCH 01/10] Add multiple projects function --- models/issues/issue.go | 16 +- models/issues/issue_list.go | 14 +- models/issues/issue_project.go | 137 ++++++++++++------ models/issues/issue_search.go | 2 + models/project/issue.go | 4 +- routers/web/org/projects.go | 10 +- routers/web/repo/issue.go | 2 +- routers/web/repo/projects.go | 10 +- templates/repo/issue/new_form.tmpl | 1 + .../repo/issue/view_content/sidebar.tmpl | 42 ++++-- templates/shared/issuelist.tmpl | 6 +- web_src/js/features/repo-legacy.js | 1 + 12 files changed, 158 insertions(+), 87 deletions(-) diff --git a/models/issues/issue.go b/models/issues/issue.go index eab18f4892ce9..7efca6e60a37b 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -100,14 +100,14 @@ type Issue struct { PosterID int64 `xorm:"INDEX"` Poster *user_model.User `xorm:"-"` OriginalAuthor string - OriginalAuthorID int64 `xorm:"index"` - Title string `xorm:"name"` - Content string `xorm:"LONGTEXT"` - RenderedContent string `xorm:"-"` - Labels []*Label `xorm:"-"` - MilestoneID int64 `xorm:"INDEX"` - Milestone *Milestone `xorm:"-"` - Project *project_model.Project `xorm:"-"` + OriginalAuthorID int64 `xorm:"index"` + Title string `xorm:"name"` + Content string `xorm:"LONGTEXT"` + RenderedContent string `xorm:"-"` + Labels []*Label `xorm:"-"` + MilestoneID int64 `xorm:"INDEX"` + Milestone *Milestone `xorm:"-"` + Projects []*project_model.Project `xorm:"-"` Priority int AssigneeID int64 `xorm:"-"` Assignee *user_model.User `xorm:"-"` diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index dad21c14776f0..596540c0c90ac 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -230,11 +230,11 @@ func (issues IssueList) loadMilestones(ctx context.Context) error { } func (issues IssueList) getProjectIDs() []int64 { - ids := make(container.Set[int64], len(issues)) + var ids []int64 for _, issue := range issues { - ids.Add(issue.ProjectID()) + ids = append(ids, issue.ProjectIDs()...) } - return ids.Values() + return ids } func (issues IssueList) loadProjects(ctx context.Context) error { @@ -261,8 +261,14 @@ func (issues IssueList) loadProjects(ctx context.Context) error { } for _, issue := range issues { - issue.Project = projectMaps[issue.ProjectID()] + projectIDs := issue.ProjectIDs() + for _, i := range projectIDs { + if projectMaps[i] != nil { + issue.Projects = append(issue.Projects, projectMaps[i]) + } + } } + return nil } diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index 04d12e055cc58..696dc348b7c95 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -14,31 +14,33 @@ import ( // LoadProject load the project the issue was assigned to func (issue *Issue) LoadProject(ctx context.Context) (err error) { - if issue.Project == nil { - var p project_model.Project - if _, err = db.GetEngine(ctx).Table("project"). + if issue.Projects == nil { + err = db.GetEngine(ctx).Table("project"). Join("INNER", "project_issue", "project.id=project_issue.project_id"). Where("project_issue.issue_id = ?", issue.ID). - Get(&p); err != nil { - return err - } - issue.Project = &p + Find(&issue.Projects) } return err } // ProjectID return project id if issue was assigned to one -func (issue *Issue) ProjectID() int64 { - return issue.projectID(db.DefaultContext) +func (issue *Issue) ProjectIDs() []int64 { + return issue.projectIDs(db.DefaultContext) } -func (issue *Issue) projectID(ctx context.Context) int64 { - var ip project_model.ProjectIssue - has, err := db.GetEngine(ctx).Where("issue_id=?", issue.ID).Get(&ip) - if err != nil || !has { - return 0 +func (issue *Issue) projectIDs(ctx context.Context) []int64 { + var ip []project_model.ProjectIssue + var ips []int64 + err := db.GetEngine(ctx).Select("project_id").Where("issue_id=?", issue.ID).Find(&ip) + if err != nil { + return nil + } + + for _, i := range ip { + ips = append(ips, i.ProjectID) } - return ip.ProjectID + + return ips } // ProjectBoardID return project board id if issue was assigned to one @@ -104,59 +106,104 @@ func LoadIssuesFromBoardList(ctx context.Context, bs project_model.BoardList) (m } // ChangeProjectAssign changes the project associated with an issue -func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64) error { +func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64, action string) error { ctx, committer, err := db.TxContext(db.DefaultContext) if err != nil { return err } defer committer.Close() - if err := addUpdateIssueProject(ctx, issue, doer, newProjectID); err != nil { + if err := addUpdateIssueProject(ctx, issue, doer, newProjectID, action); err != nil { return err } return committer.Commit() } -func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error { - oldProjectID := issue.projectID(ctx) +func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64, action string) error { if err := issue.LoadRepo(ctx); err != nil { return err } - // Only check if we add a new project and not remove it. - if newProjectID > 0 { - newProject, err := project_model.GetProjectByID(ctx, newProjectID) - if err != nil { - return err + oldProjectIDs := issue.projectIDs(ctx) + + if len(oldProjectIDs) > 0 { + for _, i := range oldProjectIDs { + // Only check if we add a new project and not remove it. + if newProjectID > 0 { + newProject, err := project_model.GetProjectByID(ctx, newProjectID) + if err != nil { + return err + } + if newProject.RepoID != issue.RepoID && newProject.OwnerID != issue.Repo.OwnerID { + return fmt.Errorf("issue's repository is not the same as project's repository") + } + } + + if action == "attach" || (action == "" && i != newProjectID) { + if err := db.Insert(ctx, &project_model.ProjectIssue{ + IssueID: issue.ID, + ProjectID: newProjectID, + }); err != nil { + return err + } + i = 0 + } else { + if action == "clear" { + if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil { + return err + } + } else if i > 0 && i == newProjectID { + if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=? AND project_issue.project_id=?", issue.ID, i).Delete(&project_model.ProjectIssue{}); err != nil { + return err + } + newProjectID = 0 + } + } + + if i > 0 || newProjectID > 0 { + if _, err := CreateComment(ctx, &CreateCommentOptions{ + Type: CommentTypeProject, + Doer: doer, + Repo: issue.Repo, + Issue: issue, + OldProjectID: i, + ProjectID: newProjectID, + }); err != nil { + return err + } + } + + if action != "clear" && newProjectID == 0 { + break + } } - if newProject.RepoID != issue.RepoID && newProject.OwnerID != issue.Repo.OwnerID { - return fmt.Errorf("issue's repository is not the same as project's repository") + } else { + if action == "attach" || action == "" { + if err := db.Insert(ctx, &project_model.ProjectIssue{ + IssueID: issue.ID, + ProjectID: newProjectID, + }); err != nil { + return err + } } - } - - if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil { - return err - } - if oldProjectID > 0 || newProjectID > 0 { - if _, err := CreateComment(ctx, &CreateCommentOptions{ - Type: CommentTypeProject, - Doer: doer, - Repo: issue.Repo, - Issue: issue, - OldProjectID: oldProjectID, - ProjectID: newProjectID, - }); err != nil { - return err + if newProjectID > 0 { + if _, err := CreateComment(ctx, &CreateCommentOptions{ + Type: CommentTypeProject, + Doer: doer, + Repo: issue.Repo, + Issue: issue, + OldProjectID: 0, + ProjectID: newProjectID, + }); err != nil { + return err + } } } - return db.Insert(ctx, &project_model.ProjectIssue{ - IssueID: issue.ID, - ProjectID: newProjectID, - }) + return nil } // MoveIssueAcrossProjectBoards move a card from one board to another diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go index 9fd13f09956af..5c6502a5f0b38 100644 --- a/models/issues/issue_search.go +++ b/models/issues/issue_search.go @@ -223,6 +223,8 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session { if opts.ProjectBoardID != 0 { if opts.ProjectBoardID > 0 { sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID})) + } else if opts.ProjectID > 0 { + sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0, "project_id": opts.ProjectID})) } else { sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0})) } diff --git a/models/project/issue.go b/models/project/issue.go index 3269197d6cde3..d2b73824e1a71 100644 --- a/models/project/issue.go +++ b/models/project/issue.go @@ -76,7 +76,7 @@ func (p *Project) NumOpenIssues() int { } // MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column -func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error { +func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64, projectID int64) error { return db.WithTx(db.DefaultContext, func(ctx context.Context) error { sess := db.GetEngine(ctx) @@ -93,7 +93,7 @@ func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) erro } for sorting, issueID := range sortedIssueIDs { - _, err = sess.Exec("UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", board.ID, sorting, issueID) + _, err = sess.Exec("UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=? AND project_id=?", board.ID, sorting, issueID, projectID) if err != nil { return err } diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index b3f6024b60606..0584e3012398a 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -430,13 +430,9 @@ func UpdateIssueProject(ctx *context.Context) { } projectID := ctx.FormInt64("id") + action := ctx.FormString("action") for _, issue := range issues { - oldProjectID := issue.ProjectID() - if oldProjectID == projectID { - continue - } - - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { + if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID, action); err != nil { ctx.ServerError("ChangeProjectAssign", err) return } @@ -718,7 +714,7 @@ func MoveIssues(ctx *context.Context) { } } - if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs); err != nil { + if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs, project.ID); err != nil { ctx.ServerError("MoveIssuesOnProjectBoard", err) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 5ab8db2e057fe..8a4568fa02009 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1176,7 +1176,7 @@ func NewIssuePost(ctx *context.Context) { ctx.Error(http.StatusBadRequest, "user hasn't permissions to read projects") return } - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { + if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID, ctx.FormString("action")); err != nil { ctx.ServerError("ChangeProjectAssign", err) return } diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 5ee5ead12177b..c5cad41213397 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -379,13 +379,9 @@ func UpdateIssueProject(ctx *context.Context) { } projectID := ctx.FormInt64("id") + action := ctx.FormString("action") for _, issue := range issues { - oldProjectID := issue.ProjectID() - if oldProjectID == projectID { - continue - } - - if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil { + if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID, action); err != nil { ctx.ServerError("ChangeProjectAssign", err) return } @@ -688,7 +684,7 @@ func MoveIssues(ctx *context.Context) { } } - if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs); err != nil { + if err = project_model.MoveIssuesOnProjectBoard(board, sortedIssueIDs, project.ID); err != nil { ctx.ServerError("MoveIssuesOnProjectBoard", err) return } diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 00da68eb06fa1..6649477c12c74 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -113,6 +113,7 @@ {{range .OpenProjects}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}} + {{end}} {{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index a053fec066190..3d2f97c6ff4a0 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -152,7 +152,7 @@ {{if .IsProjectsEnabled}}
- {{range .ClosedProjects}} - + {{$ProjectID := .ID}} + {{$checked := false}} + {{range $.Issue.Projects}} + {{if eq .ID $ProjectID}} + {{$checked = true}} + {{end}} + {{end}} + + {{svg "octicon-check"}} + {{svg .IconName 18 "gt-mr-3"}}{{.Title}} + {{end}} {{end}} -
- {{.locale.Tr "repo.issues.new.no_projects"}} + {{end}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 394b4a69185ac..d098c74fa6256 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -64,9 +64,9 @@ {{svg "octicon-milestone" 14 "gt-mr-2"}}{{.Milestone.Name}} {{end}} - {{if .Project}} - - {{svg .Project.IconName 14 "gt-mr-2"}}{{.Project.Title}} + {{range .Projects}} + + {{svg .IconName 14 "gt-mr-2"}}{{.Title}} {{end}} {{if .Ref}} diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index f23ff45470c10..4b561e359d56e 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -231,6 +231,7 @@ export function initRepoCommentForm() { // Init labels and assignees initListSubmits('select-label', 'labels'); + initListSubmits('select-projects', 'projects'); initListSubmits('select-assignees', 'assignees'); initListSubmits('select-assignees-modify', 'assignees'); initListSubmits('select-reviewers-modify', 'assignees'); From 0a9cfe3dc2dfa0c0fd80b97217c0a28086a17020 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 11:11:19 +0800 Subject: [PATCH 02/10] Fix lint check --- models/issues/issue_project.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index 696dc348b7c95..dfc026e4d531a 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -121,7 +121,6 @@ func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64 } func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64, action string) error { - if err := issue.LoadRepo(ctx); err != nil { return err } From 024fc5f35d23a4a24e8f916539311cf8c9704b27 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 11:47:47 +0800 Subject: [PATCH 03/10] Fix double projects issue --- models/issues/issue_project.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index dfc026e4d531a..a9c84de492bbb 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -140,7 +140,7 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U } } - if action == "attach" || (action == "" && i != newProjectID) { + if action == "attach" && newProjectID > 0 { if err := db.Insert(ctx, &project_model.ProjectIssue{ IssueID: issue.ID, ProjectID: newProjectID, @@ -174,7 +174,7 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U } } - if action != "clear" && newProjectID == 0 { + if action != "clear" && newProjectID == 0 || action == "attach" && newProjectID > 0 { break } } From ecccc0c8902f2e44e18f6051793b3f346a5079ec Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 12:49:29 +0800 Subject: [PATCH 04/10] Fix link --- templates/repo/issue/view_content/sidebar.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 3d2f97c6ff4a0..44fff1290c37a 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -180,7 +180,7 @@ {{$checked = true}} {{end}} {{end}} - + {{svg "octicon-check"}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}} @@ -201,7 +201,7 @@ {{$checked = true}} {{end}} {{end}} - + {{svg "octicon-check"}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}} From 57da8ac684caeb89d792056898e0c525fba1a377 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 13:46:49 +0800 Subject: [PATCH 05/10] Fix duplicate IDs issue --- models/issues/issue_list.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 596540c0c90ac..4b5ccfa6d2fb5 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -230,11 +230,12 @@ func (issues IssueList) loadMilestones(ctx context.Context) error { } func (issues IssueList) getProjectIDs() []int64 { - var ids []int64 + ids := make(container.Set[int64]) for _, issue := range issues { - ids = append(ids, issue.ProjectIDs()...) + ids.AddMultiple(issue.ProjectIDs()...) } - return ids + + return ids.Values() } func (issues IssueList) loadProjects(ctx context.Context) error { From 7b0ad6d157c6b5ae07f655b70a558f5b101e4c77 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 14:25:32 +0800 Subject: [PATCH 06/10] Add project list sort by title --- models/issues/issue_project.go | 2 +- models/project/project.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index a9c84de492bbb..a735eea938622 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -17,7 +17,7 @@ func (issue *Issue) LoadProject(ctx context.Context) (err error) { if issue.Projects == nil { err = db.GetEngine(ctx).Table("project"). Join("INNER", "project_issue", "project.id=project_issue.project_id"). - Where("project_issue.issue_id = ?", issue.ID). + Where("project_issue.issue_id = ?", issue.ID).OrderBy("title"). Find(&issue.Projects) } return err diff --git a/models/project/project.go b/models/project/project.go index 44609e60b2ea0..56bf2776b7f3c 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -228,7 +228,7 @@ func CountProjects(ctx context.Context, opts SearchOptions) (int64, error) { // FindProjects returns a list of all projects that have been created in the repository func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, error) { - e := db.GetEngine(ctx).Where(opts.toConds()) + e := db.GetEngine(ctx).Where(opts.toConds()).OrderBy("title") projects := make([]*Project, 0, setting.UI.IssuePagingNum) if opts.Page > 0 { From 0aac264f4239348cb6e9831d565100f5b2ce116c Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 14:34:16 +0800 Subject: [PATCH 07/10] Improve again project list sort --- models/project/project.go | 4 +++- routers/web/repo/issue.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/models/project/project.go b/models/project/project.go index 56bf2776b7f3c..557f4766d2491 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -228,7 +228,7 @@ func CountProjects(ctx context.Context, opts SearchOptions) (int64, error) { // FindProjects returns a list of all projects that have been created in the repository func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, error) { - e := db.GetEngine(ctx).Where(opts.toConds()).OrderBy("title") + e := db.GetEngine(ctx).Where(opts.toConds()) projects := make([]*Project, 0, setting.UI.IssuePagingNum) if opts.Page > 0 { @@ -242,6 +242,8 @@ func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, e e.Desc("updated_unix") case "leastupdate": e.Asc("updated_unix") + case "title": + e.Asc("title") default: e.Asc("created_unix") } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 8a4568fa02009..dda61c1a31071 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -520,6 +520,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) { Page: -1, IsClosed: util.OptionalBoolFalse, Type: project_model.TypeRepository, + SortType: "title", }) if err != nil { ctx.ServerError("GetProjects", err) @@ -530,6 +531,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) { Page: -1, IsClosed: util.OptionalBoolFalse, Type: project_model.TypeOrganization, + SortType: "title", }) if err != nil { ctx.ServerError("GetProjects", err) From 1e76e8668585715979ecf7476cad63feb8898d77 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Fri, 9 Jun 2023 21:51:56 +0800 Subject: [PATCH 08/10] Update new_form.tmpl Remove span tag --- templates/repo/issue/new_form.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 6649477c12c74..00da68eb06fa1 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -113,7 +113,6 @@ {{range .OpenProjects}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}} - {{end}} {{end}} From df3c4ac99cf0725a1d11812969f08a04ef8b2668 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Mon, 12 Jun 2023 17:25:50 +0800 Subject: [PATCH 09/10] Fix remove project problem --- models/issues/issue_project.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index a735eea938622..58b8a59a32fc3 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -153,11 +153,12 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil { return err } - } else if i > 0 && i == newProjectID { + } else { + i = newProjectID + newProjectID = 0 if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=? AND project_issue.project_id=?", issue.ID, i).Delete(&project_model.ProjectIssue{}); err != nil { return err } - newProjectID = 0 } } @@ -173,8 +174,7 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U return err } } - - if action != "clear" && newProjectID == 0 || action == "attach" && newProjectID > 0 { + if action != "clear" && newProjectID == 0 || newProjectID > 0 { break } } From c21240fe76f6c6eea9248bae857e529c2b3a8a32 Mon Sep 17 00:00:00 2001 From: Tyrone Yeh Date: Tue, 13 Jun 2023 17:11:14 +0800 Subject: [PATCH 10/10] Modify projectIDs function for suggest --- models/issues/issue_project.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go index 58b8a59a32fc3..dc657bdfc60cc 100644 --- a/models/issues/issue_project.go +++ b/models/issues/issue_project.go @@ -29,17 +29,11 @@ func (issue *Issue) ProjectIDs() []int64 { } func (issue *Issue) projectIDs(ctx context.Context) []int64 { - var ip []project_model.ProjectIssue var ips []int64 - err := db.GetEngine(ctx).Select("project_id").Where("issue_id=?", issue.ID).Find(&ip) - if err != nil { + if err := db.GetEngine(ctx).Table("project_issue").Select("project_id").Where("issue_id=?", issue.ID).Find(&ips); err != nil { return nil } - for _, i := range ip { - ips = append(ips, i.ProjectID) - } - return ips }