* Added models
* Added UI
* Added Routes

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
Konrad Langenberg 2017-08-26 18:58:35 +02:00 committed by Jonas Franz
parent af8594364c
commit 0588536447
4 changed files with 158 additions and 4 deletions

View File

@ -0,0 +1,79 @@
// 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 models
import (
"time"
)
// IssueDependency is connection request for receiving issue notification.
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"`
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"NOT NULL"`
Updated time.Time `xorm:"-"`
UpdatedUnix int64 `xorm:"NOT NULL"`
}
// BeforeInsert is invoked from XORM before inserting an object of this type.
func (iw *IssueDependency) BeforeInsert() {
var (
t = time.Now()
u = t.Unix()
)
iw.Created = t
iw.CreatedUnix = u
iw.Updated = t
iw.UpdatedUnix = u
}
// BeforeUpdate is invoked from XORM before updating an object of this type.
func (iw *IssueDependency) BeforeUpdate() {
var (
t = time.Now()
u = t.Unix()
)
iw.Updated = t
iw.UpdatedUnix = u
}
// CreateOrUpdateIssueDependency sets or updates a dependency for an issue
func CreateOrUpdateIssueDependency(userID, issueID int64, dep int64) error {
id, exists, err := getIssueWatch(x, userID, issueID)
if err != nil {
return err
}
if !exists {
id = &IssueWatch{
UserID: userID,
IssueID: issueID,
IsWatching: isWatching,
}
if _, err := x.Insert(iw); 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
}
}
return nil
}
//
func getIssueDep(e Engine, issueID int64) (Dependencies []*IssueDependency, err error) {
id = new(IssueDependency)
err = e.
Where("issue_id = ?", issueID).
Find(&Dependencies)
return
}

View File

@ -0,0 +1,38 @@
// 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 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)
return
}
issueIndex := c.ParamsInt64("index")
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
if err != nil {
c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
return
}
if err := models.CreateOrUpdateIssueDependency(c.User.ID, issue.ID, dep); err != nil {
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
return
}
url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex)
c.Redirect(url, http.StatusSeeOther)
}

View File

@ -485,6 +485,7 @@ func RegisterRoutes(m *macaron.Macaron) {
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)
m.Group("/stopwatch", func() {
@ -611,7 +612,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/*", repo.WikiRaw)
}, repo.MustEnableWiki, context.CheckUnit(models.UnitTypeWiki), context.CheckUnit(models.UnitTypeWiki))
m.Get("/archive/*", repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.Download)
m.Get("/archive/*", repo.MustBeNotBare, repo.Download, context.CheckUnit(models.UnitTypeCode))
m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
@ -631,11 +632,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
m.Get("/forks", repo.Forks)
}, context.RepoRef(), context.CheckUnit(models.UnitTypeCode))
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)",
repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.RawDiff)
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.MustBeNotBare, repo.RawDiff, context.CheckUnit(models.UnitTypeCode))
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists,
repo.SetDiffViewStyle, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.CompareDiff)
repo.SetDiffViewStyle, repo.MustBeNotBare, repo.CompareDiff, context.CheckUnit(models.UnitTypeCode))
}, ignSignIn, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits())
m.Group("/:username/:reponame", func() {
m.Get("/stars", repo.Stars)

View File

@ -190,5 +190,42 @@
</div>
{{end}}
{{end}}
<div class="ui divider"></div>
<div class="ui depending">
<span class="text"><strong>Dependencies</strong></span>
<div>
This issue currently doesn't have any dependencies.
</div>
<div>
<button class="fluid green ui button" onclick="showAddDependencyModal();">
Add
</button>
</div>
</div>
</div>
</div>
<div class="ui tiny modal">
<div class="header">
Add new Dependency
</div>
<div class="content">
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/addDependency" id="addDependencyForm">
<div class="ui input">
<input type="text" name="newDependency" id="newDependency" placeholder="Issuenumber...">
</div>
</form>
</div>
<div class="actions">
<div class="ui negative button">
Cancel
</div>
<div class="ui positive right labeled icon button">
Add
<i class="add icon"></i>
</div>
</div>
</div>