2018-11-29 07:16:30 +05:30
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2021-04-05 21:00:52 +05:30
|
|
|
"net/http"
|
2018-11-29 07:16:30 +05:30
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2021-01-26 21:06:53 +05:30
|
|
|
auth "code.gitea.io/gitea/modules/forms"
|
2018-11-29 07:16:30 +05:30
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2020-07-28 17:00:40 +05:30
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2019-08-15 20:16:21 +05:30
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
2018-11-29 07:16:30 +05:30
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-01-26 21:06:53 +05:30
|
|
|
"code.gitea.io/gitea/modules/web"
|
2020-05-13 03:24:35 +05:30
|
|
|
|
|
|
|
"xorm.io/builder"
|
2018-11-29 07:16:30 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tplMilestone base.TplName = "repo/issue/milestones"
|
|
|
|
tplMilestoneNew base.TplName = "repo/issue/milestone_new"
|
|
|
|
tplMilestoneIssues base.TplName = "repo/issue/milestone_issues"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Milestones render milestones page
|
|
|
|
func Milestones(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.milestones")
|
|
|
|
ctx.Data["PageIsIssueList"] = true
|
|
|
|
ctx.Data["PageIsMilestones"] = true
|
|
|
|
|
|
|
|
isShowClosed := ctx.Query("state") == "closed"
|
2020-05-13 03:24:35 +05:30
|
|
|
stats, err := models.GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"id": ctx.Repo.Repository.ID}))
|
2018-11-29 07:16:30 +05:30
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("MilestoneStats", err)
|
|
|
|
return
|
|
|
|
}
|
2020-05-13 03:24:35 +05:30
|
|
|
ctx.Data["OpenCount"] = stats.OpenCount
|
|
|
|
ctx.Data["ClosedCount"] = stats.ClosedCount
|
2018-11-29 07:16:30 +05:30
|
|
|
|
|
|
|
sortType := ctx.Query("sort")
|
|
|
|
page := ctx.QueryInt("page")
|
|
|
|
if page <= 1 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var total int
|
2020-07-28 17:00:40 +05:30
|
|
|
var state structs.StateType
|
2018-11-29 07:16:30 +05:30
|
|
|
if !isShowClosed {
|
2020-05-13 03:24:35 +05:30
|
|
|
total = int(stats.OpenCount)
|
2020-07-28 17:00:40 +05:30
|
|
|
state = structs.StateOpen
|
2018-11-29 07:16:30 +05:30
|
|
|
} else {
|
2020-05-13 03:24:35 +05:30
|
|
|
total = int(stats.ClosedCount)
|
2020-07-28 17:00:40 +05:30
|
|
|
state = structs.StateClosed
|
2018-11-29 07:16:30 +05:30
|
|
|
}
|
|
|
|
|
2020-07-28 17:00:40 +05:30
|
|
|
miles, err := models.GetMilestones(models.GetMilestonesOption{
|
|
|
|
ListOptions: models.ListOptions{
|
|
|
|
Page: page,
|
|
|
|
PageSize: setting.UI.IssuePagingNum,
|
|
|
|
},
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
State: state,
|
|
|
|
SortType: sortType,
|
|
|
|
})
|
2018-11-29 07:16:30 +05:30
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetMilestones", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ctx.Repo.Repository.IsTimetrackerEnabled() {
|
2019-06-13 01:11:28 +05:30
|
|
|
if err := miles.LoadTotalTrackedTimes(); err != nil {
|
2018-11-29 07:16:30 +05:30
|
|
|
ctx.ServerError("LoadTotalTrackedTimes", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, m := range miles {
|
|
|
|
m.RenderedContent = string(markdown.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
|
|
|
|
}
|
|
|
|
ctx.Data["Milestones"] = miles
|
|
|
|
|
|
|
|
if isShowClosed {
|
|
|
|
ctx.Data["State"] = "closed"
|
|
|
|
} else {
|
|
|
|
ctx.Data["State"] = "open"
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["SortType"] = sortType
|
|
|
|
ctx.Data["IsShowClosed"] = isShowClosed
|
2019-04-20 09:45:19 +05:30
|
|
|
|
|
|
|
pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5)
|
|
|
|
pager.AddParam(ctx, "state", "State")
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.HTML(http.StatusOK, tplMilestone)
|
2018-11-29 07:16:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// NewMilestone render creating milestone page
|
|
|
|
func NewMilestone(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
|
|
|
|
ctx.Data["PageIsIssueList"] = true
|
|
|
|
ctx.Data["PageIsMilestones"] = true
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.HTML(http.StatusOK, tplMilestoneNew)
|
2018-11-29 07:16:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// NewMilestonePost response for creating milestone
|
2021-01-26 21:06:53 +05:30
|
|
|
func NewMilestonePost(ctx *context.Context) {
|
|
|
|
form := web.GetForm(ctx).(*auth.CreateMilestoneForm)
|
2018-11-29 07:16:30 +05:30
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
|
|
|
|
ctx.Data["PageIsIssueList"] = true
|
|
|
|
ctx.Data["PageIsMilestones"] = true
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.HTML(http.StatusOK, tplMilestoneNew)
|
2018-11-29 07:16:30 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(form.Deadline) == 0 {
|
|
|
|
form.Deadline = "9999-12-31"
|
|
|
|
}
|
|
|
|
deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Data["Err_Deadline"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-01 23:26:47 +05:30
|
|
|
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
2018-11-29 07:16:30 +05:30
|
|
|
if err = models.NewMilestone(&models.Milestone{
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
Name: form.Title,
|
|
|
|
Content: form.Content,
|
2019-08-15 20:16:21 +05:30
|
|
|
DeadlineUnix: timeutil.TimeStamp(deadline.Unix()),
|
2018-11-29 07:16:30 +05:30
|
|
|
}); err != nil {
|
|
|
|
ctx.ServerError("NewMilestone", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.milestones.create_success", form.Title))
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
|
|
|
|
}
|
|
|
|
|
|
|
|
// EditMilestone render edting milestone page
|
|
|
|
func EditMilestone(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
|
|
|
|
ctx.Data["PageIsMilestones"] = true
|
|
|
|
ctx.Data["PageIsEditMilestone"] = true
|
|
|
|
|
|
|
|
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
|
|
|
if err != nil {
|
|
|
|
if models.IsErrMilestoneNotExist(err) {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetMilestoneByRepoID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["title"] = m.Name
|
|
|
|
ctx.Data["content"] = m.Content
|
|
|
|
if len(m.DeadlineString) > 0 {
|
|
|
|
ctx.Data["deadline"] = m.DeadlineString
|
|
|
|
}
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.HTML(http.StatusOK, tplMilestoneNew)
|
2018-11-29 07:16:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// EditMilestonePost response for edting milestone
|
2021-01-26 21:06:53 +05:30
|
|
|
func EditMilestonePost(ctx *context.Context) {
|
|
|
|
form := web.GetForm(ctx).(*auth.CreateMilestoneForm)
|
2018-11-29 07:16:30 +05:30
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
|
|
|
|
ctx.Data["PageIsMilestones"] = true
|
|
|
|
ctx.Data["PageIsEditMilestone"] = true
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.HTML(http.StatusOK, tplMilestoneNew)
|
2018-11-29 07:16:30 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(form.Deadline) == 0 {
|
|
|
|
form.Deadline = "9999-12-31"
|
|
|
|
}
|
|
|
|
deadline, err := time.ParseInLocation("2006-01-02", form.Deadline, time.Local)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Data["Err_Deadline"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.milestones.invalid_due_date_format"), tplMilestoneNew, &form)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-01 23:26:47 +05:30
|
|
|
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
2018-11-29 07:16:30 +05:30
|
|
|
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
|
|
|
if err != nil {
|
|
|
|
if models.IsErrMilestoneNotExist(err) {
|
|
|
|
ctx.NotFound("", nil)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("GetMilestoneByRepoID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
m.Name = form.Title
|
|
|
|
m.Content = form.Content
|
2019-08-15 20:16:21 +05:30
|
|
|
m.DeadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
2020-01-29 12:06:32 +05:30
|
|
|
if err = models.UpdateMilestone(m, m.IsClosed); err != nil {
|
2018-11-29 07:16:30 +05:30
|
|
|
ctx.ServerError("UpdateMilestone", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.milestones.edit_success", m.Name))
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
|
|
|
|
}
|
|
|
|
|
2020-08-17 08:37:38 +05:30
|
|
|
// ChangeMilestoneStatus response for change a milestone's status
|
|
|
|
func ChangeMilestoneStatus(ctx *context.Context) {
|
|
|
|
toClose := false
|
2018-11-29 07:16:30 +05:30
|
|
|
switch ctx.Params(":action") {
|
|
|
|
case "open":
|
2020-08-17 08:37:38 +05:30
|
|
|
toClose = false
|
2018-11-29 07:16:30 +05:30
|
|
|
case "close":
|
2020-08-17 08:37:38 +05:30
|
|
|
toClose = true
|
2018-11-29 07:16:30 +05:30
|
|
|
default:
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/milestones")
|
|
|
|
}
|
2020-08-17 08:37:38 +05:30
|
|
|
id := ctx.ParamsInt64(":id")
|
|
|
|
|
|
|
|
if err := models.ChangeMilestoneStatusByRepoIDAndID(ctx.Repo.Repository.ID, id, toClose); err != nil {
|
|
|
|
if models.IsErrMilestoneNotExist(err) {
|
|
|
|
ctx.NotFound("", err)
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("ChangeMilestoneStatusByIDAndRepoID", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=" + ctx.Params(":action"))
|
2018-11-29 07:16:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteMilestone delete a milestone
|
|
|
|
func DeleteMilestone(ctx *context.Context) {
|
|
|
|
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
|
|
|
|
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
|
|
|
}
|
|
|
|
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
2018-11-29 07:16:30 +05:30
|
|
|
"redirect": ctx.Repo.RepoLink + "/milestones",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
|
|
|
|
func MilestoneIssuesAndPulls(ctx *context.Context) {
|
|
|
|
milestoneID := ctx.ParamsInt64(":id")
|
|
|
|
milestone, err := models.GetMilestoneByID(milestoneID)
|
|
|
|
if err != nil {
|
2019-08-15 05:13:50 +05:30
|
|
|
if models.IsErrMilestoneNotExist(err) {
|
|
|
|
ctx.NotFound("GetMilestoneByID", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-29 07:16:30 +05:30
|
|
|
ctx.ServerError("GetMilestoneByID", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-26 06:51:13 +05:30
|
|
|
milestone.RenderedContent = string(markdown.Render([]byte(milestone.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
|
|
|
|
|
2018-11-29 07:16:30 +05:30
|
|
|
ctx.Data["Title"] = milestone.Name
|
|
|
|
ctx.Data["Milestone"] = milestone
|
|
|
|
|
2020-08-17 08:37:38 +05:30
|
|
|
issues(ctx, milestoneID, 0, util.OptionalBoolNone)
|
2020-09-11 20:18:39 +05:30
|
|
|
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
2018-11-29 07:16:30 +05:30
|
|
|
|
2020-01-16 19:48:30 +05:30
|
|
|
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWriteIssuesOrPulls(false)
|
|
|
|
ctx.Data["CanWritePulls"] = ctx.Repo.CanWriteIssuesOrPulls(true)
|
2019-03-15 21:20:27 +05:30
|
|
|
|
2021-04-05 21:00:52 +05:30
|
|
|
ctx.HTML(http.StatusOK, tplMilestoneIssues)
|
2018-11-29 07:16:30 +05:30
|
|
|
}
|