diff --git a/models/issue_dependency_add.go b/models/issue_dependency_add.go index 04db222ee..5200d57b5 100644 --- a/models/issue_dependency_add.go +++ b/models/issue_dependency_add.go @@ -6,6 +6,7 @@ package models import ( "time" + "fmt" ) // IssueDependency is connection request for receiving issue notification. @@ -13,7 +14,7 @@ type IssueDependency struct { ID int64 `xorm:"pk autoincr"` UserID int64 `xorm:"UNIQUE(watch) NOT NULL"` IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"` - DependencyID int64 `xorm:"UNIQUE(watch) NOT NULL"` + DependencyID int64 `xorm:"UNIQUE(watch) NOT NULL"` Created time.Time `xorm:"-"` CreatedUnix int64 `xorm:"NOT NULL"` Updated time.Time `xorm:"-"` @@ -43,37 +44,38 @@ func (iw *IssueDependency) BeforeUpdate() { } // CreateOrUpdateIssueDependency sets or updates a dependency for an issue -func CreateOrUpdateIssueDependency(userID, issueID int64, dep int64) error { - id, exists, err := getIssueWatch(x, userID, issueID) +func CreateOrUpdateIssueDependency(userID, issueID int64, depID int64) error { + err := x.Sync(new(IssueDependency)) + if err != nil { + return err + } + + exists, err := issueDepExists(x, issueID, depID) if err != nil { return err } if !exists { - id = &IssueWatch{ - UserID: userID, - IssueID: issueID, - IsWatching: isWatching, - } + newId := new(IssueDependency) + newId.UserID = userID + newId.IssueID = issueID + newId.DependencyID = depID - if _, err := x.Insert(iw); err != nil { + if _, err := x.Insert(newId); err != nil { return err } } else { - iw.IsWatching = isWatching - - if _, err := x.Id(iw.ID).Cols("is_watching", "updated_unix").Update(iw); err != nil { - return err - } + fmt.Println("Dependency exists") + // TODO: Should display a message on issue page } return nil } // -func getIssueDep(e Engine, issueID int64) (Dependencies []*IssueDependency, err error) { - id = new(IssueDependency) - err = e. - Where("issue_id = ?", issueID). - Find(&Dependencies) +func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err error) { + var Dependencies = IssueDependency{IssueID: issueID, DependencyID: depID} + + //err = e.Where("issue_id = ?", issueID).Where("dependency_id = ?", depID).Find(&Dependencies) + exists, err = e.Get(&Dependencies) return } diff --git a/public/js/index.js b/public/js/index.js index cded5e2a1..c808a13de 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1822,3 +1822,14 @@ function toggleStopwatch() { function cancelStopwatch() { $("#cancel_stopwatch_form").submit(); } + +function showAddDependencyModal() { + $('.tiny.modal') + .modal({ + duration: 200, + onApprove: function() { + $('#addDependencyForm').submit(); + } + }).modal('show') + ; +} diff --git a/routers/repo/issue_dependency_add.go b/routers/repo/issue_dependency_add.go index 384d04aca..3ebf20285 100644 --- a/routers/repo/issue_dependency_add.go +++ b/routers/repo/issue_dependency_add.go @@ -17,7 +17,7 @@ import ( func AddDependency(c *context.Context) { dep, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64) if err != nil { - c.Handle(http.StatusInternalServerError, "issue ID is not int", err) + c.Handle(http.StatusBadRequest, "issue ID is not int", err) return } @@ -29,7 +29,8 @@ func AddDependency(c *context.Context) { } if err := models.CreateOrUpdateIssueDependency(c.User.ID, issue.ID, dep); err != nil { - c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err) + c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err) + fmt.Println("updateerr") return } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 888ea2c92..a2e6cbcb6 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -484,7 +484,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/title", repo.UpdateIssueTitle) m.Post("/content", repo.UpdateIssueContent) m.Post("/watch", repo.IssueWatch) - m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) m.Post("/addDependency", repo.AddDependency) m.Group("/times", func() { m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually) @@ -499,6 +498,7 @@ func RegisterRoutes(m *macaron.Macaron) { return } }) + m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) }) m.Post("/labels", repo.UpdateIssueLabel, reqRepoWriter) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 4fa89bbdd..7dfb19f08 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -214,6 +214,7 @@
+ {{$.CsrfTokenHtml}}