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
df5c9252
Commit
df5c9252
authored
Jan 23, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CodeEditor] support corpus hypertext fields with markdown/json etc
parent
5d8de4c3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
150 additions
and
60 deletions
+150
-60
App.purs
src/Gargantext/Components/App.purs
+1
-1
Corpus.purs
src/Gargantext/Components/Nodes/Corpus.purs
+56
-56
Types.purs
src/Gargantext/Components/Nodes/Corpus/Types.purs
+88
-0
Lists.purs
src/Gargantext/Components/Nodes/Lists.purs
+2
-1
Tabs.purs
src/Gargantext/Components/Nodes/Lists/Tabs.purs
+1
-1
Texts.purs
src/Gargantext/Components/Nodes/Texts.purs
+2
-1
No files found.
src/Gargantext/Components/App.purs
View file @
df5c9252
...
@@ -57,7 +57,7 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where
...
@@ -57,7 +57,7 @@ appCpt = R.hooksComponent "G.C.App.app" cpt where
Home -> forested $ homeLayout EN
Home -> forested $ homeLayout EN
Login -> login { sessions, backends, visible: showLogin }
Login -> login { sessions, backends, visible: showLogin }
Folder sid _ -> withSession sid $ \_ -> forested (folder {})
Folder sid _ -> withSession sid $ \_ -> forested (folder {})
Corpus sid nodeId -> withSession sid $ \
_ -> forested $ corpusLayout { nodeId
}
Corpus sid nodeId -> withSession sid $ \
session -> forested $ corpusLayout { nodeId, session
}
Texts sid nodeId -> withSession sid $ \session -> forested $ textsLayout { nodeId, session, frontends }
Texts sid nodeId -> withSession sid $ \session -> forested $ textsLayout { nodeId, session, frontends }
Lists sid nodeId -> withSession sid $ \session -> forested $ listsLayout { nodeId, session }
Lists sid nodeId -> withSession sid $ \session -> forested $ listsLayout { nodeId, session }
Dashboard sid _nodeId -> withSession sid $ \session -> forested $ dashboardLayout {}
Dashboard sid _nodeId -> withSession sid $ \session -> forested $ dashboardLayout {}
...
...
src/Gargantext/Components/Nodes/Corpus.purs
View file @
df5c9252
module Gargantext.Components.Nodes.Corpus where
module Gargantext.Components.Nodes.Corpus where
import Prelude ((<<<))
import Data.Argonaut (class DecodeJson, encodeJson)
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?))
import Data.Array (head)
import Data.Array (head)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log2)
...
@@ -11,78 +10,79 @@ import Reactix as R
...
@@ -11,78 +10,79 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Nodes.Corpus.Types
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(NodeAPI, Children))
import Gargantext.Routes (SessionRoute(NodeAPI, Children))
import Gargantext.Sessions (Session, get)
import Gargantext.Sessions (Session, get)
import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Utils.Reactix as R2
type Props = ( nodeId :: Int )
type Props = (
nodeId :: Int
, session :: Session
)
corpusLayout :: Record Props -> R.Element
corpusLayout :: Record Props -> R.Element
corpusLayout props = R.createElement corpusLayoutCpt props []
corpusLayout props = R.createElement corpusLayoutCpt props []
corpusLayoutCpt :: R.Component Props
corpusLayoutCpt :: R.Component Props
corpusLayoutCpt = R.hooksComponent "G.P.Corpus.corpusLayout" cpt
corpusLayoutCpt = R.hooksComponent "G.C.N.C.corpusLayout" cpt
where
cpt props@{nodeId, session} _ =
useLoader props loadCorpus' $
\corpus -> corpusLayoutView {corpus, nodeId, session}
type ViewProps = (
corpus :: NodePoly CorpusHyperdata
| Props
)
corpusLayoutView :: Record ViewProps -> R.Element
corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
corpusLayoutViewCpt :: R.Component ViewProps
corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
where
where
cpt {
nodeId
} _ = do
cpt {
corpus: (NodePoly {hyperdata: CorpusHyperdata {fields}}), nodeId, session
} _ = do
pure $ H.div {}
pure $ H.div {}
[
(corpusFieldCodeEditor {nodeId, session} <$> fields)
CE.codeEditor {code, defaultCodeType: CE.Markdown, onChange}
--H.iframe { src: gargMd , width: "100%", height: "100%", style: {"border-style": "none"}} []
--H.iframe { src: gargMd , width: "100%", height: "100%", style: {"border-style": "none"}} []
]
--gargMd = "https://hackmd.iscpif.fr/g9Aah4iwQtCayIzsKQjA0Q#"
--gargMd = "https://hackmd.iscpif.fr/g9Aah4iwQtCayIzsKQjA0Q#"
code = "# Hello world\n\n## subtitle\n\n- item 1\n- item 2\n\n1. num 1\n2. num 2\n\n[purescript link](https://purescript.org)"
onChange c = do
log2 "[corpusLayoutCpt] c" c
newtype CorpusInfo =
corpusFieldCodeEditor :: Record LoadProps -> CorpusField CorpusFieldType -> R.Element
CorpusInfo
corpusFieldCodeEditor p (CorpusField {name, typ}) =
{ title :: String
H.div { className: "row panel panel-default" } [
, desc :: String
H.div { className: "panel-heading" } [ H.text name ]
, query :: String
, H.div { className: "panel-body" } [
, authors :: String
corpusFieldCodeEditor' typ
, chart :: (Maybe (Array Number))
]
, totalRecords :: Int }
]
corpusFieldCodeEditor' :: CorpusFieldType -> R.Element
hyperdataDefault :: CorpusInfo
corpusFieldCodeEditor' (Markdown {text}) =
hyperdataDefault =
CE.codeEditor {code: text, defaultCodeType: CE.Markdown, onChange}
CorpusInfo
where
{ title : "Default title"
onChange c = do
, desc : " Default desc"
log2 "[corpusFieldCodeEditor'] Markdown c" c
, query : " Default Query"
corpusFieldCodeEditor' (JSON j) = do
, authors : " Author(s): default"
CE.codeEditor {code, defaultCodeType: CE.JSON, onChange}
, chart : Nothing
where
, totalRecords : 0 }
code = R2.stringify (encodeJson j) 2
onChange c = do
corpusInfoDefault :: NodePoly CorpusInfo
log2 "[corpusFieldCodeEditor'] JSON c" c
corpusInfoDefault =
NodePoly
{ id : 0
, typename : 0
, userId : 0
, parentId : 0
, name : "Default name"
, date : " Default date"
, hyperdata : hyperdataDefault }
instance decodeCorpusInfo :: DecodeJson CorpusInfo where
type LoadProps = (
decodeJson json = do
nodeId :: Int
obj <- decodeJson json
, session :: Session
title <- obj .: "title"
)
desc <- obj .: "desc"
query <- obj .: "query"
authors <- obj .: "authors"
chart <- obj .:? "chart"
let totalRecords = 47361 -- TODO
pure $ CorpusInfo {title, desc, query, authors, chart, totalRecords}
type CorpusData = { corpusId :: Int
loadCorpus' :: Record LoadProps -> Aff (NodePoly CorpusHyperdata)
, corpusNode :: NodePoly CorpusInfo
loadCorpus' {nodeId, session} = get session $ NodeAPI Corpus (Just nodeId) ""
, defaultListId :: Int}
loadCorpus ::
{ session :: Session, nodeId :: Int }
-> Aff CorpusData
loadCorpus ::
Record LoadProps
-> Aff CorpusData
loadCorpus {
session, nodeId: listId
} = do
loadCorpus {
nodeId, session
} = do
-- fetch corpus via lists parentId
-- fetch corpus via lists parentId
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get session nodePolyRoute
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get session nodePolyRoute
corpusNode <- get session $ corpusNodeRoute corpusId ""
corpusNode <- get session $ corpusNodeRoute corpusId ""
...
@@ -93,6 +93,6 @@ loadCorpus {session, nodeId: listId} = do
...
@@ -93,6 +93,6 @@ loadCorpus {session, nodeId: listId} = do
Nothing ->
Nothing ->
throwError $ error "Missing default list"
throwError $ error "Missing default list"
where
where
nodePolyRoute = NodeAPI Corpus (Just
list
Id) ""
nodePolyRoute = NodeAPI Corpus (Just
node
Id) ""
corpusNodeRoute = NodeAPI Corpus <<< Just
corpusNodeRoute = NodeAPI Corpus <<< Just
defaultListIdsRoute = Children NodeList 0 1 Nothing <<< Just
defaultListIdsRoute = Children NodeList 0 1 Nothing <<< Just
src/Gargantext/Components/Nodes/Corpus/Types.purs
0 → 100644
View file @
df5c9252
module Gargantext.Components.Nodes.Corpus.Types where
import Data.Argonaut (class DecodeJson, decodeJson, (.:), (.:?))
import Data.Either (Either(..))
import Data.Maybe (Maybe)
import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly)
type Author = String
type Description = String
type Query = String
type Tag = String
type Title = String
type MarkdownText = String
newtype CorpusHyperdata =
CorpusHyperdata
{
fields :: Array (CorpusField CorpusFieldType)
}
instance decodeCorpusHyperdata :: DecodeJson CorpusHyperdata where
decodeJson json = do
obj <- decodeJson json
fields <- obj .: "fields"
pure $ CorpusHyperdata {fields}
newtype CorpusField a = CorpusField {
name :: String
, typ :: a
}
data CorpusFieldType = JSON {
authors :: Author
, desc :: Description
, query :: Query
, tag :: Tag
, title :: Title
}
| Markdown {
tag :: Tag
, text :: MarkdownText
}
instance decodeCorpusField :: DecodeJson (CorpusField CorpusFieldType) where
decodeJson json = do
obj <- decodeJson json
name <- obj .: "name"
type_ <- obj .: "type"
data_ <- obj .: "data"
typ <- case type_ of
"JSON" -> do
authors <- data_ .: "authors"
desc <- data_ .: "desc"
query <- data_ .: "query"
tag <- data_ .: "tag"
title <- data_ .: "title"
pure $ JSON {authors, desc, query, tag, title}
"Markdown" -> do
tag <- data_ .: "tag"
text <- data_ .: "text"
pure $ Markdown {tag, text}
_ -> Left $ "Unsupported 'type' " <> type_
pure $ CorpusField {name, typ}
newtype CorpusInfo =
CorpusInfo
{ title :: String
, desc :: String
, query :: String
, authors :: String
, chart :: (Maybe (Array Number))
, totalRecords :: Int }
instance decodeCorpusInfo :: DecodeJson CorpusInfo where
decodeJson json = do
obj <- decodeJson json
title <- obj .: "title"
desc <- obj .: "desc"
query <- obj .: "query"
authors <- obj .: "authors"
chart <- obj .:? "chart"
let totalRecords = 47361 -- TODO
pure $ CorpusInfo {title, desc, query, authors, chart, totalRecords}
type CorpusData = { corpusId :: Int
, corpusNode :: NodePoly CorpusInfo
, defaultListId :: Int}
src/Gargantext/Components/Nodes/Lists.purs
View file @
df5c9252
...
@@ -3,7 +3,8 @@ module Gargantext.Components.Nodes.Lists where
...
@@ -3,7 +3,8 @@ module Gargantext.Components.Nodes.Lists where
import Reactix as R
import Reactix as R
--------------------------------------------------------
--------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.Nodes.Corpus (CorpusInfo(..), loadCorpus)
import Gargantext.Components.Nodes.Corpus (loadCorpus)
import Gargantext.Components.Nodes.Corpus.Types (CorpusInfo(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Table as Table
import Gargantext.Components.Table as Table
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
...
...
src/Gargantext/Components/Nodes/Lists/Tabs.purs
View file @
df5c9252
...
@@ -6,7 +6,7 @@ import Data.Tuple.Nested ((/\))
...
@@ -6,7 +6,7 @@ import Data.Tuple.Nested ((/\))
import Reactix as R
import Reactix as R
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.NgramsTable as NT
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Nodes.Corpus (CorpusData)
import Gargantext.Components.Nodes.Corpus
.Types
(CorpusData)
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
import Gargantext.Components.Nodes.Corpus.Chart.Pie (pie, bar)
import Gargantext.Components.Nodes.Corpus.Chart.Pie (pie, bar)
import Gargantext.Components.Nodes.Corpus.Chart.Tree (tree)
import Gargantext.Components.Nodes.Corpus.Chart.Tree (tree)
...
...
src/Gargantext/Components/Nodes/Texts.purs
View file @
df5c9252
...
@@ -12,7 +12,8 @@ import Reactix.DOM.HTML as H
...
@@ -12,7 +12,8 @@ import Reactix.DOM.HTML as H
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable as DT
import Gargantext.Components.Loader (loader)
import Gargantext.Components.Loader (loader)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus (CorpusData, CorpusInfo(..), loadCorpus)
import Gargantext.Components.Nodes.Corpus (loadCorpus)
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, CorpusInfo(..))
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table
import Gargantext.Components.Table as Table
...
...
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