1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Finish change issue’s milestone

This commit is contained in:
Unknown 2014-05-14 10:55:36 -04:00
parent 99f2400e3b
commit 46fc36c3a6
4 changed files with 166 additions and 18 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

@ -446,6 +446,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 +514,51 @@ 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
}
}
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

@ -53,11 +53,17 @@ func Issues(ctx *middleware.Context) {
filterMode = models.FM_MENTION
}
mid, _ := base.StrTo(ctx.Query("milestone")).Int64()
midx, _ := base.StrTo(ctx.Query("milestone")).Int64()
mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, midx)
if err != nil {
ctx.Handle(500, "issue.Issues(GetMilestoneByIndex): %v", err)
return
}
page, _ := base.StrTo(ctx.Query("page")).Int()
// Get issues.
issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mid, page,
issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mile.Id, page,
isShowClosed, ctx.Query("labels"), ctx.Query("sortType"))
if err != nil {
ctx.Handle(500, "issue.Issues(GetIssues): %v", err)
@ -240,12 +246,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 +362,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 +657,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

@ -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="0" 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>
@ -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>{{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>