Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
199
Issues
199
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
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
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
Pipeline
#942
failed with stage
Changes
3
Pipelines
1
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
...
@@ -9,26 +9,33 @@ Portability : POSIX
-}
-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
module
Gargantext.API.Public
module
Gargantext.API.Public
where
where
import
Control.Lens
((
^?
),
(
^.
),
_Just
)
import
Data.Maybe
(
maybe
,
catMaybes
)
import
Data.Tuple
(
snd
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Data.List
(
replicate
)
import
Data.List
(
replicate
,
null
)
import
Data.Aeson
import
Data.Aeson
import
Data.Swagger
import
Data.Swagger
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.Database.Query.Table.Node.Error
(
HasNodeError
(
..
))
import
Gargantext.Database.Prelude
import
Gargantext.Database.Prelude
-- import Gargantext.Database.Admin.Types.Node
import
Gargantext.Database.Admin.Types.Node
-- import Gargantext.Database.Query.Table.NodeNode (selectPublicNodes)
import
Gargantext.Database.Query.Table.NodeNode
(
selectPublicNodes
)
-- import Gargantext.Database.Schema.Node (NodePoly(..))
import
Gargantext.Core.Utils.DateUtils
(
utc2year
)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Schema.Node
-- (NodePoly(..))
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Servant
import
Servant
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
import
Test.QuickCheck.Arbitrary
import
qualified
Data.Map
as
Map
------------------------------------------------------------------------
------------------------------------------------------------------------
type
API
=
Summary
" Public API"
type
API
=
Summary
" Public API"
...
@@ -36,16 +43,37 @@ type API = Summary " Public API"
...
@@ -36,16 +43,37 @@ type API = Summary " Public API"
api
::
HasNodeError
err
api
::
HasNodeError
err
=>
Cmd
err
[
PublicData
]
=>
Cmd
err
[
PublicData
]
api
=
do
api
=
catMaybes
<$>
map
toPublicData
<$>
filterPublicDatas
<$>
selectPublic
pure
$
replicate
6
defaultPublicData
{-
toPublicData :: (Node HyperdataFolder, Maybe Int) -> Maybe PublicData
selectPublic
::
HasNodeError
err
toPublicData (n, mn) = Just $ PublicData t a i u d db au
=>
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
where
d = _node_date n
hd
=
head
t = _node_name n
$
filter
(
\
(
HyperdataField
cd
_
_
)
->
cd
==
JSON
)
-}
$
n
^.
(
node_hyperdata
.
hc_fields
)
data
PublicData
=
PublicData
data
PublicData
=
PublicData
...
...
src/Gargantext/Database/Admin/Types/Hyperdata.hs
View file @
455311ee
...
@@ -35,7 +35,7 @@ import Gargantext.Viz.Types (Histo(..))
...
@@ -35,7 +35,7 @@ import Gargantext.Viz.Types (Histo(..))
data
CodeType
=
JSON
|
Markdown
|
Haskell
data
CodeType
=
JSON
|
Markdown
|
Haskell
deriving
(
Generic
)
deriving
(
Generic
,
Eq
)
instance
ToJSON
CodeType
instance
ToJSON
CodeType
instance
FromJSON
CodeType
instance
FromJSON
CodeType
instance
ToSchema
CodeType
instance
ToSchema
CodeType
...
@@ -57,6 +57,12 @@ data CorpusField = MarkdownField { _cf_text :: !Text }
...
@@ -57,6 +57,12 @@ data CorpusField = MarkdownField { _cf_text :: !Text }
|
HaskellField
{
_cf_haskell
::
!
Text
}
|
HaskellField
{
_cf_haskell
::
!
Text
}
deriving
(
Generic
)
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
)
$
(
deriveJSON
(
unPrefix
"_cf_"
)
''
C
orpusField
)
$
(
makeLenses
''
C
orpusField
)
$
(
makeLenses
''
C
orpusField
)
...
@@ -194,6 +200,7 @@ $(makeLenses ''HyperdataCorpus)
...
@@ -194,6 +200,7 @@ $(makeLenses ''HyperdataCorpus)
instance
Hyperdata
HyperdataCorpus
instance
Hyperdata
HyperdataCorpus
type
HyperdataFolder
=
HyperdataCorpus
------------------------------------------------------------------------
------------------------------------------------------------------------
data
HyperdataFrame
=
data
HyperdataFrame
=
HyperdataFrame
{
base
::
!
Text
HyperdataFrame
{
base
::
!
Text
...
...
src/Gargantext/Database/Query/Table/NodeNode.hs
View file @
455311ee
...
@@ -154,6 +154,13 @@ joinInCorpus = leftJoin queryNodeTable queryNodeNodeTable cond
...
@@ -154,6 +154,13 @@ joinInCorpus = leftJoin queryNodeTable queryNodeNodeTable cond
cond
::
(
NodeRead
,
NodeNodeRead
)
->
Column
PGBool
cond
::
(
NodeRead
,
NodeNodeRead
)
->
Column
PGBool
cond
(
n
,
nn
)
=
nn
^.
nn_node2_id
.==
(
view
node_id
n
)
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
)
selectPublicNodes
::
(
Hyperdata
a
,
QueryRunnerColumnDefault
PGJsonb
a
)
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
=>
Cmd
err
[(
Node
a
,
Maybe
Int
)]
...
@@ -161,7 +168,7 @@ selectPublicNodes = runOpaQuery (queryWithType NodeFolderPublic)
...
@@ -161,7 +168,7 @@ selectPublicNodes = runOpaQuery (queryWithType NodeFolderPublic)
queryWithType
::
NodeType
->
O
.
Query
(
NodeRead
,
Column
(
Nullable
PGInt4
))
queryWithType
::
NodeType
->
O
.
Query
(
NodeRead
,
Column
(
Nullable
PGInt4
))
queryWithType
nt
=
proc
()
->
do
queryWithType
nt
=
proc
()
->
do
(
n
,
nn
)
<-
join
InCorpus
-<
()
(
n
,
nn
)
<-
join
On1
-<
()
restrict
-<
n
^.
node_typename
.==
(
pgInt4
$
nodeTypeId
nt
)
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