Commit 38362aeb authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-search-field-styling' of...

Merge branch 'dev-search-field-styling' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev-merge
parents 6b3856df 8ea81135
...@@ -28,14 +28,19 @@ ...@@ -28,14 +28,19 @@
height: 100%; height: 100%;
} }
.search-bar-container { .search-bar-container {
margin-top: 11px;
text-align: center; text-align: center;
max-width: 800px;
height: 33px;
float: left;
display: grid;
grid-template-columns: auto auto auto;
} }
.search-bar-toggle { .search-bar-toggle {
padding: 3px; padding: 2px;
margin: 2px;
border: 0; border: 0;
} }
.search-field { .search-bar.closed {
display: grid; display: none;
grid-template-columns: auto auto auto;
} }
...@@ -49,6 +49,7 @@ import Data.Map (Map) ...@@ -49,6 +49,7 @@ import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.Monoid.Additive (Additive(..)) import Data.Monoid.Additive (Additive(..))
import Data.Ord.Down (Down(..))
import Data.Traversable (class Traversable, traverse, traverse_, sequence) import Data.Traversable (class Traversable, traverse, traverse_, sequence)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex) import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
import Data.Set (Set) import Data.Set (Set)
...@@ -57,7 +58,7 @@ import Data.String as S ...@@ -57,7 +58,7 @@ import Data.String as S
import Data.String.Regex as R import Data.String.Regex as R
import Data.String.Regex.Flags as R import Data.String.Regex.Flags as R
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..), snd)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Foreign.Object as FO import Foreign.Object as FO
...@@ -716,7 +717,16 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -716,7 +717,16 @@ ngramsTableSpec = simpleSpec performAction render
setParams params = setParams params =
loaderDispatch $ Loader.SetPath $ pageParams {params = params} loaderDispatch $ Loader.SetPath $ pageParams {params = params}
ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable ngramsTable = applyNgramsTablePatch ngramsTablePatch initTable
rows = convertRow <$> Map.toUnfoldable (Map.filter displayRow (ngramsTable ^. _NgramsTable)) orderWith =
case convOrderBy <$> pageParams.params.orderBy of
Just ScoreAsc -> A.sortWith \x -> (snd x) ^. _NgramsElement <<< _occurrences
Just ScoreDesc -> A.sortWith \x -> Down $ (snd x) ^. _NgramsElement <<< _occurrences
_ -> identity -- the server ordering is enough here
rows = convertRow <$> orderWith (addOcc <$> Map.toUnfoldable (Map.filter displayRow (ngramsTable ^. _NgramsTable)))
addOcc (Tuple ne ngramsElement) =
let Additive occurrences = sumOccurrences ngramsTable ngramsElement in
Tuple ne (ngramsElement # _NgramsElement <<< _occurrences .~ occurrences)
ngramsParentRoot :: Maybe String ngramsParentRoot :: Maybe String
ngramsParentRoot = ngramsParentRoot =
...@@ -734,11 +744,15 @@ ngramsTableSpec = simpleSpec performAction render ...@@ -734,11 +744,15 @@ ngramsTableSpec = simpleSpec performAction render
|| -- Unless they are scheduled to be removed. || -- Unless they are scheduled to be removed.
ngramsChildren ^. at ngrams == Just false ngramsChildren ^. at ngrams == Just false
convertRow (Tuple ngrams ngramsElement) = convertRow (Tuple ngrams ngramsElement) =
{ row: { row: renderNgramsItem { ngramsTable, ngrams, ngramsParent, ngramsElement, dispatch}
renderNgramsItem { ngramsTable, ngrams, ngramsParent, ngramsElement, dispatch }
, delete: false , delete: false
} }
convOrderBy (T.ASC (T.ColumnName "Score (Occurrences)")) = ScoreAsc
convOrderBy (T.DESC (T.ColumnName "Score (Occurrences)")) = ScoreDesc
convOrderBy (T.ASC _) = TermAsc
convOrderBy (T.DESC _) = TermDesc
loadNgramsTable :: PageParams -> Aff VersionedNgramsTable loadNgramsTable :: PageParams -> Aff VersionedNgramsTable
loadNgramsTable { nodeId, listIds, termListFilter, termSizeFilter loadNgramsTable { nodeId, listIds, termListFilter, termSizeFilter
, searchQuery, tabType, params: {offset, limit, orderBy}} = , searchQuery, tabType, params: {offset, limit, orderBy}} =
...@@ -749,11 +763,6 @@ loadNgramsTable { nodeId, listIds, termListFilter, termSizeFilter ...@@ -749,11 +763,6 @@ loadNgramsTable { nodeId, listIds, termListFilter, termSizeFilter
, searchQuery , searchQuery
}) })
(Just nodeId) (Just nodeId)
where
convOrderBy (T.ASC (T.ColumnName "Score (Occurrences)")) = ScoreAsc
convOrderBy (T.DESC (T.ColumnName "Score (Occurrences)")) = ScoreDesc
convOrderBy (T.ASC _) = TermAsc
convOrderBy (T.DESC _) = TermDesc
ngramsLoaderClass :: Loader.LoaderClass PageParams VersionedNgramsTable ngramsLoaderClass :: Loader.LoaderClass PageParams VersionedNgramsTable
ngramsLoaderClass = Loader.createLoaderClass "NgramsTableLoader" loadNgramsTable ngramsLoaderClass = Loader.createLoaderClass "NgramsTableLoader" loadNgramsTable
...@@ -842,10 +851,9 @@ renderNgramsItem { ngramsTable, ngrams, ngramsElement, ngramsParent, dispatch } ...@@ -842,10 +851,9 @@ renderNgramsItem { ngramsTable, ngrams, ngramsElement, ngramsParent, dispatch }
[ i [className "fas fa-plus"] [] [ i [className "fas fa-plus"] []
, span ngramsStyle [text $ " " <> ngrams] , span ngramsStyle [text $ " " <> ngrams]
] ]
, text $ show occurrences , text $ show (ngramsElement ^. _NgramsElement <<< _occurrences)
] ]
where where
Additive occurrences = sumOccurrences ngramsTable ngramsElement
termList = ngramsElement ^. _NgramsElement <<< _list termList = ngramsElement ^. _NgramsElement <<< _list
ngramsStyle = [termStyle termList] ngramsStyle = [termStyle termList]
ngramsClick = Just <<< dispatch <<< SetParentResetChildren <<< Just <<< view _ngrams ngramsClick = Just <<< dispatch <<< SetParentResetChildren <<< Just <<< view _ngrams
......
...@@ -14,10 +14,10 @@ import DOM.Simple.Element as Element ...@@ -14,10 +14,10 @@ import DOM.Simple.Element as Element
import DOM.Simple.Event as DE import DOM.Simple.Event as DE
import Effect ( Effect ) import Effect ( Effect )
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import FFI.Simple ((..)) import FFI.Simple ((..), (.=))
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as HTML import Reactix.DOM.HTML as HTML
import Reactix.DOM.HTML (text, button, div, input, option) import Reactix.DOM.HTML (text, button, div, input, option, form, span, ul, li, a)
import Reactix.SyntheticEvent as E import Reactix.SyntheticEvent as E
import Gargantext.Components.Search.Types import Gargantext.Components.Search.Types
...@@ -49,33 +49,45 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged ...@@ -49,33 +49,45 @@ searchFieldComponent = R.memo (R.hooksComponent "SearchField" cpt) hasChanged
term <- R.useState $ \_ -> pure search.term term <- R.useState $ \_ -> pure search.term
db <- R.useState $ \_ -> pure Nothing db <- R.useState $ \_ -> pure Nothing
pure $ pure $
div { className: "search-field" } div { className: "search-field input-group" }
[ databaseInput db props.databases [ databaseInput db props.databases
, searchInput term , searchInput term
, submitButton db term props.search , span { className: "input-group-btn" }
] [ submitButton db term props.search ]
]
hasChanged p p' = (fst p.search /= fst p'.search) || (p.databases /= p'.databases) hasChanged p p' = (fst p.search /= fst p'.search) || (p.databases /= p'.databases)
databaseInput :: R.State (Maybe Database) -> Array Database -> R.Element databaseInput :: R.State (Maybe Database) -> Array Database -> R.Element
databaseInput (db /\ setDB) dbs = databaseInput (db /\ setDB) dbs =
div {} [ select { className: "database", onChange } (item <$> dbs) ] div { className: "input-group-btn search-panel dropdown" }
[
dropdownBtn db
, ul {className: "dropdown-menu", role: "menu"} (liItem <$> dbs)
]
where where
onChange = mkEffectFn1 $ \e -> setDB (readDatabase (e .. "target" .. "value")) liItem db = li { onClick }
item db = option { value: (show db) } [ text (show db) ] [ a {href: "#"} [text (show db) ] ]
where
onClick = mkEffectFn1 $ \_ -> setDB $ Just db
dropdownBtnProps = { id: "search-dropdown"
, className: "btn btn-default dropdown-toggle"
, type: "button"} .= "data-toggle" $ "dropdown"
dropdownBtn (Just db) = button dropdownBtnProps [ span {} [ text (show db) ] ]
dropdownBtn (Nothing) = button dropdownBtnProps [ span {} [ text "-" ] ]
searchInput :: R.State String -> R.Element searchInput :: R.State String -> R.Element
searchInput (term /\ setTerm) = searchInput (term /\ setTerm) =
div {} [ input { defaultValue: term input { defaultValue: term
, type: "text" , className: "form-control"
, style: { maxWidth: "110px" } , type: "text"
, onChange , onChange
, placeholder } ] , placeholder }
where onChange = mkEffectFn1 $ \e -> setTerm $ e .. "target" .. "value" where onChange = mkEffectFn1 $ \e -> setTerm $ e .. "target" .. "value"
submitButton :: R.State (Maybe Database) -> R.State String -> R.State (Maybe Search) -> R.Element submitButton :: R.State (Maybe Database) -> R.State String -> R.State (Maybe Search) -> R.Element
submitButton (database /\ _) (term /\ _) (_ /\ setSearch) = submitButton (database /\ _) (term /\ _) (_ /\ setSearch) =
div {} [ button { onClick: click } [ text "Search" ] ] button { className: "btn btn-default", type: "button", onClick: click } [ text "Search" ]
where where
click = mkEffectFn1 $ \_ -> do click = mkEffectFn1 $ \_ -> do
case term of case term of
......
...@@ -95,9 +95,7 @@ layout0 layout = ...@@ -95,9 +95,7 @@ layout0 layout =
, rs bs , rs bs
] ]
ls = over _render \render d p s c -> [ ls = over _render \render d p s c -> [
div [ className "col-md-2", style {paddingTop: "60px"} ] div [ className "col-md-2", style {paddingTop: "60px"} ] $ render d p s c
$ [ R'.scuff (SB.searchBar SB.defaultProps) ]
<> (render d p s c)
] ]
rs = over _render \render d p s c -> [ rs = over _render \render d p s c -> [
...@@ -182,6 +180,7 @@ searchBar = simpleSpec defaultPerformAction render ...@@ -182,6 +180,7 @@ searchBar = simpleSpec defaultPerformAction render
, div [ className "collapse navbar-collapse" , div [ className "collapse navbar-collapse"
] ]
$ [ divDropdownLeft ] $ [ divDropdownLeft ]
<> [ R'.scuff (SB.searchBar SB.defaultProps) ]
<> [ divDropdownRight d s ] <> [ divDropdownRight d s ]
] ]
] ]
...@@ -338,7 +337,7 @@ divDropdownRight d s = ...@@ -338,7 +337,7 @@ divDropdownRight d s =
ul [className "nav navbar-nav pull-right"] ul [className "nav navbar-nav pull-right"]
[ li [className "dropdown"] [ li [className "dropdown"]
[ logLinks d s ] [ logLinks d s ]
] ]
layoutFooter :: Spec AppState {} Action layoutFooter :: Spec AppState {} Action
layoutFooter = simpleSpec performAction render layoutFooter = simpleSpec performAction render
......
...@@ -26,7 +26,7 @@ import Gargantext.Utils (id) ...@@ -26,7 +26,7 @@ import Gargantext.Utils (id)
type Props = ( open :: Boolean, databases :: Array Database ) type Props = ( open :: Boolean, databases :: Array Database )
defaultProps :: Record Props defaultProps :: Record Props
defaultProps = { open: true, databases: allDatabases } defaultProps = { open: false, databases: allDatabases }
searchBar :: Record Props -> R.Element searchBar :: Record Props -> R.Element
searchBar p = R.createElement searchBarComponent p [] searchBar p = R.createElement searchBarComponent p []
...@@ -43,9 +43,10 @@ searchBarComponent = R.hooksComponent "SearchBar" cpt ...@@ -43,9 +43,10 @@ searchBarComponent = R.hooksComponent "SearchBar" cpt
, searchFieldContainer open props.databases search ] , searchFieldContainer open props.databases search ]
searchFieldContainer :: R.State Boolean -> Array Database -> R.State (Maybe Search) -> R.Element searchFieldContainer :: R.State Boolean -> Array Database -> R.State (Maybe Search) -> R.Element
searchFieldContainer (true /\ _) databases search = searchFieldContainer (open /\ _) databases search =
H.div { className: "search-bar open" } [ searchField { databases, search } ] H.div { className: "search-bar " <> openClass } [ searchField { databases, search } ]
searchFieldContainer (false /\ _) _ _ = H.div {className: "search-bar closed"} [] where
openClass = if open then "open" else "closed"
onSearchChange :: R.State (Maybe Search) -> R.Hooks Unit onSearchChange :: R.State (Maybe Search) -> R.Hooks Unit
onSearchChange (search /\ setSearch) = onSearchChange (search /\ setSearch) =
...@@ -63,7 +64,7 @@ toggleButton :: R.State Boolean -> R.Element ...@@ -63,7 +64,7 @@ toggleButton :: R.State Boolean -> R.Element
toggleButton open = toggleButton open =
H.button { onClick: onToggleExpanded open, className: "search-bar-toggle" } H.button { onClick: onToggleExpanded open, className: "search-bar-toggle" }
[ H.i { className: "material-icons md-24" [ H.i { className: "material-icons md-24"
, style: { marginTop: "-5px", color: "#000" } } , style: { marginTop: "-2px", color: "#000" } }
[ H.text "control_point" ] ] [ H.text "control_point" ] ]
onToggleExpanded :: forall e. R.State Boolean -> EffectFn1 e Unit onToggleExpanded :: forall e. R.State Boolean -> EffectFn1 e Unit
......
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