diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2024-08-02 15:46:51 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2024-08-02 15:50:12 +0300 |
commit | 46513ec7cf50e283c9a9c29803daca5e348bff3a (patch) | |
tree | 3088da188556f35eb22d7adfa6598b4e5bd16a72 /pkg | |
parent | eapi cleanup: exclude blockers with rev deps count (diff) | |
download | soko-46513ec7cf50e283c9a9c29803daca5e348bff3a.tar.gz soko-46513ec7cf50e283c9a9c29803daca5e348bff3a.tar.bz2 soko-46513ec7cf50e283c9a9c29803daca5e348bff3a.zip |
package/overview: fix bug with showing use flags
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/app/handler/packages/overview.templ | 42 | ||||
-rw-r--r-- | pkg/app/handler/packages/utils.go | 11 |
2 files changed, 21 insertions, 32 deletions
diff --git a/pkg/app/handler/packages/overview.templ b/pkg/app/handler/packages/overview.templ index bcbe218..72019aa 100644 --- a/pkg/app/handler/packages/overview.templ +++ b/pkg/app/handler/packages/overview.templ @@ -135,6 +135,17 @@ templ maintainersList(maintainers []*models.Maintainer) { } } +templ useFlagsGroup(title string, useflags []*models.Useflag) { + <span class="kk-useflag-group">{ title }</span> + <ul class={ "kk-useflag-container", templ.KV("kk-useflag-container-many", len(useflags) >= 10), templ.KV("kk-useflag-container-few", len(useflags) < 10) }> + for _, use := range useflags { + <li class="kk-useflag"> + <a title={ use.Description } data-toggle="tooltip" href={ templ.URL("/useflags/" + use.Name) }>{ use.Name }</a> + </li> + } + </ul> +} + templ overview(pkg *models.Package) { <div class="row"> <div class="col-md-9"> @@ -332,36 +343,13 @@ templ overview(pkg *models.Package) { </div> <div class="col-xs-12 col-md-9"> if len(localUseflags) > 0 { - <span class="kk-useflag-group">Local Use Flags</span> - <ul class={ "kk-useflag-container", templ.KV("kk-useflag-container-many", len(localUseflags) >= 10), templ.KV("kk-useflag-container-few", len(localUseflags) < 10) }> - for _, use := range localUseflags { - <li class="kk-useflag"> - <a title={ use.Description } data-toggle="tooltip" href={ templ.URL("/useflags/" + use.Name) }>{ use.Name }</a> - </li> - } - </ul> + @useFlagsGroup("Local Use Flags", localUseflags) } if len(globalUseflags) > 0 { - <span class="kk-useflag-group">Global Use Flags</span> - <ul class={ "kk-useflag-container", templ.KV("kk-useflag-container-many", len(localUseflags) >= 10), templ.KV("kk-useflag-container-few", len(localUseflags) < 10) }> - for _, use := range globalUseflags { - <li class="kk-useflag"> - <a title={ use.Description } data-toggle="tooltip" href={ templ.URL("/useflags/" + use.Name) }>{ use.Name }</a> - </li> - } - </ul> + @useFlagsGroup("Global Use Flags", globalUseflags) } - if len(useExpands) > 0 { - for groupName, flags := range useExpands { - <span class="kk-useflag-group">{ groupName } (Use Expand)</span> - <ul class={ "kk-useflag-container", templ.KV("kk-useflag-container-many", len(localUseflags) >= 10), templ.KV("kk-useflag-container-few", len(localUseflags) < 10) }> - for _, use := range flags { - <li class="kk-useflag"> - <a title={ use.Description } data-toggle="tooltip" href={ templ.URL("/useflags/" + use.Name) }>{ strings.TrimPrefix(use.Name, use.UseExpand + "_") }</a> - </li> - } - </ul> - } + for groupName, flags := range useExpands { + @useFlagsGroup(groupName + " (Use Expand)", flags) } </div> </div> diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go index 131d1b1..7b319e0 100644 --- a/pkg/app/handler/packages/utils.go +++ b/pkg/app/handler/packages/utils.go @@ -139,13 +139,13 @@ 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) (localUseflags []models.Useflag, filteredGlobalUseflags []models.Useflag, useExpands map[string][]models.Useflag) { +func getPackageUseflags(gpackage *models.Package) (localUseflags []*models.Useflag, filteredGlobalUseflags []*models.Useflag, useExpands map[string][]*models.Useflag) { rawUseFlags := gpackage.AllUseflags() if len(rawUseFlags) == 0 { return } - var tmp_useflags []models.Useflag + var tmp_useflags []*models.Useflag err := database.DBCon.Model(&tmp_useflags). WhereGroup(func(q *pg.Query) (*pg.Query, error) { return q.Where("scope = ?", "local").Where("package = ?", gpackage.Atom), nil @@ -160,8 +160,8 @@ func getPackageUseflags(gpackage *models.Package) (localUseflags []models.Usefla return } - var allGlobalUseflags []models.Useflag - useExpands = make(map[string][]models.Useflag) + var allGlobalUseflags []*models.Useflag + useExpands = make(map[string][]*models.Useflag) for _, useflag := range tmp_useflags { if useflag.Scope == "global" { allGlobalUseflags = append(allGlobalUseflags, useflag) @@ -170,6 +170,7 @@ func getPackageUseflags(gpackage *models.Package) (localUseflags []models.Usefla localUseflags = append(localUseflags, useflag) } } else { + useflag.Name = strings.TrimPrefix(useflag.Name, useflag.UseExpand+"_") useExpands[useflag.UseExpand] = append(useExpands[useflag.UseExpand], useflag) } } @@ -283,7 +284,7 @@ func sortVersionsDesc(versions []*models.Version) { // containsUseflag returns true if the given list of useflags contains the // given userflag. Otherwise false will be returned. -func containsUseflag(useflag models.Useflag, useflags []models.Useflag) bool { +func containsUseflag(useflag *models.Useflag, useflags []*models.Useflag) bool { for _, flag := range useflags { if useflag.Name == flag.Name { return true |