diff options
author | Arthur Zamarin <arthurzam@gentoo.org> | 2023-04-01 10:57:35 +0300 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2023-04-01 10:57:35 +0300 |
commit | a9a8bf5c32a664526c3d19ccb91b516ea2ce2fb0 (patch) | |
tree | 04bdcaaae54e0f48bee31c89dc6da54d832c9f35 | |
parent | database: automatically create 'pg_trgm' extension (diff) | |
download | soko-a9a8bf5c32a664526c3d19ccb91b516ea2ce2fb0.tar.gz soko-a9a8bf5c32a664526c3d19ccb91b516ea2ce2fb0.tar.bz2 soko-a9a8bf5c32a664526c3d19ccb91b516ea2ce2fb0.zip |
app/useflags: use DB sorting
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | pkg/app/handler/useflags/expand.go | 4 | ||||
-rw-r--r-- | pkg/app/handler/useflags/global.go | 16 | ||||
-rw-r--r-- | pkg/app/handler/useflags/local.go | 25 |
3 files changed, 18 insertions, 27 deletions
diff --git a/pkg/app/handler/useflags/expand.go b/pkg/app/handler/useflags/expand.go index c7be9e1..631f70a 100644 --- a/pkg/app/handler/useflags/expand.go +++ b/pkg/app/handler/useflags/expand.go @@ -3,7 +3,7 @@ package useflags import ( "html/template" "net/http" - utils2 "soko/pkg/app/utils" + "soko/pkg/app/utils" "soko/pkg/database" "soko/pkg/models" @@ -31,7 +31,7 @@ func Expand(w http.ResponseWriter, r *http.Request) { Header: models.Header{Title: "Use Expand" + " – ", Tab: "useflags"}, Page: "expand", Useflags: useflags, - Application: utils2.GetApplicationData(), + Application: utils.GetApplicationData(), } templates := template.Must( diff --git a/pkg/app/handler/useflags/global.go b/pkg/app/handler/useflags/global.go index 45a9e06..63e8e3e 100644 --- a/pkg/app/handler/useflags/global.go +++ b/pkg/app/handler/useflags/global.go @@ -1,22 +1,22 @@ -// Used to search for USE flags - package useflags import ( - "github.com/go-pg/pg" "html/template" "net/http" - utils2 "soko/pkg/app/utils" + "soko/pkg/app/utils" "soko/pkg/database" "soko/pkg/models" + + "github.com/go-pg/pg" ) -// Search renders a template containing a list of search results -// for a given query of USE flags func Global(w http.ResponseWriter, r *http.Request) { var useflags []models.Useflag - err := database.DBCon.Model(&useflags).Where("scope = 'global'").Select() + err := database.DBCon.Model(&useflags). + Order("name"). + Where("scope = 'global'"). + Select() if err != nil && err != pg.ErrNoRows { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) @@ -32,7 +32,7 @@ func Global(w http.ResponseWriter, r *http.Request) { Header: models.Header{Title: "Global" + " – ", Tab: "useflags"}, Page: "global", Useflags: useflags, - Application: utils2.GetApplicationData(), + Application: utils.GetApplicationData(), } templates := template.Must( diff --git a/pkg/app/handler/useflags/local.go b/pkg/app/handler/useflags/local.go index 23d1403..63a5a76 100644 --- a/pkg/app/handler/useflags/local.go +++ b/pkg/app/handler/useflags/local.go @@ -1,37 +1,28 @@ -// Used to search for USE flags - package useflags import ( - "github.com/go-pg/pg" "html/template" "net/http" - utils2 "soko/pkg/app/utils" + "soko/pkg/app/utils" "soko/pkg/database" "soko/pkg/models" - "sort" + + "github.com/go-pg/pg" ) -// Search renders a template containing a list of search results -// for a given query of USE flags func Local(w http.ResponseWriter, r *http.Request) { var useflags []models.Useflag - err := database.DBCon.Model(&useflags).Where("scope = 'local'").Select() + err := database.DBCon.Model(&useflags). + Where("scope = 'local'"). + Order("package", "name"). + Select() if err != nil && err != pg.ErrNoRows { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } - sort.Slice(useflags, func(i, j int) bool { - if useflags[i].Package != useflags[j].Package { - return useflags[i].Package < useflags[j].Package - } else { - return useflags[i].Name < useflags[j].Name - } - }) - data := struct { Header models.Header Page string @@ -41,7 +32,7 @@ func Local(w http.ResponseWriter, r *http.Request) { Header: models.Header{Title: "Local" + " – ", Tab: "useflags"}, Page: "local", Useflags: useflags, - Application: utils2.GetApplicationData(), + Application: utils.GetApplicationData(), } templates := template.Must( |