Add download link for hoogle database

This commit is contained in:
Dan Burton 2015-04-03 15:00:12 -07:00
parent d98d3866ec
commit bfbe634e5f
4 changed files with 25 additions and 9 deletions

View File

@ -9,7 +9,7 @@ import Data.Slug (Slug)
import Handler.StackageHome (getStackageHomeR, getStackageMetadataR, getStackageCabalConfigR, getSnapshotPackagesR, getDocsR) import Handler.StackageHome (getStackageHomeR, getStackageMetadataR, getStackageCabalConfigR, getSnapshotPackagesR, getDocsR)
import Handler.StackageIndex (getStackageIndexR) import Handler.StackageIndex (getStackageIndexR)
import Handler.StackageSdist (getStackageSdistR) import Handler.StackageSdist (getStackageSdistR)
import Handler.Hoogle (getHoogleR) import Handler.Hoogle (getHoogleR, getHoogleDatabaseR)
import Handler.BuildPlan (getBuildPlanR) import Handler.BuildPlan (getBuildPlanR)
handleAliasR :: Slug -> Slug -> [Text] -> Handler () handleAliasR :: Slug -> Slug -> [Text] -> Handler ()
@ -79,5 +79,6 @@ goSid sid pieces = do
SnapshotPackagesR -> getSnapshotPackagesR slug >>= sendResponse SnapshotPackagesR -> getSnapshotPackagesR slug >>= sendResponse
DocsR -> getDocsR slug >>= sendResponse DocsR -> getDocsR slug >>= sendResponse
HoogleR -> getHoogleR slug >>= sendResponse HoogleR -> getHoogleR slug >>= sendResponse
HoogleDatabaseR -> getHoogleDatabaseR slug >>= sendResponse
BuildPlanR -> getBuildPlanR slug >>= sendResponse BuildPlanR -> getBuildPlanR slug >>= sendResponse
_ -> notFound _ -> notFound

View File

@ -32,14 +32,7 @@ getHoogleR slug = do
mdatabasePath <- getHoogleDB dirs stackage mdatabasePath <- getHoogleDB dirs stackage
heDatabase <- case mdatabasePath of heDatabase <- case mdatabasePath of
Just x -> return $ liftIO $ Hoogle.loadDatabase $ fpToString x Just x -> return $ liftIO $ Hoogle.loadDatabase $ fpToString x
Nothing -> (>>= sendResponse) $ defaultLayout $ do Nothing -> hoogleDatabaseNotAvailableFor slug
setTitle "Hoogle database not available"
[whamlet|
<div .container>
<p>The given Hoogle database is not available.
<p>
<a href=@{SnapshotR slug StackageHomeR}>Return to snapshot homepage
|]
mresults <- case mquery of mresults <- case mquery of
Just query -> runHoogleQuery heDatabase HoogleQueryInput Just query -> runHoogleQuery heDatabase HoogleQueryInput
@ -60,6 +53,25 @@ getHoogleR slug = do
setTitle "Hoogle Search" setTitle "Hoogle Search"
$(widgetFile "hoogle") $(widgetFile "hoogle")
getHoogleDatabaseR :: SnapSlug -> Handler Html
getHoogleDatabaseR slug = do
dirs <- getDirs
Entity _ stackage <- runDB $ getBy404 $ UniqueSnapshot slug
mdatabasePath <- getHoogleDB dirs stackage
case mdatabasePath of
Nothing -> hoogleDatabaseNotAvailableFor slug
Just path -> sendFile "application/octet-stream" $ fpToString path
hoogleDatabaseNotAvailableFor :: SnapSlug -> Handler a
hoogleDatabaseNotAvailableFor slug = (>>= sendResponse) $ defaultLayout $ do
setTitle "Hoogle database not available"
[whamlet|
<div .container>
<p>The given Hoogle database is not available.
<p>
<a href=@{SnapshotR slug StackageHomeR}>Return to snapshot homepage
|]
getPageCount :: Int -> Int getPageCount :: Int -> Int
getPageCount totalCount = 1 + div totalCount perPage getPageCount totalCount = 1 + div totalCount perPage

View File

@ -26,6 +26,7 @@
/packages SnapshotPackagesR GET /packages SnapshotPackagesR GET
/docs DocsR GET /docs DocsR GET
/hoogle HoogleR GET /hoogle HoogleR GET
/db.hoo HoogleDatabaseR GET
/build-plan BuildPlanR GET /build-plan BuildPlanR GET
/aliases AliasesR PUT /aliases AliasesR PUT

View File

@ -39,6 +39,8 @@ $newline never
<h3>Hoogle (experimental) <h3>Hoogle (experimental)
^{hoogleForm} ^{hoogleForm}
<a href=@{SnapshotR slug HoogleDatabaseR}>
Download this hoogle database
<h3>Packages <h3>Packages