[export] allow to export JSON as zip

parent 28f350da
Pipeline #5687 failed with stage
......@@ -62,17 +62,24 @@ actionDownloadGraphCpt = here.component "actionDownloadGraph" cpt where
where
href = url session $ Routes.NodeAPI GT.Graph (Just id) "gexf"
data NodeListDownloadFormat = NL_CSV | NL_JSON
data NodeListDownloadFormat = NL_CSV | NL_JSON | NL_JSON_ZIP
derive instance Eq NodeListDownloadFormat
derive instance Generic NodeListDownloadFormat _
instance Show NodeListDownloadFormat
where
show NL_CSV = "CSV"
show NL_JSON = "JSON"
show NL_JSON_ZIP = "JSON (zipped)"
urlNodeListDownloadFormat :: NodeListDownloadFormat -> String
urlNodeListDownloadFormat NL_CSV = "csv"
urlNodeListDownloadFormat NL_JSON = "json"
urlNodeListDownloadFormat NL_JSON_ZIP = "json.zip"
readNodeListDownloadFormat :: String -> NodeListDownloadFormat
readNodeListDownloadFormat "CSV" = NL_CSV
readNodeListDownloadFormat "JSON" = NL_JSON
readNodeListDownloadFormat "JSON (zipped)" = NL_JSON_ZIP
readNodeListDownloadFormat _ = NL_JSON
actionDownloadNodeList :: R2.Component ActionDownload
......@@ -80,7 +87,7 @@ actionDownloadNodeList = R.createElement actionDownloadNodeListCpt
actionDownloadNodeListCpt :: R.Component ActionDownload
actionDownloadNodeListCpt = here.component "actionDownloadNodeList" cpt where
cpt { id, session } _ = do
downloadFormat <- T.useBox NL_JSON
downloadFormat <- T.useBox NL_JSON_ZIP
downloadFormat' <- T.useLive T.unequal downloadFormat
pure $
......@@ -91,39 +98,43 @@ actionDownloadNodeListCpt = here.component "actionDownloadNodeList" cpt where
, defaultValue: show downloadFormat'
, on: { change: onChange downloadFormat } }
[ opt NL_CSV
, opt NL_JSON ]
, opt NL_JSON
, opt NL_JSON_ZIP ]
, H.div {} [ H.text $ info downloadFormat' ]
]
where
opt t = H.option { value: show t } [ H.text $ show t ]
onChange downloadFormat e = T.write_ (readNodeListDownloadFormat $ R.unsafeEventValue e) downloadFormat
href :: NodeListDownloadFormat -> String
href t = url session $ Routes.NodeAPI GT.NodeList (Just id) (toLower $ show t)
href t = url session $ Routes.NodeAPI GT.NodeList (Just id) (urlNodeListDownloadFormat t)
info :: NodeListDownloadFormat -> String
info t = "Info about the Documents as " <> show t <> " format"
data NodeTextsDownloadFormat = NT_CSV | NT_JSON
data NodeTextsDownloadFormat = NT_CSV | NT_JSON | NT_JSON_ZIP
derive instance Eq NodeTextsDownloadFormat
derive instance Generic NodeTextsDownloadFormat _
instance Show NodeTextsDownloadFormat where
show NT_CSV = "CSV"
show NT_JSON = "JSON"
show NT_JSON_ZIP = "JSON (zipped)"
urlNodeTextsDownloadFormat :: NodeTextsDownloadFormat -> String
urlNodeTextsDownloadFormat NT_CSV = "csv"
urlNodeTextsDownloadFormat NT_JSON = "json"
urlNodeTextsDownloadFormat NT_JSON_ZIP = "json.zip"
readNodeTextsDownloadFormat :: String -> NodeTextsDownloadFormat
readNodeTextsDownloadFormat "CSV" = NT_CSV
readNodeTextsDownloadFormat "JSON" = NT_JSON
readNodeTextsDownloadFormat _ = NT_JSON
readNodeTextsDownloadFormat "JSON (zippped)" = NT_JSON_ZIP
readNodeTextsDownloadFormat _ = NT_JSON_ZIP
actionDownloadNodeTexts :: R2.Component ActionDownload
actionDownloadNodeTexts = R.createElement actionDownloadNodeTextsCpt
actionDownloadNodeTextsCpt :: R.Component ActionDownload
actionDownloadNodeTextsCpt = here.component "actionDownloadNodeTexts" cpt where
cpt { id, session } _ = do
downloadFormat <- T.useBox NT_JSON
downloadFormat <- T.useBox NT_JSON_ZIP
downloadFormat' <- T.useLive T.unequal downloadFormat
pure $ Tools.panelWithSubmitButtonHref { action: DownloadNode
......@@ -133,7 +144,8 @@ actionDownloadNodeTextsCpt = here.component "actionDownloadNodeTexts" cpt where
, defaultValue: show downloadFormat'
, on: { change: onChange downloadFormat } }
[ opt NT_CSV
, opt NT_JSON ]
, opt NT_JSON
, opt NT_JSON_ZIP ]
, H.div {} [ H.text $ info downloadFormat' ]
]
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