mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 21:24:03 +01:00
Finish edit a milestone
This commit is contained in:
parent
98dbbae2ef
commit
2eee1e9bc2
5 changed files with 102 additions and 20 deletions
|
@ -188,7 +188,8 @@ func runWeb(*cli.Context) {
|
|||
r.Get("/issues/milestones", repo.Milestones)
|
||||
r.Get("/issues/milestones/new", repo.NewMilestone)
|
||||
r.Post("/issues/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
|
||||
r.Get("/issues/milestones/edit", repo.UpdateMilestones)
|
||||
r.Get("/issues/milestones/:index/edit", repo.UpdateMilestone)
|
||||
r.Post("/issues/milestones/:index/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.UpdateMilestonePost)
|
||||
r.Post("/comment/:action", repo.Comment)
|
||||
r.Get("/releases/new", repo.ReleasesNew)
|
||||
}, reqSignIn, middleware.RepoAssignment(true))
|
||||
|
|
|
@ -14,7 +14,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrIssueNotExist = errors.New("Issue does not exist")
|
||||
ErrIssueNotExist = errors.New("Issue does not exist")
|
||||
ErrMilestoneNotExist = errors.New("Milestone does not exist")
|
||||
)
|
||||
|
||||
// Issue represents an issue or pull request of repository.
|
||||
|
@ -412,6 +413,7 @@ type Milestone struct {
|
|||
NumOpenIssues int `xorm:"-"`
|
||||
Completeness int // Percentage(1-100).
|
||||
Deadline time.Time
|
||||
DeadlineString string `xorm:"-"`
|
||||
ClosedDate time.Time
|
||||
}
|
||||
|
||||
|
@ -441,6 +443,18 @@ func NewMilestone(m *Milestone) (err error) {
|
|||
return sess.Commit()
|
||||
}
|
||||
|
||||
// GetMilestoneByIndex returns the milestone of given repository and index.
|
||||
func GetMilestoneByIndex(repoId, idx int64) (*Milestone, error) {
|
||||
m := &Milestone{RepoId: repoId, Index: idx}
|
||||
has, err := orm.Get(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrMilestoneNotExist
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetMilestones returns a list of milestones of given repository and status.
|
||||
func GetMilestones(repoId int64, isClosed bool) ([]*Milestone, error) {
|
||||
miles := make([]*Milestone, 0, 10)
|
||||
|
@ -448,6 +462,12 @@ func GetMilestones(repoId int64, isClosed bool) ([]*Milestone, error) {
|
|||
return miles, err
|
||||
}
|
||||
|
||||
// UpdateMilestone updates information of given milestone.
|
||||
func UpdateMilestone(m *Milestone) error {
|
||||
_, err := orm.Id(m.Id).Update(m)
|
||||
return err
|
||||
}
|
||||
|
||||
// Issue types.
|
||||
const (
|
||||
IT_PLAIN = iota // Pure comment.
|
||||
|
|
|
@ -524,23 +524,22 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
|||
var deadline time.Time
|
||||
var err error
|
||||
if len(form.Deadline) == 0 {
|
||||
deadline = time.Now().AddDate(100, 0, 0)
|
||||
} else {
|
||||
deadline, err = time.Parse("01/02/2006", form.Deadline)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "issue.NewMilestonePost(time.Parse)", err)
|
||||
return
|
||||
}
|
||||
form.Deadline = "12/31/9999"
|
||||
}
|
||||
deadline, err = time.Parse("01/02/2006", form.Deadline)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "issue.NewMilestonePost(time.Parse)", err)
|
||||
return
|
||||
}
|
||||
|
||||
m := &models.Milestone{
|
||||
mile := &models.Milestone{
|
||||
RepoId: ctx.Repo.Repository.Id,
|
||||
Index: int64(ctx.Repo.Repository.NumMilestones) + 1,
|
||||
Name: form.Title,
|
||||
Content: form.Content,
|
||||
Deadline: deadline,
|
||||
}
|
||||
if err = models.NewMilestone(m); err != nil {
|
||||
if err = models.NewMilestone(mile); err != nil {
|
||||
ctx.Handle(500, "issue.NewMilestonePost(NewMilestone)", err)
|
||||
return
|
||||
}
|
||||
|
@ -548,10 +547,73 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
|||
ctx.Redirect(ctx.Repo.RepoLink + "/issues/milestones")
|
||||
}
|
||||
|
||||
func UpdateMilestones(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Update Milestones"
|
||||
func UpdateMilestone(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Update Milestone"
|
||||
ctx.Data["IsRepoToolbarIssues"] = true
|
||||
ctx.Data["IsRepoToolbarIssuesList"] = true
|
||||
|
||||
idx, _ := base.StrTo(params["index"]).Int64()
|
||||
if idx == 0 {
|
||||
ctx.Handle(404, "issue.UpdateMilestone", nil)
|
||||
return
|
||||
}
|
||||
|
||||
mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, idx)
|
||||
if err != nil {
|
||||
if err == models.ErrMilestoneNotExist {
|
||||
ctx.Handle(404, "issue.UpdateMilestone(GetMilestoneByIndex)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "issue.UpdateMilestone(GetMilestoneByIndex)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
mile.DeadlineString = mile.Deadline.UTC().Format("01/02/2006")
|
||||
if mile.DeadlineString == "12/31/9999" {
|
||||
mile.DeadlineString = ""
|
||||
}
|
||||
ctx.Data["Milestone"] = mile
|
||||
|
||||
ctx.HTML(200, "issue/milestone_edit")
|
||||
}
|
||||
|
||||
func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form auth.CreateMilestoneForm) {
|
||||
ctx.Data["Title"] = "Update Milestone"
|
||||
ctx.Data["IsRepoToolbarIssues"] = true
|
||||
ctx.Data["IsRepoToolbarIssuesList"] = true
|
||||
|
||||
idx, _ := base.StrTo(params["index"]).Int64()
|
||||
if idx == 0 {
|
||||
ctx.Handle(404, "issue.UpdateMilestone", nil)
|
||||
return
|
||||
}
|
||||
|
||||
mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, idx)
|
||||
if err != nil {
|
||||
if err == models.ErrMilestoneNotExist {
|
||||
ctx.Handle(404, "issue.UpdateMilestone(GetMilestoneByIndex)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "issue.UpdateMilestone(GetMilestoneByIndex)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var deadline time.Time
|
||||
if len(form.Deadline) == 0 {
|
||||
form.Deadline = "12/31/9999"
|
||||
}
|
||||
deadline, err = time.Parse("01/02/2006", form.Deadline)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "issue.UpdateMilestonePost(time.Parse)", err)
|
||||
return
|
||||
}
|
||||
|
||||
mile.Name = form.Title
|
||||
mile.Content = form.Content
|
||||
mile.Deadline = deadline
|
||||
if err = models.UpdateMilestone(mile); err != nil {
|
||||
ctx.Handle(500, "issue.UpdateMilestonePost(UpdateMilestone)", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/issues/milestones")
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<span class="issue-open label label-success">{{.NumClosedIssues}}</span>
|
||||
<span class="issue-close label label-warning">{{.NumOpenIssues}}</span>
|
||||
<p class="actions pull-right">
|
||||
<!-- <a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/edit">Edit</a> -->
|
||||
<a href="{{$.RepoLink}}/issues/milestones/{{.Index}}/edit">Edit</a>
|
||||
<!-- <a href="#">Open</a>
|
||||
<a href="#">Close</a> -->
|
||||
<!-- <a class="text-danger" href="#">Delete</a> -->
|
||||
|
|
|
@ -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}}/issues/milestones/{{.Milestone.Index}}/edit" method="post" id="issue-create-form">
|
||||
{{.CsrfTokenHtml}}
|
||||
{{template "base/alert" .}}
|
||||
<div class="col-md-1">
|
||||
|
@ -12,7 +12,7 @@
|
|||
</div>
|
||||
<div class="col-md-8 panel panel-default">
|
||||
<div class="form-group panel-body">
|
||||
<input class="form-control input-lg" type="text" name="title" required="required" placeholder="Title" value="{{.title}}" />
|
||||
<input class="form-control input-lg" type="text" name="title" required="required" placeholder="Title" value="{{.Milestone.Name}}" />
|
||||
</div>
|
||||
<div class="form-group panel-body">
|
||||
<div class="md-help pull-right"><!-- todo help link -->
|
||||
|
@ -25,7 +25,7 @@
|
|||
<div class="tab-content">
|
||||
<div class="tab-pane" id="issue-textarea">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" name="content" id="issue-content" rows="10" placeholder="Write some content" data-ajax-rel="issue-preview" data-ajax-val="val" data-ajax-field="text">{{.content}}</textarea>
|
||||
<textarea class="form-control" name="content" id="issue-content" rows="10" placeholder="Write some content" data-ajax-rel="issue-preview" data-ajax-val="val" data-ajax-field="text">{{.Milestone.Content}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
|
||||
|
@ -34,15 +34,14 @@
|
|||
<div class="text-right panel-body">
|
||||
<div class="form-group">
|
||||
<input type="hidden" value="id" name="repo-id"/>
|
||||
<button class="btn-success btn">Create new issue</button>
|
||||
<button class="btn-success btn">Update milestone</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<h4>Milestone Due Date</h4>
|
||||
|
||||
<div class="form-group">
|
||||
<input name="due_date" type="text" class="form-control" id="milestone-due-date">
|
||||
<input name="due_date" type="text" class="form-control" id="milestone-due-date" value="{{.Milestone.DeadlineString}}">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue