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/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost)
r.Post("/issues/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) r.Post("/issues/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
r.Post("/issues/:index/assignee", repo.UpdateAssignee) r.Post("/issues/:index/assignee", repo.UpdateAssignee)
r.Post("/issues/:index/milestone", repo.UpdateIssueMilestone)
r.Get("/issues/milestones", repo.Milestones) r.Get("/issues/milestones", repo.Milestones)
r.Get("/issues/milestones/new", repo.NewMilestone) r.Get("/issues/milestones/new", repo.NewMilestone)
r.Post("/issues/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost) r.Post("/issues/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)

View File

@ -167,6 +167,8 @@ type IssueUser struct {
Uid int64 // User ID. Uid int64 // User ID.
IssueId int64 IssueId int64
RepoId int64 RepoId int64
MilestoneId int64
Labels string `xorm:"TEXT"`
IsRead bool IsRead bool
IsAssigned bool IsAssigned bool
IsMentioned bool IsMentioned bool
@ -446,6 +448,18 @@ func NewMilestone(m *Milestone) (err error) {
return sess.Commit() 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. // GetMilestoneByIndex returns the milestone of given repository and index.
func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) { func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) {
m := &Milestone{RepoId: repoId, Index: idx} m := &Milestone{RepoId: repoId, Index: idx}
@ -502,6 +516,53 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
return sess.Commit() 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. // DeleteMilestone deletes a milestone.
func DeleteMilestone(m *Milestone) (err error) { func DeleteMilestone(m *Milestone) (err error) {
sess := orm.NewSession() sess := orm.NewSession()

View File

@ -676,10 +676,6 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
sess.Rollback() sess.Rollback()
return err return err
} }
if _, err = sess.Delete(&Issue{RepoId: repoId}); err != nil {
sess.Rollback()
return err
}
if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil { if _, err = sess.Delete(&IssueUser{RepoId: repoId}); err != nil {
sess.Rollback() sess.Rollback()
return err return err
@ -688,6 +684,28 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
sess.Rollback() sess.Rollback()
return err 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 = ?" rawSql := "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
if _, err = sess.Exec(rawSql, userId); err != nil { if _, err = sess.Exec(rawSql, userId); err != nil {

View File

@ -53,7 +53,18 @@ func Issues(ctx *middleware.Context) {
filterMode = models.FM_MENTION 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() page, _ := base.StrTo(ctx.Query("page")).Int()
// Get issues. // Get issues.
@ -114,6 +125,19 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssues"] = true
ctx.Data["IsRepoToolbarIssuesList"] = false 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, "/")) us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if err != nil { if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) 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["IsRepoToolbarIssues"] = true
ctx.Data["IsRepoToolbarIssuesList"] = false 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, "/")) us, err := models.GetCollaborators(strings.TrimPrefix(ctx.Repo.RepoLink, "/"))
if err != nil { if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
@ -240,12 +277,37 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return 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 { if err != nil {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
return return
} }
ctx.Data["Collaborators"] = us
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // 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) { func UpdateAssignee(ctx *middleware.Context) {
if !ctx.Repo.IsOwner { if !ctx.Repo.IsOwner {
ctx.Error(403) ctx.Error(403)
@ -580,6 +688,7 @@ func UpdateMilestone(ctx *middleware.Context, params martini.Params) {
} }
case "close": case "close":
if !mile.IsClosed { if !mile.IsClosed {
mile.ClosedDate = time.Now()
if err = models.ChangeMilestoneStatus(mile, true); err != nil { if err = models.ChangeMilestoneStatus(mile, true); err != nil {
ctx.Handle(500, "issue.UpdateMilestone(ChangeMilestoneStatus)", err) ctx.Handle(500, "issue.UpdateMilestone(ChangeMilestoneStatus)", err)
return return

View File

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

View File

@ -19,8 +19,8 @@
{{range .Milestones}} {{range .Milestones}}
<div class="list-group-item milestone-item"> <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> <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-open label label-success">{{.NumOpenIssues}}</span>
<span class="issue-close label label-warning">{{.NumOpenIssues}}</span> <span class="issue-close label label-warning">{{.NumClosedIssues}}</span>
<p class="actions pull-right"> <p class="actions pull-right">
<a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/edit">Edit</a> <a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/edit">Edit</a>
{{if .IsClosed}} {{if .IsClosed}}

View File

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