Added create new issue method
Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
8bd99fe32e
commit
f3c40e8aea
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -639,7 +639,6 @@ function initRepository() {
|
|||
if ($('.repository.compare.pull').length > 0) {
|
||||
initFilterSearchDropdown('.choose.branch .dropdown');
|
||||
}
|
||||
}
|
||||
|
||||
// Branches
|
||||
if ($('.repository.settings.branches').length > 0) {
|
||||
|
|
@ -1454,7 +1453,7 @@ $(document).ready(function () {
|
|||
|
||||
// Emojify
|
||||
emojify.setConfig({
|
||||
img_dir: suburl + '/img/emoji',
|
||||
img_dir: suburl + '/plugins/emojify/images',
|
||||
ignore_emoticons: true
|
||||
});
|
||||
var hasEmoji = document.getElementsByClassName('has-emoji');
|
||||
|
|
@ -1824,45 +1823,12 @@ function cancelStopwatch() {
|
|||
$("#cancel_stopwatch_form").submit();
|
||||
}
|
||||
|
||||
function timeAddManual() {
|
||||
$('.time-add-manual')
|
||||
.modal({
|
||||
duration: 200,
|
||||
onApprove: function() {
|
||||
$('#add_time_manual_form').submit();
|
||||
}
|
||||
}).modal('show')
|
||||
;
|
||||
}
|
||||
|
||||
function toggleStopwatch() {
|
||||
$("#toggle_stopwatch_form").submit();
|
||||
}
|
||||
function cancelStopwatch() {
|
||||
$("#cancel_stopwatch_form").submit();
|
||||
}
|
||||
|
||||
function deleteDependencyModal(id, type) {
|
||||
$('.remove-dependency')
|
||||
.modal({
|
||||
closable: false,
|
||||
duration: 200,
|
||||
onApprove: function () {
|
||||
$('#removeDependencyID').val(id);
|
||||
$('#dependencyType').val(type);
|
||||
$('#removeDependencyForm').submit();
|
||||
}
|
||||
}).modal('show')
|
||||
;
|
||||
}
|
||||
|
||||
function showAddDependencyModal() {
|
||||
$('.add-dependency')
|
||||
$('.tiny.modal')
|
||||
.modal({
|
||||
duration: 200,
|
||||
onApprove: function() {
|
||||
$('#addDependencyForm').submit();
|
||||
|
||||
}
|
||||
}).modal('show')
|
||||
;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -485,9 +485,6 @@ 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.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)
|
||||
m.Group("/stopwatch", func() {
|
||||
|
|
@ -501,6 +498,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
return
|
||||
}
|
||||
})
|
||||
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
||||
})
|
||||
|
||||
m.Post("/labels", repo.UpdateIssueLabel, reqRepoWriter)
|
||||
|
|
|
|||
|
|
@ -214,6 +214,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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user