1 {-# LANGUAGE OverloadedStrings #-}
    2 module Databrary.View.Ingest
    3   ( htmlIngestForm
    4   ) where
    5 
    6 import Control.Monad (void, forM_)
    7 import qualified Data.Aeson as JSON
    8 import Data.Monoid ((<>))
    9 import qualified Text.Blaze.Html5 as H
   10 
   11 import Databrary.Action.Types
   12 import Databrary.Action.Route
   13 import Databrary.Model.Id.Types
   14 import Databrary.Model.Volume
   15 import Databrary.Ingest.Service
   16 import Databrary.View.Html
   17 import Databrary.View.Form
   18 
   19 import Databrary.Controller.Angular
   20 import Databrary.Controller.Container
   21 import {-# SOURCE #-} Databrary.Controller.Ingest
   22 
   23 htmlIngestStatus :: IngestStatus -> JSOpt -> H.Html
   24 htmlIngestStatus IngestInactive _ = mempty
   25 htmlIngestStatus (IngestActive _) _ = void "An ingest is currently running..."
   26 htmlIngestStatus (IngestFailed el) _ = do
   27   void "Previous ingest failed:"
   28   H.ul $ mapM_ (H.li . H.text) el
   29 htmlIngestStatus (IngestCompleted cl) js = do
   30   void "Previous ingest completed:"
   31   H.ul $ forM_ cl $ \c ->
   32     H.li $ H.a H.! actionLink viewContainer (HTML, (Nothing, Id c)) js $ H.toMarkup c
   33 
   34 htmlIngestForm :: Volume -> IngestStatus -> RequestContext -> FormHtml JSON.Value
   35 htmlIngestForm v s = htmlForm
   36   ("Ingest " <> volumeName (volumeRow v))
   37   postIngest (volumeId $ volumeRow v)
   38   (case s of
   39     IngestActive _ ->
   40       field "abort" $ inputCheckbox False
   41     _ -> do
   42       field "run" $ inputCheckbox False
   43       field "overwrite" $ inputCheckbox False
   44       field "json" $ inputFile)
   45   (htmlIngestStatus s)