UI: basci issue list without filters

- fix isRead check
- fix paging
This commit is contained in:
Unknwon 2015-07-24 16:42:47 +08:00
parent 4447a20f87
commit 86dbda0b42
16 changed files with 95 additions and 164 deletions

View file

@ -416,14 +416,18 @@ func runWeb(ctx *cli.Context) {
m.Post("/:index/milestone", repo.UpdateIssueMilestone)
m.Post("/:index/assignee", repo.UpdateAssignee)
m.Get("/:index/attachment/:id", repo.IssueGetAttachment)
m.Post("/labels/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
m.Post("/labels/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
m.Post("/labels/delete", repo.DeleteLabel)
m.Get("/milestones/new", repo.NewMilestone)
m.Post("/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
m.Get("/milestones/:index/edit", repo.UpdateMilestone)
m.Post("/milestones/:index/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.UpdateMilestonePost)
m.Get("/milestones/:index/:action", repo.UpdateMilestone)
})
m.Group("/labels", func() {
m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
m.Post("/delete", repo.DeleteLabel)
})
m.Group("/milestones", func() {
m.Get("/new", repo.NewMilestone)
m.Post("/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
m.Get("/:index/edit", repo.UpdateMilestone)
m.Post("/:index/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.UpdateMilestonePost)
m.Get("/:index/:action", repo.UpdateMilestone)
})
m.Post("/comment/:action", repo.Comment)
@ -440,7 +444,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/releases", middleware.RepoRef(), repo.Releases)
m.Get("/issues", repo.Issues)
m.Get("/issues/:index", repo.ViewIssue)
m.Get("/issues/milestones", repo.Milestones)
m.Get("/milestones", repo.Milestones)
m.Get("/pulls", repo.Pulls)
m.Get("/branches", repo.Branches)
m.Get("/archive/*", repo.Download)

View file

@ -369,6 +369,8 @@ issues.filter_type.assigned_to_you = Assigned to you
issues.filter_type.created_by_you = Created by you
issues.filter_type.mentioning_you = Mentioning you
issues.opened_by = opened %s by <a href="/%[2]s">%[2]s</a>
issues.previous = Previous Page
issues.next = Next Page
settings = Settings
settings.options = Options

View file

@ -17,6 +17,7 @@ import (
"github.com/go-xorm/xorm"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
)
var (
@ -114,19 +115,14 @@ func (i *Issue) AfterDelete() {
// CreateIssue creates new issue for repository.
func NewIssue(issue *Issue) (err error) {
sess := x.NewSession()
defer sess.Close()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if _, err = sess.Insert(issue); err != nil {
sess.Rollback()
return err
}
rawSql := "UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?"
if _, err = sess.Exec(rawSql, issue.RepoId); err != nil {
sess.Rollback()
} else if _, err = sess.Exec("UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?", issue.RepoId); err != nil {
return err
}
@ -191,7 +187,7 @@ func GetIssueById(id int64) (*Issue, error) {
// GetIssues returns a list of issues by given conditions.
func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sortType string) ([]Issue, error) {
sess := x.Limit(20, (page-1)*20)
sess := x.Limit(setting.IssuePagingNum, (page-1)*setting.IssuePagingNum)
if rid > 0 {
sess.Where("repo_id=?", rid).And("is_closed=?", isClosed)
@ -211,9 +207,8 @@ func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sort
if len(labelIds) > 0 {
for _, label := range strings.Split(labelIds, ",") {
// Prevent SQL inject.
if com.StrTo(label).MustInt() > 0 {
sess.And("label_ids like '%$" + label + "|%'")
sess.And("label_ids like ?", "'%$"+label+"|%'")
}
}
}
@ -236,8 +231,7 @@ func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labelIds, sort
}
var issues []Issue
err := sess.Find(&issues)
return issues, err
return issues, sess.Find(&issues)
}
type IssueStatus int
@ -281,6 +275,7 @@ type IssueUser struct {
IsClosed bool
}
// FIXME: organization
// NewIssueUserPairs adds new issue-user pairs for new issue of repository.
func NewIssueUserPairs(repo *Repository, issueID, orgID, posterID, assigneeID int64) error {
users, err := repo.GetCollaborators()
@ -316,13 +311,24 @@ func NewIssueUserPairs(repo *Repository, issueID, orgID, posterID, assigneeID in
}
}
// Add owner's as well.
if repo.OwnerId != posterID {
iu.Id = 0
iu.Uid = repo.OwnerId
iu.IsAssigned = iu.Uid == assigneeID
if _, err = x.Insert(iu); err != nil {
return err
}
}
return nil
}
// PairsContains returns true when pairs list contains given issue.
func PairsContains(ius []*IssueUser, issueId int64) int {
func PairsContains(ius []*IssueUser, issueId, uid int64) int {
for i := range ius {
if ius[i].IssueId == issueId {
if ius[i].IssueId == issueId &&
ius[i].Uid == uid {
return i
}
}

File diff suppressed because one or more lines are too long

View file

@ -84,6 +84,7 @@ var (
// Repository settings.
RepoRootPath string
ScriptType string
IssuePagingNum int = 10
// Picture settings.
PictureService string

File diff suppressed because one or more lines are too long

View file

@ -35,7 +35,7 @@ function initInstall() {
$(document).ready(function () {
// Semantic UI modules.
$('.dropdown').dropdown();
$('.link.dropdown').dropdown({
$('.jump.dropdown').dropdown({
action: 'hide'
});
$('.slide.up.dropdown').dropdown({

View file

@ -52,8 +52,9 @@
.issue.list {
list-style: none;
font-size: 13px;
padding-top: 60px;
padding-top: 45px;
.item {
padding-top: 15px;
padding-bottom: 10px;
border-bottom: 1px dashed #AAA;
.title {
@ -74,5 +75,8 @@
color: #999;
}
}
.page.buttons {
padding-top: 15px;
}
}
}

View file

@ -43,8 +43,6 @@ var (
func Issues(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues")
ctx.Data["PageIsIssueList"] = true
ctx.Data["IsRepoToolbarIssues"] = true
ctx.Data["IsRepoToolbarIssuesList"] = true
viewType := ctx.Query("type")
types := []string{"assigned", "created_by", "mentioned"}
@ -54,6 +52,7 @@ func Issues(ctx *middleware.Context) {
isShowClosed := ctx.Query("state") == "closed"
// Must sign in to see issues about you.
if viewType != "all" && !ctx.IsSigned {
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl)
ctx.Redirect(setting.AppSubUrl + "/user/login")
@ -73,21 +72,23 @@ func Issues(ctx *middleware.Context) {
filterMode = models.FM_MENTION
}
repo := ctx.Repo.Repository
var mid int64
midx, _ := com.StrTo(ctx.Query("milestone")).Int64()
midx := ctx.QueryInt64("milestone")
if midx > 0 {
mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, midx)
mile, err := models.GetMilestoneByIndex(repo.Id, midx)
if err != nil {
ctx.Handle(500, "issue.Issues(GetMilestoneByIndex): %v", err)
ctx.Handle(500, "GetMilestoneByIndex: %v", err)
return
}
mid = mile.Id
}
selectLabels := ctx.Query("labels")
labels, err := models.GetLabels(ctx.Repo.Repository.Id)
labels, err := models.GetLabels(repo.Id)
if err != nil {
ctx.Handle(500, "issue.Issues(GetLabels): %v", err)
ctx.Handle(500, "GetLabels: %v", err)
return
}
for _, l := range labels {
@ -95,20 +96,29 @@ func Issues(ctx *middleware.Context) {
}
ctx.Data["Labels"] = labels
page, _ := com.StrTo(ctx.Query("page")).Int()
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
} else {
ctx.Data["PreviousPage"] = page - 1
}
if (!isShowClosed && repo.NumOpenIssues > setting.IssuePagingNum*page) ||
(isShowClosed && repo.NumClosedIssues > setting.IssuePagingNum*page) {
ctx.Data["NextPage"] = page + 1
}
// Get issues.
issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mid, page,
issues, err := models.GetIssues(assigneeId, repo.Id, posterId, mid, page,
isShowClosed, selectLabels, ctx.Query("sortType"))
if err != nil {
ctx.Handle(500, "issue.Issues(GetIssues): %v", err)
ctx.Handle(500, "GetIssues: %v", err)
return
}
// Get issue-user pairs.
pairs, err := models.GetIssueUserPairs(ctx.Repo.Repository.Id, posterId, isShowClosed)
pairs, err := models.GetIssueUserPairs(repo.Id, posterId, isShowClosed)
if err != nil {
ctx.Handle(500, "issue.Issues(GetIssueUserPairs): %v", err)
ctx.Handle(500, "GetIssueUserPairs: %v", err)
return
}
@ -119,7 +129,7 @@ func Issues(ctx *middleware.Context) {
return
}
idx := models.PairsContains(pairs, issues[i].Id)
idx := models.PairsContains(pairs, issues[i].Id, ctx.User.Id)
if filterMode == models.FM_MENTION && (idx == -1 || !pairs[idx].IsMentioned) {
continue
@ -132,7 +142,7 @@ func Issues(ctx *middleware.Context) {
}
if err = issues[i].GetPoster(); err != nil {
ctx.Handle(500, "issue.Issues(GetPoster)", fmt.Errorf("[#%d]%v", issues[i].Id, err))
ctx.Handle(500, "GetPoster", fmt.Errorf("[#%d]%v", issues[i].Id, err))
return
}
}
@ -141,9 +151,9 @@ func Issues(ctx *middleware.Context) {
if ctx.User != nil {
uid = ctx.User.Id
}
issueStats := models.GetIssueStats(ctx.Repo.Repository.Id, uid, isShowClosed, filterMode)
issueStats := models.GetIssueStats(repo.Id, uid, isShowClosed, filterMode)
ctx.Data["IssueStats"] = issueStats
ctx.Data["SelectLabels"], _ = com.StrTo(selectLabels).Int64()
ctx.Data["SelectLabels"] = com.StrTo(selectLabels).MustInt64()
ctx.Data["ViewType"] = viewType
ctx.Data["Issues"] = issues
ctx.Data["IsShowClosed"] = isShowClosed

View file

@ -44,7 +44,7 @@
<img class="img-15" src="{{.SignedUser.AvatarLink}}"/>
<span class="sr-only">{{.SignedUser.Name}}</span>
</a>
<div class="ui pointing dropdown head link item">
<div class="ui pointing dropdown head link jump item">
<span class="text">
<i class="octicon octicon-plus"></i>
<i class="dropdown icon"></i>

View file

@ -22,7 +22,7 @@
</div>
</div>
<div class="ui right floated secondary filter menu">
<div class="ui {{if not .Labels}}disabled{{end}} pointing dropdown item">
<div class="ui {{if not .Labels}}disabled{{end}} pointing dropdown jump item">
<span class="text">
{{.i18n.Tr "repo.issues.filter_label"}}
<i class="dropdown icon"></i>
@ -33,7 +33,7 @@
{{end}}
</div>
</div>
<div class="ui {{if not .Milestones}}disabled{{end}} pointing dropdown item">
<div class="ui {{if not .Milestones}}disabled{{end}} pointing dropdown jump item">
<span class="text">
{{.i18n.Tr "repo.issues.filter_milestone"}}
<i class="dropdown icon"></i>
@ -44,7 +44,7 @@
{{end}}
</div>
</div>
<div class="ui {{if not .Assignees}}disabled{{end}} pointing dropdown item">
<div class="ui {{if not .Assignees}}disabled{{end}} pointing dropdown jump item">
<span class="text">
{{.i18n.Tr "repo.issues.filter_assignee"}}
<i class="dropdown icon"></i>
@ -55,7 +55,7 @@
{{end}}
</div>
</div>
<div class="ui pointing dropdown type item">
<div class="ui pointing dropdown type jump item">
<span class="text">
{{.i18n.Tr "repo.issues.filter_type"}}
<i class="dropdown icon"></i>
@ -73,12 +73,17 @@
{{range .Issues}}
{{ $timeStr:= TimeSince .Created $.Lang }}
<li class="item">
<div class="ui black label">#{{.Id}}</div>
<div class="ui {{if .IsRead}}black{{else}}green{{end}} label">#{{.Id}}</div>
<a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Name}}</a>
<p class="desc">{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.Name|Str2html}}</p>
{{if .NumComments}}<span class="comment ui right"><i class="octicon octicon-comment"></i> {{.NumComments}}</span>{{end}}
<p class="desc">{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.Name|Str2html}}</p>
</li>
{{end}}
<div class="center page buttons">
<a class="ui {{if not .PreviousPage}}disabled{{end}} blue button" href="{{.RepoLink}}/issues?page={{.PreviousPage}}">{{.i18n.Tr "repo.issues.previous"}}</a>
<a class="ui {{if not .NextPage}}disabled{{end}} blue button" href="{{.RepoLink}}/issues?page={{.NextPage}}">{{.i18n.Tr "repo.issues.next"}}</a>
</div>
</div>
</div>
</div>

View file

@ -6,11 +6,11 @@
<div id="issue">
<div class="col-md-3 filter-list">
<ul class="list-unstyled">
<li><a href="{{.RepoLink}}/issues/milestones"{{if eq .State "open"}} class="active"{{end}}>Open Milestones <strong class="pull-right">{{.Repository.NumOpenMilestones}}</strong></a></li>
<li><a href="{{.RepoLink}}/issues/milestones?state=closed"{{if eq .State "closed"}} class="active"{{end}}>Close Milestones <strong class="pull-right">{{.Repository.NumClosedMilestones}}</strong></a></li>
<li><a href="{{.RepoLink}}/milestones"{{if eq .State "open"}} class="active"{{end}}>Open Milestones <strong class="pull-right">{{.Repository.NumOpenMilestones}}</strong></a></li>
<li><a href="{{.RepoLink}}/milestones?state=closed"{{if eq .State "closed"}} class="active"{{end}}>Close Milestones <strong class="pull-right">{{.Repository.NumClosedMilestones}}</strong></a></li>
</ul>
<hr/>
<a href="{{.RepoLink}}/issues/milestones/new" class="text-center">
<a href="{{.RepoLink}}/milestones/new" class="text-center">
<button class="btn btn-default btn-block">Create new milestone</button>
</a>
</div>
@ -22,13 +22,13 @@
<span class="issue-open label label-success">{{.NumOpenIssues}}</span>
<span class="issue-close label label-warning">{{.NumClosedIssues}}</span>
<p class="actions pull-right">
<a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/edit">Edit</a>
<a href="{{$.RepoLink}}/milestones/{{.Index}}/edit">Edit</a>
{{if .IsClosed}}
<a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/open">Open</a>
<a href="{{$.RepoLink}}/milestones/{{.Index}}/open">Open</a>
{{else}}
<a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/close">Close</a>
<a href="{{$.RepoLink}}/milestones/{{.Index}}/close">Close</a>
{{end}}
<a class="text-danger" href="{{$.RepoLink}}/issues/milestones/{{.Index}}/delete">Delete</a>
<a class="text-danger" href="{{$.RepoLink}}/milestones/{{.Index}}/delete">Delete</a>
<a href="{{$.RepoLink}}/issues?milestone={{.Index}}{{if .IsClosed}}&state=closed{{end}}">Issues</a>
</p>
<hr/>

View file

@ -4,7 +4,7 @@
{{template "repo/toolbar" .}}
<div id="body" class="container">
<div id="issue">
<form class="form" action="{{.RepoLink}}/issues/milestones/{{.Milestone.Index}}/edit" method="post" id="issue-create-form">
<form class="form" action="{{.RepoLink}}/milestones/{{.Milestone.Index}}/edit" method="post" id="issue-create-form">
{{.CsrfTokenHtml}}
{{template "base/alert" .}}
<div class="col-md-1">

View file

@ -4,7 +4,7 @@
{{template "repo/toolbar" .}}
<div id="body" class="container">
<div id="issue">
<form class="form" action="{{.RepoLink}}/issues/milestones/new" method="post" id="issue-create-form">
<form class="form" action="{{.RepoLink}}/milestones/new" method="post" id="issue-create-form">
{{.CsrfTokenHtml}}
{{template "base/alert" .}}
<div class="col-md-1">

View file

@ -1,101 +0,0 @@
{{template "ng/base/head" .}}
{{template "ng/base/header" .}}
<div id="repo-wrapper">
{{template "repo/header_old" .}}
<div class="issue-main container repo-wide-wrapper">
<ul id="issue-list-nav" class="menu menu-line">
<li class="current"><a href="#">Issue</a></li>
<li><a href="#">Pull Request</a></li>
<li><a href="#">Labels</a></li>
<li><a href="#">Milestones</a></li>
<li class="right" id="issue-new"><a href="#"><button id="issue-new-btn" class="btn btn-green text-bold">New Issue</button></a></li>
<!--<li class="right"><a href="#">Filter</a></li>-->
</ul>
<div id="issue-list-container">
<div id="issue-list-menu">
<div class="left">
<span class="mark open hover"><a href="#">
<i class="octicon octicon-issue-opened"></i> 88 Open
</a></span>
<span class="mark close"><a href="">
<i class="octicon octicon-issue-closed"></i> 12 Close
</a></span>
</div>
<ul id="issue-list-filter" class="right menu menu-line">
<li class="down drop label-filter">
<a href="#">Labels</a>
<div class="drop-down">
<h4>Labels</h4>
<ul class="labels list-no-style">
<li class="no-label"><strong>no label</strong></li>
<li><a href="#"><span class="color"></span><span class="name">bug</span></a></li>
<li><a href="#"><span class="color"></span><span class="name">feature</span></a></li>
<li><a href="#"><span class="color"></span><span class="name">roadmap</span></a></li>
</ul>
</div>
</li>
<li class="down drop milestone-filter">
<a href="#">Milestones</a>
<div class="drop-down">
<h4>Milestones</h4>
<ul class="milestones list-no-style">
<li class="no-label"><strong>no milestone</strong></li>
<li><a href="#">v1</a></li>
</ul>
</div>
</li>
<li class="down drop assignee-list">
<a href="#">Assignee</a>
<div class="drop-down">
aabbcc
</div>
</li>
</ul>
<div class="clear"></div>
</div>
<ul id="issue-list" class="list-no-style">
<li class="item" id="issue-id">
<a class="comment" href="#">
<i class="octicon octicon-comment"></i> 7
</a>
<p class="title text-bold">
<span class="label label-black index-num">#588</span>
<a href="#" class="title-text">Delete account text and/or translations missing</a>
<span class="label label-red issue-label"><a href="#">bug</a></span>
</p>
<p class="desc">opened 7 days ago by <a href="#">marcuspoehls</a></p>
</li>
<li class="item" id="issue-id2">
<a class="comment" href="#">
<i class="octicon octicon-comment"></i> 7
</a>
<p class="title text-bold">
<span class="label label-black index-num">#588</span>
<a href="#" class="title-text">Delete account text and/or translations missing</a>
<span class="label label-red issue-label"><a href="#">bug</a></span>
</p>
<p class="desc">opened 7 days ago by <a href="#">marcuspoehls</a></p>
</li>
<li class="item" id="issue-id3">
<a class="comment" href="#">
<i class="octicon octicon-comment"></i> 7
</a>
<p class="title text-bold">
<span class="label label-black index-num">#588</span>
<a href="#" class="title-text">Disabling attachments breaks issues and comments ajax submit</a>
<span class="label label-red issue-label"><a href="#">bug</a></span>
</p>
<p class="desc">opened 7 days ago by <a href="#">marcuspoehls</a></p>
</li>
</ul>
<div id="issue-list-pager" class="pager text-center">
<a class="prev invalid" href="#">Prev</a>
<a class="page" href="#">1</a>
<a class="page hover" href="#">2</a>
<a class="page" href="#">3</a>
<a class="next" href="#">Next</a>
</div>
</div>
</div>
</div>
{{template "ng/base/footer" .}}

View file

@ -12,7 +12,7 @@
{{if .IsRepoToolbarIssues}}
<li class="tmp">{{if .IsRepoToolbarIssuesList}}
<a href="{{.RepoLink}}/issues/new"><button class="btn btn-primary btn-sm">New Issue</button></a>
<a href="{{.RepoLink}}/issues/milestones"><button class="btn btn-success btn-sm">Milestones</button></a>
<a href="{{.RepoLink}}/milestones"><button class="btn btn-success btn-sm">Milestones</button></a>
{{end}}</li>
{{end}}
<li class="{{if .IsRepoToolbarReleases}}active{{end}}"><a href="{{.RepoLink}}/releases">{{if .Repository.NumTags}}<span class="badge">{{.Repository.NumTags}}</span> {{end}}Releases</a></li>