Skip to content

Commit 2fd630c

Browse files
committed
make it possible to add issues to project from projects
1 parent 68702e8 commit 2fd630c

File tree

11 files changed

+265
-109
lines changed

11 files changed

+265
-109
lines changed

models/issue.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ type IssuesOptions struct {
11001100
ExcludedLabelNames []string
11011101
SortType string
11021102
IssueIDs []int64
1103+
NotInProjectID int64
11031104
// prioritize issues from this repo
11041105
PriorityRepoID int64
11051106
}
@@ -1182,7 +1183,6 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
11821183
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
11831184
And("project_issue.project_id=?", opts.ProjectID).OrderBy("priority")
11841185
}
1185-
11861186
if opts.ProjectBoardID != 0 {
11871187
if opts.ProjectBoardID > 0 {
11881188
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}).OrderBy("priority"))
@@ -1191,6 +1191,12 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
11911191
}
11921192
}
11931193

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+
}
1199+
11941200
switch opts.IsPull {
11951201
case util.OptionalBoolTrue:
11961202
sess.And("issue.is_pull=?", true)

models/project.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Project struct {
4848
IsClosed bool `xorm:"INDEX"`
4949
BoardType ProjectBoardType
5050
Type ProjectType
51+
Repo *Repository `xorm:"-"`
5152

5253
RenderedContent string `xorm:"-"`
5354

@@ -320,13 +321,37 @@ func UpdateBoards(boards []ProjectBoard) error {
320321
}
321322

322323
// Update given issue priority and column
323-
func UpdateBoardIssues(issues []ProjectIssue) error {
324-
for _, issue := range issues {
325-
if _, err := x.ID(issue.ID).Cols("priority", "project_board_id").Update(&issue); err != nil {
326-
log.Info("failed updating cards priorities %s", err)
327-
return err
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+
}
328341
}
342+
}
343+
return nil, updatedIssues
344+
}
329345

346+
func (p *Project) LoadRepository() error {
347+
var repo = Repository{}
348+
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)
353+
}
354+
return err
330355
}
331356
return nil
332357
}

models/project_issue.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package models
77
import (
88
"fmt"
99

10+
"code.gitea.io/gitea/modules/log"
1011
"xorm.io/xorm"
1112
)
1213

@@ -143,10 +144,9 @@ func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
143144
}
144145

145146
func addUpdateIssueProject(e *xorm.Session, issue *Issue, doer *User, newProjectID int64) error {
146-
147147
oldProjectID := issue.projectID(e)
148-
149148
if _, err := e.Where("project_issue.issue_id=?", issue.ID).Delete(&ProjectIssue{}); err != nil {
149+
log.Info("failed deleting project issue %w", err)
150150
return err
151151
}
152152

@@ -167,11 +167,21 @@ func addUpdateIssueProject(e *xorm.Session, issue *Issue, doer *User, newProject
167167
}
168168
}
169169

170-
_, err := e.Insert(&ProjectIssue{
171-
IssueID: issue.ID,
172-
ProjectID: newProjectID,
173-
})
174-
return err
170+
var projectIssues []ProjectIssue
171+
if newProjectID != 0 {
172+
err := e.Where("issue_id = ? and project_id = ?", issue.ID, newProjectID).Find(&projectIssues)
173+
if err != nil {
174+
return err
175+
}
176+
if len(projectIssues) == 0 {
177+
_, err := e.Insert(&ProjectIssue{
178+
IssueID: issue.ID,
179+
ProjectID: newProjectID,
180+
})
181+
return err
182+
}
183+
}
184+
return nil
175185
}
176186

177187
// ____ _ _ ____ _

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ new_fork = New Repository Fork
5656
new_org = New Organization
5757
new_project = New Project
5858
new_project_board = New Project board
59+
add_project_issue = Add Issue
5960
manage_org = Manage Organizations
6061
admin_panel = Site Administration
6162
account_settings = Account Settings

routers/api/v1/repo/issue.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func SearchIssues(ctx *context.APIContext) {
5151
// description: repository to prioritize in the results
5252
// type: integer
5353
// format: int64
54+
// - name: not_in_project_id
55+
// in: query
56+
// description: project to exclude from search when searching issues to add to a project
57+
// type: integer
58+
// format: int64
5459
// - name: type
5560
// in: query
5661
// description: filter by type (issues / pulls) if set
@@ -158,6 +163,7 @@ func SearchIssues(ctx *context.APIContext) {
158163
SortType: "priorityrepo",
159164
PriorityRepoID: ctx.QueryInt64("priority_repo_id"),
160165
IsPull: isPull,
166+
NotInProjectID: ctx.QueryInt64("not_in_project_id"),
161167
}
162168

163169
if issues, err = models.Issues(issuesOpt); err != nil {
@@ -314,13 +320,14 @@ func ListIssues(ctx *context.APIContext) {
314320
// This would otherwise return all issues if no issues were found by the search.
315321
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
316322
issuesOpt := &models.IssuesOptions{
317-
ListOptions: listOptions,
318-
RepoIDs: []int64{ctx.Repo.Repository.ID},
319-
IsClosed: isClosed,
320-
IssueIDs: issueIDs,
321-
LabelIDs: labelIDs,
322-
MilestoneIDs: mileIDs,
323-
IsPull: isPull,
323+
ListOptions: listOptions,
324+
RepoIDs: []int64{ctx.Repo.Repository.ID},
325+
IsClosed: isClosed,
326+
IssueIDs: issueIDs,
327+
LabelIDs: labelIDs,
328+
MilestoneIDs: mileIDs,
329+
IsPull: isPull,
330+
NotInProjectID: ctx.QueryInt64("not_in_project_id"),
324331
}
325332

326333
if issues, err = models.Issues(issuesOpt); err != nil {

routers/repo/projects.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/auth"
1313
"code.gitea.io/gitea/modules/base"
1414
"code.gitea.io/gitea/modules/context"
15+
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/markup/markdown"
1617
"code.gitea.io/gitea/modules/setting"
1718
"code.gitea.io/gitea/modules/util"
@@ -265,6 +266,7 @@ func ViewProject(ctx *context.Context) {
265266
}
266267
return
267268
}
269+
268270
if project.RepoID != ctx.Repo.Repository.ID {
269271
ctx.NotFound("", nil)
270272
return
@@ -298,7 +300,10 @@ func ViewProject(ctx *context.Context) {
298300
ctx.Data["Boards"] = allBoards
299301
ctx.Data["PageIsProjects"] = true
300302
ctx.Data["RequiresDraggable"] = true
301-
303+
project.LoadRepository()
304+
if project.Repo != nil && project.Repo.ID != 0 {
305+
ctx.Data["Repo"] = project.Repo
306+
}
302307
ctx.HTML(200, tplProjectsView)
303308
}
304309

@@ -624,8 +629,10 @@ func UpdateBoardIssuePriority(ctx *context.Context, form auth.UpdateIssuePriorit
624629
return
625630
}
626631

627-
issues := form
628-
models.UpdateBoardIssues(form.Issues)
632+
err, issues := models.UpdateBoardIssues(form.Issues)
633+
if err != nil {
634+
log.Info("failed updating issues %v", err)
635+
}
629636

630637
ctx.JSON(200, issues)
631638
}

templates/repo/issue/view_content/sidebar.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="four wide column">
22
<div class="ui segment metas">
33
{{if eq .Sidebar true}}
4-
<h3>#{{.Issue.ID}} {{.Issue.Title}}</h3>
4+
<h3>#{{.Issue.Index}} {{.Issue.Title}}</h3>
55
{{end}}
66
{{template "repo/issue/branch_selector_field" .}}
77

templates/repo/projects/view.tmpl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
</div>
1212
<div class="column right aligned">
1313
{{if and .CanWriteProjects (not .Repository.IsArchived) .PageIsProjects}}
14-
<a class="ui green button show-modal item" data-modal="#new-board-item">{{.i18n.Tr "new_project_board"}}</a>
14+
<button class="ui green button show-modal item"
15+
data-modal="#new-board-item">
16+
<i class="add icon"></i>
17+
{{.i18n.Tr "new_project_board"}}</button>
18+
<button class="ui green button show-modal item"
19+
id="new-project-issue-item">
20+
<i class="add icon"></i>
21+
{{.i18n.Tr "add_project_issue"}}</button>
1522
{{end}}
1623
<div class="ui small modal" id="new-board-item">
1724
<div class="header">
@@ -68,9 +75,9 @@
6875
<div class="ui divider"></div>
6976
</div>
7077
<div class="ui container fluid padded" id="project-board">
71-
72-
<div class="board" id="board-container" data-url="{{.RepoLink}}/projects/{{$.Project.ID}}">
73-
<div class="ui segment ignore-elements hide" id="current-card-details"></div>
78+
<div id="current-card-details-input"></div>
79+
<div class="board" id="board-container" data-repourl="{{.RepoLink}}" data-projectid="{{.Project.ID}}" data-url="{{.RepoLink}}/projects/{{$.Project.ID}}">
80+
<div class="ui segment ignore-elements" id="current-card-details"></div>
7481
{{ range $board := .Boards }}
7582

7683
<div class="ui segment board-column {{if eq .ID 0}}ignore-elements{{end}}"
@@ -156,7 +163,7 @@
156163
{{else}}{{svg "octicon-issue-opened"}}
157164
{{end}}
158165
</span>
159-
<a class="project-board-title" href="{{$.RepoLink}}/{{if .Issue.IsPull}}pulls{{else}}issues{{end}}/{{.IssueID}}" data-url="{{$.RepoLink}}/{{if .Issue.IsPull}}pulls{{else}}issues{{end}}/{{.IssueID}}/sidebar/true">#{{.IssueID}} {{.Issue.Title}}</a>
166+
<a class="project-board-title" href="{{$.RepoLink}}/{{if .Issue.IsPull}}pulls{{else}}issues{{end}}/{{.Issue.Index}}" data-url="{{$.RepoLink}}/{{if .Issue.IsPull}}pulls{{else}}issues{{end}}/{{.Issue.Index}}/sidebar/true">#{{.Issue.Index}} {{.Issue.Title}}</a>
160167
</div>
161168
<div class="meta">
162169
{{ if .Issue.MilestoneID }}

0 commit comments

Comments
 (0)