Added delete Dependency function
+ Improved Event Comments Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
78e755c812
commit
6859c47397
2
conf/app.ini
vendored
2
conf/app.ini
vendored
|
|
@ -389,7 +389,7 @@ MODE = console
|
|||
; Buffer length of channel, keep it as it is if you don't know what it is.
|
||||
BUFFER_LEN = 10000
|
||||
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
|
||||
LEVEL = Debug
|
||||
LEVEL = Trace
|
||||
|
||||
; For "console" mode only
|
||||
[log.console]
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ const (
|
|||
CommentTypeCancelTracking
|
||||
// Dependency added
|
||||
CommentTypeAddedDependency
|
||||
//Dependency removed
|
||||
CommentTypeRemovedDependency
|
||||
)
|
||||
|
||||
// CommentTag defines comment tag type
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package models
|
|||
|
||||
import (
|
||||
"time"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// IssueDependency is connection request for receiving issue notification.
|
||||
|
|
@ -43,6 +44,7 @@ func (iw *IssueDependency) BeforeUpdate() {
|
|||
}
|
||||
|
||||
// CreateIssueDependency creates a new dependency for an issue
|
||||
// TODO: prevent issues having itself as dependency
|
||||
func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exists bool, depExists bool) {
|
||||
err = x.Sync(new(IssueDependency))
|
||||
if err != nil {
|
||||
|
|
@ -75,6 +77,17 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
|||
IssueID: issueID,
|
||||
PosterID: userID,
|
||||
Type: CommentTypeAddedDependency,
|
||||
Content: strconv.FormatInt(depID, 10),
|
||||
}
|
||||
|
||||
if _, err := x.Insert(comment); err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
comment = &Comment{
|
||||
IssueID: depID,
|
||||
PosterID: userID,
|
||||
Type: CommentTypeAddedDependency,
|
||||
Content: strconv.FormatInt(issueID, 10),
|
||||
}
|
||||
|
||||
if _, err := x.Insert(comment); err != nil {
|
||||
|
|
@ -86,6 +99,62 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
|||
return nil, exists, false
|
||||
}
|
||||
|
||||
// Removes a dependency from an issue
|
||||
func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (err error) {
|
||||
err = x.Sync(new(IssueDependency))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if it exists
|
||||
exists, err := issueDepExists(x, issueID, depID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If it exists, remove it, otherwise show an error message
|
||||
if exists {
|
||||
|
||||
if depType == 1{
|
||||
_, err := x.Delete(&IssueDependency{IssueID: issueID, DependencyID: depID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if depType == 2{
|
||||
_, err := x.Delete(&IssueDependency{IssueID: depID, DependencyID: issueID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add comment referencing the removed dependency
|
||||
comment := &Comment{
|
||||
IssueID: issueID,
|
||||
PosterID: userID,
|
||||
Type: CommentTypeRemovedDependency,
|
||||
Content: strconv.FormatInt(depID, 10),
|
||||
}
|
||||
|
||||
if _, err := x.Insert(comment); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
comment = &Comment{
|
||||
IssueID: depID,
|
||||
PosterID: userID,
|
||||
Type: CommentTypeRemovedDependency,
|
||||
Content: strconv.FormatInt(issueID, 10),
|
||||
}
|
||||
|
||||
if _, err := x.Insert(comment); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if the dependency already exists
|
||||
func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err error) {
|
||||
var Dependencies = IssueDependency{IssueID: issueID, DependencyID: depID}
|
||||
|
|
@ -732,6 +732,7 @@ issues.dependency.cancel = Cancel
|
|||
issues.dependency.add_header = Add New Dependency
|
||||
issues.dependency.issue_number = Issuenumber
|
||||
issues.dependency.added_dependency = `<a href="%[1]s">%[2]s</a> added a new dependency %[3]s`
|
||||
issues.dependency.removed_dependency = `<a href="%[1]s">%[2]s</a> removed a dependency %[3]s`
|
||||
|
||||
|
||||
pulls.desc = Pulls management your code review and merge requests
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func AddDependency(c *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if depExists {
|
||||
if !depExists {
|
||||
c.Flash.Error("Dependend issue does not exist!")
|
||||
}
|
||||
|
||||
|
|
|
|||
52
routers/repo/issue_dependency_remove.go
Normal file
52
routers/repo/issue_dependency_remove.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright 2017 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 (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// IssueWatch sets issue watching
|
||||
func RemoveDependency(c *context.Context) {
|
||||
dep, err := strconv.ParseInt(c.Req.PostForm.Get("removeDependencyID"), 10, 64)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||
return
|
||||
}
|
||||
|
||||
issueIndex := c.ParamsInt64("index")
|
||||
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Dependency Type
|
||||
// Types: 1 = blockedBy, 2 = blocking
|
||||
depType, err := strconv.ParseInt(c.Req.PostForm.Get("dependencyType"), 10, 64)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "GetDependecyType", err)
|
||||
return
|
||||
}
|
||||
|
||||
if depType != 1 && depType != 2{
|
||||
c.Handle(http.StatusBadRequest, "GetDependecyType", nil)
|
||||
return
|
||||
}
|
||||
|
||||
err = models.RemoveIssueDependency(c.User.ID, issue.ID, dep, depType)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||
return
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex)
|
||||
c.Redirect(url, http.StatusSeeOther)
|
||||
}
|
||||
|
|
@ -485,6 +485,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Post("/content", repo.UpdateIssueContent)
|
||||
m.Post("/watch", repo.IssueWatch)
|
||||
m.Post("/addDependency", repo.AddDependency)
|
||||
m.Post("/removeDependency", repo.RemoveDependency)
|
||||
m.Group("/times", func() {
|
||||
m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually)
|
||||
m.Group("/stopwatch", func() {
|
||||
|
|
|
|||
|
|
@ -194,5 +194,33 @@
|
|||
{{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}}
|
||||
</span>
|
||||
{{end}}
|
||||
|
||||
{{else if eq .Type 17}}
|
||||
<div class="event">
|
||||
<span class="octicon octicon-primitive-dot"></span>
|
||||
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||
<img src="{{.Poster.RelAvatarLink}}">
|
||||
</a>
|
||||
<span class="text grey">
|
||||
{{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}}
|
||||
</span>
|
||||
<div class="detail">
|
||||
<span class="octicon octicon-plus"></span>
|
||||
<span class="text grey">{{.Content}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{else if eq .Type 18}}
|
||||
<div class="event">
|
||||
<span class="octicon octicon-primitive-dot"></span>
|
||||
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||
<img src="{{.Poster.RelAvatarLink}}">
|
||||
</a>
|
||||
<span class="text grey">
|
||||
{{$.i18n.Tr "repo.issues.dependency.removed_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}}
|
||||
</span>
|
||||
<div class="detail">
|
||||
<span class="text grey octicon octicon-trashcan"></span>
|
||||
<span class="text grey">{{.Content}} </span>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@
|
|||
{{range .BlockedByDependencies}}
|
||||
<div class="item">
|
||||
<div class="right floated content">
|
||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blockedBy');">
|
||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 1);">
|
||||
<i class="delete icon text red"></i>
|
||||
</a>
|
||||
{{if .IsClosed}}
|
||||
|
|
@ -228,7 +228,7 @@
|
|||
{{range .BlockingDependencies}}
|
||||
<div class="item">
|
||||
<div class="right floated content">
|
||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blocking');">
|
||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 2);">
|
||||
<i class="delete icon text red"></i>
|
||||
</a>
|
||||
{{if .IsClosed}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user