Skip to content

Commit

Permalink
package/overview: fix useflags links for USE_EXPAND
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
  • Loading branch information
arthurzam committed Aug 5, 2024
1 parent 9b04f9f commit 55e00fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions pkg/app/handler/packages/overview.templ
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ templ maintainersList(maintainers []*models.Maintainer) {
}
}

templ useFlagsGroup(title string, useflags []*models.Useflag) {
templ useFlagsGroup(title string, useflags []packageUseFlags) {
<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/" + strings.TrimPrefix(use.Name, "+")) }>{ use.Name }</a>
<a title={ use.Description } data-toggle="tooltip" href={ templ.URL("/useflags/" + use.Href) }>{ use.Name }</a>
</li>
}
</ul>
Expand Down Expand Up @@ -349,7 +349,7 @@ templ overview(pkg *models.Package) {
@useFlagsGroup("Global Use Flags", globalUseflags)
}
for groupName, flags := range useExpands {
@useFlagsGroup(groupName + " (Use Expand)", flags)
@useFlagsGroup(groupName+" (Use Expand)", flags)
}
</div>
</div>
Expand Down
35 changes: 23 additions & 12 deletions pkg/app/handler/packages/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,15 @@ func getParameterValue(parameterName string, r *http.Request) string {
return results[0]
}

type packageUseFlags struct {
Name string
Description string
Href 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 []packageUseFlags, filteredGlobalUseflags []packageUseFlags, useExpands map[string][]packageUseFlags) {
rawUseFlags, defaultOn := gpackage.AllUseflags()
if len(rawUseFlags) == 0 {
return
Expand All @@ -161,22 +167,27 @@ func getPackageUseflags(gpackage *models.Package) (localUseflags []*models.Usefl
return
}

var allGlobalUseflags []*models.Useflag
useExpands = make(map[string][]*models.Useflag)
var allGlobalUseflags []packageUseFlags
useExpands = make(map[string][]packageUseFlags)
for _, useflag := range tmp_useflags {
isDefaultOn := slices.Contains(defaultOn, useflag.Name)
var namePrefix string
if slices.Contains(defaultOn, useflag.Name) {
namePrefix = "+"
}

if useflag.Scope == "global" {
allGlobalUseflags = append(allGlobalUseflags, useflag)
allGlobalUseflags = append(allGlobalUseflags,
packageUseFlags{Name: namePrefix + useflag.Name, Description: useflag.Description, Href: useflag.Name})
} else if useflag.Scope == "local" {
if useflag.Package == gpackage.Atom {
localUseflags = append(localUseflags, useflag)
localUseflags = append(localUseflags,
packageUseFlags{Name: namePrefix + useflag.Name, Description: useflag.Description, Href: useflag.Name})
}
} else {
useflag.Name = strings.TrimPrefix(useflag.Name, useflag.UseExpand+"_")
useExpands[useflag.UseExpand] = append(useExpands[useflag.UseExpand], useflag)
}
if isDefaultOn {
useflag.Name = "+" + useflag.Name
useExpands[useflag.UseExpand] = append(useExpands[useflag.UseExpand], packageUseFlags{
Name: namePrefix + strings.TrimPrefix(useflag.Name, useflag.UseExpand+"_"),
Description: useflag.Description, Href: useflag.Name,
})
}
}

Expand Down Expand Up @@ -289,7 +300,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 packageUseFlags, useflags []packageUseFlags) bool {
for _, flag := range useflags {
if useflag.Name == flag.Name {
return true
Expand Down

0 comments on commit 55e00fe

Please sign in to comment.