Init:
* Added models * Added UI * Added Routes Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
parent
74a0df7a3b
commit
8bd99fe32e
79
models/issue_dependency_add.go
Normal file
79
models/issue_dependency_add.go
Normal 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
|
||||
}
|
||||
|
|
@ -13,14 +13,11 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// Adds new dependencies
|
||||
// IssueWatch sets issue watching
|
||||
func AddDependency(c *context.Context) {
|
||||
|
||||
// TODO: should should an issue only have dependencies in it's own repo?
|
||||
|
||||
depID, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64)
|
||||
dep, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||
c.Handle(http.StatusInternalServerError, "issue ID is not int", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -31,39 +28,11 @@ func AddDependency(c *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// Check if the Repo is allowed to have dependencies
|
||||
if !c.Repo.Repository.UnitEnabled(models.UnitTypeIssueDependencies) {
|
||||
c.Handle(404, "MustEnableIssueDependencies", nil)
|
||||
if err := models.CreateOrUpdateIssueDependency(c.User.ID, issue.ID, dep); err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Dependency
|
||||
dep, err := models.GetIssueByID(depID)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "GetIssueByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if issue and dependency is the same
|
||||
if dep.Index == issueIndex{
|
||||
c.Flash.Error(c.Tr("issues.dependency.add_error_same_issue"))
|
||||
} else {
|
||||
|
||||
err, exists, depExists := models.CreateIssueDependency(c.User, issue, dep)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !depExists {
|
||||
c.Flash.Error(c.Tr("add_error_dep_not_exist"))
|
||||
}
|
||||
|
||||
if exists {
|
||||
c.Flash.Error(c.Tr("add_error_dep_exists"))
|
||||
}
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex)
|
||||
c.Redirect(url, http.StatusSeeOther)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -487,6 +487,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
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() {
|
||||
|
|
@ -613,7 +614,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)
|
||||
|
|
@ -633,11 +634,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)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@
|
|||
<div class="ui buttons two fluid start-add">
|
||||
<button onclick="this.disabled=true;toggleStopwatch()" class="ui button poping up start" data-content='{{.i18n.Tr "repo.issues.start_tracking"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.start_tracking_short"}}</button>
|
||||
<button onclick="timeAddManual()" class="ui button green poping up add-time" data-content='{{.i18n.Tr "repo.issues.add_time"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.add_time_short"}}</button>
|
||||
<div class="ui mini modal time-add-manual">
|
||||
<div class="ui mini modal">
|
||||
<div class="header">{{.i18n.Tr "repo.issues.add_time"}}</div>
|
||||
<div class="content">
|
||||
<form method="POST" id="add_time_manual_form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/times/add" class="ui action input fluid">
|
||||
|
|
@ -191,82 +191,16 @@
|
|||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{if .IssueDependenciesEnabled}}
|
||||
<div class="ui divider"></div>
|
||||
|
||||
<div class="ui depending">
|
||||
<span class="text"><strong>{{.i18n.Tr "repo.issues.dependency.title"}}</strong></span>
|
||||
<br>
|
||||
{{if .BlockedByDependencies}}
|
||||
<span class="text">
|
||||
{{if .Issue.IsPull}}
|
||||
{{.i18n.Tr "repo.issues.dependency.issue_closing_blockedby"}}:
|
||||
{{else}}
|
||||
{{.i18n.Tr "repo.issues.dependency.pr_closing_blockedby"}}:
|
||||
{{end}}
|
||||
</span>
|
||||
<div class="ui relaxed divided list">
|
||||
{{range .BlockedByDependencies}}
|
||||
<div class="item">
|
||||
<div class="right floated content">
|
||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 1);">
|
||||
<i class="delete icon text red"></i>
|
||||
</a>
|
||||
{{if .IsClosed}}
|
||||
<div class="ui red mini label">
|
||||
<i class="octicon octicon-issue-closed"></i>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="ui green mini label">
|
||||
<i class="octicon octicon-issue-opened"></i>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="ui black label">#{{.Index}}</div>
|
||||
<a class="title has-emoji" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
<span class="text"><strong>Dependencies</strong></span>
|
||||
<div>
|
||||
This issue currently doesn't have any dependencies.
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .BlockingDependencies}}
|
||||
<div class="ui relaxed divided list">
|
||||
<span class="text">
|
||||
{{if .Issue.IsPull}}
|
||||
{{.i18n.Tr "repo.issues.dependency.pr_close_blocks"}}:
|
||||
{{else}}
|
||||
{{.i18n.Tr "repo.issues.dependency.issue_close_blocks"}}:
|
||||
{{end}}
|
||||
</span>
|
||||
{{range .BlockingDependencies}}
|
||||
<div class="item">
|
||||
<div class="right floated content">
|
||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 2);">
|
||||
<i class="delete icon text red"></i>
|
||||
</a>
|
||||
{{if .IsClosed}}
|
||||
<div class="ui red tiny label">
|
||||
<i class="octicon octicon-issue-closed"></i>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="ui green mini label">
|
||||
<i class="octicon octicon-issue-opened"></i>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="ui black label">#{{.Index}}</div>
|
||||
<a class="title has-emoji" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if (and (not .BlockedByDependencies) (not .BlockingDependencies))}}
|
||||
<p>{{.i18n.Tr "repo.issues.dependency.no_dependencies"}}</p>
|
||||
{{end}}
|
||||
<div>
|
||||
<button class="fluid green ui button" onclick="showAddDependencyModal();">
|
||||
{{.i18n.Tr "repo.issues.dependency.add"}}
|
||||
Add
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -274,52 +208,24 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div class="ui mini modal add-dependency">
|
||||
<div class="ui tiny modal">
|
||||
<div class="header">
|
||||
{{.i18n.Tr "repo.issues.dependency.add_header"}}
|
||||
Add new Dependency
|
||||
</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='{{.i18n.Tr "repo.issues.dependency.issue_number"}}'>
|
||||
<input type="text" name="newDependency" id="newDependency" placeholder="Issuenumber...">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui negative button">
|
||||
{{.i18n.Tr "repo.issues.dependency.cancel"}}
|
||||
Cancel
|
||||
</div>
|
||||
<div class="ui positive right labeled icon button">
|
||||
{{.i18n.Tr "repo.issues.dependency.add"}}
|
||||
Add
|
||||
<i class="add icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="ui basic modal remove-dependency">
|
||||
<div class="ui icon header">
|
||||
<i class="trash icon"></i>
|
||||
{{.i18n.Tr "repo.issues.dependency.remove_header"}}
|
||||
</div>
|
||||
<div class="content">
|
||||
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/removeDependency" id="removeDependencyForm">
|
||||
{{$.CsrfTokenHtml}}
|
||||
<input type="hidden" value="" name="removeDependencyID" id="removeDependencyID"/>
|
||||
<input type="hidden" value="" name="dependencyType" id="dependencyType"/>
|
||||
</form>
|
||||
<p>{{.i18n.Tr "repo.issues.dependency.remove_text"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<div class="ui basic red cancel inverted button">
|
||||
<i class="remove icon"></i>
|
||||
{{.i18n.Tr "repo.issues.dependency.cancel"}}
|
||||
</div>
|
||||
<div class="ui basic green ok inverted button">
|
||||
<i class="checkmark icon"></i>
|
||||
{{.i18n.Tr "repo.issues.dependency.remove"}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user