aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2024-08-02 16:02:12 +0300
committerArthur Zamarin <arthurzam@gentoo.org>2024-08-02 16:02:12 +0300
commit9b04f9f7236563e1bf05711f6c82bb896327c434 (patch)
tree4ed417034898886eb9e8345503aefd8ad93bec48
parentpackage/overview: fix bug with showing use flags (diff)
downloadsoko-9b04f9f7236563e1bf05711f6c82bb896327c434.tar.gz
soko-9b04f9f7236563e1bf05711f6c82bb896327c434.tar.bz2
soko-9b04f9f7236563e1bf05711f6c82bb896327c434.zip
package/overview: mark default on useflags with +
Resolves: https://github.com/gentoo/soko/issues/29 Closes: https://bugs.gentoo.org/935395 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--pkg/app/handler/packages/overview.templ2
-rw-r--r--pkg/app/handler/packages/utils.go7
-rw-r--r--pkg/models/package.go24
3 files changed, 24 insertions, 9 deletions
diff --git a/pkg/app/handler/packages/overview.templ b/pkg/app/handler/packages/overview.templ
index 72019aa..291fee8 100644
--- a/pkg/app/handler/packages/overview.templ
+++ b/pkg/app/handler/packages/overview.templ
@@ -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>
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go
index 7b319e0..99dbf53 100644
--- a/pkg/app/handler/packages/utils.go
+++ b/pkg/app/handler/packages/utils.go
@@ -6,6 +6,7 @@ package packages
import (
"log/slog"
"net/http"
+ "slices"
"soko/pkg/database"
"soko/pkg/models"
"sort"
@@ -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
}
@@ -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" {
@@ -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
diff --git a/pkg/models/package.go b/pkg/models/package.go
index e0a1ce3..16f1b61 100644
--- a/pkg/models/package.go
+++ b/pkg/models/package.go
@@ -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
}