diff options
author | 2024-08-05 19:57:20 +0300 | |
---|---|---|
committer | 2024-08-05 19:57:20 +0300 | |
commit | 55e00fe2c04000441e500989a608cda7fa4e7c87 (patch) | |
tree | 54f2a519c521329543446fd3597d2c25b3fa4693 | |
parent | package/overview: mark default on useflags with + (diff) | |
download | soko-master.tar.gz soko-master.tar.bz2 soko-master.zip |
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/app/handler/packages/overview.templ | 6 | ||||
-rw-r--r-- | pkg/app/handler/packages/utils.go | 35 |
2 files changed, 26 insertions, 15 deletions
diff --git a/pkg/app/handler/packages/overview.templ b/pkg/app/handler/packages/overview.templ index 291fee8..b843edd 100644 --- a/pkg/app/handler/packages/overview.templ +++ b/pkg/app/handler/packages/overview.templ @@ -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> @@ -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> diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go index 99dbf53..1df2180 100644 --- a/pkg/app/handler/packages/utils.go +++ b/pkg/app/handler/packages/utils.go @@ -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 @@ -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, + }) } } @@ -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 |