Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
4389f602
Commit
4389f602
authored
Nov 29, 2023
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev-epo-integration' into dev
parents
3a89c6a0
28e79ca1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
259 additions
and
21 deletions
+259
-21
SearchField.purs
...omponents/Forest/Tree/Node/Action/Search/SearchField.purs
+98
-1
Types.purs
...text/Components/Forest/Tree/Node/Action/Search/Types.purs
+23
-1
GraphQL.purs
src/Gargantext/Components/GraphQL.purs
+3
-1
Endpoints.purs
src/Gargantext/Components/GraphQL/Endpoints.purs
+20
-0
User.purs
src/Gargantext/Components/GraphQL/User.purs
+12
-0
User.purs
src/Gargantext/Components/Nodes/Annuaire/User.purs
+103
-18
No files found.
src/Gargantext/Components/Forest/Tree/Node/Action/Search/SearchField.purs
View file @
4389f602
...
...
@@ -42,6 +42,8 @@ defaultSearch :: Search
defaultSearch = { databases : Empty
, datafield : Just (External Empty)
, node_id : Nothing
, epoApiUser : Nothing
, epoApiToken : Nothing
, pubmedApiKey : Nothing
, lang : Nothing
, term : ""
...
...
@@ -226,6 +228,12 @@ isPubmed ( Just
) = true
isPubmed _ = false
isEPO :: Maybe DataField -> Boolean
isEPO ( Just
( External EPO )
) = true
isEPO _ = false
needsLang :: Maybe DataField -> Boolean
needsLang (Just Gargantext) = true
needsLang (Just Web) = true
...
...
@@ -394,7 +402,7 @@ pubmedInputCpt = here.component "pubmedInput" cpt where
, render: \user -> pubmedInputLoaded { pubmedAPIKey: user.u_hyperdata.pubmed_api_key
, search } [] }
where
errorHandler = logRESTError here "[
componentIMT
]"
errorHandler = logRESTError here "[
pubmedInput
]"
type PubmedInputLoadedProps = (
...
...
@@ -431,6 +439,74 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt where
s { pubmedApiKey = mVal }) search
type EPOInputProps = (
search :: T.Box Search
, session :: Session
)
epoInput :: R2.Component EPOInputProps
epoInput = R.createElement epoInputCpt
epoInputCpt :: R.Component EPOInputProps
epoInputCpt = here.component "epoInput" cpt where
cpt { search, session: session@(Session { treeId }) } _ = do
useLoader { errorHandler
, loader: \_ -> getUser session treeId
, path: unit
, render: \user -> epoInputLoaded { epoAPIUser: user.u_hyperdata.epo_api_user
, epoAPIToken: user.u_hyperdata.epo_api_token
, search } [] }
where
errorHandler = logRESTError here "[epoInput]"
type EPOInputLoadedProps = (
epoAPIUser :: Maybe String
, epoAPIToken :: Maybe String
, search :: T.Box Search
)
epoInputLoaded :: R2.Component EPOInputLoadedProps
epoInputLoaded = R.createElement epoInputLoadedCpt
epoInputLoadedCpt :: R.Component EPOInputLoadedProps
epoInputLoadedCpt = here.component "epoInputLoaded" cpt where
cpt { epoAPIUser, epoAPIToken, search } _ = do
search' <- T.useLive T.unequal search
R.useEffectOnce' $ do
when (search'.epoApiUser /= epoAPIUser || search'.epoApiToken /= epoAPIToken) $ do
T.write_ (search' { epoApiUser = epoAPIUser
, epoApiToken = epoAPIToken }) search
pure $
H.div { className: "form-group p-1 m-0" }
[ H.div { className: "text-primary center" } [ H.text "EPO API User" ]
, H.input { className: "form-control"
, defaultValue: fromMaybe "" search'.epoApiUser
, on: { blur: modifyEPOAPIUser search
, change: modifyEPOAPIUser search
, input: modifyEPOAPIUser search } }
, H.div { className: "text-primary center" } [ H.text "EPO API Token" ]
, H.input { className: "form-control"
, defaultValue: fromMaybe "" search'.epoApiToken
, on: { blur: modifyEPOAPIToken search
, change: modifyEPOAPIToken search
, input: modifyEPOAPIToken search } } ]
where
modifyEPOAPIUser search e = do
let val = R.unsafeEventValue e
let mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s -> s { epoApiUser = mVal }) search
modifyEPOAPIToken search e = do
let val = R.unsafeEventValue e
let mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s -> s { epoApiToken = mVal }) search
type OrgInputProps =
( orgs :: Array Org
| ComponentProps)
...
...
@@ -499,6 +575,10 @@ datafieldInputCpt = here.component "datafieldInput" cpt where
then pubmedInput { search, session } []
else H.div {} []
, if isEPO search'.datafield
then epoInput { search, session } []
else H.div {} []
, if isHAL search'.datafield
then orgInput { orgs: allOrgs, search } []
else H.div {} []
...
...
@@ -673,6 +753,23 @@ searchQuery selection { databases
, query = queryHAL term (Just imtOrgs) lang years
, selection = selection
}) defaultSearchQuery
searchQuery selection { databases
, datafield: datafield@(Just (External EPO))
, lang
, epoApiUser
, epoApiToken
, node_id
, term
, years } =
over SearchQuery (_ { databases = databases
, datafield = datafield
, lang = lang
, node_id = node_id
, epoAPIUser = epoApiUser
, epoAPIToken = epoApiToken
, query = term
, selection = selection
}) defaultSearchQuery
searchQuery selection { databases
, datafield: datafield@(Just (External PubMed))
, lang
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Search/Types.purs
View file @
4389f602
...
...
@@ -29,6 +29,8 @@ type Search = { databases :: Database
, url :: String
, lang :: Maybe Lang
, node_id :: Maybe Int
, epoApiUser :: Maybe String
, epoApiToken :: Maybe String
, pubmedApiKey :: Maybe String
, term :: String
, years :: Array String
...
...
@@ -110,6 +112,7 @@ data Database = All_Databases
| IsTex
| IsTex_Advanced
| Isidore
| EPO
-- | News
-- | SocialNetworks
derive instance Generic Database _
...
...
@@ -125,6 +128,7 @@ instance Show Database where
show IsTex = "IsTex"
show IsTex_Advanced = "IsTex_Advanced"
show Isidore = "Isidore"
show EPO = "EPO"
show Empty = "Empty"
-- show News = "News"
-- show SocialNetworks = "Social Networks"
...
...
@@ -138,6 +142,7 @@ instance Doc Database where
doc IsTex = "All Elsevier enriched by CNRS/INIST"
doc IsTex_Advanced = "IsTex advanced search"
doc Isidore = "All (French) Social Sciences"
doc EPO = "European Patent Office"
doc Empty = "Empty"
-- doc News = "Web filtered by News"
-- doc SocialNetworks = "Web filtered by MicroBlogs"
...
...
@@ -167,6 +172,7 @@ allDatabases = [ Empty
, Arxiv
, OpenAlex
, IsTex
, EPO
--, IsTex_Advanced
--, Isidore
--, Web
...
...
@@ -183,6 +189,7 @@ dbToInputValue (HAL _) = "hal"
dbToInputValue IsTex = "istex"
dbToInputValue IsTex_Advanced = "istex_advanced"
dbToInputValue Isidore = "isidore"
dbToInputValue EPO = "epo"
dbToInputValue Empty = "empty"
dbFromInputValue :: String -> Maybe Database
...
...
@@ -194,6 +201,7 @@ dbFromInputValue "hal" = Just (HAL Nothing)
dbFromInputValue "istex" = Just IsTex
dbFromInputValue "istex_advanced" = Just IsTex_Advanced
dbFromInputValue "isidore" = Just Isidore
dbFromInputValue "epo" = Just EPO
dbFromInputValue "empty" = Just Empty
dbFromInputValue _ = Nothing
...
...
@@ -274,6 +282,8 @@ newtype SearchQuery = SearchQuery
, node_id :: Maybe Int
, offset :: Maybe Int
, order :: Maybe SearchOrder
, epoAPIUser :: Maybe String
, epoAPIToken :: Maybe String
, pubmedAPIKey :: Maybe String
, selection :: ListSelection.Selection
}
...
...
@@ -292,13 +302,23 @@ instance GT.ToQuery SearchQuery where
pair k = maybe [] $ \v ->
[ QP.keyFromString k /\ Just (QP.valueFromString $ show v) ]
instance JSON.WriteForeign SearchQuery where
writeImpl (SearchQuery { databases, datafield, lang, node_id, pubmedAPIKey, query, selection }) =
writeImpl (SearchQuery { databases
, datafield
, lang
, node_id
, epoAPIUser
, epoAPIToken
, pubmedAPIKey
, query
, selection }) =
JSON.writeImpl { query: query -- String.replace (String.Pattern "\"") (String.Replacement "\\\"") query
, databases
, datafield
, lang: maybe "EN" show lang
, node_id: fromMaybe 0 node_id
, flowListWith: selection
, epoAPIUser
, epoAPIToken
, pubmedAPIKey
}
...
...
@@ -313,6 +333,8 @@ defaultSearchQuery = SearchQuery
, node_id : Nothing
, offset : Nothing
, order : Nothing
, epoAPIUser : Nothing
, epoAPIToken : Nothing
, pubmedAPIKey : Nothing
, selection : ListSelection.NoList -- MyListsFirst
}
...
...
src/Gargantext/Components/GraphQL.purs
View file @
4389f602
...
...
@@ -16,7 +16,7 @@ import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.NLP as GQLNLP
import Gargantext.Components.GraphQL.Node as GQLNode
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, BreadcrumbInfo)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM, UserPubmedAPIKeyM)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM, UserPubmedAPIKeyM
, UserEPOAPIUserM, UserEPOAPITokenM
)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..))
...
...
@@ -92,5 +92,7 @@ type Schema
type Mutation
= { update_user_info :: UserInfoM ==> Int
, update_user_pubmed_api_key :: UserPubmedAPIKeyM ==> Int
, update_user_epo_api_user :: UserEPOAPIUserM ==> Int
, update_user_epo_api_token :: UserEPOAPITokenM ==> Int
, delete_team_membership :: TeamDeleteM ==> Array Int
, update_node_context_category :: GQLCTX.NodeContextCategoryM ==> Array Int }
src/Gargantext/Components/GraphQL/Endpoints.purs
View file @
4389f602
...
...
@@ -81,6 +81,26 @@ updateUserPubmedAPIKey session user_id api_key = do
{ update_user_pubmed_api_key: onlyArgs { user_id
, api_key } }
pure $ Right unit
updateUserEPOAPIUser :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIUser session user_id api_user = do
client <- liftEffect $ getClient session
{ update_user_epo_api_user } <- mutation
client
"update_user_epo_api_user"
{ update_user_epo_api_user: onlyArgs { user_id
, api_user } }
pure $ Right unit
updateUserEPOAPIToken :: Session -> Int -> String -> AffRESTError Unit
updateUserEPOAPIToken session user_id api_token = do
client <- liftEffect $ getClient session
{ update_user_epo_api_token } <- mutation
client
"update_user_epo_api_token"
{ update_user_epo_api_token: onlyArgs { user_id
, api_token } }
pure $ Right unit
getUserInfo :: Session -> Int -> AffRESTError UserInfo
getUserInfo session id = do
...
...
src/Gargantext/Components/GraphQL/User.purs
View file @
4389f602
...
...
@@ -148,6 +148,8 @@ type User
{ organization :: Array String }
}
, pubmed_api_key :: Maybe String
, epo_api_user :: Maybe String
, epo_api_token :: Maybe String
}
, u_username :: String
, u_email :: String
...
...
@@ -172,6 +174,8 @@ userQuery = { users: { user_id: Var :: _ "id" Int } =>>
, "where": { organization: unit }
}
, pubmed_api_key: unit
, epo_api_user: unit
, epo_api_token: unit
}
, u_username: unit
, u_email: unit
...
...
@@ -182,3 +186,11 @@ userQuery = { users: { user_id: Var :: _ "id" Int } =>>
type UserPubmedAPIKeyM =
{ user_id :: Int
, api_key :: String }
type UserEPOAPIUserM =
{ user_id :: Int
, api_user :: String }
type UserEPOAPITokenM =
{ user_id :: Int
, api_token :: String }
src/Gargantext/Components/Nodes/Annuaire/User.purs
View file @
4389f602
...
...
@@ -15,7 +15,7 @@ import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.GraphQL (getClient)
import Gargantext.Components.GraphQL.Endpoints (getUserInfo, getUser, updateUserPubmedAPIKey)
import Gargantext.Components.GraphQL.Endpoints (getUserInfo, getUser, updateUserPubmedAPIKey
, updateUserEPOAPIUser, updateUserEPOAPIToken
)
import Gargantext.Components.GraphQL.User (UserInfo, _ui_cwCity, _ui_cwCountry, _ui_cwFirstName, _ui_cwLabTeamDeptsFirst, _ui_cwLastName, _ui_cwOffice, _ui_cwOrganizationFirst, _ui_cwRole, _ui_cwTouchMail, _ui_cwTouchPhone, _ui_cwDescription)
import Gargantext.Components.InputWithEnter (inputWithEnter)
import Gargantext.Components.Nodes.Annuaire.Tabs as Tabs
...
...
@@ -114,6 +114,7 @@ userLayoutWithKeyCpt = here.component "userLayoutWithKey" cpt where
display { title: fromMaybe "no name" (Just ui_username) }
(contactInfos userInfo (onUpdateUserInfo boxes.errors reload))
, pubmedSettings { boxes, nodeId, session }
, epoSettings { boxes, nodeId, session }
-- , Tabs.tabs {
-- boxes
-- , cacheState
...
...
@@ -185,7 +186,7 @@ pubmedSettingsLoaded :: R2.Leaf PubmedSettingsLoadedProps
pubmedSettingsLoaded = R2.leaf pubmedSettingsLoadedCpt
pubmedSettingsLoadedCpt :: R.Component PubmedSettingsLoadedProps
pubmedSettingsLoadedCpt = here.component "pubmedSettingsLoaded" cpt where
cpt { boxes
: { errors }
cpt { boxes
, nodeId
, mPubmedAPIKey
, session } _ = do
...
...
@@ -197,26 +198,110 @@ pubmedSettingsLoadedCpt = here.component "pubmedSettingsLoaded" cpt where
[ R2.col 12
[ R2.row
[ H.h2 {} [ H.text "PubMed settings" ] ]
, H.div { className: "form-group row"}
[ H.span { className: "col-sm-2 col-form-label" } [ H.text "API Key" ]
, H.div { className: "input-group col-sm-6"}
[ itemEditable { defaultVal: ""
, isEditing
, onUpdate: \s -> do
here.log2 "[pubmedSettingsLoaded] new api key" s
case s of
"" -> pure unit
_ -> do
launchAff_ $ do
res <- updateUserPubmedAPIKey session nodeId s
handleRESTError here errors res $ \_result ->
liftEffect $ here.log "[pubmedSettingsLoaded] api key updated"
, valueBox: box }]
]
, editableUserField { boxes
, callback: updateUserPubmedAPIKey session nodeId
, description: "API Key"
, mValue: mPubmedAPIKey }
]
]
]
------------------------------------------------------------
type EPOSettingsProps =
( boxes :: Boxes
, nodeId :: CorpusId
, session :: Session )
epoSettings :: R2.Leaf EPOSettingsProps
epoSettings = R2.leaf epoSettingsCpt
epoSettingsCpt :: R.Component EPOSettingsProps
epoSettingsCpt = here.component "epoSettings" cpt where
cpt { boxes
, nodeId
, session } _ = do
useLoader { errorHandler
, loader: \_ -> getUser session nodeId
, path: unit
, render: \user -> epoSettingsLoaded { boxes
, nodeId
, mEPOAPIUser: user.u_hyperdata.epo_api_user
, mEPOAPIToken: user.u_hyperdata.epo_api_token
, session } }
where
errorHandler = logRESTError here "[epoSettings]"
type EPOSettingsLoadedProps =
( mEPOAPIUser :: Maybe String
, mEPOAPIToken :: Maybe String
| EPOSettingsProps )
epoSettingsLoaded :: R2.Leaf EPOSettingsLoadedProps
epoSettingsLoaded = R2.leaf epoSettingsLoadedCpt
epoSettingsLoadedCpt :: R.Component EPOSettingsLoadedProps
epoSettingsLoadedCpt = here.component "epoSettingsLoaded" cpt where
cpt { boxes
, nodeId
, mEPOAPIUser
, mEPOAPIToken
, session } _ = do
pure $ R2.row
[ R2.col 12
[ R2.col 12
[ R2.row
[ H.h2 {} [ H.text "EPO settings" ] ]
, editableUserField { boxes
, callback: updateUserEPOAPIUser session nodeId
, description: "API User"
, mValue: mEPOAPIUser }
, editableUserField { boxes
, callback: updateUserEPOAPIToken session nodeId
, description: "API Token"
, mValue: mEPOAPIToken }
]
]
]
------------------------------------------------------------
type EditableUserField =
( boxes :: Boxes
, callback :: String -> AffRESTError Unit
, description :: String
, mValue :: Maybe String )
editableUserField :: R2.Leaf EditableUserField
editableUserField = R2.leaf editableUserFieldCpt
editableUserFieldCpt :: R.Component EditableUserField
editableUserFieldCpt = here.component "editableUserField" cpt where
cpt { boxes: { errors }
, callback
, description
, mValue } _ = do
box <- T.useBox $ fromMaybe "" mValue
isEditing <- T.useBox false
pure $ H.div { className: "form-group row"}
[ H.span { className: "col-sm-2 col-form-label" } [ H.text description ]
, H.div { className: "input-group col-sm-6"}
[ itemEditable { defaultVal: ""
, isEditing
, onUpdate: \s -> do
here.log2 ("[editableUserField] " <> description) s
case s of
"" -> pure unit
_ -> do
launchAff_ $ do
res <- callback s
handleRESTError here errors res $ \_result ->
liftEffect $ here.log ("[editableUserField] " <> description <> " updated")
, valueBox: box }]
]
------------------------------------------------------------
-- | TODO format data in better design (UI) shape
contactInfos :: UserInfo -> (UserInfo -> Effect Unit) -> Array R.Element
contactInfos userInfo onUpdateUserInfo = item <$> contactInfoItems where
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment