Commit c237ff21 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[simple-json] fix graph explorer json

parent 229f9ba3
...@@ -36,6 +36,8 @@ cameraP = SProxy :: SProxy "camera" ...@@ -36,6 +36,8 @@ cameraP = SProxy :: SProxy "camera"
mCameraP = SProxy :: SProxy "mCamera" mCameraP = SProxy :: SProxy "mCamera"
idP = SProxy :: SProxy "id" idP = SProxy :: SProxy "id"
id_P = SProxy :: SProxy "id_" id_P = SProxy :: SProxy "id_"
typeP = SProxy :: SProxy "type"
type_P = SProxy :: SProxy "type_"
derive instance Generic Node _ derive instance Generic Node _
derive instance Newtype Node _ derive instance Newtype Node _
...@@ -44,9 +46,17 @@ instance Ord Node where compare (Node n1) (Node n2) = compare n1.id_ n2.id_ ...@@ -44,9 +46,17 @@ instance Ord Node where compare (Node n1) (Node n2) = compare n1.id_ n2.id_
instance JSON.ReadForeign Node where instance JSON.ReadForeign Node where
readImpl f = do readImpl f = do
inst <- JSON.readImpl f inst <- JSON.readImpl f
pure $ Node $ Record.rename x_coordP xP $ Record.rename y_coordP yP inst pure $ Node $
Record.rename idP id_P $
Record.rename typeP type_P $
Record.rename x_coordP xP $
Record.rename y_coordP yP inst
instance JSON.WriteForeign Node where instance JSON.WriteForeign Node where
writeImpl (Node nd) = JSON.writeImpl $ Record.rename xP x_coordP $ Record.rename yP y_coordP nd writeImpl (Node nd) = JSON.writeImpl $
Record.rename id_P idP $
Record.rename type_P typeP $
Record.rename xP x_coordP $
Record.rename yP y_coordP nd
newtype Cluster = Cluster { clustDefault :: Int } newtype Cluster = Cluster { clustDefault :: Int }
...@@ -110,15 +120,16 @@ instance JSON.ReadForeign GraphData where ...@@ -110,15 +120,16 @@ instance JSON.ReadForeign GraphData where
readImpl f = do readImpl f = do
inst :: { nodes :: Array Node inst :: { nodes :: Array Node
, edges :: Array Edge , edges :: Array Edge
, metadata :: Maybe MetaData , metadata :: MetaData } <- JSON.readImpl f
, corpusId :: Array CorpusId let (MetaData metadata) = inst.metadata
, listId :: ListId } <- JSON.readImpl f let side x = GraphSideCorpus { corpusId: x
let side x = GraphSideCorpus { corpusId: x, corpusLabel: "Publications", listId : inst.listId} , corpusLabel: "Publications"
let sides = side <$> inst.corpusId , listId : metadata.list.listId }
let sides = side <$> metadata.corpusId
pure $ GraphData { nodes: inst.nodes pure $ GraphData { nodes: inst.nodes
, edges: inst.edges , edges: inst.edges
, sides , sides
, metaData: inst.metadata } , metaData: Just inst.metadata }
instance JSON.WriteForeign GraphData where instance JSON.WriteForeign GraphData where
writeImpl (GraphData gd) = JSON.writeImpl { nodes: gd.nodes writeImpl (GraphData gd) = JSON.writeImpl { nodes: gd.nodes
, edges: gd.edges , edges: gd.edges
...@@ -127,9 +138,9 @@ instance JSON.WriteForeign GraphData where ...@@ -127,9 +138,9 @@ instance JSON.WriteForeign GraphData where
newtype MetaData = MetaData newtype MetaData = MetaData
{ corpusId :: Array Int { corpusId :: Array Int
, legend :: Array Legend , legend :: Array Legend
, list :: { listId :: ListId , list :: { listId :: ListId
, version :: Version , version :: Version
} }
, metric :: String -- dummy value , metric :: String -- dummy value
, startForceAtlas :: Boolean , startForceAtlas :: Boolean
, title :: String , title :: String
...@@ -188,8 +199,12 @@ derive instance Generic Legend _ ...@@ -188,8 +199,12 @@ derive instance Generic Legend _
derive instance Newtype Legend _ derive instance Newtype Legend _
instance Eq Legend where eq (Legend l1) (Legend l2) = eq l1.id_ l2.id_ instance Eq Legend where eq (Legend l1) (Legend l2) = eq l1.id_ l2.id_
instance Ord Legend where compare (Legend l1) (Legend l2) = compare l1.id_ l2.id_ instance Ord Legend where compare (Legend l1) (Legend l2) = compare l1.id_ l2.id_
derive newtype instance JSON.ReadForeign Legend instance JSON.ReadForeign Legend where
derive newtype instance JSON.WriteForeign Legend readImpl f = do
inst <- JSON.readImpl f
pure $ Legend $ Record.rename idP id_P inst
instance JSON.WriteForeign Legend where
writeImpl (Legend l) = JSON.writeImpl $ Record.rename id_P idP l
getLegendData :: GraphData -> Array Legend getLegendData :: GraphData -> Array Legend
......
module Gargantext.Types where module Gargantext.Types where
import Data.Array as A import Data.Array as A
import Data.Either (Either(..))
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.String as S import Data.String as S
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
...@@ -9,7 +8,7 @@ import Data.Eq.Generic (genericEq) ...@@ -9,7 +8,7 @@ import Data.Eq.Generic (genericEq)
import Data.Ord.Generic (genericCompare) import Data.Ord.Generic (genericCompare)
import Data.Show.Generic (genericShow) import Data.Show.Generic (genericShow)
import Data.Int (toNumber) import Data.Int (toNumber)
import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.Maybe (Maybe(..), maybe)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Foreign as F import Foreign as F
import Prim.Row (class Union) import Prim.Row (class Union)
...@@ -429,10 +428,10 @@ instance JSON.ReadForeign ApiVersion where ...@@ -429,10 +428,10 @@ instance JSON.ReadForeign ApiVersion where
readImpl f = do readImpl f = do
s <- JSON.readImpl f s <- JSON.readImpl f
case s of case s of
"v0" -> pure V0 "v0" -> pure V0
"v1.0" -> pure V10 "v1.0" -> pure V10
"v1.1" -> pure V11 "v1.1" -> pure V11
x -> F.fail $ F.ErrorAtProperty x $ F.ForeignError "unknown API value" x -> F.fail $ F.ErrorAtProperty x $ F.ForeignError "unknown API value"
instance JSON.WriteForeign ApiVersion where instance JSON.WriteForeign ApiVersion where
writeImpl v = F.unsafeToForeign $ JSON.writeImpl $ show v writeImpl v = F.unsafeToForeign $ JSON.writeImpl $ show v
instance Show ApiVersion where instance Show ApiVersion where
...@@ -633,8 +632,7 @@ newtype AsyncTask = ...@@ -633,8 +632,7 @@ newtype AsyncTask =
derive instance Generic AsyncTask _ derive instance Generic AsyncTask _
derive instance Newtype AsyncTask _ derive instance Newtype AsyncTask _
derive newtype instance JSON.ReadForeign AsyncTask derive newtype instance JSON.ReadForeign AsyncTask
instance Eq AsyncTask where instance Eq AsyncTask where eq = genericEq
eq = genericEq
newtype AsyncTaskWithType = AsyncTaskWithType { newtype AsyncTaskWithType = AsyncTaskWithType {
task :: AsyncTask task :: AsyncTask
...@@ -687,8 +685,7 @@ prettyNodeType nt = S.replace (S.Pattern "Node") (S.Replacement " ") ...@@ -687,8 +685,7 @@ prettyNodeType nt = S.replace (S.Pattern "Node") (S.Replacement " ")
data SidePanelState = InitialClosed | Opened | Closed data SidePanelState = InitialClosed | Opened | Closed
derive instance Generic SidePanelState _ derive instance Generic SidePanelState _
instance Eq SidePanelState where instance Eq SidePanelState where eq = genericEq
eq = genericEq
toggleSidePanelState :: SidePanelState -> SidePanelState toggleSidePanelState :: SidePanelState -> SidePanelState
toggleSidePanelState InitialClosed = Opened toggleSidePanelState InitialClosed = Opened
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment