Skip to content

Commit ee388a2

Browse files
committed
fix backend lint
as reported in https://drone.gitea.io/go-gitea/gitea/28939/1/4 use log.Error instead of log.Info fix comments fix eslint fix goimport order add migrations for project priorities fix _repository.less lint errors update swagger fixes according to @6543 suggestions s/NotInProjectID/ExcludeProjectID/g update boards priority in a single transaction as per @zeripath Co-authored-by: zeripath <art27@cantab.net> update swagger Clean up the indenting Co-authored-by: zeripath <art27@cantab.net> use tabs Co-authored-by: zeripath <art27@cantab.net> use tabs add loadRepository as per @zeripath suggestion move projects css to features/projects.less as per @silverwind request go-gitea#12506 (review) use transaction to update projects issues priorities as per @zeripath suggestion go-gitea#12506 (comment) make import fit on one line make use of loadRepository indent html properly as per suggestion by @silverwind go-gitea#12506 (comment) remove non-working code as per @zeripath suggestion go-gitea#12506 (comment) remove non-used code as per @zeripath suggestion go-gitea#12506 (comment) fix syntax, remove content-type on request go-gitea#12506 (comment) use closest instead of parent as per @silverwind suggestion go-gitea#12506 (review) use for instead of forEach because @silverwind use for instead of forEach because @silverwind go-gitea#12506 (review) use // falls through as per @silverwind go-gitea#12506 (comment) listen to body keyup only on project page go-gitea#12506 (review) Update models/project_board.go Co-authored-by: Lauris BH <lauris@nix.lv> move all issue related code to its own util file and re-use those functions in index.js and projects.js as per @silverwind and @zeripath Update models/project_issue.go Co-authored-by: 6543 <6543@obermui.de> fix linting Update web_src/js/features/issuesutil.js Co-authored-by: silverwind <me@silverwind.io> Update web_src/js/features/issuesutil.js Co-authored-by: silverwind <me@silverwind.io> Update web_src/js/features/issuesutil.js Co-authored-by: silverwind <me@silverwind.io> Update web_src/js/features/projects.js Co-authored-by: silverwind <me@silverwind.io> Update web_src/js/features/projects.js Co-authored-by: silverwind <me@silverwind.io> Update models/project_issue.go Update models/issue.go Co-authored-by: zeripath <art27@cantab.net> Update web_src/js/features/issuesutil.js Co-authored-by: silverwind <me@silverwind.io> various js fix per @silverwind suggestions various fixes according to @silverwind and @zeripath use await for fetch when possible specify table name as per @lafriks suggestion specify table name as per @lafriks suggestion in more queries go-gitea#12506 (review) go-gitea#12506 (comment) Update templates/repo/projects/view.tmpl Co-authored-by: silverwind <me@silverwind.io> Update templates/repo/projects/view.tmpl Co-authored-by: silverwind <me@silverwind.io> Update web_src/js/features/projects.js Co-authored-by: silverwind <me@silverwind.io> fix project_issue table name in query make another fetch async as per @silverwind Update models/project.go Co-authored-by: Lauris BH <lauris@nix.lv> Update models/project.go Co-authored-by: Lauris BH <lauris@nix.lv> more and rename UpdateBoards functions as per @6543 Update models/project.go Co-authored-by: Lauris BH <lauris@nix.lv> Update models/project.go Co-authored-by: Lauris BH <lauris@nix.lv> add / to route fixup! fix backend lint as reported in https://drone.gitea.io/go-gitea/gitea/28939/1/4 Update models/project.go Co-authored-by: zeripath <art27@cantab.net> Update routers/repo/issue.go Co-authored-by: zeripath <art27@cantab.net> Update web_src/less/features/projects.less Co-authored-by: silverwind <me@silverwind.io> fix uneeded column in query and remove css class as suggested by @silverwind Update models/project.go Co-authored-by: Lauris BH <lauris@nix.lv> add X to close sidebar and other css suggestions by @silverwind add emoji to project issue titles use issue.* instead as suggested by @zeripath still waiting for xorm v1.0.5 to update go.mod fix project_issue query for now fix card details css
1 parent 2fd630c commit ee388a2

File tree

23 files changed

+2019
-1870
lines changed

23 files changed

+2019
-1870
lines changed

Diff for: go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
288288
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
289289
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
290290
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
291+
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77 h1:ZLWiTTzTUBb0WEXUxobYI/RxULIzOoIP7pgfDd4p1cw=
291292
github.com/ethantkoenig/rupture v0.0.0-20181029165146-c3b3b810dc77/go.mod h1:MkKY/CB98aVE4VxO63X5vTQKUgcn+3XP15LMASe3lYs=
292293
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
293294
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
@@ -655,6 +656,7 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f
655656
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
656657
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
657658
github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da/go.mod h1:ks+b9deReOc7jgqp+e7LuFiCBH6Rm5hL32cLcEAArb4=
659+
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7 h1:g0fAGBisHaEQ0TRq1iBvemFRf+8AEWEmBESSiWB3Vsc=
658660
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk=
659661
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
660662
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
@@ -684,6 +686,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
684686
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
685687
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
686688
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
689+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
687690
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
688691
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
689692
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
@@ -1025,6 +1028,7 @@ github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM=
10251028
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
10261029
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
10271030
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
1031+
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo=
10281032
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
10291033
github.com/steveyen/gtreap v0.1.0 h1:CjhzTa274PyJLJuMZwIzCO1PfC00oRa8d1Kc78bFXJM=
10301034
github.com/steveyen/gtreap v0.1.0/go.mod h1:kl/5J7XbrOmlIbYIXdRHDDE5QxHqpk0cmkT7Z4dM9/Y=
@@ -1069,6 +1073,7 @@ github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnl
10691073
github.com/unknwon/i18n v0.0.0-20190805065654-5c6446a380b6/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
10701074
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c h1:679/gJXwrsHC3RATr0YYjZvDMJPYN7W9FGSGNoLmKxM=
10711075
github.com/unknwon/i18n v0.0.0-20200823051745-09abd91c7f2c/go.mod h1:+5rDk6sDGpl3azws3O+f+GpFSyN9GVr0K8cvQLQM2ZQ=
1076+
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae h1:ihaXiJkaca54IaCSnEXtE/uSZOmPxKZhDfVLrzZLFDs=
10721077
github.com/unknwon/paginater v0.0.0-20200328080006-042474bd0eae/go.mod h1:1fdkY6xxl6ExVs2QFv7R0F5IRZHKA8RahhB9fMC9RvM=
10731078
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
10741079
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=

Diff for: models/issue.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"code.gitea.io/gitea/modules/base"
1616
"code.gitea.io/gitea/modules/log"
17+
"code.gitea.io/gitea/modules/markup"
1718
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/modules/structs"
1920
api "code.gitea.io/gitea/modules/structs"
@@ -63,6 +64,7 @@ type Issue struct {
6364
Reactions ReactionList `xorm:"-"`
6465
TotalTrackedTime int64 `xorm:"-"`
6566
Assignees []*User `xorm:"-"`
67+
ProjectIssueID ProjectIssue
6668

6769
// IsLocked limits commenting abilities to users on an issue
6870
// with write access
@@ -1100,9 +1102,10 @@ type IssuesOptions struct {
11001102
ExcludedLabelNames []string
11011103
SortType string
11021104
IssueIDs []int64
1103-
NotInProjectID int64
1105+
ExcludeProjectID int64
11041106
// prioritize issues from this repo
1105-
PriorityRepoID int64
1107+
PriorityRepoID int64
1108+
RenderEmojiTitle util.OptionalBool
11061109
}
11071110

11081111
// sortIssuesSession sort an issues-related session based on the provided
@@ -1181,20 +1184,19 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
11811184

11821185
if opts.ProjectID > 0 {
11831186
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
1184-
And("project_issue.project_id=?", opts.ProjectID).OrderBy("priority")
1187+
And("project_issue.project_id=?", opts.ProjectID).OrderBy("`project_issue`.priority")
11851188
}
1189+
11861190
if opts.ProjectBoardID != 0 {
11871191
if opts.ProjectBoardID > 0 {
1188-
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}).OrderBy("priority"))
1192+
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}).OrderBy("`project_issue`.priority"))
11891193
} else {
1190-
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}).OrderBy("priority"))
1194+
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}).OrderBy("`project_issue`.priority"))
11911195
}
11921196
}
11931197

