Commit 9a926f2d authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] Annuaire Table with links to User pages (todo). Todo: refactor table...

[FEAT] Annuaire Table with links to User pages (todo). Todo: refactor table with options like pagination (from Corpus Document).
parent 9264eae1
......@@ -9,34 +9,58 @@ import Data.Either (Either(..))
import Data.Lens (Lens', Prism', lens, prism, (?~))
import Data.Maybe (Maybe(..), maybe)
import Effect.Class (liftEffect)
import React.DOM (div, h1, h3, hr, i, p, text)
import React.DOM.Props (className, style)
import React (ReactElement)
import React.DOM (div, h1, h3, hr, i, p, text, thead, tbody, input, br', b, b', tr, th, table, td, a)
import React.DOM.Props (_type, className, href, onChange, onClick, scope, selected, value, style)
import Thermite (Render, Spec
, simpleSpec, defaultPerformAction
, PerformAction, modifyState)
import Effect.Console (log)
import Effect.Aff (Aff)
import Gargantext.Config (toUrl, NodeType(..), End(..))
import Gargantext.Config.REST (get)
import Gargantext.Pages.Corpus.User.Users.Types.Types (User(..))
import Gargantext.Pages.Corpus.User.Users.Types.Types (User(..), HyperData(..))
import Gargantext.Utils.DecodeMaybe ((.?|))
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
------------------------------------------------------------------------------
type State = { info :: Maybe AnnuaireInfo
, table :: Maybe AnnuaireTable
, stable :: Maybe AnnuaireTable
}
type Offset = Int
type Limit = Int
type PageSize = Int
data Action = Load Int
-- | ChangePageSize PageSizes
-- | ChangePage Int
| ChangePageSize PageSize -- TODO
| ChangePage Int -- TODO
type AnnuaireTable' = Table IndividuView
newtype Table a
= Table
{ rows :: Array { row :: a }
, totalPages :: Int
, currentPage :: Int
, pageSize :: PageSize
, totalRecords :: Int
, title :: String
}
newtype IndividuView
= CorpusView
{ id :: Int
, name :: String
, role :: String
, company :: String
}
------------------------------------------------------------------------------
initialState :: State
initialState = { info : Nothing, table : Nothing }
initialState = { info : Nothing, stable : Nothing }
defaultAnnuaireTable :: AnnuaireTable
defaultAnnuaireTable = AnnuaireTable { annuaireTable : [Nothing] }
......@@ -70,18 +94,51 @@ render dispatch _ state _ = [ div [className "row"]
]
, div [ className "col-md-4 content"]
[ p [] [ i [className "fa fa-calendar"] []
, text info.date
, text ("Last update: " <> info.date)
]
]
]
]
, p [] [text $ foldl (<>) " "
$ map (maybe "Nothing" (\(User u) -> show u.name))
$ maybe (toRows defaultAnnuaireTable) toRows state.table]
, p [] []
, div [] [ text " Filter ", input []]
, br'
, div [className "row"]
[ div [className "col-md-1"] [b [] [text "title"]]
--, div [className "col-md-2"] [sizeDD d.pageSize dispatch]
--, div [className "col-md-3"] [textDescription d.currentPage d.pageSize d.totalRecords]
--, div [className "col-md-3"] [pagination dispatch d.totalPages d.currentPage]
]
, table [ className "table"]
[thead [ className "thead-dark"]
[tr [] [ th [scope "col"] [ b' [text ""] ]
, th [scope "col"] [ b' [text "Name"] ]
, th [scope "col"] [ b' [text "Role"] ]
, th [scope "col"] [ b' [text "Service"] ]
, th [scope "col"] [ b' [text "Company"] ]
]
]
, tbody [] $ map showRow individuals
]
]
where
(AnnuaireInfo info) = maybe defaultAnnuaireInfo identity state.info
(AnnuaireTable table) = maybe defaultAnnuaireTable identity state.table
(AnnuaireInfo info) = maybe defaultAnnuaireInfo identity state.info
(AnnuaireTable stable) = maybe defaultAnnuaireTable identity state.stable
individuals = maybe (toRows defaultAnnuaireTable) toRows state.stable
showRow :: Maybe User -> ReactElement
showRow Nothing = tr [][]
showRow (Just (User { id : id, hyperdata : (HyperData user) })) =
tr []
[ td [] [ a [ href (toUrl Back NodeUser id) ] [ text $ maybe' user.nom <> " " <> maybe' user.prenom ] ]
, td [] [text $ maybe' user.fonction]
, td [] [text $ maybe' user.service]
, td [] [text $ maybe' user.groupe]
]
where
maybe' = maybe "Unknown" identity
------------------------------------------------------------------------------
newtype AnnuaireInfo = AnnuaireInfo { id :: Int
......@@ -145,7 +202,7 @@ getInfo :: Int -> Aff (Either String AnnuaireInfo)
getInfo id = get $ toUrl Back Node id
------------------------------------------------------------------------------
_table :: Lens' State (Maybe AnnuaireTable)
_table = lens (\s -> s.table) (\s ss -> s{table = ss})
_table = lens (\s -> s.stable) (\s ss -> s{stable = ss})
_info :: Lens' State (Maybe AnnuaireInfo)
_info = lens (\s -> s.info) (\s ss -> s{info = ss})
......
......@@ -83,6 +83,7 @@ derive instance genericCorpus :: Generic CorpusView _
instance showCorpus :: Show CorpusView where
show = genericShow
newtype Response = Response
{ cid :: Int
, created :: String
......@@ -91,6 +92,7 @@ newtype Response = Response
, ngramCount :: Int
}
newtype Hyperdata = Hyperdata
{ title :: String
, source :: String
......
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