Commit f78c341a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[DESIGN] download buttons

parent 42732ad0
module Gargantext.Components.Forest.Tree where module Gargantext.Components.Forest.Tree where
import DOM.Simple.Console (log2) import DOM.Simple.Console (log, log2)
import Data.Array as A import Data.Array as A
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Data.Set as Set import Data.Set as Set
...@@ -297,6 +297,9 @@ performAction (UploadFile nodeType fileType mName contents) { session ...@@ -297,6 +297,9 @@ performAction (UploadFile nodeType fileType mName contents) { session
liftEffect $ log2 "Uploaded, task:" task liftEffect $ log2 "Uploaded, task:" task
------- -------
performAction DownloadNode _ = do
liftEffect $ log "[performAction] DownloadNode"
-------
performAction RefreshTree { reload: (_ /\ setReload) } = do performAction RefreshTree { reload: (_ /\ setReload) } = do
liftEffect $ setReload (_ + 1) liftEffect $ setReload (_ + 1)
------- -------
...@@ -27,6 +27,7 @@ data Action = AddNode String GT.NodeType ...@@ -27,6 +27,7 @@ data Action = AddNode String GT.NodeType
| ShareNode String | ShareNode String
| DoSearch GT.AsyncTaskWithType | DoSearch GT.AsyncTaskWithType
| UploadFile GT.NodeType FileType (Maybe String) UploadFileContents | UploadFile GT.NodeType FileType (Maybe String) UploadFileContents
| DownloadNode
| RefreshTree | RefreshTree
...@@ -39,6 +40,7 @@ instance showShow :: Show Action where ...@@ -39,6 +40,7 @@ instance showShow :: Show Action where
show (DoSearch _ )= "SearchQuery" show (DoSearch _ )= "SearchQuery"
show (UploadFile _ _ _ _)= "UploadFile" show (UploadFile _ _ _ _)= "UploadFile"
show RefreshTree = "RefreshTree" show RefreshTree = "RefreshTree"
show DownloadNode = "Download"
type Props = type Props =
( dispatch :: Action -> Aff Unit ( dispatch :: Action -> Aff Unit
...@@ -56,6 +58,7 @@ icon (ShareNode _) = glyphiconNodeAction Share ...@@ -56,6 +58,7 @@ icon (ShareNode _) = glyphiconNodeAction Share
icon (DoSearch _) = glyphiconNodeAction SearchBox icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh icon RefreshTree = glyphiconNodeAction Refresh
icon DownloadNode = glyphiconNodeAction Download
-- icon _ = "hand-o-right" -- icon _ = "hand-o-right"
text :: Action -> String text :: Action -> String
...@@ -67,4 +70,5 @@ text (ShareNode _ )= "Share !" ...@@ -67,4 +70,5 @@ text (ShareNode _ )= "Share !"
text (DoSearch _ )= "Launch search !" text (DoSearch _ )= "Launch search !"
text (UploadFile _ _ _ _)= "Upload File !" text (UploadFile _ _ _ _)= "Upload File !"
text RefreshTree = "Refresh Tree !" text RefreshTree = "Refresh Tree !"
text DownloadNode = "Download !"
----------------------------------------------------------------------- -----------------------------------------------------------------------
module Gargantext.Components.Forest.Tree.Node.Action.Download where module Gargantext.Components.Forest.Tree.Node.Action.Download where
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT) import Gargantext.Components.Forest.Tree.Node.Action (Action(DownloadNode))
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 (pure, ($))
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
...@@ -13,54 +14,31 @@ import Reactix.DOM.HTML as H ...@@ -13,54 +14,31 @@ import Reactix.DOM.HTML as H
-- | Action : Download -- | Action : Download
actionDownload :: NodeType -> ID -> Session -> R.Hooks R.Element actionDownload :: NodeType -> ID -> Session -> R.Hooks R.Element
actionDownload NodeList id session = downloadButton href label info actionDownload NodeList id session = pure $ panel [H.div {} [H.text info]]
(submitButtonHref DownloadNode href)
where where
href = url session $ Routes.NodeAPI GT.NodeList (Just id) "" href = url session $ Routes.NodeAPI GT.NodeList (Just id) ""
label = "Download List"
info = "Info about the List as JSON format" info = "Info about the List as JSON format"
actionDownload GT.Graph id session = downloadButton href label info actionDownload GT.Graph id session = pure $ panel [H.div {} [H.text info]]
(submitButtonHref DownloadNode href)
where where
href = url session $ Routes.NodeAPI GT.Graph (Just id) "gexf" href = url session $ Routes.NodeAPI GT.Graph (Just id) "gexf"
label = "Download Graph"
info = "Info about the Graph as GEXF format" info = "Info about the Graph as GEXF format"
actionDownload GT.Corpus id session = downloadButton href label info actionDownload GT.Corpus id session = pure $ panel [H.div {} [H.text info]]
(submitButtonHref DownloadNode href)
where where
href = url session $ Routes.NodeAPI GT.Corpus (Just id) "export" href = url session $ Routes.NodeAPI GT.Corpus (Just id) "export"
label = "Download Corpus"
info = "Download as JSON" info = "Download as JSON"
actionDownload GT.Texts id session = downloadButton href label info {-
-- TODO fix the route
actionDownload GT.Texts id session = pure $ panel [H.div {} [H.text info]]
(submitButtonHref DownloadNode href)
where where
href = url session $ Routes.NodeAPI GT.Texts (Just id) "" href = url session $ Routes.NodeAPI GT.Texts (Just id) ""
label = "Download texts"
info = "TODO: fix the backend route. What is the expected result ?" info = "TODO: fix the backend route. What is the expected result ?"
-}
actionDownload _ _ _ = pure $ fragmentPT $ "Soon, you will be able to dowload your file here " actionDownload _ _ _ = pure $ fragmentPT $ "Soon, you will be able to download your file here "
type Href = String
type Label = String
type Info = String
downloadButton :: Href -> Label -> Info -> R.Hooks R.Element
downloadButton href label info = do
pure $ R.fragment [ H.div { className: "row"}
[ H.div { className: "col-md-2"} []
, H.div { className: "col-md-7 flex-center"}
[ H.p {} [H.text info] ]
]
, H.span { className: "row" }
[ H.div { className: "panel-footer"}
[ H.div { className: "col-md-3"} []
, H.div { className: "col-md-3 flex-center"}
[ H.a { className: "btn btn-primary"
, style : { width: "50%" }
, href
, target: "_blank" }
[ H.text label ]
]
]
]
]
...@@ -60,7 +60,7 @@ textInputBox p@{ boxName, boxAction, dispatch, isOpen: (true /\ setIsOpen) } = R ...@@ -60,7 +60,7 @@ textInputBox p@{ boxName, boxAction, dispatch, isOpen: (true /\ setIsOpen) } = R
renameNodeName <- R.useState' text renameNodeName <- R.useState' text
pure $ H.div {className: "from-group row-no-padding"} pure $ H.div {className: "from-group row-no-padding"}
[ textInput renameNodeName [ textInput renameNodeName
, submitBtn renameNodeName , submitBtn renameNodeName
, cancelBtn , cancelBtn
] ]
where where
...@@ -162,6 +162,7 @@ formChoice nodeTypes defaultNodeType setNodeType = ...@@ -162,6 +162,7 @@ formChoice nodeTypes defaultNodeType setNodeType =
] ]
-- | Button Form -- | Button Form
-- FIXME: currently needs a click from the user (by default, we could avoid such click)
formButton :: forall a b c formButton :: forall a b c
. a . a
-> ((b -> a) -> Effect c) -> ((b -> a) -> Effect c)
...@@ -178,6 +179,8 @@ formButton nodeType setNodeType = ...@@ -178,6 +179,8 @@ formButton nodeType setNodeType =
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
submitButton :: Action -> (Action -> Aff Unit) -> R.Element submitButton :: Action -> (Action -> Aff Unit) -> R.Element
submitButton action dispatch = submitButton action dispatch =
H.button { className : "btn btn-primary fa fa-" <> icon action H.button { className : "btn btn-primary fa fa-" <> icon action
...@@ -189,3 +192,18 @@ submitButton action dispatch = ...@@ -189,3 +192,18 @@ submitButton action dispatch =
} }
[ H.text $ " " <> text action] [ H.text $ " " <> text action]
type Href = String
submitButtonHref :: Action -> Href -> R.Element
submitButtonHref action href =
H.a { className : "btn btn-primary fa fa-" <> icon action
, style : { width: "50%" }
, href
, target: "_blank"
}
[ H.text $ " " <> text action]
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