Skip to content

Add lastVersion in listings (#749) #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datafiles/static/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const replaceRows = (response) => {
tr.appendChild(createSimpleText(row.description));
tr.appendChild(createTags(row.tags));
tr.appendChild(createLastUpload(row.lastUpload));
tr.appendChild(createSimpleText(row.lastVersion));
tr.appendChild(createMaintainers(row.maintainers));
l.appendChild(tr);
}
Expand Down
1 change: 1 addition & 0 deletions datafiles/templates/Html/browse.html.st
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<th id=arrow-description><a href="javascript: sort('description')">Description</a></th>
<th id=arrow-tags><a href="javascript: sort('tags')">Tags</a></th>
<th id=arrow-lastUpload><a href="javascript: sort('lastUpload')">Last U/L</a></th>
<th id=arrow-lastVersion><a href="javascript: sort('lastVersion')">Last Version</a></th>
<th id=arrow-maintainers><a href="javascript: sort('maintainers')">Maintainers</a></th>
</tr>
</thead>
Expand Down
3 changes: 2 additions & 1 deletion datafiles/templates/Html/table-interface.html.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<th><div style="min-width:160px">Description</div></th>
<th><div style="width:140px">Tags</div></th>
<th><div style="width:80px">Last U/L</div></th>
<th><div style="width:100px">Maintainer</div></th>
<th><div style="width:80px">Last Version</div></th>
<th><div style="width:100px">Maintainers</div></th>
</tr>
</thead>
<tbody>
Expand Down
3 changes: 2 additions & 1 deletion src/Distribution/Server/Features/Browse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ packageIndexInfoToValue :: CoreResource -> TagsResource -> UserResource -> Packa
packageIndexInfoToValue
coreResource tagsResource userResource
PackageItem{itemName, itemDownloads, itemVotes,
itemDesc, itemTags, itemLastUpload, itemMaintainer} =
itemDesc, itemTags, itemLastUpload, itemLastVersion, itemMaintainer} =
object
[ Key.fromString "name" .= renderPackage itemName
, Key.fromString "downloads" .= itemDownloads
, Key.fromString "votes" .= itemVotes
, Key.fromString "description" .= itemDesc
, Key.fromString "tags" .= map renderTag (S.toAscList itemTags)
, Key.fromString "lastUpload" .= iso8601Show itemLastUpload
, Key.fromString "lastVersion" .= itemLastVersion
, Key.fromString "maintainers" .= map renderUser itemMaintainer
]
where
Expand Down
1 change: 1 addition & 0 deletions src/Distribution/Server/Features/Browse/ApplyFilter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ sort isSearch sortColumn sortDirection =
Description -> comparing itemDesc
Tags -> comparing (S.toAscList . itemTags)
LastUpload -> comparing itemLastUpload
LastVersion -> comparing itemLastVersion
Maintainers -> comparing itemMaintainer
in sortBy (maybeReverse comparer)
where
Expand Down
4 changes: 3 additions & 1 deletion src/Distribution/Server/Features/Browse/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Distribution.Server.Features.Browse.Parsers (Filter, conditions, condsToF

data IsSearch = IsSearch | IsNotSearch

data NormalColumn = Name | Downloads | Rating | Description | Tags | LastUpload | Maintainers
data NormalColumn = Name | Downloads | Rating | Description | Tags | LastUpload | LastVersion | Maintainers
deriving (Show, Eq)

data Column = DefaultColumn | NormalColumn NormalColumn
Expand All @@ -36,6 +36,7 @@ instance FromJSON Column where
"description" -> pure $ NormalColumn Description
"tags" -> pure $ NormalColumn Tags
"lastUpload" -> pure $ NormalColumn LastUpload
"lastVersion" -> pure $ NormalColumn LastVersion
"maintainers" -> pure $ NormalColumn Maintainers
t -> fail $ "Column invalid: " ++ T.unpack t

Expand All @@ -48,6 +49,7 @@ columnToTemplateName = \case
NormalColumn Description -> "description"
NormalColumn Tags -> "tags"
NormalColumn LastUpload -> "lastUpload"
NormalColumn LastVersion -> "lastVersion"
NormalColumn Maintainers -> "maintainers"

instance FromJSON Direction where
Expand Down
1 change: 1 addition & 0 deletions src/Distribution/Server/Features/Html/HtmlUtilities.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ htmlUtilities CoreFeature{coreResource}
, td $ toHtml $ itemDesc item
, td $ " (" +++ renderTags (itemTags item) +++ ")"
, td $ toHtml $ formatTime defaultTimeLocale "%F" (itemLastUpload item)
, td $ toHtml $ itemLastVersion item
, td $ "" +++ intersperse (toHtml ", ") (map renderUser (itemMaintainer item))
]
where
Expand Down
13 changes: 9 additions & 4 deletions src/Distribution/Server/Features/PackageList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Distribution.Server.Users.Types
import Distribution.Package
import Distribution.PackageDescription
import Distribution.PackageDescription.Configuration
import Distribution.Pretty (prettyShow)
import Distribution.Utils.ShortText (fromShortText)

import Control.Concurrent
Expand Down Expand Up @@ -85,18 +86,20 @@ data PackageItem = PackageItem {
-- How many benchmarks (>=0) this package has.
itemNumBenchmarks :: !Int,
-- Last upload date
itemLastUpload :: !UTCTime
itemLastUpload :: !UTCTime,
-- Last version
itemLastVersion :: !String
-- Hotness: a more heuristic way to sort packages. presently non-existent.
--itemHotness :: Int
}

instance MemSize PackageItem where
memSize (PackageItem a b c d e f g h i j k l) = memSize12 a b c d e f g h i j k l
memSize (PackageItem a b c d e f g h i j k l o) = memSize13 a b c d e f g h i j k l o


emptyPackageItem :: PackageName -> PackageItem
emptyPackageItem pkg = PackageItem pkg Set.empty Nothing "" []
0 0 False 0 0 0 (UTCTime (toEnum 0) 0)
0 0 False 0 0 0 (UTCTime (toEnum 0) 0) ""


initListFeature :: ServerEnv
Expand Down Expand Up @@ -249,6 +252,7 @@ listFeature CoreFeature{..}
constructItem :: PkgInfo -> IO (PackageName, PackageItem)
constructItem pkg = do
let pkgname = packageName pkg
desc = pkgDesc pkg
-- [reverse index disabled] revCount <- query . GetReverseCount $ pkgname
users <- queryGetUserDb
tags <- queryTagsForPackage pkgname
Expand All @@ -257,14 +261,15 @@ listFeature CoreFeature{..}
deprs <- queryGetDeprecatedFor pkgname
maintainers <- queryUserGroup (maintainersGroup pkgname)

return $ (,) pkgname $ (updateDescriptionItem (pkgDesc pkg) $ emptyPackageItem pkgname) {
return $ (,) pkgname $ (updateDescriptionItem desc $ emptyPackageItem pkgname) {
itemTags = tags
, itemMaintainer = map (userIdToName users) (UserIdSet.toList maintainers)
, itemDeprecated = deprs
, itemDownloads = cmFind pkgname downs
-- [reverse index disabled] , itemRevDepsCount = directReverseCount revCount
, itemVotes = votes
, itemLastUpload = fst (pkgOriginalUploadInfo pkg)
, itemLastVersion = prettyShow $ pkgVersion $ pkgInfoId pkg
}

------------------------------
Expand Down