summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Warner <antarus@gentoo.org>2020-05-17 14:50:42 -0700
committerAlec Warner <antarus@gentoo.org>2020-05-17 14:50:42 -0700
commit976a1d85db9d08b7f59dd7bdc5cda26be2901eb4 (patch)
tree6125757a59512a367416c88114b0961776d5dcb6
parentAdd gorilla feeds. (diff)
downloadsoko-976a1d85db9d08b7f59dd7bdc5cda26be2901eb4.tar.gz
soko-976a1d85db9d08b7f59dd7bdc5cda26be2901eb4.tar.bz2
soko-976a1d85db9d08b7f59dd7bdc5cda26be2901eb4.zip
Packages should print out different USE_EXPAND sources.
Extend GetPackageUseflags to return a map instead of a list. Keys are USE_EXPAND categories, and values are the flags. Fix json and useflag templates to properly emit the flags. Signed-off-by: Alec Warner <antarus@gentoo.org>
-rw-r--r--pkg/app/handler/packages/json.go12
-rw-r--r--pkg/app/handler/packages/utils.go21
-rw-r--r--web/templates/packages/useflag.tmpl9
3 files changed, 25 insertions, 17 deletions
diff --git a/pkg/app/handler/packages/json.go b/pkg/app/handler/packages/json.go
index 4af551c..24cb2e7 100644
--- a/pkg/app/handler/packages/json.go
+++ b/pkg/app/handler/packages/json.go
@@ -125,11 +125,13 @@ func getJSONUseflag(gpackage *models.Package) Use {
Description: useflag.Description,
})
}
- for _, useflag := range useExpands {
- useflags.UseExpand = append(useflags.UseExpand, Useflag{
- Name: useflag.Name,
- Description: useflag.Description,
- })
+ for _, flags := range useExpands {
+ for _, flag := range flags {
+ useflags.UseExpand = append(useflags.UseExpand, Useflag{
+ Name: flag.Name,
+ Description: flag.Description,
+ })
+ }
}
return useflags
}
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go
index a6add3c..3553725 100644
--- a/pkg/app/handler/packages/utils.go
+++ b/pkg/app/handler/packages/utils.go
@@ -168,7 +168,7 @@ func getSearchData(packages []models.Package, search string) interface{} {
Packages []models.Package
Application models.Application
}{
- Header: models.Header{Title: search + " – ", Tab: "packages", },
+ Header: models.Header{Title: search + " – ", Tab: "packages"},
Search: search,
Packages: packages,
Application: utils.GetApplicationData(),
@@ -246,8 +246,9 @@ func getParameterValue(parameterName string, r *http.Request) string {
// getPackageUseflags retrieves all local USE flags, global USE
// flags and use expands for a given package
-func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Useflag, []models.Useflag) {
- var localUseflags, globalUseflags, useExpands []models.Useflag
+func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Useflag, map[string][]models.Useflag) {
+ var localUseflags, globalUseflags []models.Useflag
+ useExpands := make(map[string][]models.Useflag)
for _, rawUseflag := range gpackage.Versions[0].Useflags {
var tmp_useflags []models.Useflag
@@ -269,7 +270,11 @@ func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Us
localUseflags = append(localUseflags, useflag)
}
} else {
- useExpands = append(useExpands, useflag)
+ if _, ok := useExpands[useflag.UseExpand]; !ok {
+ useExpands[useflag.UseExpand] = []models.Useflag{useflag}
+ } else {
+ useExpands[useflag.UseExpand] = append(useExpands[useflag.UseExpand], useflag)
+ }
}
}
}
@@ -277,7 +282,7 @@ func getPackageUseflags(gpackage *models.Package) ([]models.Useflag, []models.Us
}
// createPackageData creates the data used in the show package template
-func createPackageData(gpackage *models.Package, localUseflags []models.Useflag, globalUseflags []models.Useflag, useExpands []models.Useflag) interface{} {
+func createPackageData(gpackage *models.Package, localUseflags []models.Useflag, globalUseflags []models.Useflag, useExpands map[string][]models.Useflag) interface{} {
return struct {
Header models.Header
Package models.Package
@@ -285,10 +290,10 @@ func createPackageData(gpackage *models.Package, localUseflags []models.Useflag,
Masks []models.Mask
LocalUseflags []models.Useflag
GlobalUseflags []models.Useflag
- UseExpands []models.Useflag
+ UseExpands map[string][]models.Useflag
Application models.Application
}{
- Header: models.Header{Title: gpackage.Atom + " – ", Tab: "packages", },
+ Header: models.Header{Title: gpackage.Atom + " – ", Tab: "packages"},
Package: *gpackage,
Versions: gpackage.Versions,
LocalUseflags: localUseflags,
@@ -307,7 +312,7 @@ func CreateFeedData(name string, versions []*models.Version) interface{} {
Versions []*models.Version
Application models.Application
}{
- Header: models.Header{Title: "Packages – ", Tab: "packages", },
+ Header: models.Header{Title: "Packages – ", Tab: "packages"},
Name: name,
Versions: versions,
Application: utils.GetApplicationData(),
diff --git a/web/templates/packages/useflag.tmpl b/web/templates/packages/useflag.tmpl
index db4bf07..a1940e1 100644
--- a/web/templates/packages/useflag.tmpl
+++ b/web/templates/packages/useflag.tmpl
@@ -26,14 +26,15 @@
{{ if .UseExpands }}
- <!-- TODO group by -->
- <span class="kk-useflag-group">{{ (index .UseExpands 0).UseExpand}} (Use Expand)</span>
- <ul class="kk-useflag-container {{ if ge (len .UseExpands) 10 }}kk-useflag-container-many{{else}}kk-useflag-container-few{{end}}">
- {{range .UseExpands}}
+ {{range $key, $flags := .UseExpands}}
+ <span class="kk-useflag-group">{{ $key }} (Use Expand)</span>
+ <ul class="kk-useflag-container {{ if ge (len $flags) 10 }}kk-useflag-container-many{{else}}kk-useflag-container-few{{end}}">
+ {{range $flags}}
<li class="kk-useflag">
<a title="{{.Description}}" data-toggle="tooltip" href="/useflags/{{.Name}}">{{ replaceall .Name (print .UseExpand "_") "" }}</a>
</li>
{{end}}
</ul>
+ {{end}}
{{end}}
{{end}}