summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-03-27 16:02:12 +0100
committerMax Magorsch <arzano@gentoo.org>2020-03-27 16:08:50 +0100
commit13a1000fd6cfdca26af09eede1bdc53f4807d31c (patch)
tree40d732408cc9e14885b285f22c3dfe3c15fcf92a
parentFix the updated packages feed (diff)
downloadsoko-13a1000fd6cfdca26af09eede1bdc53f4807d31c.tar.gz
soko-13a1000fd6cfdca26af09eede1bdc53f4807d31c.tar.bz2
soko-13a1000fd6cfdca26af09eede1bdc53f4807d31c.zip
Sort the ebuild versions in the version table
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/app/handler/packages/show.go2
-rw-r--r--pkg/app/handler/packages/utils.go25
-rw-r--r--pkg/config/config.go2
-rw-r--r--web/templates/packages/versions.tmpl2
4 files changed, 29 insertions, 2 deletions
diff --git a/pkg/app/handler/packages/show.go b/pkg/app/handler/packages/show.go
index 4a7a252..90413d8 100644
--- a/pkg/app/handler/packages/show.go
+++ b/pkg/app/handler/packages/show.go
@@ -34,6 +34,8 @@ func Show(w http.ResponseWriter, r *http.Request) {
return
}
+ sortVersionsDesc(gpackage.Versions)
+
localUseflags, globalUseflags, useExpands := getPackageUseflags(gpackage)
renderPackageTemplate("show",
diff --git a/pkg/app/handler/packages/utils.go b/pkg/app/handler/packages/utils.go
index a08a035..d814535 100644
--- a/pkg/app/handler/packages/utils.go
+++ b/pkg/app/handler/packages/utils.go
@@ -7,6 +7,7 @@ import (
"encoding/hex"
"github.com/go-pg/pg"
"github.com/go-pg/pg/v9/orm"
+ "github.com/mcuadros/go-version"
"html/template"
"net/http"
"soko/pkg/app/utils"
@@ -14,6 +15,7 @@ import (
"soko/pkg/logger"
"soko/pkg/models"
utils2 "soko/pkg/utils"
+ "sort"
"strings"
)
@@ -329,3 +331,26 @@ func showRemovalNotice(versions []*models.Version) bool {
}
return showNotice
}
+
+// sort the versions in ascending order
+func sortVersionsAsc(versions []*models.Version){
+ sortVersions(versions, "<")
+}
+
+// sort the versions in descending order
+func sortVersionsDesc(versions []*models.Version){
+ sortVersions(versions, ">")
+}
+
+// sort the versions - the order is given by the given operator
+func sortVersions(versions []*models.Version, operator string){
+ sort.SliceStable(versions, func(i, j int) bool {
+ // the version library normally results in i.e. 1.1-r1 < 1.1
+ // that's why we replace -rXXX by .XXX so that 1.1-r1 > 1.1
+ firstVersion := strings.ReplaceAll(versions[i].Version, "-r", ".")
+ secondVersion := strings.ReplaceAll(versions[j].Version, "-r", ".")
+ firstVersion = version.Normalize(firstVersion)
+ secondVersion = version.Normalize(secondVersion)
+ return version.Compare(firstVersion, secondVersion, operator)
+ })
+}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 1d9e3eb..cc0ce31 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -39,7 +39,7 @@ func LogFile() string {
}
func Version() string {
- return getEnv("SOKO_VERSION", "v0.1.7")
+ return getEnv("SOKO_VERSION", "v0.1.8")
}
func Port() string {
diff --git a/web/templates/packages/versions.tmpl b/web/templates/packages/versions.tmpl
index c4514b5..2605f36 100644
--- a/web/templates/packages/versions.tmpl
+++ b/web/templates/packages/versions.tmpl
@@ -29,7 +29,7 @@
</thead>
<tbody>
{{range $index, $element := .Package.Versions}}
- {{template "versionrow" (getReverse $index $.Package.Versions)}}
+ {{template "versionrow" $element}}
{{end}}
</tbody>
</table>