|
@@ -6,6 +6,7 @@ package repo
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "net/url"
|
|
|
|
|
|
"github.com/codegangsta/martini"
|
|
|
|
|
@@ -17,23 +18,41 @@ import (
|
|
|
"github.com/gogits/gogs/modules/middleware"
|
|
|
)
|
|
|
|
|
|
-func Issues(ctx *middleware.Context, params martini.Params) {
|
|
|
+func Issues(ctx *middleware.Context) {
|
|
|
+ if !ctx.Repo.IsValid {
|
|
|
+ ctx.Handle(404, "issue.Issues(invalid repo):", nil)
|
|
|
+ }
|
|
|
+
|
|
|
ctx.Data["Title"] = "Issues"
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true
|
|
|
ctx.Data["IsRepoToolbarIssuesList"] = true
|
|
|
+ ctx.Data["ViewType"] = "all"
|
|
|
+
|
|
|
+ milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int()
|
|
|
+ page, _ := base.StrTo(ctx.Query("page")).Int()
|
|
|
|
|
|
- milestoneId, _ := base.StrTo(params["milestone"]).Int()
|
|
|
- page, _ := base.StrTo(params["page"]).Int()
|
|
|
+ ctx.Data["IssueCreatedCount"] = 0
|
|
|
+
|
|
|
+ var posterId int64 = 0
|
|
|
+ if ctx.Query("type") == "created_by" {
|
|
|
+ if !ctx.IsSigned {
|
|
|
+ ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI))
|
|
|
+ ctx.Redirect("/user/login/", 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ posterId = ctx.User.Id
|
|
|
+ ctx.Data["ViewType"] = "created_by"
|
|
|
+ ctx.Data["IssueCreatedCount"] = models.GetUserIssueCount(posterId, ctx.Repo.Repository.Id)
|
|
|
+ }
|
|
|
|
|
|
// Get issues.
|
|
|
- issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, 0,
|
|
|
- int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"])
|
|
|
+ issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, posterId, int64(milestoneId), page,
|
|
|
+ ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType"))
|
|
|
if err != nil {
|
|
|
ctx.Handle(200, "issue.Issues: %v", err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- var closedCount int
|
|
|
// Get posters.
|
|
|
for i := range issues {
|
|
|
u, err := models.GetUserById(issues[i].PosterId)
|
|
@@ -41,21 +60,22 @@ func Issues(ctx *middleware.Context, params martini.Params) {
|
|
|
ctx.Handle(200, "issue.Issues(get poster): %v", err)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if issues[i].IsClosed {
|
|
|
- closedCount++
|
|
|
- }
|
|
|
issues[i].Poster = u
|
|
|
}
|
|
|
|
|
|
ctx.Data["Issues"] = issues
|
|
|
- ctx.Data["IssueCount"] = len(issues)
|
|
|
- ctx.Data["OpenCount"] = len(issues) - closedCount
|
|
|
- ctx.Data["ClosedCount"] = closedCount
|
|
|
+ ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues
|
|
|
+ ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues
|
|
|
+ ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues
|
|
|
+ ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed"
|
|
|
ctx.HTML(200, "issue/list")
|
|
|
}
|
|
|
|
|
|
func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
|
|
|
+ if !ctx.Repo.IsValid {
|
|
|
+ ctx.Handle(404, "issue.CreateIssue(invalid repo):", nil)
|
|
|
+ }
|
|
|
+
|
|
|
ctx.Data["Title"] = "Create issue"
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true
|
|
|
ctx.Data["IsRepoToolbarIssuesList"] = false
|
|
@@ -71,15 +91,16 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
|
|
|
}
|
|
|
|
|
|
issue, err := models.CreateIssue(ctx.User.Id, ctx.Repo.Repository.Id, form.MilestoneId, form.AssigneeId,
|
|
|
- form.IssueName, form.Labels, form.Content, false)
|
|
|
+ ctx.Repo.Repository.NumIssues, form.IssueName, form.Labels, form.Content, false)
|
|
|
if err != nil {
|
|
|
ctx.Handle(200, "issue.CreateIssue", err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// Notify watchers.
|
|
|
- if err = models.NotifyWatchers(ctx.User.Id, ctx.Repo.Repository.Id, models.OP_CREATE_ISSUE,
|
|
|
- ctx.User.Name, ctx.Repo.Repository.Name, "", fmt.Sprintf("%d|%s", issue.Index, issue.Name)); err != nil {
|
|
|
+ if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name,
|
|
|
+ OpType: models.OP_CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),
|
|
|
+ RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil {
|
|
|
ctx.Handle(200, "issue.CreateIssue", err)
|
|
|
return
|
|
|
}
|
|
@@ -97,6 +118,10 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
|
|
|
}
|
|
|
|
|
|
func ViewIssue(ctx *middleware.Context, params martini.Params) {
|
|
|
+ if !ctx.Repo.IsValid {
|
|
|
+ ctx.Handle(404, "issue.ViewIssue(invalid repo):", nil)
|
|
|
+ }
|
|
|
+
|
|
|
index, err := base.StrTo(params["index"]).Int()
|
|
|
if err != nil {
|
|
|
ctx.Handle(404, "issue.ViewIssue", err)
|
|
@@ -120,6 +145,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
|
|
|
return
|
|
|
}
|
|
|
issue.Poster = u
|
|
|
+ issue.Content = string(base.RenderMarkdown([]byte(issue.Content), ""))
|
|
|
|
|
|
// Get comments.
|
|
|
comments, err := models.GetIssueComments(issue.Id)
|
|
@@ -136,6 +162,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
|
|
|
return
|
|
|
}
|
|
|
comments[i].Poster = u
|
|
|
+ comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ""))
|
|
|
}
|
|
|
|
|
|
ctx.Data["Title"] = issue.Name
|
|
@@ -147,6 +174,10 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
|
|
|
}
|
|
|
|
|
|
func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
|
|
|
+ if !ctx.Repo.IsValid {
|
|
|
+ ctx.Handle(404, "issue.UpdateIssue(invalid repo):", nil)
|
|
|
+ }
|
|
|
+
|
|
|
index, err := base.StrTo(params["index"]).Int()
|
|
|
if err != nil {
|
|
|
ctx.Handle(404, "issue.UpdateIssue", err)
|
|
@@ -183,6 +214,10 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
|
|
|
}
|
|
|
|
|
|
func Comment(ctx *middleware.Context, params martini.Params) {
|
|
|
+ if !ctx.Repo.IsValid {
|
|
|
+ ctx.Handle(404, "issue.Comment(invalid repo):", nil)
|
|
|
+ }
|
|
|
+
|
|
|
index, err := base.StrTo(ctx.Query("issueIndex")).Int()
|
|
|
if err != nil {
|
|
|
ctx.Handle(404, "issue.Comment", err)
|