mirror of
https://github.com/go-gitea/gitea
synced 2024-11-15 14:31:41 +01:00
remove Index field of milestone
This commit is contained in:
parent
952c480f4f
commit
9d414d4dd9
5 changed files with 29 additions and 47 deletions
|
@ -435,9 +435,9 @@ func runWeb(ctx *cli.Context) {
|
||||||
m.Group("/milestones", func() {
|
m.Group("/milestones", func() {
|
||||||
m.Get("/new", repo.NewMilestone)
|
m.Get("/new", repo.NewMilestone)
|
||||||
m.Post("/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
|
m.Post("/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
|
||||||
m.Get("/:index/edit", repo.EditMilestone)
|
m.Get("/:id/edit", repo.EditMilestone)
|
||||||
m.Post("/:index/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost)
|
m.Post("/:id/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost)
|
||||||
m.Get("/:index/:action", repo.ChangeMilestonStatus)
|
m.Get("/:id/:action", repo.ChangeMilestonStatus)
|
||||||
m.Post("/delete", repo.DeleteMilestone)
|
m.Post("/delete", repo.DeleteMilestone)
|
||||||
}, reqRepoAdmin)
|
}, reqRepoAdmin)
|
||||||
|
|
||||||
|
|
|
@ -234,7 +234,6 @@ func (err ErrRepoNotExist) Error() string {
|
||||||
|
|
||||||
type ErrMilestoneNotExist struct {
|
type ErrMilestoneNotExist struct {
|
||||||
ID int64
|
ID int64
|
||||||
Index int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrMilestoneNotExist(err error) bool {
|
func IsErrMilestoneNotExist(err error) bool {
|
||||||
|
@ -243,5 +242,5 @@ func IsErrMilestoneNotExist(err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err ErrMilestoneNotExist) Error() string {
|
func (err ErrMilestoneNotExist) Error() string {
|
||||||
return fmt.Sprintf("milestone does not exist [id: %d, index: %d]", err.ID, err.Index)
|
return fmt.Sprintf("milestone does not exist [id: %d]", err.ID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
|
||||||
var err error
|
var err error
|
||||||
switch colName {
|
switch colName {
|
||||||
case "milestone_id":
|
case "milestone_id":
|
||||||
i.Milestone, err = GetMilestoneById(i.MilestoneID)
|
i.Milestone, err = GetMilestoneByID(i.MilestoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(3, "GetMilestoneById: %v", err)
|
log.Error(3, "GetMilestoneById: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -644,7 +644,6 @@ func DeleteLabel(repoID, labelID int64) error {
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
RepoID int64 `xorm:"INDEX"`
|
RepoID int64 `xorm:"INDEX"`
|
||||||
Index int64
|
|
||||||
Name string
|
Name string
|
||||||
Content string `xorm:"TEXT"`
|
Content string `xorm:"TEXT"`
|
||||||
RenderedContent string `xorm:"-"`
|
RenderedContent string `xorm:"-"`
|
||||||
|
@ -680,44 +679,30 @@ func (m *Milestone) CalOpenIssues() {
|
||||||
// NewMilestone creates new milestone of repository.
|
// NewMilestone creates new milestone of repository.
|
||||||
func NewMilestone(m *Milestone) (err error) {
|
func NewMilestone(m *Milestone) (err error) {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sessionRelease(sess)
|
||||||
if err = sess.Begin(); err != nil {
|
if err = sess.Begin(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Deadline = m.Deadline.Local()
|
||||||
if _, err = sess.Insert(m); err != nil {
|
if _, err = sess.Insert(m); err != nil {
|
||||||
sess.Rollback()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rawSql := "UPDATE `repository` SET num_milestones = num_milestones + 1 WHERE id = ?"
|
if _, err = sess.Exec("UPDATE `repository` SET num_milestones=num_milestones+1 WHERE id=?", m.RepoID); err != nil {
|
||||||
if _, err = sess.Exec(rawSql, m.RepoID); err != nil {
|
|
||||||
sess.Rollback()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return sess.Commit()
|
return sess.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMilestoneById returns the milestone by given ID.
|
// GetMilestoneByID returns the milestone of given ID.
|
||||||
func GetMilestoneById(id int64) (*Milestone, error) {
|
func GetMilestoneByID(id int64) (*Milestone, error) {
|
||||||
m := &Milestone{ID: id}
|
m := &Milestone{ID: id}
|
||||||
has, err := x.Get(m)
|
has, err := x.Get(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return nil, ErrMilestoneNotExist{id, 0}
|
return nil, ErrMilestoneNotExist{id}
|
||||||
}
|
|
||||||
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}
|
|
||||||
has, err := x.Get(m)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if !has {
|
|
||||||
return nil, ErrMilestoneNotExist{0, idx}
|
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
@ -736,7 +721,6 @@ func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error)
|
||||||
sess = sess.Limit(setting.IssuePagingNum, (page-1)*setting.IssuePagingNum)
|
sess = sess.Limit(setting.IssuePagingNum, (page-1)*setting.IssuePagingNum)
|
||||||
}
|
}
|
||||||
return miles, sess.Find(&miles)
|
return miles, sess.Find(&miles)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateMilestone(e Engine, m *Milestone) error {
|
func updateMilestone(e Engine, m *Milestone) error {
|
||||||
|
@ -808,7 +792,7 @@ func ChangeMilestoneIssueStats(issue *Issue) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := GetMilestoneById(issue.MilestoneID)
|
m, err := GetMilestoneByID(issue.MilestoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -835,7 +819,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldMid > 0 {
|
if oldMid > 0 {
|
||||||
m, err := GetMilestoneById(oldMid)
|
m, err := GetMilestoneByID(oldMid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -863,7 +847,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if mid > 0 {
|
if mid > 0 {
|
||||||
m, err := GetMilestoneById(mid)
|
m, err := GetMilestoneByID(mid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -895,7 +879,7 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
|
||||||
|
|
||||||
// DeleteMilestoneByID deletes a milestone by given ID.
|
// DeleteMilestoneByID deletes a milestone by given ID.
|
||||||
func DeleteMilestoneByID(mid int64) error {
|
func DeleteMilestoneByID(mid int64) error {
|
||||||
m, err := GetMilestoneById(mid)
|
m, err := GetMilestoneByID(mid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsErrMilestoneNotExist(err) {
|
if IsErrMilestoneNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -382,7 +382,7 @@ func ViewIssue(ctx *middleware.Context) {
|
||||||
|
|
||||||
// Get assigned milestone.
|
// Get assigned milestone.
|
||||||
if issue.MilestoneID > 0 {
|
if issue.MilestoneID > 0 {
|
||||||
ctx.Data["Milestone"], err = models.GetMilestoneById(issue.MilestoneID)
|
ctx.Data["Milestone"], err = models.GetMilestoneByID(issue.MilestoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if models.IsErrMilestoneNotExist(err) {
|
||||||
log.Warn("GetMilestoneById: %v", err)
|
log.Warn("GetMilestoneById: %v", err)
|
||||||
|
@ -1044,7 +1044,6 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
||||||
|
|
||||||
if err = models.NewMilestone(&models.Milestone{
|
if err = models.NewMilestone(&models.Milestone{
|
||||||
RepoID: ctx.Repo.Repository.Id,
|
RepoID: ctx.Repo.Repository.Id,
|
||||||
Index: int64(ctx.Repo.Repository.NumMilestones) + 1,
|
|
||||||
Name: form.Title,
|
Name: form.Title,
|
||||||
Content: form.Content,
|
Content: form.Content,
|
||||||
Deadline: deadline,
|
Deadline: deadline,
|
||||||
|
@ -1063,12 +1062,12 @@ func EditMilestone(ctx *middleware.Context) {
|
||||||
ctx.Data["PageIsEditMilestone"] = true
|
ctx.Data["PageIsEditMilestone"] = true
|
||||||
ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
|
ctx.Data["DateLang"] = setting.DateLang(ctx.Locale.Language())
|
||||||
|
|
||||||
m, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, ctx.ParamsInt64(":index"))
|
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if models.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Handle(404, "GetMilestoneByIndex", nil)
|
ctx.Handle(404, "GetMilestoneByID", nil)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetMilestoneByIndex", err)
|
ctx.Handle(500, "GetMilestoneByID", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1101,12 +1100,12 @@ func EditMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, ctx.ParamsInt64(":index"))
|
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if models.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Handle(404, "GetMilestoneByIndex", nil)
|
ctx.Handle(404, "GetMilestoneByID", nil)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetMilestoneByIndex", err)
|
ctx.Handle(500, "GetMilestoneByID", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1123,12 +1122,12 @@ func EditMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChangeMilestonStatus(ctx *middleware.Context) {
|
func ChangeMilestonStatus(ctx *middleware.Context) {
|
||||||
m, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, ctx.ParamsInt64(":index"))
|
m, err := models.GetMilestoneByID(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if models.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Handle(404, "GetMilestoneByIndex", err)
|
ctx.Handle(404, "GetMilestoneByID", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetMilestoneByIndex", err)
|
ctx.Handle(500, "GetMilestoneByID", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,11 +54,11 @@
|
||||||
</div>
|
</div>
|
||||||
{{if $.IsRepositoryAdmin}}
|
{{if $.IsRepositoryAdmin}}
|
||||||
<div class="ui right operate">
|
<div class="ui right operate">
|
||||||
<a href="{{$.Link}}/{{.Index}}/edit" data-id={{.ID}} data-title={{.Name}}><i class="octicon octicon-pencil"></i> {{$.i18n.Tr "repo.issues.label_edit"}}</a>
|
<a href="{{$.Link}}/{{.ID}}/edit" data-id={{.ID}} data-title={{.Name}}><i class="octicon octicon-pencil"></i> {{$.i18n.Tr "repo.issues.label_edit"}}</a>
|
||||||
{{if .IsClosed}}
|
{{if .IsClosed}}
|
||||||
<a href="{{$.Link}}/{{.Index}}/open" data-id={{.ID}} data-title={{.Name}}><i class="octicon octicon-check"></i> {{$.i18n.Tr "repo.milestones.open"}}</a>
|
<a href="{{$.Link}}/{{.ID}}/open" data-id={{.ID}} data-title={{.Name}}><i class="octicon octicon-check"></i> {{$.i18n.Tr "repo.milestones.open"}}</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="{{$.Link}}/{{.Index}}/close" data-id={{.ID}} data-title={{.Name}}><i class="octicon octicon-x"></i> {{$.i18n.Tr "repo.milestones.close"}}</a>
|
<a href="{{$.Link}}/{{.ID}}/close" data-id={{.ID}} data-title={{.Name}}><i class="octicon octicon-x"></i> {{$.i18n.Tr "repo.milestones.close"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
<a class="delete-button" href="#" data-url="{{$.RepoLink}}/milestones/delete" data-id="{{.ID}}"><i class="octicon octicon-trashcan"></i> {{$.i18n.Tr "repo.issues.label_delete"}}</a>
|
<a class="delete-button" href="#" data-url="{{$.RepoLink}}/milestones/delete" data-id="{{.ID}}"><i class="octicon octicon-trashcan"></i> {{$.i18n.Tr "repo.issues.label_delete"}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue