]> source.dussan.org Git - gitea.git/commitdiff
Included tag search capabilities (#32045)
authorBruno Sofiato <bruno.sofiato@gmail.com>
Tue, 17 Sep 2024 18:33:11 +0000 (15:33 -0300)
committerGitHub <noreply@github.com>
Tue, 17 Sep 2024 18:33:11 +0000 (02:33 +0800)
Resolves #31998

The first screenshot shows the tag page without any filter being
applied:

![image](https://github.com/user-attachments/assets/eac0e51c-9e48-42b2-bb1c-a25896ca40cb)

The second one, shows the page when the given filter returns no tag:

![image](https://github.com/user-attachments/assets/98df191e-1a7b-4947-b0ef-4987a0293c3e)

The last one shows a single tag being filtered:

![image](https://github.com/user-attachments/assets/79c7e05e-8c86-4f06-b17e-15818b7b9291)

Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com>
models/repo/release.go
options/locale/locale_en-US.ini
routers/web/repo/release.go
templates/repo/tag/list.tmpl

index 1643258301144e85d51a005064942843523a9eac..7c66cbc1af708eecfba2c6d7cb1a478c5fcc8f59 100644 (file)
@@ -234,6 +234,7 @@ type FindReleasesOptions struct {
        IsDraft       optional.Option[bool]
        TagNames      []string
        HasSha1       optional.Option[bool] // useful to find draft releases which are created with existing tags
+       NamePattern   optional.Option[string]
 }
 
 func (opts FindReleasesOptions) ToConds() builder.Cond {
@@ -261,6 +262,11 @@ func (opts FindReleasesOptions) ToConds() builder.Cond {
                        cond = cond.And(builder.Eq{"sha1": ""})
                }
        }
+
+       if opts.NamePattern.Has() && opts.NamePattern.Value() != "" {
+               cond = cond.And(builder.Like{"lower_tag_name", strings.ToLower(opts.NamePattern.Value())})
+       }
+
        return cond
 }
 
index 601671d8b907d2e7bb8d5c2f637672ed05bc10b4..951994253ac34815bd26ad5cd165bdc78e3c1861 100644 (file)
@@ -178,6 +178,8 @@ code_search_by_git_grep = Current code search results are provided by "git grep"
 package_kind = Search packages...
 project_kind = Search projects...
 branch_kind = Search branches...
+tag_kind = Search tags...
+tag_tooltip = Search for matching tags. Use '%' to match any sequence of numbers.
 commit_kind = Search commits...
 runner_kind = Search runners...
 no_results = No matching results found.
index a28330349254cd12d566354c5349aedf61dbe2a6..f551fffe956bc75c31f4e8f8f09c4a2ddbedef6d 100644 (file)
@@ -214,6 +214,8 @@ func TagsList(ctx *context.Context) {
        ctx.Data["HideBranchesInDropdown"] = true
        ctx.Data["CanCreateRelease"] = ctx.Repo.CanWrite(unit.TypeReleases) && !ctx.Repo.Repository.IsArchived
 
+       namePattern := ctx.FormTrim("q")
+
        listOptions := db.ListOptions{
                Page:     ctx.FormInt("page"),
                PageSize: ctx.FormInt("limit"),
@@ -233,6 +235,7 @@ func TagsList(ctx *context.Context) {
                IncludeTags:   true,
                HasSha1:       optional.Some(true),
                RepoID:        ctx.Repo.Repository.ID,
+               NamePattern:   optional.Some(namePattern),
        }
 
        releases, err := db.Find[repo_model.Release](ctx, opts)
@@ -241,14 +244,21 @@ func TagsList(ctx *context.Context) {
                return
        }
 
+       count, err := db.Count[repo_model.Release](ctx, opts)
+       if err != nil {
+               ctx.ServerError("GetReleasesByRepoID", err)
+               return
+       }
+
+       ctx.Data["Keyword"] = namePattern
        ctx.Data["Releases"] = releases
+       ctx.Data["TagCount"] = count
 
-       numTags := ctx.Data["NumTags"].(int64)
-       pager := context.NewPagination(int(numTags), opts.PageSize, opts.Page, 5)
+       pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
        pager.SetDefaultParams(ctx)
        ctx.Data["Page"] = pager
-
        ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases)
+
        ctx.HTML(http.StatusOK, tplTagsList)
 }
 
index 354808ed2e03b9a325d284be2e74ddcce33c49fd..eac846da7dd382eebe42b04ed612a31848ff332b 100644 (file)
@@ -4,14 +4,19 @@
        <div class="ui container">
                {{template "base/alert" .}}
                {{template "repo/release_tag_header" .}}
-               {{if .Releases}}
                <h4 class="ui top attached header">
                        <div class="five wide column tw-flex tw-items-center">
-                               {{svg "octicon-tag" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.release.tags"}}
+                               {{.TagCount}} {{ctx.Locale.Tr "repo.release.tags"}}
                        </div>
                </h4>
                {{$canReadReleases := $.Permission.CanRead ctx.Consts.RepoUnitTypeReleases}}
+               <div class="ui attached segment">
+                       <form class="ignore-dirty" method="get">
+                               {{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.tag_kind") "Tooltip" (ctx.Locale.Tr "search.tag_tooltip")}}
+                       </form>
+               </div>
                <div class="ui attached table segment">
+                       {{if .Releases}}
                        <table class="ui very basic striped fixed table single line" id="tags-table">
                                <tbody class="tag-list">
                                        {{range $idx, $release := .Releases}}
                                        {{end}}
                                </tbody>
                        </table>
+                       {{else}}
+                               {{if .NumTags}}
+                                       <p class="tw-p-4">{{ctx.Locale.Tr "no_results_found"}}</p>
+                               {{end}}
+                       {{end}}
                </div>
-               {{end}}
-
                {{template "base/paginate" .}}
        </div>
 </div>