[contexts] add GraphQL endpoint for node contexts

Also, implement rating on Document view.
parent bc0abe91
Pipeline #3566 canceled with stage
......@@ -7,13 +7,17 @@ import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Bootstrap as B
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.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.Sessions (Session, put)
import Gargantext.Types (NodeID, NodeType(..))
......@@ -47,21 +51,6 @@ ratingCpt = here.component "rating" cpt where
, session
, setLocalCategories
} _ = 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
-- |
let
......@@ -84,11 +73,89 @@ ratingCpt = here.component "rating" cpt where
{ className: "rating-group" } $
stars <#> \s ->
B.iconButton
{ name: icon' score s
{ name: ratingIcon score s
, callback: onClick s
, overlay: false
, variant: variant' score s
, className: className' score s
, variant: ratingVariant 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
import Gargantext.Prelude
import Data.Array as A
import Data.Maybe (Maybe(..), fromMaybe, isJust, maybe)
import Data.Ord (greaterThan)
import Data.String (length)
......@@ -14,6 +15,8 @@ import Gargantext.Components.Annotation.Types as AFT
import Gargantext.Components.AutoUpdate (autoUpdate)
import Gargantext.Components.Bootstrap as B
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.NgramsTable.AutoSync (useAutoSync)
import Gargantext.Components.Node (NodePoly(..))
......@@ -48,7 +51,7 @@ here = R2.here "Gargantext.Components.Document.Layout"
layout :: forall r. R2.OptLeaf Options Props r
layout = R2.optLeaf layoutCpt options
layoutCpt :: R.Component Props
layoutCpt = here.component "main" cpt where
layoutCpt = here.component "layout" cpt where
-- Component
cpt { path
, loaded:
......@@ -273,6 +276,11 @@ layoutCpt = here.component "main" cpt where
{ className: "document-layout__date__content" }
(publicationDate $ Document doc)
]
, case path.mCorpusId of
Nothing -> H.div {} []
Just corpusId -> ratingSimpleLoader { docId: path.nodeId
, corpusId
, session: path.session } []
,
R2.when hasAbstract $
......
......@@ -60,7 +60,6 @@ type Props =
sidebar :: R2.Leaf Props
sidebar = R2.leaf sidebarCpt
sidebarCpt :: R.Component Props
sidebarCpt = here.component "sidebar" cpt where
cpt props _ = do
......
......@@ -10,6 +10,8 @@ import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
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.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
......@@ -18,7 +20,6 @@ import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact)
import GraphQL.Client.Args (type (==>))
import GraphQL.Client.BaseClients.Urql (UrqlClient, createClient)
import GraphQL.Client.Query (queryWithDecoder)
......@@ -72,6 +73,7 @@ queryGql session name q = do
-- Schema
type Schema
= { imt_schools :: {} ==> Array GQLIMT.School
, contexts :: { context_id :: Int, node_id :: Int } ==> Array GQLCTX.NodeContext
, nodes :: { node_id :: Int } ==> Array Node
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, user_infos :: { user_id :: Int } ==> Array UserInfo
......
module Gargnatext.Components.GraphQL.Contact
module Gargantext.Components.GraphQL.Contact
( AnnuaireContact
, annuaireContactQuery
-- 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(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
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.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Team (Team, teamQuery)
......@@ -17,7 +19,6 @@ import Gargantext.Config.REST (RESTError(..), AffRESTError)
import Gargantext.Sessions (Session(..))
import Gargantext.Types (NodeType)
import Gargantext.Utils.Reactix as R2
import Gargnatext.Components.GraphQL.Contact (AnnuaireContact, annuaireContactQuery)
import GraphQL.Client.Args (onlyArgs)
import GraphQL.Client.Query (mutation)
import GraphQL.Client.Variables (withVars)
......@@ -97,3 +98,11 @@ deleteTeamMembership session sharedFolderId teamNodeId = do
Just _ -> Right sharedFolderId
where
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
import Gargantext.Prelude
......
......@@ -16,7 +16,7 @@ import Gargantext.Hooks.Session (useSession)
import Gargantext.Types (NodeID)
import Gargantext.Utils (nbsp)
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.DOM.HTML as H
......
......@@ -541,7 +541,6 @@ type SideText =
sideText :: R2.Leaf ( key :: String | SideText )
sideText = R2.leaf sideTextCpt
sideTextCpt :: R.Component ( key :: String | SideText )
sideTextCpt = here.component "sideText" cpt where
cpt { sidePanelText: { corpusId, listId, nodeId }
......
......@@ -17,12 +17,10 @@ export function _init(graph, options) {
}
export function _start(layout) {
console.log('[noverlap] _start', layout);
return layout.start();
}
export function _stop(layout) {
console.log('[noverlap] _stop', layout);
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