Implemented custom type DependencyType

Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
Konrad Langenberg 2017-09-24 17:31:47 +02:00 committed by Konrad
parent 2c5a743df8
commit 29aafb3ef8
3 changed files with 30 additions and 24 deletions

View File

@ -21,9 +21,11 @@ type IssueDependency struct {
} }
// Define Dependency Type Constants // Define Dependency Type Constants
type DependencyType int
const ( const (
DependencyTypeBlockedBy int64 = 1 DependencyTypeBlockedBy DependencyType = iota
DependencyTypeBlocking int64 = 2 DependencyTypeBlocking
) )
// CreateIssueDependency creates a new dependency for an issue // CreateIssueDependency creates a new dependency for an issue
@ -66,7 +68,7 @@ func CreateIssueDependency(user *User, issue, dep *Issue) (exists bool, err erro
} }
// RemoveIssueDependency removes a dependency from an issue // RemoveIssueDependency removes a dependency from an issue
func RemoveIssueDependency(user *User, issue *Issue, dep *Issue, depType int64) (err error) { func RemoveIssueDependency(user *User, issue *Issue, dep *Issue, depType DependencyType) (err error) {
sess := x.NewSession() sess := x.NewSession()
// Check if it exists // Check if it exists
@ -78,18 +80,20 @@ func RemoveIssueDependency(user *User, issue *Issue, dep *Issue, depType int64)
// If it exists, remove it, otherwise show an error message // If it exists, remove it, otherwise show an error message
if exists { if exists {
if depType == DependencyTypeBlockedBy { var issueDepToDelete IssueDependency
_, err := x.Delete(&IssueDependency{IssueID: issue.ID, DependencyID: dep.ID})
if err != nil { switch depType {
return err case DependencyTypeBlockedBy:
} issueDepToDelete = IssueDependency{IssueID: issue.ID, DependencyID: dep.ID}
case DependencyTypeBlocking:
issueDepToDelete = IssueDependency{IssueID: dep.ID, DependencyID: issue.ID}
default:
return
} }
if depType == DependencyTypeBlocking { _, err := x.Delete(&issueDepToDelete)
_, err := x.Delete(&IssueDependency{IssueID: dep.ID, DependencyID: issue.ID}) if err != nil {
if err != nil { return err
return err
}
} }
// Add comment referencing the removed dependency // Add comment referencing the removed dependency

View File

@ -29,16 +29,18 @@ func RemoveDependency(c *context.Context) {
} }
// Dependency Type // Dependency Type
// Types: 1 = blockedBy, 2 = blocking depTypeStr := c.Req.PostForm.Get("dependencyType")
depType, err := strconv.ParseInt(c.Req.PostForm.Get("dependencyType"), 10, 64)
if err != nil {
c.Handle(http.StatusInternalServerError, "GetDependecyType", err)
return
}
if depType != models.DependencyTypeBlockedBy && depType != models.DependencyTypeBlocking { var depType models.DependencyType
c.Handle(http.StatusBadRequest, "GetDependecyType", nil)
return switch depTypeStr {
case "blockedBy":
depType = models.DependencyTypeBlockedBy
case "blocking":
depType = models.DependencyTypeBlocking
default:
c.Handle(http.StatusBadRequest, "GetDependecyType", nil)
return
} }
// Dependency // Dependency

View File

@ -209,7 +209,7 @@
{{range .BlockedByDependencies}} {{range .BlockedByDependencies}}
<div class="item"> <div class="item">
<div class="right floated content"> <div class="right floated content">
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.Issue.ID}}, 1);"> <a class="delete-dependency-button" onclick="deleteDependencyModal({{.Issue.ID}}, 'blockedBy');">
<i class="delete icon text red"></i> <i class="delete icon text red"></i>
</a> </a>
{{if .IsClosed}} {{if .IsClosed}}
@ -241,7 +241,7 @@
{{range .BlockingDependencies}} {{range .BlockingDependencies}}
<div class="item"> <div class="item">
<div class="right floated content"> <div class="right floated content">
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.Issue.ID}}, 2);"> <a class="delete-dependency-button" onclick="deleteDependencyModal({{.Issue.ID}}, 'blocking');">
<i class="delete icon text red"></i> <i class="delete icon text red"></i>
</a> </a>
{{if .IsClosed}} {{if .IsClosed}}