1194-
if opts.NotInProjectID != 0 {
1195-
if opts.NotInProjectID > 0 {
1196-
sess.NotIn("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_id": opts.NotInProjectID}).OrderBy("priority"))
1197-
}
1198+
if opts.ExcludeProjectID != 0 {
1199+
sess.NotIn("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_id": opts.ExcludeProjectID}).OrderBy("`project_issue`.priority"))
11981200
}
11991201

12001202
switch opts.IsPull {
@@ -1286,7 +1288,15 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
12861288
if err := IssueList(issues).LoadAttributes(); err != nil {
12871289
return nil, fmt.Errorf("LoadAttributes: %v", err)
12881290
}
1289-
1291+
if opts.RenderEmojiTitle == util.OptionalBoolTrue {
1292+
var issuesWithEmojis []*Issue
1293+
for _, issue := range issues {
1294+
title := string(markup.RenderEmoji(issue.Title))
1295+
issue.Title = title
1296+
issuesWithEmojis = append(issuesWithEmojis, issue)
1297+
}
1298+
return issuesWithEmojis, nil
1299+
}
12901300
return issues, nil
12911301
}
12921302

Diff for: models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ var migrations = []Migration{
252252
NewMigration("ensure repo topics are up-to-date", fixRepoTopics),
253253
// v158 -> v159
254254
NewMigration("code comment replies should have the commitID of the review they are replying to", updateCodeCommentReplies),
255+
// v159 -> v160
256+
NewMigration("Add projects boards and issues priorities", addProjectsIssuesBoardsPriority),
255257
}
256258

257259
// GetCurrentDBVersion returns the current db version

Diff for: models/migrations/v159.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func addProjectsIssuesBoardsPriority(x *xorm.Engine) error {
12+
// ProjectIssue saves relation from issue to a project
13+
type ProjectIssue struct {
14+
Priority int `xorm:"NOT NULL DEFAULT 0"`
15+
}
16+
17+
if err := x.Sync2(new(ProjectIssue)); err != nil {
18+
return err
19+
}
20+
21+
type ProjectBoard struct {
22+
Priority int `xorm:"NOT NULL DEFAULT 0"`
23+
}
24+
25+
return x.Sync2(new(ProjectBoard))
26+
}

Diff for: models/project.go

+12-39
Original file line numberDiff line numberDiff line change
@@ -308,50 +308,23 @@ func deleteProjectByID(e Engine, id int64) error {
308308
return updateRepositoryProjectCount(e, p.RepoID)
309309
}
310310

