Skip to content

Commit 309e86a

Browse files
authored
Use dynamic package type list (#22263)
Replace the hardcoded list with the dynamic list.
1 parent ca67c5a commit 309e86a

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

Diff for: routers/web/admin/packages.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func Packages(ctx *context.Context) {
6262
ctx.Data["PageIsAdminPackages"] = true
6363
ctx.Data["Query"] = query
6464
ctx.Data["PackageType"] = packageType
65+
ctx.Data["AvailableTypes"] = packages_model.TypeList
6566
ctx.Data["SortType"] = sort
6667
ctx.Data["PackageDescriptors"] = pds
6768
ctx.Data["Total"] = total

Diff for: routers/web/repo/packages.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func Packages(ctx *context.Context) {
6161
ctx.Data["ContextUser"] = ctx.ContextUser
6262
ctx.Data["Query"] = query
6363
ctx.Data["PackageType"] = packageType
64+
ctx.Data["AvailableTypes"] = packages.TypeList
6465
ctx.Data["HasPackages"] = hasPackages
6566
if ctx.Repo != nil {
6667
ctx.Data["CanWritePackages"] = ctx.IsUserRepoWriter([]unit.Type{unit.TypePackages}) || ctx.IsUserSiteAdmin()

Diff for: routers/web/user/package.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func ListPackages(ctx *context.Context) {
8989
ctx.Data["ContextUser"] = ctx.ContextUser
9090
ctx.Data["Query"] = query
9191
ctx.Data["PackageType"] = packageType
92+
ctx.Data["AvailableTypes"] = packages_model.TypeList
9293
ctx.Data["HasPackages"] = hasPackages
9394
ctx.Data["PackageDescriptors"] = pds
9495
ctx.Data["Total"] = total

Diff for: templates/admin/packages/list.tmpl

+3-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,9 @@
1313
<select class="ui dropdown" name="type">
1414
<option value="">{{.locale.Tr "packages.filter.type"}}</option>
1515
<option value="all">{{.locale.Tr "packages.filter.type.all"}}</option>
16-
<option value="composer" {{if eq .PackageType "composer"}}selected="selected"{{end}}>Composer</option>
17-
<option value="conan" {{if eq .PackageType "conan"}}selected="selected"{{end}}>Conan</option>
18-
<option value="container" {{if eq .PackageType "container"}}selected="selected"{{end}}>Container</option>
19-
<option value="generic" {{if eq .PackageType "generic"}}selected="selected"{{end}}>Generic</option>
20-
<option value="helm" {{if eq .PackageType "helm"}}selected="selected"{{end}}>Helm</option>
21-
<option value="maven" {{if eq .PackageType "maven"}}selected="selected"{{end}}>Maven</option>
22-
<option value="npm" {{if eq .PackageType "npm"}}selected="selected"{{end}}>npm</option>
23-
<option value="nuget" {{if eq .PackageType "nuget"}}selected="selected"{{end}}>NuGet</option>
24-
<option value="pub" {{if eq .PackageType "pub"}}selected="selected"{{end}}>Pub</option>
25-
<option value="pypi" {{if eq .PackageType "pypi"}}selected="selected"{{end}}>PyPi</option>
26-
<option value="rubygems" {{if eq .PackageType "rubygems"}}selected="selected"{{end}}>RubyGems</option>
27-
<option value="vagrant" {{if eq .PackageType "vagrant"}}selected="selected"{{end}}>Vagrant</option>
16+
{{range $type := .AvailableTypes}}
17+
<option{{if eq $.PackageType $type}} selected="selected"{{end}} value="{{$type}}">{{$type.Name}}</option>
18+
{{end}}
2819
</select>
2920
<button class="ui primary button">{{.locale.Tr "explore.search"}}</button>
3021
</div>

Diff for: templates/package/shared/list.tmpl

+3-12
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66
<select class="ui dropdown" name="type">
77
<option value="">{{.locale.Tr "packages.filter.type"}}</option>
88
<option value="all">{{.locale.Tr "packages.filter.type.all"}}</option>
9-
<option value="composer" {{if eq .PackageType "composer"}}selected="selected"{{end}}>Composer</option>
10-
<option value="conan" {{if eq .PackageType "conan"}}selected="selected"{{end}}>Conan</option>
11-
<option value="container" {{if eq .PackageType "container"}}selected="selected"{{end}}>Container</option>
12-
<option value="generic" {{if eq .PackageType "generic"}}selected="selected"{{end}}>Generic</option>
13-
<option value="helm" {{if eq .PackageType "helm"}}selected="selected"{{end}}>Helm</option>
14-
<option value="maven" {{if eq .PackageType "maven"}}selected="selected"{{end}}>Maven</option>
15-
<option value="npm" {{if eq .PackageType "npm"}}selected="selected"{{end}}>npm</option>
16-
<option value="nuget" {{if eq .PackageType "nuget"}}selected="selected"{{end}}>NuGet</option>
17-
<option value="pub" {{if eq .PackageType "pub"}}selected="selected"{{end}}>Pub</option>
18-
<option value="pypi" {{if eq .PackageType "pypi"}}selected="selected"{{end}}>PyPi</option>
19-
<option value="rubygems" {{if eq .PackageType "rubygems"}}selected="selected"{{end}}>RubyGems</option>
20-
<option value="vagrant" {{if eq .PackageType "vagrant"}}selected="selected"{{end}}>Vagrant</option>
9+
{{range $type := .AvailableTypes}}
10+
<option{{if eq $.PackageType $type}} selected="selected"{{end}} value="{{$type}}">{{$type.Name}}</option>
11+
{{end}}
2112
</select>
2213
<button class="ui primary button">{{.locale.Tr "explore.search"}}</button>
2314
</div>

0 commit comments

Comments
 (0)