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

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

parents 60ad658d 39a68fe8
...@@ -439,9 +439,9 @@ pageLayoutCpt = here.component "pageLayout" cpt where ...@@ -439,9 +439,9 @@ pageLayoutCpt = here.component "pageLayout" cpt where
let loader p = do let loader p = do
let route = tableRouteWithPage (p { params = paramsS', query = query }) let route = tableRouteWithPage (p { params = paramsS', query = query })
eRes <- get session $ route eRes <- get session $ route
liftEffect $ do --liftEffect $ do
here.log2 "table route" route -- here.log2 "table route" route
here.log2 "table res" eRes -- here.log2 "table res" eRes
pure $ handleResponse <$> eRes pure $ handleResponse <$> eRes
let render (Tuple count documents) = pagePaintRaw { documents let render (Tuple count documents) = pagePaintRaw { documents
, layout: props { params = paramsS' , layout: props { params = paramsS'
......
module Gargantext.Components.Forest.Tree.Node.Action.Download where module Gargantext.Components.Forest.Tree.Node.Action.Download where
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Reactix as R import Data.Show.Generic (genericShow)
import Reactix.DOM.HTML as H import Data.String.Common (toLower)
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(DownloadNode)) import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(DownloadNode))
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, panel, submitButtonHref) import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, panel, submitButtonHref)
import Gargantext.Ends (url) import Gargantext.Ends (url)
import Gargantext.Prelude (pure, ($)) import Gargantext.Prelude
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (ID) import Gargantext.Types (ID)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2 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
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Download" here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Download"
...@@ -66,17 +69,40 @@ actionDownloadNodeListCpt = here.component "actionDownloadNodeList" cpt where ...@@ -66,17 +69,40 @@ actionDownloadNodeListCpt = here.component "actionDownloadNodeList" cpt where
href = url session $ Routes.NodeAPI GT.NodeList (Just id) "" href = url session $ Routes.NodeAPI GT.NodeList (Just id) ""
info = "Info about the List as JSON format" 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 :: R2.Component ActionDownload
actionDownloadNodeTexts = R.createElement actionDownloadNodeTextsCpt actionDownloadNodeTexts = R.createElement actionDownloadNodeTextsCpt
actionDownloadNodeTextsCpt :: R.Component ActionDownload actionDownloadNodeTextsCpt :: R.Component ActionDownload
actionDownloadNodeTextsCpt = here.component "actionDownloadNodeTexts" cpt where actionDownloadNodeTextsCpt = here.component "actionDownloadNodeTexts" cpt where
cpt { id, session } _ = do cpt { id, session } _ = do
pure $ panel [H.div {} [H.text info]] downloadFormat <- T.useBox JSON
(submitButtonHref DownloadNode href) downloadFormat' <- T.useLive T.unequal downloadFormat
where
href = url session $ Routes.NodeAPI GT.NodeTexts (Just id) "export"
info = "Download as JSON"
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
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 -- TODO fix the route
......
...@@ -36,7 +36,6 @@ type Choice = Maybe Score ...@@ -36,7 +36,6 @@ type Choice = Maybe Score
scoreEl :: R2.Component Props scoreEl :: R2.Component Props
scoreEl = R.createElement scoreElCpt scoreEl = R.createElement scoreElCpt
scoreElCpt :: R.Component Props scoreElCpt :: R.Component Props
scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt
where 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