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
e56e5cce
Commit
e56e5cce
authored
Feb 20, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-list-upload' into dev-merge
parents
2f839b7e
9c3c8b11
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
314 additions
and
111 deletions
+314
-111
Login.css
dist/styles/Login.css
+11
-0
Login.sass
dist/styles/Login.sass
+11
-0
Tree.purs
src/Gargantext/Components/Forest/Tree.purs
+1
-1
Node.purs
src/Gargantext/Components/Forest/Tree/Node.purs
+5
-0
Upload.purs
...Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
+135
-12
Box.purs
src/Gargantext/Components/Forest/Tree/Node/Box.purs
+151
-98
No files found.
dist/styles/Login.css
View file @
e56e5cce
...
...
@@ -211,4 +211,15 @@ a:focus, a:hover {
cursor
:
pointer
;
}
.copy-from-corpus
.tree
.node
{
padding-left
:
10px
;
}
.copy-from-corpus
.tree
.node
.name.clickable
{
color
:
#337ab7
;
cursor
:
pointer
;
}
.copy-from-corpus
.tree
.node
.name.clickable
:hover
{
text-decoration
:
underline
;
}
/*# sourceMappingURL=Login.css.map */
dist/styles/Login.sass
View file @
e56e5cce
...
...
@@ -197,3 +197,14 @@ li
a
:focus
,
a
:hover
cursor
:
pointer
.copy-from-corpus
.tree
.node
padding-left
:
10px
.name
&
.clickable
color
:
#337ab7
cursor
:
pointer
&
:hover
text-decoration
:
underline
src/Gargantext/Components/Forest/Tree.purs
View file @
e56e5cce
src/Gargantext/Components/Forest/Tree/Node.purs
View file @
e56e5cce
...
...
@@ -22,6 +22,7 @@ data NodeAction = Documentation NodeType
| Move | Clone | Delete
| Share | Link NodeType
| Add (Array NodeType)
| CopyFromCorpus
instance eqNodeAction :: Eq NodeAction where
...
...
@@ -36,6 +37,7 @@ instance eqNodeAction :: Eq NodeAction where
eq Share Share = true
eq (Link x) (Link y) = true && (x == y)
eq (Add x) (Add y) = true && (x == y)
eq CopyFromCorpus CopyFromCorpus = true
eq _ _ = false
instance showNodeAction :: Show NodeAction where
...
...
@@ -50,6 +52,7 @@ instance showNodeAction :: Show NodeAction where
show Share = "Share"
show (Link x) = "Link to " <> show x
show (Add xs) = foldl (\a b -> a <> show b) "Add " xs
show CopyFromCorpus = "Copy from corpus"
glyphiconNodeAction :: NodeAction -> String
...
...
@@ -60,6 +63,7 @@ glyphiconNodeAction SearchBox = "search"
glyphiconNodeAction Upload = "upload"
glyphiconNodeAction (Link _) = "transfer"
glyphiconNodeAction Download = "download"
glyphiconNodeAction CopyFromCorpus = "random"
glyphiconNodeAction _ = ""
...
...
@@ -183,6 +187,7 @@ settingsBox NodeList = SettingsBox {
, edit : false
, doc : Documentation NodeList
, buttons : [ Upload
, CopyFromCorpus
, Download
, Delete
]
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
View file @
e56e5cce
module Gargantext.Components.Forest.Tree.Node.Action.Upload where
import
Prelude (class Show, Unit, bind, const, discard, map, pure, show, void, ($))
import
Data.Array as A
import Data.Maybe (Maybe(..), fromJust)
import Data.Newtype (class Newtype)
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..)
, fst, snd
)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect)
import Effect (Effect)
import Partial.Unsafe (unsafePartial)
import React.SyntheticEvent as E
import Reactix as R
...
...
@@ -14,36 +16,38 @@ import Reactix.DOM.HTML as H
import URI.Extra.QueryPairs as QP
import Web.File.FileReader.Aff (readAsText)
import Gargantext.Prelude
import Gargantext.Components.Data.Lang (readLang, Lang(..))
import Gargantext.Components.Forest.Tree.Node.Action
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as GR
import Gargantext.Sessions (Session
, postWwwUrlencoded
)
import Gargantext.Sessions (Session
(..), postWwwUrlencoded, get
)
import Gargantext.Types as GT
import Gargantext.Utils (id)
import Gargantext.Utils.Reactix as R2
type Props =
( id :: Int
( dispatch :: Action -> Aff Unit
, id :: Int
, nodeType :: GT.NodeType
, session :: Session
)
uploadFileView ::
(Action -> Aff Unit) ->
Record Props -> R.Element
uploadFileView
d props = R.createElement (uploadFileViewCpt d)
props []
uploadFileView :: Record Props -> R.Element
uploadFileView
props = R.createElement uploadFileViewCpt
props []
uploadFileViewCpt ::
(Action -> Aff Unit) ->
R.Component Props
uploadFileViewCpt
d = R.hooksComponent "
UploadFileView" cpt
uploadFileViewCpt :: R.Component Props
uploadFileViewCpt
= R.hooksComponent "G.C.F.T.N.A.U.
UploadFileView" cpt
where
cpt {id, nodeType} _ = do
cpt {
dispatch: d,
id, nodeType} _ = do
mContents :: R.State (Maybe UploadFileContents) <- R.useState' Nothing
fileType :: R.State FileType <- R.useState' CSV
lang :: R.State (Maybe Lang) <- R.useState' (Just EN)
pure $ H.div {} [
H.div {} [ H.text "Upload file!" ]
, H.div {} [ H.input { type: "file"
H.div {} [ H.input { type: "file"
, placeholder: "Choose file"
, on: {change: onChangeContents mContents}
}
...
...
@@ -75,6 +79,7 @@ uploadFileViewCpt d = R.hooksComponent "UploadFileView" cpt
renderOptionLang :: Lang -> R.Element
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
blob <- R2.inputFileBlob e
E.preventDefault e
...
...
@@ -84,6 +89,7 @@ uploadFileViewCpt d = R.hooksComponent "UploadFileView" cpt
liftEffect $ do
setMContents $ const $ Just $ UploadFileContents contents
onChangeFileType :: forall e. R.State FileType -> e -> Effect Unit
onChangeFileType (fileType /\ setFileType) e = do
setFileType $ const
$ unsafePartial
...
...
@@ -91,6 +97,7 @@ uploadFileViewCpt d = R.hooksComponent "UploadFileView" cpt
$ readFileType
$ R2.unsafeEventValue e
onChangeLang :: forall e. R.State (Maybe Lang) -> e -> Effect Unit
onChangeLang (lang /\ setLang) e = do
setLang $ const
$ unsafePartial
...
...
@@ -234,3 +241,119 @@ uploadFile session nodeType id fileType (UploadFileContents fileContents) = do
Tuple "_wf_data" (Just fileContents)
, Tuple "_wf_filetype" (Just $ show fileType)
]
uploadTermListView :: Record Props -> R.Element
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.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
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 []
uploadTermButtonCpt :: R.Component UploadTermButtonProps
uploadTermButtonCpt = R.hooksComponent "G.C.F.T.N.A.U.uploadTermButton" cpt
where
cpt {dispatch, id, mContents: (mContents /\ setMContents), nodeType} _ = do
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
copyFromCorpusView :: Record Props -> R.Element
copyFromCorpusView props = R.createElement copyFromCorpusViewCpt props []
copyFromCorpusViewCpt :: R.Component Props
copyFromCorpusViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusView" cpt
where
cpt {dispatch, id, nodeType, session} _ = do
useLoader session loadCorporaTree $
\tree ->
copyFromCorpusViewLoaded {dispatch, id, nodeType, session, tree}
type CorpusTreeProps =
(
tree :: FTree
| Props
)
copyFromCorpusViewLoaded :: Record CorpusTreeProps -> R.Element
copyFromCorpusViewLoaded props = R.createElement copyFromCorpusViewLoadedCpt props []
copyFromCorpusViewLoadedCpt :: R.Component CorpusTreeProps
copyFromCorpusViewLoadedCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusViewLoadedCpt" cpt
where
cpt p@{dispatch, id, nodeType, session, tree} _ = do
pure $ H.div { className: "copy-from-corpus" } [
H.div { className: "tree" } [copyFromCorpusTreeView p]
]
copyFromCorpusTreeView :: Record CorpusTreeProps -> R.Element
copyFromCorpusTreeView props = R.createElement copyFromCorpusTreeViewCpt props []
copyFromCorpusTreeViewCpt :: R.Component CorpusTreeProps
copyFromCorpusTreeViewCpt = R.hooksComponent "G.C.F.T.N.A.U.copyFromCorpusTreeViewCpt" cpt
where
cpt p@{id, tree: NTree (LNode { id: sourceId, name, nodeType }) ary} _ = do
pure $ H.div { className: "node" } ([
H.span { className: "name " <> clickable
, on: { click: onClick }
} [ H.text name ]
] <> children)
where
children = map (\c -> copyFromCorpusTreeView (p { tree = c })) ary
validNodeType = (A.elem nodeType [GT.Corpus, GT.NodeList]) && (id /= sourceId)
clickable = if validNodeType then "clickable" else ""
onClick _ = case validNodeType of
false -> pure unit
true -> do
log2 "[copyFromCorpusTreeViewCpt] issue copy into" id
log2 "[copyFromCorpusTreeViewCpt] issue copy from" sourceId
loadCorporaTree :: Session -> Aff FTree
loadCorporaTree session = getCorporaTree session treeId
where
Session { treeId } = session
getCorporaTree :: Session -> Int -> Aff FTree
getCorporaTree session treeId = get session $ GR.NodeAPI GT.Tree (Just treeId) "?type=NodeList&type=NodeCorpus"
src/Gargantext/Components/Forest/Tree/Node/Box.purs
View file @
e56e5cce
This diff is collapsed.
Click to expand it.
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