Skip to content

Commit 343af58

Browse files
committed
tried to add an column and failed
1 parent 327af26 commit 343af58

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

datafiles/templates/Html/noscript-search-form.html.st

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<option $if(tags)$ selected $endif$ value=tags>tags</option>
2424
<option $if(lastUpload)$ selected $endif$ value=lastUpload>date of last upload</option>
2525
<option $if(maintainers)$ selected $endif$ value=maintainers>maintainers</option>
26+
<option $if(packageRank)$ selected $endif$ value=packageRank>packageRank</option>
2627
</select>
2728
</label>
2829
</div>

src/Distribution/Server/Features/Browse.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ packageIndexInfoToValue :: CoreResource -> TagsResource -> UserResource -> Packa
138138
packageIndexInfoToValue
139139
coreResource tagsResource userResource
140140
PackageItem{itemName, itemDownloads, itemVotes,
141-
itemDesc, itemTags, itemLastUpload, itemMaintainer} =
141+
itemDesc, itemTags, itemLastUpload, itemMaintainer, itemPackageRank} =
142142
object
143143
[ Key.fromString "name" .= renderPackage itemName
144144
, Key.fromString "downloads" .= itemDownloads
@@ -147,6 +147,7 @@ packageIndexInfoToValue
147147
, Key.fromString "tags" .= map renderTag (S.toAscList itemTags)
148148
, Key.fromString "lastUpload" .= iso8601Show itemLastUpload
149149
, Key.fromString "maintainers" .= map renderUser itemMaintainer
150+
, Key.fromString "packageRank" .= itemPackageRank
150151
]
151152
where
152153
renderTag :: Tag -> Value

src/Distribution/Server/Features/Browse/ApplyFilter.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ sort isSearch sortColumn sortDirection =
6464
Tags -> comparing (S.toAscList . itemTags)
6565
LastUpload -> comparing itemLastUpload
6666
Maintainers -> comparing itemMaintainer
67+
PackageRank -> comparing itemPackageRank
6768
in sortBy (maybeReverse comparer)
6869
where
6970
maybeReverse =

src/Distribution/Server/Features/Browse/Options.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Distribution.Server.Features.Browse.Parsers (Filter, conditions, condsToF
99

1010
data IsSearch = IsSearch | IsNotSearch
1111

12-
data NormalColumn = Name | Downloads | Rating | Description | Tags | LastUpload | Maintainers
12+
data NormalColumn = Name | Downloads | Rating | Description | Tags | LastUpload | Maintainers | PackageRank
1313
deriving (Show, Eq)
1414

1515
data Column = DefaultColumn | NormalColumn NormalColumn
@@ -37,6 +37,7 @@ instance FromJSON Column where
3737
"tags" -> pure $ NormalColumn Tags
3838
"lastUpload" -> pure $ NormalColumn LastUpload
3939
"maintainers" -> pure $ NormalColumn Maintainers
40+
"packageRank" -> pure $ NormalColumn PackageRank
4041
t -> fail $ "Column invalid: " ++ T.unpack t
4142

4243
columnToTemplateName :: Column -> String
@@ -49,6 +50,7 @@ columnToTemplateName = \case
4950
NormalColumn Tags -> "tags"
5051
NormalColumn LastUpload -> "lastUpload"
5152
NormalColumn Maintainers -> "maintainers"
53+
NormalColumn PackageRank -> "packageRank"
5254

5355
instance FromJSON Direction where
5456
parseJSON =

src/Distribution/Server/Features/Browse/Parsers.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ allowedAfterOpeningBrace AllowNot = "not " <|> allowedAfterOpeningBrace Disallow
8585
allowedAfterOpeningBrace _ =
8686
asum
8787
[ "downloads", "rating", "lastUpload" , "ageOfLastUpload"
88-
, "tag:", "maintainer:", "deprecated:", "distro:"
88+
, "tag:", "maintainer:", "deprecated:", "distro:", "packageRank"
8989
]
9090

9191
-- Whether the 'not' operator can be used.
@@ -113,6 +113,7 @@ filterWith allowNot = do
113113
"maintainer:" -> MaintainerFilter <$> wordWoSpaceOrParens
114114
"deprecated:" -> DeprecatedFilter <$> deprecatedOption
115115
"distro:" -> DistroFilter <$> wordWoSpaceOrParens
116+
"packageRank" -> DownloadsFilter <$> opAndSndParam decimal
116117
_ -> fail "Impossible since fieldName possibilities are known at compile time"
117118
pure filt
118119

0 commit comments

Comments
 (0)