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
05e18035
Commit
05e18035
authored
Feb 19, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[forest] custom terms upload for NodeList
parent
20d691d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
17 deletions
+87
-17
Tree.purs
src/Gargantext/Components/Forest/Tree.purs
+1
-1
Upload.purs
...Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
+81
-12
Box.purs
src/Gargantext/Components/Forest/Tree/Node/Box.purs
+5
-4
No files found.
src/Gargantext/Components/Forest/Tree.purs
View file @
05e18035
src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
View file @
05e18035
...
@@ -7,6 +7,7 @@ import Data.Tuple (Tuple(..))
...
@@ -7,6 +7,7 @@ import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff)
import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Effect (Effect)
import Partial.Unsafe (unsafePartial)
import Partial.Unsafe (unsafePartial)
import React.SyntheticEvent as E
import React.SyntheticEvent as E
import Reactix as R
import Reactix as R
...
@@ -23,19 +24,20 @@ import Gargantext.Utils (id)
...
@@ -23,19 +24,20 @@ import Gargantext.Utils (id)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
type Props =
type Props =
( id :: Int
( dispatch :: Action -> Aff Unit
, id :: Int
, nodeType :: GT.NodeType
, nodeType :: GT.NodeType
, session :: Session
, session :: Session
)
)
uploadFileView ::
(Action -> Aff Unit) ->
Record Props -> R.Element
uploadFileView :: Record Props -> R.Element
uploadFileView
d props = R.createElement (uploadFileViewCpt d)
props []
uploadFileView
props = R.createElement uploadFileViewCpt
props []
uploadFileViewCpt ::
(Action -> Aff Unit) ->
R.Component Props
uploadFileViewCpt :: R.Component Props
uploadFileViewCpt
d
= R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
uploadFileViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
where
where
cpt {id, nodeType} _ = do
cpt {
dispatch: d,
id, nodeType} _ = do
mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing
mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing
fileType :: R.State FileType <- R.useState' CSV
fileType :: R.State FileType <- R.useState' CSV
lang :: R.State (Maybe Lang) <- R.useState' (Just EN)
lang :: R.State (Maybe Lang) <- R.useState' (Just EN)
...
@@ -75,6 +77,7 @@ uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
...
@@ -75,6 +77,7 @@ uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
renderOptionLang :: Lang -> R.Element
renderOptionLang :: Lang -> R.Element
renderOptionLang opt = H.option {} [ H.text $ show opt ]
renderOptionLang opt = H.option {} [ H.text $ show opt ]
onChangeContents :: forall e. R.State (Maybe UploadFileContents) -> E.SyntheticEvent_ e -> Effect Unit
onChangeContents (mContents /\ setMContents) e = do
onChangeContents (mContents /\ setMContents) e = do
blob <- R2.inputFileBlob e
blob <- R2.inputFileBlob e
E.preventDefault e
E.preventDefault e
...
@@ -84,6 +87,7 @@ uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
...
@@ -84,6 +87,7 @@ uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
liftEffect $ do
liftEffect $ do
setMContents $ const $ Just $ UploadFileContents contents
setMContents $ const $ Just $ UploadFileContents contents
onChangeFileType :: forall e. R.State FileType -> e -> Effect Unit
onChangeFileType (fileType /\ setFileType) e = do
onChangeFileType (fileType /\ setFileType) e = do
setFileType $ const
setFileType $ const
$ unsafePartial
$ unsafePartial
...
@@ -91,6 +95,7 @@ uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
...
@@ -91,6 +95,7 @@ uploadFileViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadFileView" cpt
$ readFileType
$ readFileType
$ R2.unsafeEventValue e
$ R2.unsafeEventValue e
onChangeLang :: forall e. R.State (Maybe Lang) -> e -> Effect Unit
onChangeLang (lang /\ setLang) e = do
onChangeLang (lang /\ setLang) e = do
setLang $ const
setLang $ const
$ unsafePartial
$ unsafePartial
...
@@ -235,11 +240,75 @@ uploadFile session nodeType id fileType (UploadFileContents fileContents) = do
...
@@ -235,11 +240,75 @@ uploadFile session nodeType id fileType (UploadFileContents fileContents) = do
, Tuple "_wf_filetype" (Just $ show fileType)
, Tuple "_wf_filetype" (Just $ show fileType)
]
]
uploadTermListView :: (Action -> Aff Unit) -> Record Props -> R.Element
uploadTermListView :: Record Props -> R.Element
uploadTermListView d props = R.createElement (uploadFileViewCpt d) props []
uploadTermListView props = R.createElement uploadTermListViewCpt props []
uploadTermListViewCpt :: R.Component Props
uploadTermListViewCpt = R.hooksComponent "G.C.F.T.N.A.U.UploadTermListView" cpt
where
cpt {dispatch, id, nodeType} _ = do
mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing
pure $ H.div {} [
H.div {} [ H.text "Upload file!" ]
, H.div {} [ H.input { type: "file"
, placeholder: "Choose file"
, on: {change: onChangeContents mContents}
}
]
, H.div {} [ uploadTermButton { dispatch, id, mContents, nodeType } ]
]
onChangeContents :: forall e. R.State (Maybe UploadFileContents) -> E.SyntheticEvent_ e -> Effect Unit
onChangeContents (mContents /\ setMContents) e = do
blob <- R2.inputFileBlob e
E.preventDefault e
E.stopPropagation e
void $ launchAff do
contents <- readAsText blob
liftEffect $ do
setMContents $ const $ Just $ UploadFileContents contents
onChangeFileType (fileType /\ setFileType) e = do
setFileType $ const
$ unsafePartial
$ fromJust
$ readFileType
$ R2.unsafeEventValue e
onChangeLang (lang /\ setLang) e = do
setLang $ const
$ unsafePartial
$ readLang
$ R2.unsafeEventValue e
type UploadTermButtonProps =
(
dispatch :: Action -> Aff Unit
, id :: Int
, mContents :: R.State (Maybe UploadFileContents)
, nodeType :: GT.NodeType
)
uploadTermButton :: Record UploadTermButtonProps -> R.Element
uploadTermButton props = R.createElement uploadTermButtonCpt props []
uploadTerm
ListViewCpt :: (Action -> Aff Unit) -> R.Component
Props
uploadTerm
ButtonCpt :: R.Component UploadTermButton
Props
uploadTerm
ListViewCpt d = R.hooksComponent "G.C.F.T.N.A.U.UploadTermListView
" cpt
uploadTerm
ButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadTermButton
" cpt
where
where
cpt {id, nodeType} _ = do
cpt {dispatch, id, mContents: (mContents /\ setMContents), nodeType} _ = do
pure $ H.div {} [ H.text "Upload term list" ]
pure $ H.button {className: "btn btn-primary", disabled, on: {click: onClick}} [ H.text "Upload" ]
where
disabled = case mContents of
Nothing -> "1"
Just _ -> ""
onClick e = do
let contents = unsafePartial $ fromJust mContents
void $ launchAff do
_ <- dispatch $ UploadFile nodeType CSV contents
liftEffect $ do
setMContents $ const $ Nothing
src/Gargantext/Components/Forest/Tree/Node/Box.purs
View file @
05e18035
...
@@ -4,6 +4,7 @@ import Data.Array as A
...
@@ -4,6 +4,7 @@ import Data.Array as A
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..), snd)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff, launchAff, launchAff_)
import Effect.Aff (Aff, launchAff, launchAff_)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
...
@@ -411,10 +412,10 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
...
@@ -411,10 +412,10 @@ panelActionCpt = R.hooksComponent "G.C.F.T.N.B.panelAction" cpt
cpt {action: Link _} _ = do
cpt {action: Link _} _ = do
pure $ fragmentPT "Soon, you will be able to link the corpus with your Annuaire (and reciprocally)."
pure $ fragmentPT "Soon, you will be able to link the corpus with your Annuaire (and reciprocally)."
cpt {action: Upload, dispatch
: d
, id, nodeType: GT.NodeList, session} _ = do
cpt {action: Upload, dispatch, id, nodeType: GT.NodeList, session} _ = do
pure $ uploadTermListView
d {
id, nodeType: GT.NodeList, session}
pure $ uploadTermListView
{dispatch,
id, nodeType: GT.NodeList, session}
cpt {action: Upload, dispatch
: d
, id, nodeType, session} _ = do
cpt {action: Upload, dispatch, id, nodeType, session} _ = do
pure $ uploadFileView
d {
id, nodeType, session}
pure $ uploadFileView
{dispatch,
id, nodeType, session}
cpt {action: Download} _ = do
cpt {action: Download} _ = do
pure $ fragmentPT "Soon, you will be able to dowload your file here"
pure $ fragmentPT "Soon, you will be able to dowload your file here"
cpt props@{action: SearchBox, search, session} _ = do
cpt props@{action: SearchBox, search, session} _ = do
...
...
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