mirror of
1
Fork 0

Merge branch 'dev' of github.com:gogits/gogs into dev

This commit is contained in:
Lunny Xiao 2014-05-15 09:55:16 +08:00
commit 839a9bb054
7 changed files with 243 additions and 34 deletions

View File

@ -185,6 +185,7 @@ func runWeb(*cli.Context) {
r.Post("/issues/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost)
r.Post("/issues/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
r.Post("/issues/:index/assignee", repo.UpdateAssignee)
r.Post("/issues/:index/milestone", repo.UpdateIssueMilestone)
r.Get("/issues/milestones", repo.Milestones)
r.Get("/issues/milestones/new", repo.NewMilestone)
r.Post("/issues/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)

View File

@ -167,6 +167,8 @@ type IssueUser struct {
Uid int64 // User ID.
IssueId int64
RepoId int64
MilestoneId int64
Labels string `xorm:"TEXT"`
IsRead bool
IsAssigned bool
IsMentioned bool
@ -446,6 +448,18 @@ func NewMilestone(m *Milestone) (err error) {
return sess.Commit()
}
// GetMilestoneById returns the milestone by given ID.
func GetMilestoneById(id int64) (*Milestone, error) {
m := &Milestone{Id: id}
has, err := orm.Get(m)
if err != nil {
return nil, err
} else if !has {
return nil, ErrMilestoneNotExist
}
return m, nil
}
// GetMilestoneByIndex returns the milestone of given repository and index.
func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) {
m := &Milestone{RepoId: repoId, Index: idx}
@ -502,6 +516,53 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
return sess.Commit()
}
// ChangeMilestoneAssign changes assignment of milestone for issue.
func ChangeMilestoneAssign(oldMid, mid int64, isIssueClosed bool) (err error) {
sess := orm.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
if oldMid > 0 {
m, err := GetMilestoneById(oldMid)
if err != nil {
return err
}
m.NumIssues--
if isIssueClosed {
m.NumClosedIssues--
}
if m.NumIssues > 0 {
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
} else {
m.Completeness = 0
}
if _, err = sess.Id(m.Id).Update(m); err != nil {
sess.Rollback()
return err
}
}
if mid > 0 {
m, err := GetMilestoneById(mid)
if err != nil {
return err
}
m.NumIssues++
if isIssueClosed {
m.NumClosedIssues++
}
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
if _, err = sess.Id(m.Id).Update(m); err != nil {
sess.Rollback()
return err
}
}
return sess.Commit()
}
// DeleteMilestone deletes a milestone.
func DeleteMilestone(m *Milestone) (err error) {
sess := orm.NewSession()

View File

@ -676,10 +676,6 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
sess.Rollback()
return err
}
if _, err = sess.Delete(&Issue{RepoId: repoId}); err != nil {
sess.Rollback()
return err
}
if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil {
sess.Rollback()
return err
@ -688,6 +684,28 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
sess.Rollback()
return err
}
if _, err = sess.Delete(&Release{RepoId: repoId}); err != nil {
sess.Rollback()
return err
}
// Delete comments.
if err = orm.Iterate(&Issue{RepoId: repoId}, func(idx int, bean interface{}) error {
issue := bean.(*Issue)
if _, err = sess.Delete(&Comment{IssueId: issue.Id}); err != nil {
sess.Rollback()
return err
}
return nil
}); err != nil {
sess.Rollback()
return err
}
if _, err = sess.Delete(&Issue{RepoId: repoId}); err != nil {
sess.Rollback()
return err
}
rawSql := "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
if _, err = sess.Exec(rawSql, userId); err != nil {

View File

@ -53,7 +53,18 @@ func Issues(ctx *middleware.Context) {
filterMode = models.FM_MENTION
}
mid, _ := base.StrTo(ctx.Query("milestone")).Int64()
var mid int64
midx, _ := base.StrTo(ctx.Query("milestone")).Int64()
if midx > 0 {
mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, midx)
if err != nil {
ctx.Handle(500, "issue.Issues(GetMilestoneByIndex): %v", err)
return
}
mid = mile.Id
}
fmt.Println(mid)
page, _ := base.StrTo(ctx.Query("page")).Int()
// Get issues.
@ -114,6 +125,19 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
ctx.Data["IsRepoToolbarIssues"] = true
ctx.Data["IsRepoToolbarIssuesList"] = false
var err error
// Get all milestones.
ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, false)
if err != nil {
ctx.Handle(500, "issue.ViewIssue(GetMilestones.1): %v", err)
return
}
ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, true)
if err != nil {
ctx.Handle(500, "issue.ViewIssue(GetMilestones.2): %v", err)
return
}
us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
@ -128,6 +152,19 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
ctx.Data["IsRepoToolbarIssues"] = true
ctx.Data["IsRepoToolbarIssuesList"] = false
var err error
// Get all milestones.
ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, false)
if err != nil {
ctx.Handle(500, "issue.ViewIssue(GetMilestones.1): %v", err)
return
}
ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, true)
if err != nil {
ctx.Handle(500, "issue.ViewIssue(GetMilestones.2): %v", err)
return
}
us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
@ -240,12 +277,37 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return
}
us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
// Get assigned milestone.
if issue.MilestoneId > 0 {
ctx.Data["Milestone"], err = models.GetMilestoneById(issue.MilestoneId)
if err != nil {
if err == models.ErrMilestoneNotExist {
log.Warn("issue.ViewIssue(GetMilestoneById): %v", err)
} else {
ctx.Handle(500, "issue.ViewIssue(GetMilestoneById)", err)
return
}
}
}
// Get all milestones.
ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, false)
if err != nil {
ctx.Handle(500, "issue.ViewIssue(GetMilestones.1): %v", err)
return
}
ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.Id, true)
if err != nil {
ctx.Handle(500, "issue.ViewIssue(GetMilestones.2): %v", err)
return
}
// Get all collaborators.
ctx.Data["Collaborators"], err = models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
return
}
ctx.Data["Collaborators"] = us
if ctx.IsSigned {
// Update issue-user.
@ -331,6 +393,52 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
})
}
func UpdateIssueMilestone(ctx *middleware.Context) {
if !ctx.Repo.IsOwner {
ctx.Error(403)
return
}
issueId, err := base.StrTo(ctx.Query("issue")).Int64()
if err != nil {
ctx.Error(404)
return
}
issue, err := models.GetIssueById(issueId)
if err != nil {
if err == models.ErrIssueNotExist {
ctx.Handle(404, "issue.UpdateIssueMilestone(GetIssueById)", err)
} else {
ctx.Handle(500, "issue.UpdateIssueMilestone(GetIssueById)", err)
}
return
}
oldMid := issue.MilestoneId
mid, _ := base.StrTo(ctx.Query("milestone")).Int64()
if oldMid == mid {
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
return
}
// Not check for invalid milestone id and give responsibility to owners.
issue.MilestoneId = mid
if err = models.ChangeMilestoneAssign(oldMid, mid, issue.IsClosed); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
return
} else if err = models.UpdateIssue(issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(UpdateIssue)", err)
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
})
}
func UpdateAssignee(ctx *middleware.Context) {
if !ctx.Repo.IsOwner {
ctx.Error(403)
@ -580,6 +688,7 @@ func UpdateMilestone(ctx *middleware.Context, params martini.Params) {
}
case "close":
if !mile.IsClosed {
mile.ClosedDate = time.Now()
if err = models.ChangeMilestoneStatus(mile, true); err != nil {
ctx.Handle(500, "issue.UpdateMilestone(ChangeMilestoneStatus)", err)
return

View File

@ -48,25 +48,33 @@
</ul>
<div class="tab-content">
<div class="tab-pane active" id="milestone-open">
{{if not .OpenMilestones}}
<p class="milestone-item">Nothing to show</p>
{{else}}
<ul class="list-unstyled">
<li class="milestone-item" data-id="1">
<p><strong>Milestone name</strong></p>
<p>due to 3 days later</p>
</li>
<li class="milestone-item" data-id="1">
<p><strong>Milestone name</strong></p>
<p>due to 3 days later</p>
{{range .OpenMilestones}}
<li class="milestone-item" data-id="{{.Id}}">
<p><strong>{{.Name}}</strong></p>
<!-- <p>due to 3 days later</p> -->
</li>
{{end}}
</ul>
{{end}}
</div>
<div class="tab-pane" id="milestone-close">
{{if not .ClosedMilestones}}
<p class="milestone-item">Nothing to show</p>
{{else}}
<ul class="list-unstyled">
<li class="milestone-item" data-id="1">
<p><strong>Milestone name</strong></p>
<p>closed 3 days ago</p>
{{range .ClosedMilestones}}
<li class="milestone-item" data-id="{{.Id}}">
<p><strong>{{.Name}}</strong></p>
<p>Closed {{TimeSince .ClosedDate}}</p>
</li>
{{end}}
</ul>
{{end}}
</div>
</div>
</li>

View File

@ -19,8 +19,8 @@
{{range .Milestones}}
<div class="list-group-item milestone-item">
<h4 class="title pull-left"><a href="{{$.RepoLink}}/issues?milestone={{.Index}}{{if .IsClosed}}&state=closed{{end}}">{{.Name}}</a></h4>
<span class="issue-open label label-success">{{.NumClosedIssues}}</span>
<span class="issue-close label label-warning">{{.NumOpenIssues}}</span>
<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>
{{if .IsClosed}}

View File

@ -100,7 +100,7 @@
</div>
<div class="issue-bar col-md-2">
<div class="milestone" data-milestone="0" data-ajax="{url}">
<div class="milestone" data-milestone="{{.Milestone.Id}}" data-ajax="{{.Issue.Index}}/milestone">
<div class="pull-right action">
<button class="btn btn-default btn-sm" data-toggle="dropdown">
<i class="fa fa-check-square-o"></i>
@ -108,7 +108,7 @@
</button>
<div class="dropdown-menu dropdown-menu-right">
<ul class="list-unstyled">
<li data-id="0" class="clear-milestone milestone-item hidden"><i class="fa fa-times-circle-o"></i> Clear milestone </li>
<li data-id="0" class="clear-milestone milestone-item hidden"><i class="fa fa-times-circle-o"></i> Clear milestone </li>
<li class="milestone-list">
<ul class="nav nav-tabs" data-init="tabs">
<li class="active"><a href="#milestone-open" data-toggle="tab">Open</a></li>
@ -116,25 +116,33 @@
</ul>
<div class="tab-content">
<div class="tab-pane active" id="milestone-open">
{{if not .OpenMilestones}}
<p class="milestone-item">Nothing to show</p>
{{else}}
<ul class="list-unstyled">
<li class="milestone-item" data-id="1">
<p><strong>Milestone name</strong></p>
<p>due to 3 days later</p>
</li>
<li class="milestone-item" data-id="1">
<p><strong>Milestone name</strong></p>
<p>due to 3 days later</p>
{{range .OpenMilestones}}
<li class="milestone-item" data-id="{{.Id}}">
<p><strong>{{.Name}}</strong></p>
<!-- <p>due to 3 days later</p> -->
</li>
{{end}}
</ul>
{{end}}
</div>
<div class="tab-pane" id="milestone-close">
{{if not .ClosedMilestones}}
<p class="milestone-item">Nothing to show</p>
{{else}}
<ul class="list-unstyled">
<li class="milestone-item" data-id="1">
<p><strong>Milestone name</strong></p>
<p>closed 3 days ago</p>
{{range .ClosedMilestones}}
<li class="milestone-item" data-id="{{.Id}}">
<p><strong>{{.Name}}</strong></p>
<p>Closed {{TimeSince .ClosedDate}}</p>
</li>
{{end}}
</ul>
{{end}}
</div>
</div>
</li>
@ -142,10 +150,14 @@
</div>
</div>
<h4>Milestone</h4>
<p class="completion"><span style="width:80%">&nbsp;</span></p>
<p class="name"><strong><a href="#">Milestone name</a></strong></p>
{{if .Milestone}}
<p class="completion{{if eq .Milestone.Completeness 0}} hidden{{end}}"><span style="width:{{.Milestone.Completeness}}%">&nbsp;</span></p>
<p class="name"><strong><a href="{{$.RepoLink}}/issues?milestone={{.Milestone.Index}}{{if $.Issue.IsClosed}}&state=closed{{end}}">{{.Milestone.Name}}</a></strong></p>
{{else}}
<p class="name">No milestone</p>
{{end}}
</div>
<div class="assignee" data-assigned="{{if .Issue.Assignee}}{{.Issue.Assignee.Id}}{{else}}0{{end}}" data-ajax="{{.Issue.Index}}/assignee">{{if .IsRepositoryOwner}}
<div class="pull-right action">
<button type="button" class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown">
@ -166,7 +178,7 @@
</div>
</div><!--
<div class="col-md-3">
label assignment milestone dashboard
label dashboard
</div>-->
</div>
</div>