API.purs 2.64 KB
Newer Older
1 2
module Gargantext.Components.GraphExplorer.API where

3 4 5
import Gargantext.Prelude

import Data.Either (Either(..))
6
import Data.Maybe (Maybe)
7
import Effect.Aff (Aff)
8 9
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Components.NgramsTable.Core as NTC
10
import Gargantext.Config.REST (RESTError)
11 12
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Routes as GR
13
import Gargantext.Sessions (Session, get, post)
14 15 16
import Gargantext.Types as GT

type GraphAsyncUpdateParams =
17
  ( graphId :: Int
18 19 20 21 22 23 24
  , listId :: Int
  , nodes :: Array (Record SigmaxT.Node)
  , session :: Session
  , termList :: GT.TermList
  , version :: NTC.Version
  )

25
graphAsyncUpdate :: Record GraphAsyncUpdateParams -> Aff (Either RESTError GT.AsyncTaskWithType)
26
graphAsyncUpdate { graphId, listId, nodes, session, termList, version } = do
27 28
  eTask <- post session p q
  pure $ (\task -> GT.AsyncTaskWithType { task, typ: GT.GraphRecompute }) <$> eTask
29
  where
30
    p = GR.GraphAPI graphId $ GT.asyncTaskTypePath GT.GraphRecompute
31 32 33 34 35
    q = { listId
        , nodes
        , termList
        , version
        }
36 37

type GraphAsyncRecomputeParams =
38
  ( graphId :: Int
39 40 41
  , session :: Session
  )

42
graphAsyncRecompute :: Record GraphAsyncRecomputeParams -> Aff (Either RESTError GT.AsyncTaskWithType)
43
graphAsyncRecompute { graphId, session } = do
44 45
  eTask <- post session p q
  pure $ (\task -> GT.AsyncTaskWithType { task, typ: GT.GraphRecompute }) <$> eTask
46
  where
47
    p = GR.GraphAPI graphId $ GT.asyncTaskTypePath GT.GraphRecompute
48 49 50
    q = {}

type QueryProgressParams =
51
  ( graphId :: Int
52 53 54 55
  , session :: Session
  , taskId  :: String
  )

56
queryProgress :: Record QueryProgressParams -> Aff (Either RESTError GT.AsyncProgress)
57 58
queryProgress { graphId, session, taskId } = do
  get session $ GR.GraphAPI graphId $ "async/" <> taskId <> "/poll"
59 60

type GraphVersions =
61
  ( gv_graph :: Maybe Int
62 63 64 65
  , gv_repo :: Int
  )

type GraphVersionsParams =
66
  ( graphId :: Int
67 68 69
  , session :: Session
  )

70
graphVersions :: Record GraphVersionsParams -> Aff (Either RESTError (Record GraphVersions))
71 72 73
graphVersions { graphId, session }  = get session $ GR.GraphAPI graphId $ "versions"

type UpdateGraphVersionsParams =
74
  ( graphId :: Int
75 76 77
  , session :: Session
  )

78
updateGraphVersions :: Record UpdateGraphVersionsParams -> Aff (Either RESTError GET.GraphData)
79
updateGraphVersions { graphId, session } = post session (GR.GraphAPI graphId $ "versions") {}
80 81

type CloneGraphParams =
82
  ( hyperdataGraph :: GET.HyperdataGraph
83 84 85 86
  , id :: Int
  , session :: Session
  )

87
cloneGraph :: Record CloneGraphParams -> Aff (Either RESTError Int)
88
cloneGraph { hyperdataGraph, id, session } = post session (GR.GraphAPI id $ "clone") hyperdataGraph