Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-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
Przemyslaw Kaminski
haskell-gargantext
Commits
455311ee
Commit
455311ee
authored
Jul 11, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PUB] backend connected
parent
8f01b456
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
17 deletions
+59
-17
Public.hs
src/Gargantext/API/Public.hs
+42
-14
Hyperdata.hs
src/Gargantext/Database/Admin/Types/Hyperdata.hs
+8
-1
NodeNode.hs
src/Gargantext/Database/Query/Table/NodeNode.hs
+9
-2
No files found.
src/Gargantext/API/Public.hs
View file @
455311ee
...
...
@@ -9,26 +9,33 @@ Portability : POSIX
-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
module
Gargantext.API.Public
where
import
Control.Lens
((
^?
),
(
^.
),
_Just
)
import
Data.Maybe
(
maybe
,
catMaybes
)
import
Data.Tuple
(
snd
)
import
Data.Text
(
Text
)
import
Data.List
(
replicate
)
import
Data.List
(
replicate
,
null
)
import
Data.Aeson
import
Data.Swagger
import
GHC.Generics
(
Generic
)
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.Database.Prelude
-- import Gargantext.Database.Admin.Types.Node
-- import Gargantext.Database.Query.Table.NodeNode (selectPublicNodes)
-- import Gargantext.Database.Schema.Node (NodePoly(..))
import
Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Query.Table.NodeNode
(
selectPublicNodes
)
import
Gargantext.Core.Utils.DateUtils
(
utc2year
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Schema.Node
-- (NodePoly(..))
import
Gargantext.Prelude
import
Servant
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
import
qualified
Data.Map
as
Map
------------------------------------------------------------------------
type
API
=
Summary
" Public API"
...
...
@@ -36,16 +43,37 @@ type API = Summary " Public API"
api
::
HasNodeError
err
=>
Cmd
err
[
PublicData
]
api
=
do
pure
$
replicate
6
defaultPublicData
api
=
catMaybes
<$>
map
toPublicData
<$>
filterPublicDatas
<$>
selectPublic
{-
toPublicData :: (Node HyperdataFolder, Maybe Int) -> Maybe PublicData
toPublicData (n, mn) = Just $ PublicData t a i u d db au
selectPublic
::
HasNodeError
err
=>
Cmd
err
[(
Node
HyperdataFolder
,
Maybe
Int
)]
selectPublic
=
selectPublicNodes
-- | For tests only
-- pure $ replicate 6 defaultPublicData
filterPublicDatas
::
[(
Node
HyperdataFolder
,
Maybe
Int
)]
->
[(
Node
HyperdataFolder
,
[
NodeId
])]
filterPublicDatas
datas
=
map
(
\
(
n
,
mi
)
->
let
mi'
=
NodeId
<$>
mi
in
(
_node_id
n
,
(
n
,
maybe
[]
(
:
[]
)
mi'
))
)
datas
&
Map
.
fromListWith
(
\
(
n1
,
i1
)
(
_n2
,
i2
)
->
(
n1
,
i1
<>
i2
))
&
Map
.
filter
(
not
.
null
.
snd
)
&
Map
.
elems
toPublicData
::
(
Node
HyperdataFolder
,
[
NodeId
])
->
Maybe
PublicData
toPublicData
(
n
,
_mn
)
=
PublicData
<$>
(
hd
^?
(
_Just
.
hf_data
.
cf_title
))
<*>
(
hd
^?
(
_Just
.
hf_data
.
cf_desc
))
<*>
Just
"images/Gargantextuel-212x300.jpg"
<*>
Just
"https://.."
<*>
Just
(
cs
$
show
$
utc2year
(
n
^.
node_date
))
<*>
(
hd
^?
(
_Just
.
hf_data
.
cf_query
))
<*>
(
hd
^?
(
_Just
.
hf_data
.
cf_authors
))
where
d = _node_date n
t = _node_name n
-}
hd
=
head
$
filter
(
\
(
HyperdataField
cd
_
_
)
->
cd
==
JSON
)
$
n
^.
(
node_hyperdata
.
hc_fields
)
data
PublicData
=
PublicData
...
...
src/Gargantext/Database/Admin/Types/Hyperdata.hs
View file @
455311ee
...
...
@@ -35,7 +35,7 @@ import Gargantext.Viz.Types (Histo(..))
data
CodeType
=
JSON
|
Markdown
|
Haskell
deriving
(
Generic
)
deriving
(
Generic
,
Eq
)
instance
ToJSON
CodeType
instance
FromJSON
CodeType
instance
ToSchema
CodeType
...
...
@@ -57,6 +57,12 @@ data CorpusField = MarkdownField { _cf_text :: !Text }
|
HaskellField
{
_cf_haskell
::
!
Text
}
deriving
(
Generic
)
isField
::
CodeType
->
CorpusField
->
Bool
isField
Markdown
(
MarkdownField
_
)
=
True
isField
JSON
(
JsonField
_
_
_
_
)
=
True
isField
Haskell
(
HaskellField
_
)
=
True
isField
_
_
=
False
$
(
deriveJSON
(
unPrefix
"_cf_"
)
''
C
orpusField
)
$
(
makeLenses
''
C
orpusField
)
...
...
@@ -194,6 +200,7 @@ $(makeLenses ''HyperdataCorpus)
instance
Hyperdata
HyperdataCorpus
type
HyperdataFolder
=
HyperdataCorpus
------------------------------------------------------------------------
data
HyperdataFrame
=
HyperdataFrame
{
base
::
!
Text
...
...
src/Gargantext/Database/Query/Table/NodeNode.hs
View file @
455311ee
...
...
@@ -154,6 +154,13 @@ joinInCorpus = leftJoin queryNodeTable queryNodeNodeTable cond
cond
::
(
NodeRead
,
NodeNodeRead
)
->
Column
PGBool
cond
(
n
,
nn
)
=
nn
^.
nn_node2_id
.==
(
view
node_id
n
)
joinOn1
::
O
.
Query
(
NodeRead
,
NodeNodeReadNull
)
joinOn1
=
leftJoin
queryNodeTable
queryNodeNodeTable
cond
where
cond
::
(
NodeRead
,
NodeNodeRead
)
->
Column
PGBool
cond
(
n
,
nn
)
=
nn
^.
nn_node1_id
.==
n
^.
node_id
------------------------------------------------------------------------
selectPublicNodes
::
(
Hyperdata
a
,
QueryRunnerColumnDefault
PGJsonb
a
)
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
...
...
@@ -161,7 +168,7 @@ selectPublicNodes = runOpaQuery (queryWithType NodeFolderPublic)
queryWithType
::
NodeType
->
O
.
Query
(
NodeRead
,
Column
(
Nullable
PGInt4
))
queryWithType
nt
=
proc
()
->
do
(
n
,
nn
)
<-
join
InCorpus
-<
()
(
n
,
nn
)
<-
join
On1
-<
()
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeId
nt
)
returnA
-<
(
n
,
nn
^.
nn_node2_id
)
returnA
-<
(
n
,
nn
^.
nn_node2_id
)
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