Added create new issue method

Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
Konrad Langenberg 2017-08-26 22:37:52 +02:00 committed by Konrad
parent 9298795186
commit 0a4925fb17
5 changed files with 38 additions and 23 deletions

View File

@ -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
}

View File

@ -1474,7 +1474,7 @@ $(document).ready(function () {
var $this = $(this);
var filter = "";
if ($this.attr("id")) {
filter += "#"+$this.attr("id")
filter += "#"+$this.attr("id")
}
$('.delete.modal'+filter).modal({
closable: false,
@ -1715,3 +1715,14 @@ function initDashboardSearch() {
}
});
}
function showAddDependencyModal() {
$('.tiny.modal')
.modal({
duration: 200,
onApprove: function() {
$('#addDependencyForm').submit();
}
}).modal('show')
;
}

View File

@ -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
}

View File

@ -466,8 +466,8 @@ 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.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
})
m.Post("/labels", repo.UpdateIssueLabel, reqRepoWriter)

View File

@ -145,6 +145,7 @@
</div>
<div class="content">
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/addDependency" id="addDependencyForm">
{{$.CsrfTokenHtml}}
<div class="ui input">
<input type="text" name="newDependency" id="newDependency" placeholder="Issuenumber...">
</div>