Skip to content

Commit

Permalink
package/overview: mark default on useflags with +
Browse files Browse the repository at this point in the history
Resolves: #29
Closes: https://bugs.gentoo.org/935395
Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Aug 2, 2024
1 parent 46513ec commit 9b04f9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/app/handler/packages/overview.templ
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ templ useFlagsGroup(title string, useflags []*models.Useflag) {
<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>
<a title={ use.Description } data-toggle="tooltip" href={ templ.URL("/useflags/" + strings.TrimPrefix(use.Name, "+")) }>{ use.Name }</a>
</li>
}
</ul>
Expand Down
7 changes: 6 additions & 1 deletion pkg/app/handler/packages/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package packages
import (
"log/slog"
"net/http"
"slices"
"soko/pkg/database"
"soko/pkg/models"
"sort"
Expand Down Expand Up @@ -140,7 +141,7 @@ 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) {
rawUseFlags := gpackage.AllUseflags()
rawUseFlags, defaultOn := gpackage.AllUseflags()
if len(rawUseFlags) == 0 {
return
}
Expand All @@ -163,6 +164,7 @@ func getPackageUseflags(gpackage *models.Package) (localUseflags []*models.Usefl
var allGlobalUseflags []*models.Useflag
useExpands = make(map[string][]*models.Useflag)
for _, useflag := range tmp_useflags {
isDefaultOn := slices.Contains(defaultOn, useflag.Name)
if useflag.Scope == "global" {
allGlobalUseflags = append(allGlobalUseflags, useflag)
} else if useflag.Scope == "local" {
Expand All @@ -173,6 +175,9 @@ func getPackageUseflags(gpackage *models.Package) (localUseflags []*models.Usefl
useflag.Name = strings.TrimPrefix(useflag.Name, useflag.UseExpand+"_")
useExpands[useflag.UseExpand] = append(useExpands[useflag.UseExpand], useflag)
}
if isDefaultOn {
useflag.Name = "+" + useflag.Name
}
}

// Only add global useflags that are not present in the local useflags
Expand Down
24 changes: 17 additions & 7 deletions pkg/models/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,27 @@ func (p Package) AllBugs() []*Bug {
return allBugsList
}

func (p *Package) AllUseflags() []string {
useflags := make(map[string]struct{})
func (p *Package) AllUseflags() (useflags []string, defaultOn []string) {
useflagsSet := make(map[string]struct{})
defaultOnSet := make(map[string]struct{})
for _, version := range p.Versions {
for _, useflag := range version.Useflags {
useflags[strings.TrimPrefix(useflag, "+")] = struct{}{}
if useflag[0] == '+' {
defaultOnSet[useflag[1:]] = struct{}{}
useflagsSet[useflag[1:]] = struct{}{}
} else {
useflagsSet[useflag] = struct{}{}
}
}
}

useflagsList := make([]string, 0, len(useflags))
for useflag := range useflags {
useflagsList = append(useflagsList, useflag)
useflags = make([]string, 0, len(useflagsSet))
for useflag := range useflagsSet {
useflags = append(useflags, useflag)
}
defaultOn = make([]string, 0, len(defaultOnSet))
for useflag := range defaultOnSet {
defaultOn = append(defaultOn, useflag)
}
return useflagsList
return
}

0 comments on commit 9b04f9f

Please sign in to comment.