Commit 9ee9bf21 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

Merge branch '339-dev-corpus-download' into 339-dev-docs-download

parents 60ad658d 39a68fe8
Pipeline #2354 failed with stage
in 0 seconds
......@@ -439,9 +439,9 @@ pageLayoutCpt = here.component "pageLayout" cpt where
let loader p = do
let route = tableRouteWithPage (p { params = paramsS', query = query })
eRes <- get session $ route
liftEffect $ do
here.log2 "table route" route
here.log2 "table res" eRes
--liftEffect $ do
-- here.log2 "table route" route
-- here.log2 "table res" eRes
pure $ handleResponse <$> eRes
let render (Tuple count documents) = pagePaintRaw { documents
, layout: props { params = paramsS'
......
module Gargantext.Components.Forest.Tree.Node.Action.Download where
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Reactix as R
import Reactix.DOM.HTML as H
import Data.Show.Generic (genericShow)
import Data.String.Common (toLower)
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(DownloadNode))
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, panel, submitButtonHref)
import Gargantext.Ends (url)
import Gargantext.Prelude (pure, ($))
import Gargantext.Prelude
import Gargantext.Routes as Routes
import Gargantext.Sessions (Session)
import Gargantext.Types (ID)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Download"
......@@ -66,17 +69,40 @@ actionDownloadNodeListCpt = here.component "actionDownloadNodeList" cpt where
href = url session $ Routes.NodeAPI GT.NodeList (Just id) ""
info = "Info about the List as JSON format"
data NodeTextsDownloadFormat = CSV | JSON
derive instance Eq NodeTextsDownloadFormat
derive instance Generic NodeTextsDownloadFormat _
instance Show NodeTextsDownloadFormat where show = genericShow
readDownloadFormat :: String -> NodeTextsDownloadFormat
readDownloadFormat "CSV" = CSV
readDownloadFormat "JSON" = JSON
readDownloadFormat _ = JSON
actionDownloadNodeTexts :: R2.Component ActionDownload
actionDownloadNodeTexts = R.createElement actionDownloadNodeTextsCpt
actionDownloadNodeTextsCpt :: R.Component ActionDownload
actionDownloadNodeTextsCpt = here.component "actionDownloadNodeTexts" cpt where
cpt { id, session } _ = do
pure $ panel [H.div {} [H.text info]]
(submitButtonHref DownloadNode href)
downloadFormat <- T.useBox JSON
downloadFormat' <- T.useLive T.unequal downloadFormat
pure $ panel
[ R2.select { className: "form-control"
, defaultValue: show downloadFormat'
, on: { change: onChange downloadFormat } }
[ opt CSV downloadFormat
, opt JSON downloadFormat ]
, H.div {} [ H.text $ info downloadFormat' ]
]
(submitButtonHref DownloadNode $ href downloadFormat')
where
href = url session $ Routes.NodeAPI GT.NodeTexts (Just id) "export"
info = "Download as JSON"
opt t downloadFormat = H.option { value: show t } [ H.text $ show t ]
where
onClick _ = T.write_ t downloadFormat
onChange downloadFormat e = T.write_ (readDownloadFormat $ R.unsafeEventValue e) downloadFormat
href t = url session $ Routes.NodeAPI GT.NodeTexts (Just id) ("export/" <> (toLower $ show t))
info t = "Info about the Documents as " <> show t <> " format"
{-
-- TODO fix the route
......
......@@ -36,7 +36,6 @@ type Choice = Maybe Score
scoreEl :: R2.Component Props
scoreEl = R.createElement scoreElCpt
scoreElCpt :: R.Component Props
scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt
where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment