[search] move EPO user/token into the datafield

parent b01a85eb
Pipeline #7210 passed with stages
in 19 minutes and 12 seconds
......@@ -38,8 +38,6 @@ defaultSearch :: Search
defaultSearch =
{ datafield: External Empty
, node_id: Nothing
, epoApiUser: Nothing
, epoApiToken: Nothing
, lang: Nothing
, term: ""
, url: ""
......@@ -243,7 +241,7 @@ getPubmedAPIKey (External (PubMed mAPI)) = mAPI
getPubmedAPIKey _ = Nothing
isEPO :: DataField -> Boolean
isEPO (External EPO) = true
isEPO (External (EPO _ _)) = true
isEPO _ = false
needsLang :: DataField -> Boolean
......@@ -513,6 +511,14 @@ type EPOInputLoadedProps =
, search :: T.Box Search
)
searchEPOAPIUser :: Search -> Maybe String
searchEPOAPIUser { datafield: External (EPO mAPIUser _) } = mAPIUser
searchEPOAPIUser _ = Nothing
searchEPOAPIToken :: Search -> Maybe String
searchEPOAPIToken { datafield: External (EPO _ mAPIToken) } = mAPIToken
searchEPOAPIToken _ = Nothing
epoInputLoaded :: R2.Component EPOInputLoadedProps
epoInputLoaded = R.createElement epoInputLoadedCpt
......@@ -523,11 +529,10 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
search' <- T.useLive T.unequal search
R.useEffectOnce' $ do
when (search'.epoApiUser /= epoAPIUser || search'.epoApiToken /= epoAPIToken) $ do
when (searchEPOAPIUser search' /= epoAPIUser || searchEPOAPIToken search' /= epoAPIToken) $ do
T.write_
( search'
{ epoApiUser = epoAPIUser
, epoApiToken = epoAPIToken
{ datafield = External (EPO epoAPIUser epoAPIToken)
}
)
search
......@@ -537,7 +542,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
[ H.div { className: "text-primary center" } [ H.text "EPO API User" ]
, H.input
{ className: "form-control"
, defaultValue: fromMaybe "" search'.epoApiUser
, defaultValue: fromMaybe "" $ searchEPOAPIUser search'
, on:
{ blur: modifyEPOAPIUser search
, change: modifyEPOAPIUser search
......@@ -547,7 +552,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
, H.div { className: "text-primary center" } [ H.text "EPO API Token" ]
, H.input
{ className: "form-control"
, defaultValue: fromMaybe "" search'.epoApiToken
, defaultValue: fromMaybe "" $ searchEPOAPIToken search'
, on:
{ blur: modifyEPOAPIToken search
, change: modifyEPOAPIToken search
......@@ -562,7 +567,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s -> s { epoApiUser = mVal }) searchS
T.modify_ (\s -> s { datafield = External (EPO mVal (searchEPOAPIToken s)) }) searchS
modifyEPOAPIToken searchS e = do
let val = R.unsafeEventValue e
......@@ -570,7 +575,7 @@ epoInputLoadedCpt = here.component "epoInputLoaded" cpt
mVal = case val of
"" -> Nothing
s -> Just s
T.modify_ (\s -> s { epoApiToken = mVal }) searchS
T.modify_ (\s -> s { datafield = External (EPO (searchEPOAPIUser s) mVal) }) searchS
type OrgInputProps =
( orgs :: Array Org
......@@ -832,44 +837,6 @@ searchQuery
}
)
defaultSearchQuery
searchQuery
selection
{ datafield: datafield@(External EPO)
, lang
, epoApiUser
, epoApiToken
, node_id
, term
} =
over SearchQuery
( _
{ datafield = datafield
, lang = lang
, node_id = node_id
, epoAPIUser = epoApiUser
, epoAPIToken = epoApiToken
, query = term
, selection = selection
}
)
defaultSearchQuery
searchQuery
selection
{ datafield: datafield@(External (PubMed mAPIKey))
, lang
, node_id
, term
} =
over SearchQuery
( _
{ datafield = datafield
, lang = lang
, node_id = node_id
, query = term
, selection = selection
}
)
defaultSearchQuery
searchQuery selection { datafield, lang, term, node_id } =
over SearchQuery
( _
......
......@@ -31,8 +31,6 @@ type Search =
, url :: String
, lang :: Maybe Lang
, node_id :: Maybe Int
, epoApiUser :: Maybe String
, epoApiToken :: Maybe String
, term :: String
, years :: Array String
}
......@@ -118,7 +116,7 @@ data Database
| IsTex
| IsTex_Advanced
| Isidore
| EPO
| EPO (Maybe String) (Maybe String)
-- | News
-- | SocialNetworks
......@@ -135,7 +133,7 @@ instance Show Database where
show IsTex = "IsTex"
show IsTex_Advanced = "IsTex_Advanced"
show Isidore = "Isidore"
show EPO = "EPO"
show (EPO _ _) = "EPO"
show Empty = "Empty"
-- show News = "News"
......@@ -150,7 +148,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 (EPO _ _) = "European Patent Office"
doc Empty = "Empty"
-- doc News = "Web filtered by News"
......@@ -173,6 +171,11 @@ instance Doc Database where
derive instance Eq Database
instance JSON.WriteForeign Database where
writeImpl (PubMed mAPIKey) = JSON.writeImpl { "db": "PubMed", "api_key": mAPIKey }
writeImpl (EPO mAPIUser mAPIToken) = JSON.writeImpl
{ "db": "PubMed"
, "api_user": mAPIUser
, "api_token": mAPIToken
}
writeImpl (HAL mOrg) = JSON.writeImpl { "db": "HAL", "org": mOrg }
writeImpl d = JSON.writeImpl { "db": show d }
......@@ -184,7 +187,7 @@ allDatabases =
, Arxiv
, OpenAlex
, IsTex
-- , EPO
-- , EPO Nothing Nothing
--, IsTex_Advanced
--, Isidore
--, Web
......@@ -201,7 +204,7 @@ dbToInputValue (HAL _) = "hal"
dbToInputValue IsTex = "istex"
dbToInputValue IsTex_Advanced = "istex_advanced"
dbToInputValue Isidore = "isidore"
dbToInputValue EPO = "epo"
dbToInputValue (EPO _ _) = "epo"
dbToInputValue Empty = "empty"
dbFromInputValue :: String -> Maybe Database
......@@ -213,7 +216,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 "epo" = Just (EPO Nothing Nothing)
dbFromInputValue "empty" = Just Empty
dbFromInputValue _ = Nothing
......@@ -252,7 +255,7 @@ instance Read Org where
derive instance Eq Org
-- | NOTE: IMT_org list isn't really used here in JSON
-- | encoding. Instead, for HAL, a special query is constructed in
-- | SearchField (queryHAL function).)
-- | SearchField (queryHAL function).
instance JSON.WriteForeign Org where
writeImpl = JSON.writeImpl <<< show
......
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