Commit 8627e463 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[HAL] implement multiple year chooser

parent 1f8edfc9
Pipeline #2663 failed with stage
in 0 seconds
...@@ -2,11 +2,13 @@ module Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField where ...@@ -2,11 +2,13 @@ module Gargantext.Components.Forest.Tree.Node.Action.Search.SearchField where
import Gargantext.Prelude import Gargantext.Prelude
import Data.Array as A
import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Newtype (over) import Data.Newtype (over)
import Data.Nullable (null) import Data.Nullable (null)
import Data.Set as Set import Data.Set as Set
import Data.String.Common (joinWith) import Data.String.Common (joinWith)
import Data.Tuple (Tuple(..))
import DOM.Simple.Console (log, log2) import DOM.Simple.Console (log, log2)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
...@@ -40,7 +42,7 @@ defaultSearch = { databases: Empty ...@@ -40,7 +42,7 @@ defaultSearch = { databases: Empty
, lang : Nothing , lang : Nothing
, term : "" , term : ""
, url : "" , url : ""
, year : "" , years : []
} }
type Props = type Props =
...@@ -78,17 +80,41 @@ searchFieldCpt = here.component "searchField" cpt ...@@ -78,17 +80,41 @@ searchFieldCpt = here.component "searchField" cpt
type ComponentProps = type ComponentProps =
( search :: T.Box Search ) ( search :: T.Box Search )
componentYear :: R2.Component ComponentProps componentYears :: R2.Component ComponentProps
componentYear = R.createElement componentYearCpt componentYears = R.createElement componentYearsCpt
componentYearCpt :: R.Component ComponentProps componentYearsCpt :: R.Component ComponentProps
componentYearCpt = here.component "componentYear" cpt where componentYearsCpt = here.component "componentYears" cpt where
cpt { search } _ = do cpt { search } _ = do
{ years } <- T.useLive T.unequal search
let yearsZ = A.zip (A.range 0 (A.length years)) years
newYear <- T.useBox ""
pure $ H.div {} pure $ H.div {}
[ H.input { on: { blur: modify ((yearCpt search <$> yearsZ) <>
, change: modify [ H.div {}
, input: modify } } ] [ H.input { on: { blur: modify newYear
, change: modify newYear
, input: modify newYear } }
, H.span { className: "btn btn-primary fa fa-check"
, on: { click: clickAdd newYear search }} []
]
])
where where
modify e = T.modify_ (_ { year = R.unsafeEventValue e }) search clickAdd newYear search _ = do
newYear' <- T.read newYear
T.modify_ (\s@{ years } -> s { years = A.snoc years newYear' }) search
clickRemove idx search _ =
T.modify_ (\s@{ years } -> s { years = left idx years <> right (A.length years - idx) years }) search
where
left 0 years = []
left idx years = A.take idx years
right 0 years = []
right len years = A.takeEnd (len - 1) years
modify newYear e = T.write_ (R.unsafeEventValue e) newYear
yearCpt search (Tuple idx year) =
H.div {}
[ H.span {} [ H.text year ]
, H.span { className: "btn btn-danger fa fa-times"
, on: { click: clickRemove idx search } } [] ]
type ComponentIMTProps = type ComponentIMTProps =
( session :: Session ( session :: Session
...@@ -419,7 +445,7 @@ datafieldInputCpt = here.component "datafieldInput" cpt where ...@@ -419,7 +445,7 @@ datafieldInputCpt = here.component "datafieldInput" cpt where
else H.div {} [] else H.div {} []
, if isHAL search'.datafield , if isHAL search'.datafield
then componentYear { search } [] then componentYears { search } []
else H.div {} [] else H.div {} []
, if isCNRS search'.datafield , if isCNRS search'.datafield
...@@ -555,12 +581,12 @@ searchQuery selection { databases ...@@ -555,12 +581,12 @@ searchQuery selection { databases
, lang , lang
, term , term
, node_id , node_id
, year } = , years } =
over SearchQuery (_ { databases = databases over SearchQuery (_ { databases = databases
, datafield = datafield , datafield = datafield
, lang = lang , lang = lang
, node_id = node_id , node_id = node_id
, query = queryHAL term Nothing lang year , query = queryHAL term Nothing lang years
, selection = selection , selection = selection
}) defaultSearchQuery }) defaultSearchQuery
searchQuery selection { databases searchQuery selection { databases
...@@ -568,12 +594,12 @@ searchQuery selection { databases ...@@ -568,12 +594,12 @@ searchQuery selection { databases
, lang , lang
, term , term
, node_id , node_id
, year } = , years } =
over SearchQuery (_ { databases = databases over SearchQuery (_ { databases = databases
, datafield = datafield , datafield = datafield
, lang = lang , lang = lang
, node_id = node_id , node_id = node_id
, query = queryHAL term (Just imtOrgs) lang year , query = queryHAL term (Just imtOrgs) lang years
, selection = selection , selection = selection
}) defaultSearchQuery }) defaultSearchQuery
searchQuery selection { databases, datafield, lang, term, node_id } = searchQuery selection { databases, datafield, lang, term, node_id } =
...@@ -585,8 +611,8 @@ searchQuery selection { databases, datafield, lang, term, node_id } = ...@@ -585,8 +611,8 @@ searchQuery selection { databases, datafield, lang, term, node_id } =
, selection = selection , selection = selection
}) defaultSearchQuery }) defaultSearchQuery
queryHAL :: String -> Maybe (Set.Set IMT_org) -> Maybe Lang -> String -> String queryHAL :: String -> Maybe (Set.Set IMT_org) -> Maybe Lang -> Array String -> String
queryHAL term mIMTOrgs lang year = queryHAL term mIMTOrgs lang years =
"(" <> langPrefix <> "_title_t:\"" <> termEscaped <> "(" <> langPrefix <> "_title_t:\"" <> termEscaped <>
"\" OR " <> langPrefix <> "_abstract_t:\"" <> termEscaped <> "\")" <> "\" OR " <> langPrefix <> "_abstract_t:\"" <> termEscaped <> "\")" <>
structQuery <> yearQuery structQuery <> yearQuery
...@@ -602,10 +628,8 @@ queryHAL term mIMTOrgs lang year = ...@@ -602,10 +628,8 @@ queryHAL term mIMTOrgs lang year =
"" ""
else else
" AND (" <> (structIds imtOrgs) <> ")" " AND (" <> (structIds imtOrgs) <> ")"
yearQuery = if year == "" then yearQuery' = joinWith " AND " $ (\year -> "producedDateY_i:" <> year) <$> years
"" yearQuery = if yearQuery' == "" then "" else " AND " <> yearQuery'
else
" AND producedDateY_i:" <> year
joinFunc :: IMT_org -> String joinFunc :: IMT_org -> String
joinFunc All_IMT = "" joinFunc All_IMT = ""
joinFunc (IMT_org { school_id }) = "structId_i:" <> school_id joinFunc (IMT_org { school_id }) = "structId_i:" <> school_id
......
...@@ -29,7 +29,7 @@ type Search = { databases :: Database ...@@ -29,7 +29,7 @@ type Search = { databases :: Database
, lang :: Maybe Lang , lang :: Maybe Lang
, node_id :: Maybe Int , node_id :: Maybe Int
, term :: String , term :: String
, year :: String -- TODO Array Int , years :: Array String
} }
isIsTex_Advanced :: Maybe DataField -> Boolean isIsTex_Advanced :: Maybe DataField -> Boolean
......
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