mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 16:47:30 +00:00
Search branches (#27055)
Resolve #25233 <img width="1315" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/3ba59b58-471a-4e1b-985c-87edac2268c0"> <img width="1297" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/b6caa12f-323b-4f70-9c44-ef91cb71a26c">
This commit is contained in:
parent
dcf4b9e314
commit
47b878858a
|
@ -70,6 +70,7 @@ type FindBranchOptions struct {
|
||||||
ExcludeBranchNames []string
|
ExcludeBranchNames []string
|
||||||
IsDeletedBranch util.OptionalBool
|
IsDeletedBranch util.OptionalBool
|
||||||
OrderBy string
|
OrderBy string
|
||||||
|
Keyword string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *FindBranchOptions) Cond() builder.Cond {
|
func (opts *FindBranchOptions) Cond() builder.Cond {
|
||||||
|
@ -84,6 +85,9 @@ func (opts *FindBranchOptions) Cond() builder.Cond {
|
||||||
if !opts.IsDeletedBranch.IsNone() {
|
if !opts.IsDeletedBranch.IsNone() {
|
||||||
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
|
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
|
||||||
}
|
}
|
||||||
|
if opts.Keyword != "" {
|
||||||
|
cond = cond.And(builder.Like{"name", opts.Keyword})
|
||||||
|
}
|
||||||
return cond
|
return cond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2515,6 +2515,7 @@ branch.default_deletion_failed = Branch "%s" is the default branch. It cannot be
|
||||||
branch.restore = Restore Branch "%s"
|
branch.restore = Restore Branch "%s"
|
||||||
branch.download = Download Branch "%s"
|
branch.download = Download Branch "%s"
|
||||||
branch.rename = Rename Branch "%s"
|
branch.rename = Rename Branch "%s"
|
||||||
|
branch.search = Search Branch
|
||||||
branch.included_desc = This branch is part of the default branch
|
branch.included_desc = This branch is part of the default branch
|
||||||
branch.included = Included
|
branch.included = Included
|
||||||
branch.create_new_branch = Create branch from branch:
|
branch.create_new_branch = Create branch from branch:
|
||||||
|
|
|
@ -51,7 +51,9 @@ func Branches(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
pageSize := setting.Git.BranchesRangeSize
|
pageSize := setting.Git.BranchesRangeSize
|
||||||
|
|
||||||
defaultBranch, branches, branchesCount, err := repo_service.LoadBranches(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, util.OptionalBoolNone, page, pageSize)
|
kw := ctx.FormString("q")
|
||||||
|
|
||||||
|
defaultBranch, branches, branchesCount, err := repo_service.LoadBranches(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, util.OptionalBoolNone, kw, page, pageSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("LoadBranches", err)
|
ctx.ServerError("LoadBranches", err)
|
||||||
return
|
return
|
||||||
|
@ -73,6 +75,7 @@ func Branches(ctx *context.Context) {
|
||||||
commitStatus[commitID] = git_model.CalcCommitStatus(cs)
|
commitStatus[commitID] = git_model.CalcCommitStatus(cs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.Data["Keyword"] = kw
|
||||||
ctx.Data["Branches"] = branches
|
ctx.Data["Branches"] = branches
|
||||||
ctx.Data["CommitStatus"] = commitStatus
|
ctx.Data["CommitStatus"] = commitStatus
|
||||||
ctx.Data["CommitStatuses"] = commitStatuses
|
ctx.Data["CommitStatuses"] = commitStatuses
|
||||||
|
|
|
@ -66,7 +66,7 @@ type Branch struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadBranches loads branches from the repository limited by page & pageSize.
|
// LoadBranches loads branches from the repository limited by page & pageSize.
|
||||||
func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch util.OptionalBool, page, pageSize int) (*Branch, []*Branch, int64, error) {
|
func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch util.OptionalBool, keyword string, page, pageSize int) (*Branch, []*Branch, int64, error) {
|
||||||
defaultDBBranch, err := git_model.GetBranch(ctx, repo.ID, repo.DefaultBranch)
|
defaultDBBranch, err := git_model.GetBranch(ctx, repo.ID, repo.DefaultBranch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, 0, err
|
return nil, nil, 0, err
|
||||||
|
@ -79,6 +79,7 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: pageSize,
|
PageSize: pageSize,
|
||||||
},
|
},
|
||||||
|
Keyword: keyword,
|
||||||
}
|
}
|
||||||
|
|
||||||
totalNumOfBranches, err := git_model.CountBranches(ctx, branchOpts)
|
totalNumOfBranches, err := git_model.CountBranches(ctx, branchOpts)
|
||||||
|
|
|
@ -70,9 +70,20 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .Branches}}
|
{{if .Branches}}
|
||||||
<h4 class="ui top attached header">
|
<h4 class="ui top attached header gt-df gt-ac gt-sb">
|
||||||
|
<div class="gt-df gt-ac">
|
||||||
{{.locale.Tr "repo.branches"}}
|
{{.locale.Tr "repo.branches"}}
|
||||||
|
</div>
|
||||||
|
<div class="gt-whitespace-nowrap">
|
||||||
|
<form class="ignore-dirty" method="get">
|
||||||
|
<div class="ui tiny search input">
|
||||||
|
<input name="q" placeholder="{{.locale.Tr "repo.branch.search"}}" value="{{.Keyword}}" autofocus>
|
||||||
|
</div>
|
||||||
|
<button class="ui primary tiny button gt-mr-0" data-tooltip-content={{.locale.Tr "repo.commits.search.tooltip"}}>{{.locale.Tr "repo.commits.find"}}</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<div class="ui attached table segment">
|
<div class="ui attached table segment">
|
||||||
<table class="ui very basic striped fixed table single line">
|
<table class="ui very basic striped fixed table single line">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
Loading…
Reference in a new issue