[search] pubmed constructor with api key

parent 282dafcd
Pipeline #7191 passed with stages
in 20 minutes and 22 seconds
...@@ -41,7 +41,6 @@ defaultSearch = ...@@ -41,7 +41,6 @@ defaultSearch =
, node_id: Nothing , node_id: Nothing
, epoApiUser: Nothing , epoApiUser: Nothing
, epoApiToken: Nothing , epoApiToken: Nothing
, pubmedApiKey: Nothing
, lang: Nothing , lang: Nothing
, term: "" , term: ""
, url: "" , url: ""
...@@ -252,10 +251,14 @@ isCNRS _ = false ...@@ -252,10 +251,14 @@ isCNRS _ = false
isPubmed :: Maybe DataField -> Boolean isPubmed :: Maybe DataField -> Boolean
isPubmed isPubmed
( Just ( Just
(External PubMed) (External (PubMed _))
) = true ) = true
isPubmed _ = false isPubmed _ = false
getPubmedAPIKey :: Maybe DataField -> Maybe String
getPubmedAPIKey (Just (External (PubMed mAPI))) = mAPI
getPubmedAPIKey _ = Nothing
isEPO :: Maybe DataField -> Boolean isEPO :: Maybe DataField -> Boolean
isEPO isEPO
( Just ( Just
...@@ -477,15 +480,16 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt ...@@ -477,15 +480,16 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt
search' <- T.useLive T.unequal search search' <- T.useLive T.unequal search
R.useEffectOnce' $ do R.useEffectOnce' $ do
when (search'.pubmedApiKey /= pubmedAPIKey) $ do when (getPubmedAPIKey search'.datafield /= pubmedAPIKey) $ do
T.write_ (search' { pubmedApiKey = pubmedAPIKey }) search T.modify_ (\s -> s { datafield = Just $ External $ PubMed pubmedAPIKey }) search
-- T.write_ (search' { pubmedApiKey = pubmedAPIKey }) search
pure $ pure $
H.div { className: "form-group p-1 m-0" } H.div { className: "form-group p-1 m-0" }
[ H.div { className: "text-primary center" } [ H.text "Pubmed API key" ] [ H.div { className: "text-primary center" } [ H.text "Pubmed API key" ]
, H.input , H.input
{ className: "form-control" { className: "form-control"
, defaultValue: fromMaybe "" search'.pubmedApiKey , defaultValue: fromMaybe "" pubmedAPIKey
, on: , on:
{ blur: modifyPubmedAPIKey search { blur: modifyPubmedAPIKey search
, change: modifyPubmedAPIKey search , change: modifyPubmedAPIKey search
...@@ -502,7 +506,7 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt ...@@ -502,7 +506,7 @@ pubmedInputLoadedCpt = here.component "pubmedInputLoaded" cpt
s -> Just s s -> Just s
T.modify_ T.modify_
( \s -> ( \s ->
s { pubmedApiKey = mVal } s { datafield = Just $ External $ PubMed mVal }
) )
searchS searchS
...@@ -894,9 +898,8 @@ searchQuery ...@@ -894,9 +898,8 @@ searchQuery
searchQuery searchQuery
selection selection
{ databases { databases
, datafield: datafield@(Just (External PubMed)) , datafield: datafield@(Just (External (PubMed mAPIKey)))
, lang , lang
, pubmedApiKey
, node_id , node_id
, term , term
} = } =
...@@ -906,7 +909,7 @@ searchQuery ...@@ -906,7 +909,7 @@ searchQuery
, datafield = datafield , datafield = datafield
, lang = lang , lang = lang
, node_id = node_id , node_id = node_id
, pubmedAPIKey = pubmedApiKey , pubmedAPIKey = mAPIKey
, query = term , query = term
, selection = selection , selection = selection
} }
......
...@@ -33,7 +33,6 @@ type Search = ...@@ -33,7 +33,6 @@ type Search =
, node_id :: Maybe Int , node_id :: Maybe Int
, epoApiUser :: Maybe String , epoApiUser :: Maybe String
, epoApiToken :: Maybe String , epoApiToken :: Maybe String
, pubmedApiKey :: Maybe String
, term :: String , term :: String
, years :: Array String , years :: Array String
} }
...@@ -116,7 +115,7 @@ data Database ...@@ -116,7 +115,7 @@ data Database
= All_Databases = All_Databases
| Empty | Empty
| OpenAlex | OpenAlex
| PubMed | PubMed (Maybe String)
| Arxiv | Arxiv
| HAL (Maybe Org) | HAL (Maybe Org)
| IsTex | IsTex
...@@ -133,7 +132,7 @@ derive instance Generic Database _ ...@@ -133,7 +132,7 @@ derive instance Generic Database _
instance Show Database where instance Show Database where
show All_Databases = "All Databases" show All_Databases = "All Databases"
show OpenAlex = "OpenAlex" show OpenAlex = "OpenAlex"
show PubMed = "PubMed" show (PubMed _) = "PubMed"
show Arxiv = "Arxiv" show Arxiv = "Arxiv"
show (HAL _) = "HAL" show (HAL _) = "HAL"
show IsTex = "IsTex" show IsTex = "IsTex"
...@@ -148,7 +147,7 @@ instance Show Database where ...@@ -148,7 +147,7 @@ instance Show Database where
instance Doc Database where instance Doc Database where
doc All_Databases = "All databases" doc All_Databases = "All databases"
doc OpenAlex = "OpenAlex db" doc OpenAlex = "OpenAlex db"
doc PubMed = "All Medical publications" doc (PubMed _) = "All Medical publications"
doc Arxiv = "Arxiv" doc Arxiv = "Arxiv"
doc (HAL _) = "All open science (archives ouvertes)" doc (HAL _) = "All open science (archives ouvertes)"
doc IsTex = "All Elsevier enriched by CNRS/INIST" doc IsTex = "All Elsevier enriched by CNRS/INIST"
...@@ -181,7 +180,7 @@ instance JSON.WriteForeign Database where ...@@ -181,7 +180,7 @@ instance JSON.WriteForeign Database where
allDatabases :: Array Database allDatabases :: Array Database
allDatabases = allDatabases =
[ Empty [ Empty
, PubMed , PubMed Nothing
, HAL Nothing , HAL Nothing
, Arxiv , Arxiv
, OpenAlex , OpenAlex
...@@ -197,7 +196,7 @@ allDatabases = ...@@ -197,7 +196,7 @@ allDatabases =
dbToInputValue :: Database -> String dbToInputValue :: Database -> String
dbToInputValue All_Databases = "all_databases" dbToInputValue All_Databases = "all_databases"
dbToInputValue OpenAlex = "openalex" dbToInputValue OpenAlex = "openalex"
dbToInputValue PubMed = "pubmed" dbToInputValue (PubMed _) = "pubmed"
dbToInputValue Arxiv = "arxiv" dbToInputValue Arxiv = "arxiv"
dbToInputValue (HAL _) = "hal" dbToInputValue (HAL _) = "hal"
dbToInputValue IsTex = "istex" dbToInputValue IsTex = "istex"
...@@ -209,7 +208,7 @@ dbToInputValue Empty = "empty" ...@@ -209,7 +208,7 @@ dbToInputValue Empty = "empty"
dbFromInputValue :: String -> Maybe Database dbFromInputValue :: String -> Maybe Database
dbFromInputValue "all_databases" = Just All_Databases dbFromInputValue "all_databases" = Just All_Databases
dbFromInputValue "openalex" = Just OpenAlex dbFromInputValue "openalex" = Just OpenAlex
dbFromInputValue "pubmed" = Just PubMed dbFromInputValue "pubmed" = Just (PubMed Nothing)
dbFromInputValue "arxiv" = Just Arxiv dbFromInputValue "arxiv" = Just Arxiv
dbFromInputValue "hal" = Just (HAL Nothing) dbFromInputValue "hal" = Just (HAL Nothing)
dbFromInputValue "istex" = Just IsTex dbFromInputValue "istex" = Just IsTex
......
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