Commit 9e228236 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[contact] add HyperdataUser model

parent 2f839b7e
......@@ -9,7 +9,7 @@ import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact(..), HyperdataContact(..), ContactWhere(..))
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Table as T
import Gargantext.Ends (url, Frontends)
import Gargantext.Routes (SessionRoute(..))
......@@ -100,7 +100,7 @@ type PageProps =
, frontends :: Frontends
, pagePath :: R.State PagePath
-- , info :: AnnuaireInfo
, table :: TableResult Contact
, table :: TableResult CT.Contact
)
page :: Record PageProps -> R.Element
......@@ -124,10 +124,19 @@ pageCpt = R.hooksComponent "LoadedAnnuairePage" cpt
type AnnuaireId = Int
contactCells :: Session -> Frontends -> AnnuaireId -> Contact -> Array R.Element
contactCells :: Session -> Frontends -> AnnuaireId -> CT.Contact -> Array R.Element
contactCells session frontends aId = render
where
render (Contact { id, hyperdata : (HyperdataContact contact@{who: who, ou:ou} ) }) =
render (CT.Contact { id, hyperdata : (CT.HyperdataUser {shared: Nothing} )}) =
[ H.text ""
, H.span {} [ H.text "name" ]
--, H.a { href, target: "blank" } [ H.text $ maybe "name" identity contact.title ]
, H.text "No ContactWhere"
, H.text "No ContactWhereDept"
, H.div {className: "nooverflow"}
[ H.text "No ContactWhereRole" ]
]
render (CT.Contact { id, hyperdata : (CT.HyperdataUser {shared: Just (CT.HyperdataContact contact@{who: who, ou:ou}) } )}) =
--let nodepath = NodePath (sessionId session) NodeContact (Just id)
let nodepath = Routes.ContactPage (sessionId session) aId id
href = url frontends nodepath in
......@@ -135,17 +144,18 @@ contactCells session frontends aId = render
, H.a { href} [ H.text $ maybe "name" identity contact.title ]
--, H.a { href, target: "blank" } [ H.text $ maybe "name" identity contact.title ]
, H.text $ maybe "No ContactWhere" contactWhereOrg (head $ ou)
, H.text $ maybe "No ContactWhere" contactWhereDept (head $ ou)
, H.text $ maybe "No ContactWhereDept" contactWhereDept (head $ ou)
, H.div {className: "nooverflow"}
[ H.text $ maybe "No ContactWhere" contactWhereRole (head $ ou) ] ]
contactWhereOrg (ContactWhere { organization: [] }) = "No Organization"
contactWhereOrg (ContactWhere { organization: orga }) =
[ H.text $ maybe "No ContactWhereRole" contactWhereRole (head $ ou) ] ]
contactWhereOrg (CT.ContactWhere { organization: [] }) = "No Organization"
contactWhereOrg (CT.ContactWhere { organization: orga }) =
maybe "No orga (list)" identity (head orga)
contactWhereDept (ContactWhere { labTeamDepts : [] }) = "Empty Dept"
contactWhereDept (ContactWhere { labTeamDepts : dept }) =
contactWhereDept (CT.ContactWhere { labTeamDepts : [] }) = "Empty Dept"
contactWhereDept (CT.ContactWhere { labTeamDepts : dept }) =
maybe "No Dept (list)" identity (head dept)
contactWhereRole (ContactWhere { role: Nothing }) = "Empty Role"
contactWhereRole (ContactWhere { role: Just role }) = role
contactWhereRole (CT.ContactWhere { role: Nothing }) = "Empty Role"
contactWhereRole (CT.ContactWhere { role: Just role }) = role
data HyperdataAnnuaire = HyperdataAnnuaire
......@@ -198,7 +208,7 @@ instance decodeAnnuaireInfo :: DecodeJson AnnuaireInfo where
------------------------------------------------------------------------
loadPage :: Session -> PagePath -> AffTableResult Contact
loadPage :: Session -> PagePath -> AffTableResult CT.Contact
loadPage session {nodeId, params: { offset, limit, orderBy }} =
get session children
-- TODO orderBy
......
......@@ -14,10 +14,7 @@ import Data.String (joinWith)
import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Loader (loader)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types
( Contact(..), ContactData, ContactTouch(..), ContactWhere(..)
, ContactWho(..), HyperData(..), HyperdataContact(..) )
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs as Tabs
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes as Routes
......@@ -41,6 +38,7 @@ display title elems =
, H.div { className: "col-md-8"} elems
]]]]
getFirstName :: Maybe ContactWho -> String
getFirstName obj = fromMaybe "Empty title" $ getFirstName' <$> obj
getFirstName' = fromMaybe "Empty first name" <<< _.firstName <<< unwrap
......@@ -96,10 +94,24 @@ getMail' :: ContactTouch -> String
getMail' = fromMaybe "Empty mail" <<< _.mail <<< unwrap
-- | TODO format data in better design (UI) shape
contactInfos :: HyperdataContact -> Array R.Element
contactInfos (HyperdataContact {who:who, ou:ou}) = item <$> items
contactInfos :: HyperdataUser -> Array R.Element
contactInfos (HyperdataUser { shared }) = item <$> contactInfoItems shared
where
items =
item (name /\ value) =
H.li { className: "list-group-item" }
(infoRender (name /\ (" " <> value)))
contactInfoItems Nothing =
[ "Last Name" /\ "Empty Last Name"
, "First Name" /\ "Empty First Name"
, "Organisation" /\ "Empty Organisation"
, "Lab/Team/Dept" /\ "Empty Lab/Team/Dept"
, "Office" /\ "Empty Office"
, "City" /\ "Empty City"
, "Country" /\ "Empty Country"
, "Role" /\ "Empty Role"
, "Phone" /\ "Empty Phone"
, "Mail" /\ "Empty Mail" ]
contactInfoItems (Just (HyperdataContact {who:who, ou:ou})) =
[ "Last Name" /\ getLastName who
, "First Name" /\ getFirstName who
, "Organisation" /\ getOrga ou
......@@ -110,9 +122,6 @@ contactInfos (HyperdataContact {who:who, ou:ou}) = item <$> items
, "Role" /\ getRole ou
, "Phone" /\ getPhone ou
, "Mail" /\ getMail ou ]
item (name /\ value) =
H.li { className: "list-group-item" }
(infoRender (name /\ (" " <> value)))
listInfo :: Tuple String String -> R.Element
listInfo s = listElement $ infoRender s
......@@ -131,10 +140,11 @@ userLayout :: Record LayoutProps -> R.Element
userLayout props = R.createElement userLayoutCpt props []
userLayoutCpt :: R.Component LayoutProps
userLayoutCpt = R.staticComponent "G.C.Nodes.Annuaire.User.Contacts.userLayout" cpt
userLayoutCpt = R.hooksComponent "G.C.Nodes.Annuaire.User.Contacts.userLayout" cpt
where
cpt {frontends, nodeId, session} _ =
loader nodeId (getContact session) $
cpt {frontends, nodeId, session} _ = do
--loader nodeId (getContact session) $
useLoader nodeId (getContact session) $
\contactData@{contactNode: Contact {name, hyperdata}} ->
H.ul { className: "col-md-12 list-group" }
[ display (fromMaybe "no name" name) (contactInfos hyperdata)
......@@ -143,7 +153,7 @@ userLayoutCpt = R.staticComponent "G.C.Nodes.Annuaire.User.Contacts.userLayout"
-- | toUrl to get data
getContact :: Session -> Int -> Aff ContactData
getContact session id = do
contactNode <- get session $ Routes.NodeAPI NodeContact (Just id) ""
contactNode <- get session $ Routes.NodeAPI Node (Just id) ""
-- TODO: we need a default list for the pairings
--defaultListIds <- get $ toUrl endConfigStateful Back (Children NodeList 0 1 Nothing) $ Just id
--case (head defaultListIds :: Maybe (NodePoly HyperdataList)) of
......
......@@ -17,7 +17,7 @@ newtype Contact =
, parentId :: Maybe Int
, name :: Maybe String
, date :: Maybe String
, hyperdata :: HyperdataContact
, hyperdata :: HyperdataUser
}
derive instance newtypeContact :: Newtype Contact _
......@@ -102,6 +102,18 @@ instance decodeContactTouch :: DecodeJson ContactTouch
pure $ ContactTouch {mail, phone, url}
newtype HyperdataUser =
HyperdataUser { shared :: Maybe HyperdataContact }
derive instance newtypeHyperdataUser :: Newtype HyperdataUser _
instance decodeHyperdataUser :: DecodeJson HyperdataUser
where
decodeJson json = do
obj <- decodeJson json
shared <- obj .:! "shared"
pure $ HyperdataUser { shared }
newtype HyperdataContact =
HyperdataContact { bdd :: Maybe String
, who :: Maybe ContactWho
......
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