mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-11 19:58:28 +01:00
Introduces highlighting package version differences
This commit is contained in:
parent
298d1d5b52
commit
cfb9ed248f
@ -4,10 +4,12 @@ module Stackage.Snapshot.Diff
|
||||
, snapshotDiff
|
||||
, SnapshotDiff()
|
||||
, toDiffList
|
||||
, toVersionedDiffList
|
||||
, VersionChange(..)
|
||||
, WithSnapshotNames(..)
|
||||
) where
|
||||
|
||||
import qualified Data.Text as T(commonPrefixes)
|
||||
import Data.Align
|
||||
import Data.Aeson
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
@ -36,6 +38,20 @@ instance ToJSON (WithSnapshotNames SnapshotDiff) where
|
||||
toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)]
|
||||
toDiffList = sortOn (toCaseFold . unPackageName . fst) . HashMap.toList . unSnapshotDiff
|
||||
|
||||
versionPrefix :: VersionChange -> Maybe (Text,Text,Text)
|
||||
versionPrefix vc = case unVersionChange vc of
|
||||
These (Version a) (Version b) -> T.commonPrefixes a b
|
||||
_ -> Nothing
|
||||
|
||||
versionedDiffList :: [(PackageName, VersionChange)] -> [(PackageName, VersionChange, Maybe (Text,Text,Text))]
|
||||
versionedDiffList = map withPrefixedVersion
|
||||
where
|
||||
withPrefixedVersion (packageName, versionChange) = (packageName, versionChange, versionPrefix versionChange)
|
||||
|
||||
|
||||
toVersionedDiffList :: SnapshotDiff -> [(PackageName, VersionChange, Maybe (Text, Text, Text))]
|
||||
toVersionedDiffList = versionedDiffList . toDiffList
|
||||
|
||||
-- | Versions of a package as it occurs in the listings provided to `snapshotDiff`.
|
||||
--
|
||||
-- Would be represented with `These v1 v2` if the package is present in both listings,
|
||||
|
||||
@ -2,4 +2,13 @@
|
||||
.table th, .table td {
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.table span.version-removed {
|
||||
background-color: red;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.table span.version-added {
|
||||
background-color: green;
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
$else
|
||||
<option value=@{StackageDiffR name1 name2'}>#{toPathPiece name2'}
|
||||
<tbody>
|
||||
$forall (pkgname, VersionChange verChange) <- toDiffList snapDiff
|
||||
$forall (pkgname, VersionChange verChange, versionDiff) <- toVersionedDiffList snapDiff
|
||||
<tr>
|
||||
$case verChange
|
||||
$of This oldVersion
|
||||
@ -47,9 +47,19 @@
|
||||
<a href=@{packageUrl name2 pkgname newVersion}#changes>
|
||||
#{pkgname}-#{newVersion}
|
||||
$of These oldVersion newVersion
|
||||
<td>
|
||||
<a href=@{packageUrl name1 pkgname oldVersion}#changes>
|
||||
#{pkgname}-#{oldVersion}
|
||||
<td>
|
||||
<a href=@{packageUrl name2 pkgname newVersion}#changes>
|
||||
#{pkgname}-#{newVersion}
|
||||
$maybe (common, old, new) <- versionDiff
|
||||
<td>
|
||||
<a href=@{packageUrl name1 pkgname oldVersion}#changes>
|
||||
#{pkgname}-#{common}#
|
||||
<span .version-removed>#{old}
|
||||
<td>
|
||||
<a href=@{packageUrl name2 pkgname newVersion}#changes>
|
||||
#{pkgname}-#{common}#
|
||||
<span .version-added>#{new}
|
||||
$nothing
|
||||
<td>
|
||||
<a href=@{packageUrl name1 pkgname oldVersion}#changes>
|
||||
#{pkgname}-#{oldVersion}
|
||||
<td>
|
||||
<a href=@{packageUrl name2 pkgname newVersion}#changes>
|
||||
#{pkgname}-#{newVersion}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user