Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
6cd7a7d5
Commit
6cd7a7d5
authored
Aug 10, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[upload] upload arbitrary file
parent
b2ba68f5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
63 deletions
+107
-63
Tree.purs
src/Gargantext/Components/Forest/Tree.purs
+10
-1
Action.purs
src/Gargantext/Components/Forest/Tree/Node/Action.purs
+49
-45
Upload.purs
...Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
+39
-12
Types.purs
...text/Components/Forest/Tree/Node/Action/Upload/Types.purs
+2
-1
Types.purs
src/Gargantext/Types.purs
+7
-4
No files found.
src/Gargantext/Components/Forest/Tree.purs
View file @
6cd7a7d5
...
@@ -26,7 +26,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Rename (RenameValue(..), re
...
@@ -26,7 +26,7 @@ import Gargantext.Components.Forest.Tree.Node.Action.Rename (RenameValue(..), re
import Gargantext.Components.Forest.Tree.Node.Action.Share as Share
import Gargantext.Components.Forest.Tree.Node.Action.Share as Share
import Gargantext.Components.Forest.Tree.Node.Action.Contact as Contact
import Gargantext.Components.Forest.Tree.Node.Action.Contact as Contact
import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest)
import Gargantext.Components.Forest.Tree.Node.Action.Update (updateRequest)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile)
import Gargantext.Components.Forest.Tree.Node.Action.Upload (uploadFile
, uploadArbitraryFile
)
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Components.Forest.Tree.Node.Tools.FTree (FTree, LNode(..), NTree(..))
import Gargantext.Components.Forest.Tree.Node.Tools.Task (Tasks, tasksStruct)
import Gargantext.Components.Forest.Tree.Node.Tools.Task (Tasks, tasksStruct)
import Gargantext.Ends (Frontends)
import Gargantext.Ends (Frontends)
...
@@ -331,6 +331,15 @@ performAction (UploadFile nodeType fileType mName contents) { session
...
@@ -331,6 +331,15 @@ performAction (UploadFile nodeType fileType mName contents) { session
liftEffect $ onTaskAdd task
liftEffect $ onTaskAdd task
liftEffect $ log2 "Uploaded, task:" task
liftEffect $ log2 "Uploaded, task:" task
performAction (UploadArbitraryFile nodeType mName contents) { session
, tasks: { onTaskAdd }
, tree: (NTree (LNode {id}) _)
} =
do
task <- uploadArbitraryFile session nodeType id { contents, mName }
liftEffect $ onTaskAdd task
liftEffect $ log2 "Uploaded, task:" task
-------
-------
performAction DownloadNode _ = do
performAction DownloadNode _ = do
liftEffect $ log "[performAction] DownloadNode"
liftEffect $ log "[performAction] DownloadNode"
...
...
src/Gargantext/Components/Forest/Tree/Node/Action.purs
View file @
6cd7a7d5
...
@@ -25,6 +25,7 @@ data Action = AddNode String GT.NodeType
...
@@ -25,6 +25,7 @@ data Action = AddNode String GT.NodeType
| UpdateNode UpdateNodeParams
| UpdateNode UpdateNodeParams
| DoSearch GT.AsyncTaskWithType
| DoSearch GT.AsyncTaskWithType
| UploadFile GT.NodeType FileType (Maybe String) UploadFileContents
| UploadFile GT.NodeType FileType (Maybe String) UploadFileContents
| UploadArbitraryFile GT.NodeType (Maybe String) UploadFileContents
| DownloadNode
| DownloadNode
| RefreshTree
| RefreshTree
...
@@ -54,57 +55,60 @@ setTreeOut a _ = a
...
@@ -54,57 +55,60 @@ setTreeOut a _ = a
instance showShow :: Show Action where
instance showShow :: Show Action where
show (AddNode _ _ )= "AddNode"
show (AddNode _ _ ) = "AddNode"
show (DeleteNode _ )= "DeleteNode"
show (DeleteNode _ ) = "DeleteNode"
show (RenameNode _ )= "RenameNode"
show (RenameNode _ ) = "RenameNode"
show (UpdateNode _ )= "UpdateNode"
show (UpdateNode _ ) = "UpdateNode"
show (ShareTeam _ )= "ShareTeam"
show (ShareTeam _ ) = "ShareTeam"
show (AddContact _ )= "AddContact"
show (AddContact _ ) = "AddContact"
show (SharePublic _ )= "SharePublic"
show (SharePublic _ ) = "SharePublic"
show (DoSearch _ )= "SearchQuery"
show (DoSearch _ ) = "SearchQuery"
show (UploadFile _ _ _ _)= "UploadFile"
show (UploadFile _ _ _ _) = "UploadFile"
show RefreshTree = "RefreshTree"
show (UploadArbitraryFile _ _ _) = "UploadArbitraryFile"
show DownloadNode = "Download"
show RefreshTree = "RefreshTree"
show (MoveNode _ ) = "MoveNode"
show DownloadNode = "Download"
show (MergeNode _ ) = "MergeNode"
show (MoveNode _ ) = "MoveNode"
show (LinkNode _ ) = "LinkNode"
show (MergeNode _ ) = "MergeNode"
show NoAction = "NoAction"
show (LinkNode _ ) = "LinkNode"
show NoAction = "NoAction"
-----------------------------------------------------------------------
-----------------------------------------------------------------------
icon :: Action -> String
icon :: Action -> String
icon (AddNode _ _) = glyphiconNodeAction (Add [])
icon (AddNode _ _) = glyphiconNodeAction (Add [])
icon (DeleteNode _) = glyphiconNodeAction Delete
icon (DeleteNode _) = glyphiconNodeAction Delete
icon (RenameNode _) = glyphiconNodeAction Config
icon (RenameNode _) = glyphiconNodeAction Config
icon (UpdateNode _) = glyphiconNodeAction Refresh
icon (UpdateNode _) = glyphiconNodeAction Refresh
icon (ShareTeam _) = glyphiconNodeAction Share
icon (ShareTeam _) = glyphiconNodeAction Share
icon (AddContact _) = glyphiconNodeAction Share
icon (AddContact _) = glyphiconNodeAction Share
icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (SharePublic _ ) = glyphiconNodeAction (Publish { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (DoSearch _) = glyphiconNodeAction SearchBox
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon (UploadFile _ _ _ _) = glyphiconNodeAction Upload
icon RefreshTree = glyphiconNodeAction Refresh
icon (UploadArbitraryFile _ _ _ ) = glyphiconNodeAction Upload
icon DownloadNode = glyphiconNodeAction Download
icon RefreshTree = glyphiconNodeAction Refresh
icon (MoveNode _ ) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon DownloadNode = glyphiconNodeAction Download
icon (MergeNode _ ) = glyphiconNodeAction (Merge { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (MoveNode _ ) = glyphiconNodeAction (Move { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (LinkNode _ ) = glyphiconNodeAction (Link { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (MergeNode _ ) = glyphiconNodeAction (Merge { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon (LinkNode _ ) = glyphiconNodeAction (Link { subTreeParams : SubTreeParams {showtypes:[], valitypes:[] }})
icon NoAction = "hand-o-right"
icon NoAction
= "hand-o-right"
-- icon _ = "hand-o-right"
-- icon _ = "hand-o-right"
text :: Action -> String
text :: Action -> String
text (AddNode _ _ )= "Add !"
text (AddNode _ _ ) = "Add !"
text (DeleteNode _ )= "Delete !"
text (DeleteNode _ ) = "Delete !"
text (RenameNode _ )= "Rename !"
text (RenameNode _ ) = "Rename !"
text (UpdateNode _ )= "Update !"
text (UpdateNode _ ) = "Update !"
text (ShareTeam _ )= "Share with team !"
text (ShareTeam _ ) = "Share with team !"
text (AddContact _ )= "Add contact !"
text (AddContact _ ) = "Add contact !"
text (SharePublic _ )= "Publish !"
text (SharePublic _ ) = "Publish !"
text (DoSearch _ )= "Launch search !"
text (DoSearch _ ) = "Launch search !"
text (UploadFile _ _ _ _)= "Upload File !"
text (UploadFile _ _ _ _) = "Upload File !"
text RefreshTree = "Refresh Tree !"
text (UploadArbitraryFile _ _ _) = "Upload arbitrary file !"
text DownloadNode = "Download !"
text RefreshTree = "Refresh Tree !"
text (MoveNode _ ) = "Move !"
text DownloadNode = "Download !"
text (MergeNode _ ) = "Merge !"
text (MoveNode _ ) = "Move !"
text (LinkNode _ ) = "Link !"
text (MergeNode _ ) = "Merge !"
text NoAction = "No Action"
text (LinkNode _ ) = "Link !"
text NoAction = "No Action"
-----------------------------------------------------------------------
-----------------------------------------------------------------------
src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
View file @
6cd7a7d5
...
@@ -5,24 +5,27 @@ import Data.Newtype (class Newtype)
...
@@ -5,24 +5,27 @@ import Data.Newtype (class Newtype)
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff, launchAff)
import Effect.Aff (Aff, launchAff
, throwError
)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Partial.Unsafe (unsafePartial)
import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as QP
import Web.File.FileReader.Aff (readAsText)
import Gargantext.Prelude
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), Props)
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), Props)
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileContents(..))
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileContents(..))
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, formChoiceSafe, panel)
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, formChoiceSafe, panel)
import Gargantext.Components.Lang (Lang(..))
import Gargantext.Components.Lang (Lang(..))
import Gargantext.Prelude (class Show, Unit, discard, bind, const, id, map, pure, show, unit, void, ($), read)
import Gargantext.Routes as GR
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, postWwwUrlencoded)
import Gargantext.Sessions (Session, postWwwUrlencoded)
import Gargantext.Types (NodeType(..), ID)
import Gargantext.Types (NodeType(..), ID)
import Gargantext.Types as GT
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Partial.Unsafe (unsafePartial)
import React.SyntheticEvent as E
import Reactix as R
import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as QP
import Web.File.FileReader.Aff (readAsText)
-- UploadFile Action
-- UploadFile Action
...
@@ -81,6 +84,7 @@ uploadFileViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
...
@@ -81,6 +84,7 @@ uploadFileViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
, CSV_HAL
, CSV_HAL
, WOS
, WOS
, PresseRIS
, PresseRIS
, Arbitrary
] CSV setFileType
] CSV setFileType
]
]
...
@@ -162,9 +166,13 @@ uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt
...
@@ -162,9 +166,13 @@ uploadButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadButton" cpt
Just _ -> ""
Just _ -> ""
onClick e = do
onClick e = do
let {
name, contents
} = unsafePartial $ fromJust mFile
let {
contents, name
} = unsafePartial $ fromJust mFile
void $ launchAff do
void $ launchAff do
_ <- dispatch $ UploadFile nodeType fileType (Just name) contents
case fileType of
Arbitrary ->
dispatch $ UploadArbitraryFile nodeType (Just name) contents
_ ->
dispatch $ UploadFile nodeType fileType (Just name) contents
liftEffect $ do
liftEffect $ do
setMFile $ const $ Nothing
setMFile $ const $ Nothing
setFileType $ const $ CSV
setFileType $ const $ CSV
...
@@ -279,8 +287,6 @@ uploadFile session nodeType id fileType {mName, contents: UploadFileContents con
...
@@ -279,8 +287,6 @@ uploadFile session nodeType id fileType {mName, contents: UploadFileContents con
pure $ GT.AsyncTaskWithType {task, typ: GT.Form}
pure $ GT.AsyncTaskWithType {task, typ: GT.Form}
--postMultipartFormData session p fileContents
--postMultipartFormData session p fileContents
where
where
q = FileUploadQuery { fileType: fileType }
--p = NodeAPI GT.Corpus (Just id) $ "add/file/async/nobody" <> Q.print (toQuery q)
p = case nodeType of
p = case nodeType of
Corpus -> GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.Form
Corpus -> GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.Form
Annuaire -> GR.NodeAPI nodeType (Just id) "annuaire"
Annuaire -> GR.NodeAPI nodeType (Just id) "annuaire"
...
@@ -291,6 +297,27 @@ uploadFile session nodeType id fileType {mName, contents: UploadFileContents con
...
@@ -291,6 +297,27 @@ uploadFile session nodeType id fileType {mName, contents: UploadFileContents con
, Tuple "_wf_name" mName
, Tuple "_wf_name" mName
]
]
uploadArbitraryFile :: Session
-> GT.NodeType
-> ID
-> {contents :: UploadFileContents, mName :: Maybe String}
-> Aff GT.AsyncTaskWithType
uploadArbitraryFile session nodeType id {mName, contents: UploadFileContents contents} = do
if nodeType == Corpus then
pure unit
else
throwError $ error $ "[uploadArbitraryFile] NodeType " <> (show nodeType) <> " not supported"
task <- postWwwUrlencoded session p bodyParams
pure $ GT.AsyncTaskWithType { task, typ: GT.Form }
where
p = GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.UploadFile
bodyParams = [ Tuple "_wfi_data" (Just contents)
, Tuple "_wfi_name" mName
]
------------------------------------------------------------------------
------------------------------------------------------------------------
uploadTermListView :: Record Props -> R.Element
uploadTermListView :: Record Props -> R.Element
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Upload/Types.purs
View file @
6cd7a7d5
...
@@ -7,7 +7,7 @@ import Data.Maybe (Maybe(..))
...
@@ -7,7 +7,7 @@ import Data.Maybe (Maybe(..))
import Gargantext.Prelude (class Read, class Show, class Eq)
import Gargantext.Prelude (class Read, class Show, class Eq)
data FileType = CSV | CSV_HAL | WOS | PresseRIS
data FileType = CSV | CSV_HAL | WOS | PresseRIS
| Arbitrary
derive instance genericFileType :: Generic FileType _
derive instance genericFileType :: Generic FileType _
...
@@ -23,6 +23,7 @@ instance readFileType :: Read FileType where
...
@@ -23,6 +23,7 @@ instance readFileType :: Read FileType where
read "CSV_HAL" = Just CSV_HAL
read "CSV_HAL" = Just CSV_HAL
read "PresseRIS" = Just PresseRIS
read "PresseRIS" = Just PresseRIS
read "WOS" = Just WOS
read "WOS" = Just WOS
read "Arbitrary" = Just Arbitrary
read _ = Nothing
read _ = Nothing
...
...
src/Gargantext/Types.purs
View file @
6cd7a7d5
...
@@ -566,6 +566,7 @@ modeFromString _ = Nothing
...
@@ -566,6 +566,7 @@ modeFromString _ = Nothing
-- corresponds to /add/form/async or /add/query/async
-- corresponds to /add/form/async or /add/query/async
data AsyncTaskType = Form
data AsyncTaskType = Form
| UploadFile
| GraphT
| GraphT
| Query
| Query
| AddNode
| AddNode
...
@@ -583,16 +584,18 @@ instance decodeJsonAsyncTaskType :: DecodeJson AsyncTaskType where
...
@@ -583,16 +584,18 @@ instance decodeJsonAsyncTaskType :: DecodeJson AsyncTaskType where
obj <- decodeJson json
obj <- decodeJson json
case obj of
case obj of
"Form" -> pure Form
"Form" -> pure Form
"UploadFile" -> pure UploadFile
"GraphT" -> pure GraphT
"GraphT" -> pure GraphT
"Query" -> pure Query
"Query" -> pure Query
"AddNode" -> pure AddNode
"AddNode" -> pure AddNode
s -> Left ("Unknown string " <> s)
s -> Left ("Unknown string " <> s)
asyncTaskTypePath :: AsyncTaskType -> String
asyncTaskTypePath :: AsyncTaskType -> String
asyncTaskTypePath Form = "add/form/async/"
asyncTaskTypePath Form = "add/form/async/"
asyncTaskTypePath Query = "query/"
asyncTaskTypePath UploadFile = "add/file/async/"
asyncTaskTypePath GraphT = "async/"
asyncTaskTypePath Query = "query/"
asyncTaskTypePath AddNode = "async/nobody/"
asyncTaskTypePath GraphT = "async/"
asyncTaskTypePath AddNode = "async/nobody/"
asyncTaskTypePath UpdateNode = "update/"
asyncTaskTypePath UpdateNode = "update/"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment