diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-10-23 03:18:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-23 09:18:15 +0800 |
commit | 876ee8c3cd956025aadda14175f80ce4cccfe1bb (patch) | |
tree | e3108620f171979e0b9606e993317190ec262b49 /models/packages/package_version.go | |
parent | 63ebb53fd526021666bd9fab1f9d092380f7a2f4 (diff) | |
download | gitea-876ee8c3cd956025aadda14175f80ce4cccfe1bb.tar.gz gitea-876ee8c3cd956025aadda14175f80ce4cccfe1bb.zip |
Allow package version sorting (#21453)
Diffstat (limited to 'models/packages/package_version.go')
-rw-r--r-- | models/packages/package_version.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/models/packages/package_version.go b/models/packages/package_version.go index 5479bae1c2..f9965bcb74 100644 --- a/models/packages/package_version.go +++ b/models/packages/package_version.go @@ -163,6 +163,17 @@ type SearchValue struct { ExactMatch bool } +type VersionSort = string + +const ( + SortNameAsc VersionSort = "name_asc" + SortNameDesc VersionSort = "name_desc" + SortVersionAsc VersionSort = "version_asc" + SortVersionDesc VersionSort = "version_desc" + SortCreatedAsc VersionSort = "created_asc" + SortCreatedDesc VersionSort = "created_desc" +) + // PackageSearchOptions are options for SearchXXX methods // Besides IsInternal are all fields optional and are not used if they have their default value (nil, "", 0) type PackageSearchOptions struct { @@ -176,7 +187,7 @@ type PackageSearchOptions struct { IsInternal util.OptionalBool HasFileWithName string // only results are found which are associated with a file with the specific name HasFiles util.OptionalBool // only results are found which have associated files - Sort string + Sort VersionSort db.Paginator } @@ -254,15 +265,15 @@ func (opts *PackageSearchOptions) toConds() builder.Cond { func (opts *PackageSearchOptions) configureOrderBy(e db.Engine) { switch opts.Sort { - case "alphabetically": + case SortNameAsc: e.Asc("package.name") - case "reversealphabetically": + case SortNameDesc: e.Desc("package.name") - case "highestversion": + case SortVersionDesc: e.Desc("package_version.version") - case "lowestversion": + case SortVersionAsc: e.Asc("package_version.version") - case "oldest": + case SortCreatedAsc: e.Asc("package_version.created_unix") default: e.Desc("package_version.created_unix") |