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