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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
494295c0
Commit
494295c0
authored
Jul 21, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[upload] upload JSON type works now
parent
2a668be5
Pipeline
#1632
failed with stage
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
21 deletions
+31
-21
Tree.purs
src/Gargantext/Components/Forest/Tree.purs
+2
-2
Upload.purs
...Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
+24
-19
Types.purs
...text/Components/Forest/Tree/Node/Action/Upload/Types.purs
+5
-0
No files found.
src/Gargantext/Components/Forest/Tree.purs
View file @
494295c0
...
...
@@ -237,8 +237,8 @@ addNode' name nodeType p@{ forestOpen, tree: (NTree (LNode { id }) _) } = do
liftEffect $ T.modify_ (openNodesInsert (mkNodeId p.session id)) forestOpen
refreshTree p
uploadFile' nodeType fileType mName
blob
p@{ tasks, tree: (NTree (LNode { id }) _) } = do
task <- uploadFile p.session nodeType id fileType {mName,
blob
}
uploadFile' nodeType fileType mName
contents
p@{ tasks, tree: (NTree (LNode { id }) _) } = do
task <- uploadFile p.session nodeType id fileType {mName,
contents
}
liftEffect $ do
GAT.insert id task tasks
log2 "[performAction] UploadFile, uploaded, task:" task
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
View file @
494295c0
...
...
@@ -20,16 +20,16 @@ import Reactix.DOM.HTML as H
import Toestand as T
import URI.Extra.QueryPairs as QP
-- import Web.File.Blob (Blob)
import Web.File.FileReader.Aff (readAsDataURL
, readAsText
)
import Web.File.FileReader.Aff (readAsDataURL)
import Gargantext.Prelude
import Gargantext.Components.Forest.Tree.Node.Action (Action(..), Props)
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileBlob(..))
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileBlob(..)
, readUFBAsText
)
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, formChoiceSafe, panel)
import Gargantext.Components.Lang (Lang(..))
import Gargantext.Routes as GR
import Gargantext.Sessions (Session, postWwwUrlencoded)
import Gargantext.Sessions (Session, postWwwUrlencoded
, post
)
import Gargantext.Types (NodeType(..), ID)
import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2
...
...
@@ -79,7 +79,6 @@ instance Eq DroppedFile where
type FileHash = String
type UploadFile =
{ blob :: UploadFileBlob
, name :: String
...
...
@@ -203,7 +202,7 @@ uploadButtonCpt = here.component "uploadButton" cpt
Arbitrary ->
dispatch $ UploadArbitraryFile (Just name) blob
_ -> do
contents <- readAsText blob
contents <- read
UFB
AsText blob
dispatch $ UploadFile nodeType fileType' (Just name) contents
liftEffect $ do
T.write_ Nothing mFile
...
...
@@ -289,7 +288,9 @@ fileTypeViewCpt = here.component "fileTypeView" cpt
, type: "button"
, on: {click: \_ -> do
T.write_ Nothing droppedFile
launchAff $ dispatch $ UploadFile nodeType ft Nothing blob
launchAff $ do
contents <- readUFBAsText blob
dispatch $ UploadFile nodeType ft Nothing contents
}
} [H.text "Upload"]
Nothing ->
...
...
@@ -316,22 +317,26 @@ uploadFile :: Session
-> FileType
-> {contents :: String, mName :: Maybe String}
-> Aff GT.AsyncTaskWithType
uploadFile session NodeList id fileType { mName, contents } = do
let url = GR.NodeAPI NodeList (Just id) $ GT.asyncTaskTypePath GT.ListUpload
-- { input: { data: ..., filetype: "JSON", name: "..." } }
let body = { input: { data: contents
, filetype: "JSON"
, name: fromMaybe "" mName } }
task <- post session url body
pure $ GT.AsyncTaskWithType { task, typ: GT.Form }
uploadFile session nodeType id fileType { mName, contents } = do
-- contents <- readAsText blob
task <- postWwwUrlencoded session p
(bodyParams contents)
task <- postWwwUrlencoded session p
bodyParams
pure $ GT.AsyncTaskWithType {task, typ: GT.Form}
--postMultipartFormData session p fileContents
where
p = case nodeType of
Corpus -> GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.Form
Annuaire -> GR.NodeAPI nodeType (Just id) "annuaire"
NodeList -> GR.NodeAPI nodeType (Just id) $ GT.asyncTaskTypePath GT.ListUpload
_ -> GR.NodeAPI nodeType (Just id) ""
-- { input: { data: ..., filetype: "JSON", name: "..." } }
bodyParams c = case nodeType of
NodeList -> []
_ -> [ Tuple "_wf_data" (Just c)
bodyParams = [ Tuple "_wf_data" (Just contents)
, Tuple "_wf_filetype" (Just $ show fileType)
, Tuple "_wf_name" mName
]
...
...
@@ -454,7 +459,7 @@ uploadTermButtonCpt = here.component "uploadTermButton" cpt
onClick mFile' uploadType' e = do
let {name, blob} = unsafePartial $ fromJust mFile'
void $ launchAff do
contents <- readAsText blob
contents <- read
UFB
AsText blob
_ <- dispatch $ UploadFile nodeType uploadType' (Just name) contents
liftEffect $ do
T.write_ Nothing mFile
src/Gargantext/Components/Forest/Tree/Node/Action/Upload/Types.purs
View file @
494295c0
...
...
@@ -4,7 +4,9 @@ import Data.Generic.Rep (class Generic)
import Data.Eq.Generic (genericEq)
import Data.Show.Generic (genericShow)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import Web.File.Blob (Blob, size)
import Web.File.FileReader.Aff (readAsText)
import Gargantext.Prelude
...
...
@@ -31,3 +33,6 @@ newtype UploadFileBlob = UploadFileBlob Blob
derive instance Generic UploadFileBlob _
instance Eq UploadFileBlob where
eq (UploadFileBlob b1) (UploadFileBlob b2) = eq (size b1) (size b2)
readUFBAsText :: UploadFileBlob -> Aff String
readUFBAsText (UploadFileBlob b) = readAsText b
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