diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-13 13:28:21 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-13 13:28:21 -0400 |
commit | 2eee1e9bc22d77a68b436682fdd4eb8f60fd5d45 (patch) | |
tree | 9aa763565291f64ea4a5c72cd6fab0979fabe195 | |
parent | 98dbbae2efd5c232d94f5e4d8df9d388cace2ebc (diff) | |
download | gitea-2eee1e9bc22d77a68b436682fdd4eb8f60fd5d45.tar.gz gitea-2eee1e9bc22d77a68b436682fdd4eb8f60fd5d45.zip |
Finish edit a milestone
-rw-r--r-- | cmd/web.go | 3 | ||||
-rw-r--r-- | models/issue.go | 22 | ||||
-rw-r--r-- | routers/repo/issue.go | 84 | ||||
-rw-r--r-- | templates/issue/milestone.tmpl | 2 | ||||
-rw-r--r-- | templates/issue/milestone_edit.tmpl | 11 |
5 files changed, 102 insertions, 20 deletions
diff --git a/cmd/web.go b/cmd/web.go index c343566d70..d2b148d7e6 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -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)) diff --git a/models/issue.go b/models/issue.go index fa9d9427ae..213fd1f2ab 100644 --- a/models/issue.go +++ b/models/issue.go @@ -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. diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 2958d8eb1a..38a971a0f2 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -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") +} diff --git a/templates/issue/milestone.tmpl b/templates/issue/milestone.tmpl index 3c2cf93a6c..e15d964140 100644 --- a/templates/issue/milestone.tmpl +++ b/templates/issue/milestone.tmpl @@ -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> --> diff --git a/templates/issue/milestone_edit.tmpl b/templates/issue/milestone_edit.tmpl index 2db55ae91b..8f1a05e012 100644 --- a/templates/issue/milestone_edit.tmpl +++ b/templates/issue/milestone_edit.tmpl @@ -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> |