311-
// Update given boards priority for a project
312-
func UpdateBoards(boards []ProjectBoard) error {
313-
for _, board := range boards {
314-
if _, err := x.ID(board.ID).Cols("priority").Update(&board); err != nil {
315-
log.Info("failed updating board priorities %s", err)
316-
return err
317-
}
318-
319-
}
320-
return nil
311+
// LoadRepository loads repository of a given project
312+
func (p *Project) LoadRepository() error {
313+
return p.loadRepository(x)
321314
}
322315

323-
// Update given issue priority and column
324-
func UpdateBoardIssues(issues []ProjectIssue) (error, []ProjectIssue) {
325-
var updatedIssues []ProjectIssue
326-
for _, pissue := range issues {
327-
if pissue.ID != 0 {
328-
if _, err := x.ID(pissue.ID).Cols("priority", "project_board_id").Update(&pissue); err != nil {
329-
log.Info("failed updating cards priorities %s", err)
330-
return err, updatedIssues
331-
} else {
332-
updatedIssues = append(updatedIssues, pissue)
333-
}
334-
} else {
335-
if _, err := x.Insert(&pissue); err != nil {
336-
log.Info("failed inserting cards priorities %s", err)
337-
return err, updatedIssues
338-
} else {
339-
updatedIssues = append(updatedIssues, pissue)
340-
}
341-
}
316+
// loadRepository loads repository of a given project
317+
func (p *Project) loadRepository(e Engine) error {
318+
if p.Repo != nil {
319+
return nil
342320
}
343-
return nil, updatedIssues
344-
}
345-
346-
func (p *Project) LoadRepository() error {
347-
var repo = Repository{}
348321
if p.Type == ProjectTypeRepository {
349-
_, err := x.ID(p.RepoID).Get(&repo)
350-
p.Repo = &repo
351-
if err != nil {
352-
log.Info("failed getting repo %w", err)
322+
repo := &Repository{}
323+
if _, err := e.ID(p.RepoID).Get(repo); err != nil {
324+
log.Info("failed getting repo %v", err)
325+
return err
353326
}
354-
return err
327+
p.Repo = repo
355328
}
356329
return nil
357330
}

Diff for: models/project_board.go

+36-18
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ProjectBoard struct {
3636
ID int64 `xorm:"pk autoincr"`
3737
Title string
3838
Default bool `xorm:"NOT NULL DEFAULT false"` // issues not assigned to a specific board will be assigned to this board
39-
Priority int
39+
Priority int `xorm:"NOT NULL DEFAULT 0"`
4040

4141
ProjectID int64 `xorm:"INDEX NOT NULL"`
4242
CreatorID int64 `xorm:"NOT NULL"`
@@ -190,7 +190,7 @@ func GetUncategorizedBoard(projectID int64) (*ProjectBoard, error) {
190190
}, nil
191191
}
192192

193-
// LoadIssues load issues assigned to this board
193+
// LoadProjectIssues load project issues assigned to this board
194194
func (b *ProjectBoard) LoadProjectIssues() ([]*ProjectIssue, error) {
195195
var boardID int64
196196
if !b.Default {
@@ -200,25 +200,27 @@ func (b *ProjectBoard) LoadProjectIssues() ([]*ProjectIssue, error) {
200200
// Issues without ProjectBoardID
201201
boardID = 0
202202
}
203-
var projectIssuesDB []*ProjectIssue
204203
var projectIssues []*ProjectIssue
205-
err := x.Table("project_issue").Where("project_board_id = ? and project_id =?",
206-
boardID, b.ProjectID).
207-
OrderBy("priority").Find(&projectIssuesDB)
208-
for _, projectIssue := range projectIssuesDB {
209-
if issue, err := getIssueByID(x, projectIssue.IssueID); err != nil {
210-
log.Info("failed getting projectIssue's issue %v\n", err)
211-
} else {
212-
issue.LoadLabels()
213-
issue.LoadMilestone()
214-
issue.loadAssignees(x)
215-
projectIssue.Issue = issue
216-
projectIssues = append(projectIssues, projectIssue)
217-
}
204+
var issues []*Issue
205+
if err := x.Table("issue").
206+
Cols("issue.id, issue.repo_id, issue.index, issue.poster_id,issue.name,issue.milestone_id,issue.is_closed,issue.is_pull,issue.created_unix,issue.updated_unix, project_issue.id as project_issue_id, project_issue.project_id as project_issue_project_id, project_issue.project_board_id as project_issue_project_board_id").
207+
Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
208+
Where("project_board_id = ? and project_id =?",
209+
boardID, b.ProjectID).
210+
OrderBy("`project_issue`.priority").Find(&issues); err != nil {
211+
log.Error("LoadAttributes: %v", err)
212+
}
213+
214+
if err := IssueList(issues).LoadAttributes(); err != nil {
215+
log.Error("LoadAttributes: %v", err)
218216
}
219217

220-
b.ProjectIssues = projectIssues
221-
return projectIssues, err
218+
for _, issue := range issues {
219+
projectIssue := issue.ProjectIssueID
220+
projectIssue.Issue = issue
221+
projectIssues = append(projectIssues, &projectIssue)
222+
}
223+
return projectIssues, nil
222224
}
223225

224226
// LoadIssues load issues assigned to the boards
@@ -232,3 +234,19 @@ func (bs ProjectBoardList) LoadIssues() error {
232234
}
233235
return nil
234236
}
237+
238+
// UpdateBoardsPriority updates boards priority for a project
239+
func UpdateBoardsPriority(boards []ProjectBoard) error {
240+
sess := x.NewSession()
241+
if err := sess.Begin(); err != nil {
242+
return err
243+
}
244+
defer sess.Close()
245+
for _, board := range boards {
246+
if _, err := sess.ID(board.ID).Cols("priority").Update(&board); err != nil {
247+
log.Info("failed updating board priorities %s", err)
248+
return err
249+
}
250+
}
251+
return sess.Commit()
252+
}

Diff for: models/project_issue.go

+43-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import (
88
"fmt"
99

1010
"code.gitea.io/gitea/modules/log"
11+
1112
"xorm.io/xorm"
1213
)
1314

1415
// ProjectIssue saves relation from issue to a project
1516
type ProjectIssue struct {
16-
ID int64 `xorm:"pk autoincr"`
17-
IssueID int64 `xorm:"INDEX"`
18-
ProjectID int64 `xorm:"INDEX"`
19-
IssueTitle string `xorm:"-"`
20-
IssueIsPull bool `xorm:"-"`
21-
Priority int
22-
Issue *Issue `xorm:"-"`
17+
ID int64 `xorm:"pk autoincr"`
18+
IssueID int64 `xorm:"INDEX"`
19+
ProjectID int64 `xorm:"INDEX"`
20+
Priority int `xorm:"NOT NULL DEFAULT 0"`
21+
Issue *Issue `xorm:"-"`
2322

2423
// If 0, then it has not been added to a specific board in the project
2524
ProjectBoardID int64 `xorm:"INDEX"`
@@ -69,12 +68,12 @@ func (i *Issue) projectID(e Engine) int64 {
6968
return ip.ProjectID
7069
}
7170

72-
// ProjectBoardID return project board id if issue was assigned to one
73-
func (i *Issue) ProjectBoardID() int64 {
74-
return i.projectBoardID(x)
71+
// LoadProjectBoardID return project board id if issue was assigned to one
72+
func (i *Issue) LoadProjectBoardID() int64 {
73+
return i.loadProjectBoardID(x)
7574
}
7675

77-
func (i *Issue) projectBoardID(e Engine) int64 {
76+
func (i *Issue) loadProjectBoardID(e Engine) int64 {
7877
var ip ProjectIssue
7978
has, err := e.Where("issue_id=?", i.ID).Get(&ip)
8079
if err != nil || !has {
@@ -146,7 +145,6 @@ func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
146145
func addUpdateIssueProject(e *xorm.Session, issue *Issue, doer *User, newProjectID int64) error {
147146
oldProjectID := issue.projectID(e)
148147
if _, err := e.Where("project_issue.issue_id=?", issue.ID).Delete(&ProjectIssue{}); err != nil {
149-
log.Info("failed deleting project issue %w", err)
150148
return err
151149
}
152150

@@ -222,3 +220,36 @@ func (pb *ProjectBoard) removeIssues(e Engine) error {
222220
_, err := e.Exec("UPDATE `project_issue` SET project_board_id = 0 WHERE project_board_id = ? ", pb.ID)
223221
return err
224222
}
223+
224+
// UpdateBoardIssuesPriority update given board issue priority
225+
func UpdateBoardIssuesPriority(issues []ProjectIssue) ([]ProjectIssue, error) {
226+
sess := x.NewSession()
227+
if err := sess.Begin(); err != nil {
228+
var updatedIssues []ProjectIssue
229+
return updatedIssues, err
230+
}
231+
defer sess.Close()
232+
var updatedIssues []ProjectIssue
233+
for _, pissue := range issues {
234+
if pissue.ID != 0 {
235+
if _, err := sess.ID(pissue.ID).Cols("priority", "project_board_id").Update(&pissue); err != nil {
236+
log.Info("failed updating cards priorities %s", err)
237+
return updatedIssues, err
238+
}
239+
updatedIssues = append(updatedIssues, pissue)
240+
} else {
241+
var existingIssue ProjectIssue
242+
if found, err := sess.Where("issue_id = ? and project_id = ?", pissue.IssueID, pissue.ProjectID).
243+
Get(&existingIssue); err != nil {
244+
log.Error("failed finding issue %s", err)
245+
} else if !found {
246+
if _, err := sess.Insert(&pissue); err != nil {
247+
log.Info("failed inserting cards priorities %s", err)
248+
return updatedIssues, err
249+
}
250+
updatedIssues = append(updatedIssues, pissue)
251+
}
252+
}
253+
}
254+
return updatedIssues, sess.Commit()
255+
}

Diff for: modules/auth/repo_form.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) bindi
762762

763763
// UpdateBoardPriorityForm form for updating cards on drag and drop
764764
type UpdateBoardPriorityForm struct {
765-
Boards []models.ProjectBoard `form:"boards" json:"boards"`
765+
Boards []models.ProjectBoard
766766
}
767767

768768
// Validate validates the fields

0 commit comments

Comments
 (0)