[contexts] add GraphQL endpoint for node contexts

Also, implement rating on Document view.
parent bc0abe91
...@@ -7,13 +7,17 @@ import Data.Array as A ...@@ -7,13 +7,17 @@ import Data.Array as A
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..)) import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, categories, clickAgain, star2score, stars) import Gargantext.Components.Category.Types (Category(..), Star(..), cat2score, categories, clickAgain, decodeStar, star2score, stars)
import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories, LocalUserScore) import Gargantext.Components.DocsTable.Types (DocumentsView(..), LocalCategories, LocalUserScore)
import Gargantext.Config.REST (AffRESTError) import Gargantext.Components.GraphQL.Context (NodeContext, NodeContext')
import Gargantext.Components.GraphQL.Endpoints (getNodeContext)
import Gargantext.Config.REST (AffRESTError, RESTError(..))
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(NodeAPI)) import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, put) import Gargantext.Sessions (Session, put)
import Gargantext.Types (NodeID, NodeType(..)) import Gargantext.Types (NodeID, NodeType(..))
...@@ -47,21 +51,6 @@ ratingCpt = here.component "rating" cpt where ...@@ -47,21 +51,6 @@ ratingCpt = here.component "rating" cpt where
, session , session
, setLocalCategories , setLocalCategories
} _ = do } _ = do
-- | Computed
-- |
let
icon' Star_0 Star_0 = "times-circle"
icon' _ Star_0 = "times"
icon' c s = star2score c < star2score s ? "star-o" $ "star"
variant' Star_0 Star_0 = Dark
variant' _ Star_0 = Dark
variant' _ _ = Dark
className' Star_0 Star_0 = "rating-group__action"
className' _ Star_0 = "rating-group__action"
className' _ _ = "rating-group__star"
-- | Behaviors -- | Behaviors
-- | -- |
let let
...@@ -84,11 +73,89 @@ ratingCpt = here.component "rating" cpt where ...@@ -84,11 +73,89 @@ ratingCpt = here.component "rating" cpt where
{ className: "rating-group" } $ { className: "rating-group" } $
stars <#> \s -> stars <#> \s ->
B.iconButton B.iconButton
{ name: icon' score s { name: ratingIcon score s
, callback: onClick s , callback: onClick s
, overlay: false , overlay: false
, variant: variant' score s , variant: ratingVariant score s
, className: className' score s , className: ratingClassName score s
}
ratingIcon Star_0 Star_0 = "times-circle"
ratingIcon _ Star_0 = "times"
ratingIcon c s = star2score c < star2score s ? "star-o" $ "star"
ratingVariant Star_0 Star_0 = Dark
ratingVariant _ Star_0 = Dark
ratingVariant _ _ = Dark
ratingClassName Star_0 Star_0 = "rating-group__action"
ratingClassName _ Star_0 = "rating-group__action"
ratingClassName _ _ = "rating-group__star"
------------------------------------------------
type RatingSimpleLoaderProps =
( docId :: NodeID
, corpusId :: NodeID
, session :: Session
)
ratingSimpleLoader :: R2.Component RatingSimpleLoaderProps
ratingSimpleLoader = R.createElement ratingSimpleLoaderCpt
ratingSimpleLoaderCpt :: R.Component RatingSimpleLoaderProps
ratingSimpleLoaderCpt = here.component "ratingSimpleLoader" cpt where
cpt { docId
, corpusId
, session
} _ = do
useLoader { errorHandler
, loader: loadDocumentContext session
, path: { docId, corpusId }
, render: \nc -> renderRatingSimple nc [] }
where
errorHandler err = do
here.warn2 "[pageLayout] RESTError" err
case err of
ReadJSONError err' -> here.warn2 "[pageLayout] ReadJSONError" $ show err'
_ -> pure unit
type ContextParams =
( docId :: NodeID
, corpusId :: NodeID )
loadDocumentContext :: Session -> Record ContextParams -> AffRESTError NodeContext
loadDocumentContext session { docId, corpusId } = getNodeContext session docId corpusId
renderRatingSimple :: R2.Component NodeContext'
renderRatingSimple = R.createElement renderRatingSimpleCpt
renderRatingSimpleCpt :: R.Component NodeContext'
renderRatingSimpleCpt = here.component "renderRatingSimple" cpt where
cpt { nc_category
} _ = do
pure $ case nc_category of
Nothing -> H.div {} []
Just category -> ratingSimple { score: decodeStar category } []
type RatingSimpleProps =
( score :: Star )
ratingSimple :: R2.Component RatingSimpleProps
ratingSimple = R.createElement ratingSimpleCpt
ratingSimpleCpt :: R.Component RatingSimpleProps
ratingSimpleCpt = here.component "ratingSimple" cpt where
cpt { score
} _ = do
pure $
H.div
{ className: "rating-group" } $
stars <#> \s ->
B.iconButton
{ name: ratingIcon score s
, callback: \_ -> pure unit -- onClick s
, overlay: false
, variant: ratingVariant score s
, className: ratingClassName score s
} }
......
...@@ -4,6 +4,7 @@ module Gargantext.Components.Document.Layout ...@@ -4,6 +4,7 @@ module Gargantext.Components.Document.Layout
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array as A
import Data.Maybe (Maybe(..), fromMaybe, isJust, maybe) import Data.Maybe (Maybe(..), fromMaybe, isJust, maybe)
import Data.Ord (greaterThan) import Data.Ord (greaterThan)
import Data.String (length) import Data.String (length)
...@@ -14,6 +15,8 @@ import Gargantext.Components.Annotation.Types as AFT ...@@ -14,6 +15,8 @@ import Gargantext.Components.Annotation.Types as AFT
import Gargantext.Components.AutoUpdate (autoUpdate) import Gargantext.Components.AutoUpdate (autoUpdate)
import Gargantext.Components.Bootstrap as B import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), SpinnerTheme(..)) import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), SpinnerTheme(..))
import Gargantext.Components.Category (ratingSimpleLoader)
import Gargantext.Components.Category.Types (decodeStar)
import Gargantext.Components.Document.Types (DocPath, Document(..), LoadedData, initialState) import Gargantext.Components.Document.Types (DocPath, Document(..), LoadedData, initialState)
import Gargantext.Components.NgramsTable.AutoSync (useAutoSync) import Gargantext.Components.NgramsTable.AutoSync (useAutoSync)
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
...@@ -48,7 +51,7 @@ here = R2.here "Gargantext.Components.Document.Layout" ...@@ -48,7 +51,7 @@ here = R2.here "Gargantext.Components.Document.Layout"
layout :: forall r. R2.OptLeaf Options Props r layout :: forall r. R2.OptLeaf Options Props r
layout = R2.optLeaf layoutCpt options layout = R2.optLeaf layoutCpt options
layoutCpt :: R.Component Props layoutCpt :: R.Component Props
layoutCpt = here.component "main" cpt where layoutCpt = here.component "layout" cpt where
-- Component -- Component
cpt { path cpt { path
, loaded: , loaded:
...@@ -273,6 +276,11 @@ layoutCpt = here.component "main" cpt where ...@@ -273,6 +276,11 @@ layoutCpt = here.component "main" cpt where
{ className: "document-layout__date__content" } { className: "document-layout__date__content" }
(publicationDate $ Document doc) (publicationDate $ Document doc)
] ]
, case path.mCorpusId of
Nothing -> H.div {} []
Just corpusId -> ratingSimpleLoader { docId: path.nodeId
, corpusId
, session: path.session } []
, ,
R2.when hasAbstract $ R2.when hasAbstract $
......
...@@ -60,7 +60,6 @@ type Props = ...@@ -60,7 +60,6 @@ type Props =
sidebar :: R2.Leaf Props sidebar :: R2.Leaf Props
sidebar = R2.leaf sidebarCpt sidebar = R2.leaf sidebarCpt
sidebarCpt :: R.Component Props sidebarCpt :: R.Component Props
sidebarCpt = here.component "sidebar" cpt where sidebarCpt = here.component "sidebar" cpt where
cpt props _ = do cpt props _ = do
......
...@@ -10,6 +10,8 @@ import Effect (Effect) ...@@ -10,6 +10,8 @@ import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Foreign (unsafeToForeign, ForeignError) import Foreign (unsafeToForeign, ForeignError)
import Gargantext.Components.GraphQL.Contact (AnnuaireContact)
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node) import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel) import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
...@@ -18,7 +20,6 @@ import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM) ...@@ -18,7 +20,6 @@ import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
import Gargantext.Ends (Backend(..)) import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..)) import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact)
import GraphQL.Client.Args (type (==>)) import GraphQL.Client.Args (type (==>))
import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient) import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient)
import GraphQL.Client.Query (queryWithDecoder) import GraphQL.Client.Query (queryWithDecoder)
...@@ -72,6 +73,7 @@ queryGql session name q = do ...@@ -72,6 +73,7 @@ queryGql session name q = do
-- Schema -- Schema
type Schema type Schema
= { imt_schools :: {} ==> Array GQLIMT.School = { imt_schools :: {} ==> Array GQLIMT.School
, contexts :: { context_id :: Int, node_id :: Int } ==> Array GQLCTX.NodeContext
, nodes :: { node_id :: Int } ==> Array Node , nodes :: { node_id :: Int } ==> Array Node
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType , node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, user_infos :: { user_id :: Int } ==> Array UserInfo , user_infos :: { user_id :: Int } ==> Array UserInfo
......
module Gargnatext.Components.GraphQL.Contact module Gargantext.Components.GraphQL.Contact
( AnnuaireContact ( AnnuaireContact
, annuaireContactQuery , annuaireContactQuery
-- Lenses -- Lenses
......
module Gargantext.Components.GraphQL.Context
( NodeContext
, NodeContext'
, nodeContextQuery
) where
import Gargantext.Prelude
import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe)
import GraphQL.Client.Args (Args, (=>>))
import GraphQL.Client.Variable (Var(..))
import Data.Array as A
type NodeContext'
= ( nc_id :: Maybe Int
, nc_node_id :: Int
, nc_context_id :: Int
, nc_score :: Maybe Number
, nc_category :: Maybe Int
)
type NodeContext = Record NodeContext'
type NodeContextQuery
= { contexts :: Args
{ context_id :: Var "context_id" Int
, node_id :: Var "node_id" Int }
{ nc_id :: Unit
, nc_node_id :: Unit
, nc_context_id :: Unit
, nc_score :: Unit
, nc_category :: Unit
}
}
nodeContextQuery :: NodeContextQuery
nodeContextQuery
= { contexts:
{ context_id: Var :: _ "context_id" Int
, node_id: Var :: _ "node_id" Int } =>>
{ nc_id: unit
, nc_node_id: unit
, nc_context_id: unit
, nc_score: unit
, nc_category: unit
}
}
------------------------------------------------------------------------
...@@ -8,6 +8,8 @@ import Data.Maybe (Maybe(..)) ...@@ -8,6 +8,8 @@ import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (getClient, queryGql) import Gargantext.Components.GraphQL (getClient, queryGql)
import Gargantext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import Gargantext.Components.GraphQL.Context as GQLCTX
import Gargantext.Components.GraphQL.IMT as GQLIMT import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery) import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Team (Team, teamQuery) import Gargantext.Components.GraphQL.Team (Team, teamQuery)
...@@ -17,7 +19,6 @@ import Gargantext.Config.REST (RESTError(..), AffRESTError) ...@@ -17,7 +19,6 @@ import Gargantext.Config.REST (RESTError(..), AffRESTError)
import Gargantext.Sessions (Session(..)) import Gargantext.Sessions (Session(..))
import Gargantext.Types (NodeType) import Gargantext.Types (NodeType)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import GraphQL.Client.Args (onlyArgs) import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation) import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars) import GraphQL.Client.Variables (withVars)
...@@ -97,3 +98,11 @@ deleteTeamMembership session sharedFolderId teamNodeId = do ...@@ -97,3 +98,11 @@ deleteTeamMembership session sharedFolderId teamNodeId = do
Just _ -> Right sharedFolderId Just _ -> Right sharedFolderId
where where
getToken (Session { token }) = token getToken (Session { token }) = token
getNodeContext :: Session -> Int -> Int -> AffRESTError GQLCTX.NodeContext
getNodeContext session context_id node_id = do
{ contexts } <- queryGql session "get node context" $ GQLCTX.nodeContextQuery `withVars` { context_id, node_id }
liftEffect $ here.log2 "[getNodeContext] node context" contexts
case A.head contexts of
Nothing -> pure $ Left $ CustomError "no node context found"
Just context -> pure $ Right context -- TODO: error handling
module Gargantext.Components.Node module Gargantext.Components.Node
where where
import Gargantext.Prelude import Gargantext.Prelude
......
...@@ -16,7 +16,7 @@ import Gargantext.Hooks.Session (useSession) ...@@ -16,7 +16,7 @@ import Gargantext.Hooks.Session (useSession)
import Gargantext.Types (NodeID) import Gargantext.Types (NodeID)
import Gargantext.Utils (nbsp) import Gargantext.Utils (nbsp)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact, _ac_city, _ac_country, _ac_firstName, _ac_labTeamDeptsFirst, _ac_lastName, _ac_office, _ac_organizationFirst, _ac_role, _ac_touchMail, _ac_touchPhone, _ac_touchUrl) import Gargantext.Components.GraphQL.Contact (AnnuaireContact, _ac_city, _ac_country, _ac_firstName, _ac_labTeamDeptsFirst, _ac_lastName, _ac_office, _ac_organizationFirst, _ac_role, _ac_touchMail, _ac_touchPhone, _ac_touchUrl)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
......
...@@ -541,7 +541,6 @@ type SideText = ...@@ -541,7 +541,6 @@ type SideText =
sideText :: R2.Leaf ( key :: String | SideText ) sideText :: R2.Leaf ( key :: String | SideText )
sideText = R2.leaf sideTextCpt sideText = R2.leaf sideTextCpt
sideTextCpt :: R.Component ( key :: String | SideText ) sideTextCpt :: R.Component ( key :: String | SideText )
sideTextCpt = here.component "sideText" cpt where sideTextCpt = here.component "sideText" cpt where
cpt { sidePanelText: { corpusId, listId, nodeId } cpt { sidePanelText: { corpusId, listId, nodeId }
......
...@@ -17,12 +17,10 @@ export function _init(graph, options) { ...@@ -17,12 +17,10 @@ export function _init(graph, options) {
} }
export function _start(layout) { export function _start(layout) {
console.log('[noverlap] _start', layout);
return layout.start(); return layout.start();
} }
export function _stop(layout) { export function _stop(layout) {
console.log('[noverlap] _stop', layout);
return layout.stop(); return layout.stop();
} }
......
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