[corpus] add download option, in JSON and SQLite

Related to haskell-gargantext#362
parent 2e43c474
Pipeline #7333 passed with stages
in 23 minutes and 22 seconds
...@@ -39,6 +39,24 @@ actionDownloadCpt = here.component "actionDownload" cpt ...@@ -39,6 +39,24 @@ actionDownloadCpt = here.component "actionDownload" cpt
cpt props@{ nodeType: GT.Phylo } _ = pure $ actionDownloadPhylo props [] cpt props@{ nodeType: GT.Phylo } _ = pure $ actionDownloadPhylo props []
cpt props@{ nodeType: _ } _ = pure $ actionDownloadOther props [] cpt props@{ nodeType: _ } _ = pure $ actionDownloadOther props []
data CorpusDownloadFormat = CD_SQLITE | CD_JSON
derive instance Eq CorpusDownloadFormat
derive instance Generic CorpusDownloadFormat _
instance Show CorpusDownloadFormat
where
show CD_JSON = "JSON"
show CD_SQLITE = "SQLite"
urlCorpusDownloadFormat :: CorpusDownloadFormat -> String
urlCorpusDownloadFormat CD_JSON = "export"
urlCorpusDownloadFormat CD_SQLITE = "sqlite"
readCorpusDownloadFormat :: String -> CorpusDownloadFormat
readCorpusDownloadFormat "JSON" = CD_JSON
readCorpusDownloadFormat "SQLite" = CD_SQLITE
readCorpusDownloadFormat _ = CD_SQLITE
actionDownloadCorpus :: R2.Component ActionDownload actionDownloadCorpus :: R2.Component ActionDownload
actionDownloadCorpus = R.createElement actionDownloadCorpusCpt actionDownloadCorpus = R.createElement actionDownloadCorpusCpt
...@@ -46,17 +64,35 @@ actionDownloadCorpusCpt :: R.Component ActionDownload ...@@ -46,17 +64,35 @@ actionDownloadCorpusCpt :: R.Component ActionDownload
actionDownloadCorpusCpt = here.component "actionDownloadCorpus" cpt actionDownloadCorpusCpt = here.component "actionDownloadCorpus" cpt
where where
cpt { id, session } _ = do cpt { id, session } _ = do
downloadFormat <- T.useBox CD_SQLITE
downloadFormat' <- T.useLive T.unequal downloadFormat
pure $ pure $
Tools.panelWithSubmitButtonHref Tools.panelWithSubmitButtonHref
{ action: DownloadNode { action: DownloadNode
, href , href: href downloadFormat'
, mError: Nothing , mError: Nothing
, iconName: "download" , iconName: "download"
, textTitle: "Download the corpus" , textTitle: "Download the corpus"
} }
[ H.div {} [ H.text "Download as JSON" ] ] [ R2.select
{ className: "form-control"
, defaultValue: show downloadFormat'
, on: { change: onChange downloadFormat }
}
[ opt CD_SQLITE
, opt CD_JSON
]
, H.div {} [ H.text $ info downloadFormat' ]
]
where where
href = url session $ Routes.NodeAPI GT.Corpus (Just id) "export" opt t = H.option { value: show t } [ H.text $ show t ]
onChange downloadFormat e = T.write_ (readCorpusDownloadFormat $ R.unsafeEventValue e) downloadFormat
href t = url session $ Routes.NodeAPI GT.Corpus (Just id) (urlCorpusDownloadFormat t)
info :: CorpusDownloadFormat -> String
info t = "Download corpus in " <> show t <> " format"
actionDownloadGraph :: R2.Component ActionDownload actionDownloadGraph :: R2.Component ActionDownload
actionDownloadGraph = R.createElement actionDownloadGraphCpt actionDownloadGraph = R.createElement actionDownloadGraphCpt
......
...@@ -175,11 +175,11 @@ settingsBoxLens Corpus = ...@@ -175,11 +175,11 @@ settingsBoxLens Corpus =
, Calc , Calc
] ]
, Upload , Upload
, Download
, SearchBox , SearchBox
, WriteNodesDocuments , WriteNodesDocuments
-- , ReloadWithSettings -- TODO -- , ReloadWithSettings -- TODO
, Move moveParameters , Move moveParameters
-- , Download
-- , Link (linkParams Annuaire) -- , Link (linkParams Annuaire)
, ShareURL , ShareURL
, Delete , Delete
......
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