2 Module : Gargantext.Viz.Phylo.API
3 Description : Phylo API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 {-# LANGUAGE RankNTypes #-}
15 {-# LANGUAGE DataKinds #-}
16 {-# LANGUAGE NoImplicitPrelude #-}
17 {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
18 {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
19 {-# LANGUAGE TypeOperators #-}
20 {-# LANGUAGE FlexibleContexts #-}
21 {-# LANGUAGE FlexibleInstances #-}
22 {-# LANGUAGE MultiParamTypeClasses #-}
24 module Gargantext.Viz.Phylo.API
27 import Data.String.Conversions
28 --import Control.Monad.Reader (ask)
29 import qualified Data.ByteString as DB
30 import qualified Data.ByteString.Lazy as DBL
32 import Gargantext.API.Types
33 import Gargantext.Database.Types.Node (PhyloId, ListId, CorpusId)
34 import Gargantext.Database.Schema.Node (insertNodes, nodePhyloW, getNodePhylo)
35 import Gargantext.Database.Types.Node -- (NodePhylo(..))
36 import Gargantext.Prelude
37 import Gargantext.Viz.Phylo
38 import Gargantext.Viz.Phylo.Main
39 import Gargantext.Viz.Phylo.Example
40 import Gargantext.Core.Types (TODO(..))
42 import Test.QuickCheck (elements)
43 import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
44 import Web.HttpApiData (parseUrlPiece, readTextData)
45 import Control.Monad.IO.Class (liftIO)
46 import Network.HTTP.Media ((//), (/:))
48 ------------------------------------------------------------------------
49 type PhyloAPI = Summary "Phylo API"
55 phyloAPI :: PhyloId -> UserId -> GargServer PhyloAPI
56 phyloAPI n u = getPhylo n
61 newtype SVG = SVG DB.ByteString
65 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy TODO)
67 instance Show SVG where
70 instance Accept SVG where
71 contentType _ = "SVG" // "image/svg+xml" /: ("charset", "utf-8")
73 instance Show a => MimeRender PlainText a where
74 mimeRender _ val = cs ("" <> show val)
76 instance MimeRender SVG SVG where
77 mimeRender _ (SVG s) = DBL.fromStrict s
79 ------------------------------------------------------------------------
80 type GetPhylo = QueryParam "listId" ListId
81 :> QueryParam "level" Level
82 :> QueryParam "minSizeBranch" MinSizeBranch
83 {- :> QueryParam "filiation" Filiation
84 :> QueryParam "childs" Bool
85 :> QueryParam "depth" Level
86 :> QueryParam "metrics" [Metric]
87 :> QueryParam "periodsInf" Int
88 :> QueryParam "periodsSup" Int
89 :> QueryParam "minNodes" Int
90 :> QueryParam "taggers" [Tagger]
91 :> QueryParam "sort" Sort
92 :> QueryParam "order" Order
93 :> QueryParam "export" ExportMode
94 :> QueryParam "display" DisplayMode
95 :> QueryParam "verbose" Bool
100 -- Add real text processing
101 -- Fix Filter parameters
102 getPhylo :: PhyloId -> GargServer GetPhylo
103 --getPhylo phId _lId l msb _f _b _l' _ms _x _y _z _ts _s _o _e _d _b' = do
104 getPhylo phId _lId l msb = do
105 phNode <- getNodePhylo phId
107 level = maybe 2 identity l
108 branc = maybe 2 identity msb
109 maybePhylo = hyperdataPhylo_data $ _node_hyperdata phNode
111 p <- liftIO $ viewPhylo2Svg $ viewPhylo level branc $ maybe phyloFromQuery identity maybePhylo
113 ------------------------------------------------------------------------
114 type PostPhylo = QueryParam "listId" ListId
115 -- :> ReqBody '[JSON] PhyloQueryBuild
116 :> (Post '[JSON] NodeId)
118 postPhylo :: CorpusId -> UserId -> GargServer PostPhylo
119 postPhylo n userId _lId = do
120 -- TODO get Reader settings
123 -- _vrs = Just ("1" :: Text)
124 -- _sft = Just (Software "Gargantext" "4")
125 -- _prm = initPhyloParam vrs sft (Just q)
127 pId <- insertNodes [nodePhyloW (Just "Phylo") (Just $ HyperdataPhylo Nothing (Just phy)) n userId]
128 pure $ NodeId (fromIntegral pId)
130 ------------------------------------------------------------------------
131 -- | DELETE Phylo == delete a node
132 ------------------------------------------------------------------------
133 ------------------------------------------------------------------------
135 type PutPhylo = (Put '[JSON] Phylo )
136 --putPhylo :: PhyloId -> Maybe ListId -> PhyloQueryBuild -> Phylo
137 putPhylo :: PhyloId -> GargServer PutPhylo
143 instance Arbitrary PhyloView
145 arbitrary = elements [phyloView]
147 -- | TODO add phyloGroup ex
148 instance Arbitrary PhyloGroup
150 arbitrary = elements []
152 instance Arbitrary Phylo
154 arbitrary = elements [phylo]
156 instance ToSchema Order
158 instance ToParamSchema Order
159 instance FromHttpApiData Order
161 parseUrlPiece = readTextData
164 instance ToParamSchema Metric
165 instance FromHttpApiData [Metric]
167 parseUrlPiece = readTextData
168 instance FromHttpApiData Metric
170 parseUrlPiece = readTextData
173 instance ToParamSchema DisplayMode
174 instance FromHttpApiData DisplayMode
176 parseUrlPiece = readTextData
179 instance ToParamSchema ExportMode
180 instance FromHttpApiData ExportMode
182 parseUrlPiece = readTextData
185 instance FromHttpApiData Sort
187 parseUrlPiece = readTextData
188 instance ToParamSchema Sort
190 instance FromHttpApiData [Tagger]
192 parseUrlPiece = readTextData
193 instance FromHttpApiData Tagger
195 parseUrlPiece = readTextData
196 instance ToParamSchema Tagger
198 instance FromHttpApiData Filiation
200 parseUrlPiece = readTextData
201 instance ToParamSchema Filiation