Implement missing Handler.Download functionality

This commit is contained in:
Michael Snoyman 2015-05-20 12:13:17 +03:00
parent c60612be34
commit 2feecaa88a
2 changed files with 29 additions and 37 deletions

View File

@ -10,6 +10,7 @@ import Import
import Data.GhcLinks import Data.GhcLinks
import Yesod.GitRepo (grContent) import Yesod.GitRepo (grContent)
import Stackage.Database import Stackage.Database
import qualified Data.Text as T
executableFor :: SupportedArch -> StackageExecutable executableFor :: SupportedArch -> StackageExecutable
executableFor Win32 = StackageWindowsExecutable executableFor Win32 = StackageWindowsExecutable
@ -36,30 +37,13 @@ getDownloadR = defaultLayout $ do
setTitle "Download" setTitle "Download"
$(widgetFile "download") $(widgetFile "download")
{- FIXME
ltsMajorVersions :: YesodDB App [Lts]
ltsMajorVersions =
(dropOldMinors . map entityVal)
<$> selectList [] [Desc LtsMajor, Desc LtsMinor]
dropOldMinors :: [Lts] -> [Lts]
dropOldMinors [] = []
dropOldMinors (l@(Lts x _ _):rest) =
l : dropOldMinors (dropWhile sameMinor rest)
where
sameMinor (Lts y _ _) = x == y
-}
getDownloadSnapshotsJsonR :: Handler Value getDownloadSnapshotsJsonR :: Handler Value
getDownloadSnapshotsJsonR = getDownloadLtsSnapshotsJsonR getDownloadSnapshotsJsonR = getDownloadLtsSnapshotsJsonR
getDownloadLtsSnapshotsJsonR :: Handler Value getDownloadLtsSnapshotsJsonR :: Handler Value
getDownloadLtsSnapshotsJsonR = do getDownloadLtsSnapshotsJsonR = do
error "getDownloadLtsSnapshotsJsonR" mlatestNightly <- newestNightly
{- ltses <- ltsMajorVersions
(mlatestNightly, ltses) <- runDB $ (,)
<$> getLatestNightly
<*> ltsMajorVersions
let lts = case ltses of let lts = case ltses of
[] -> [] [] -> []
majorVersions@(latest:_) -> majorVersions@(latest:_) ->
@ -70,31 +54,25 @@ getDownloadLtsSnapshotsJsonR = do
Just n -> (("nightly" .= printNightly n):) Just n -> (("nightly" .= printNightly n):)
return $ object $ nightly lts return $ object $ nightly lts
where where
toObj lts@(Lts major _ _) = toObj lts@(major, _) =
pack ("lts-" ++ show major) .= printLts lts pack ("lts-" ++ show major) .= printLts lts
printLts (Lts major minor _) = printLts (major, minor) =
"lts-" ++ show major ++ "." ++ show minor "lts-" ++ show major ++ "." ++ show minor
printNightly (Entity _ (Nightly day _ _)) = printNightly day = "nightly-" ++ tshow day
"nightly-" ++ tshow day
getLatestNightly = selectFirst [] [Desc NightlyDay]
-- Print the ghc major version for the given snapshot. -- Print the ghc major version for the given snapshot.
-- Assumes 7.8 if unspecified ghcMajorVersionText :: Snapshot -> Text
ghcMajorVersionText :: Stackage -> Text ghcMajorVersionText =
ghcMajorVersionText snapshot getMajorVersion . snapshotGhc
= ghcMajorVersionToText where
$ fromMaybe (GhcMajorVersion 7 8) getMajorVersion :: Text -> Text
$ stackageGhcMajorVersion snapshot getMajorVersion = intercalate "." . take 2 . T.splitOn "."
-}
getGhcMajorVersionR :: SnapName -> Handler Text getGhcMajorVersionR :: SnapName -> Handler Text
getGhcMajorVersionR _slug = do getGhcMajorVersionR name = do
error "getGhcMajorVersionR" snapshot <- lookupSnapshot name >>= maybe notFound return
{- return $ ghcMajorVersionText $ entityVal snapshot
snapshot <- runDB $ getBy404 $ UniqueSnapshot slug
return $ ghcMajorVersionText $ entityVal snapshot
-}
getDownloadGhcLinksR :: SupportedArch -> Text -> Handler TypedContent getDownloadGhcLinksR :: SupportedArch -> Text -> Handler TypedContent
getDownloadGhcLinksR arch fileName = do getDownloadGhcLinksR arch fileName = do

View File

@ -5,6 +5,7 @@ module Stackage.Database
, Snapshot (..) , Snapshot (..)
, newestLTS , newestLTS
, newestLTSMajor , newestLTSMajor
, ltsMajorVersions
, newestNightly , newestNightly
, lookupSnapshot , lookupSnapshot
, snapshotTitle , snapshotTitle
@ -401,6 +402,19 @@ newestLTSMajor :: GetStackageDatabase m => Int -> m (Maybe Int)
newestLTSMajor x = newestLTSMajor x =
run $ liftM (fmap $ ltsMinor . entityVal) $ selectFirst [LtsMajor ==. x] [Desc LtsMinor] run $ liftM (fmap $ ltsMinor . entityVal) $ selectFirst [LtsMajor ==. x] [Desc LtsMinor]
ltsMajorVersions :: GetStackageDatabase m => m [(Int, Int)]
ltsMajorVersions =
run $ liftM (dropOldMinors . map (toPair . entityVal))
$ selectList [] [Desc LtsMajor, Desc LtsMinor]
where
toPair (Lts _ x y) = (x, y)
dropOldMinors [] = []
dropOldMinors (l@(x, _):rest) =
l : dropOldMinors (dropWhile sameMinor rest)
where
sameMinor (y, _) = x == y
newestNightly :: GetStackageDatabase m => m (Maybe Day) newestNightly :: GetStackageDatabase m => m (Maybe Day)
newestNightly = newestNightly =
run $ liftM (fmap $ nightlyDay . entityVal) $ selectFirst [] [Desc NightlyDay] run $ liftM (fmap $ nightlyDay . entityVal) $ selectFirst [] [Desc NightlyDay]