Commit 350f3412 authored by Mael NICOLAS's avatar Mael NICOLAS

working on "user", derived DecodeJson, move Users in Gargantext

parent 416afc66
module Gargantext.Users.API
where
import Control.Monad.Aff (Aff)
import Control.Monad.Aff.Console (CONSOLE)
import Data.Either (Either)
import Gargantext.REST (get)
import Gargantext.Users (User)
import Network.HTTP.Affjax (AJAX)
import Prelude (show, ($), (<>))
user :: forall eff. Int -> Aff
(console :: CONSOLE, ajax :: AJAX | eff) (Either String User)
user id = get $ "localhost:8008/node/" <> show id
......@@ -40,12 +40,12 @@ userInfos =
ul [className "list-group"]
[
listElement <<< infoRender $ Tuple "Fonction: " "Enseignant chercheur"
,listElement <<< infoRender $ Tuple "Entité, service: " "Mines Saint-Etienne SPIN -PTSI"
,listElement <<< infoRender $ Tuple "Téléphone: " "(+33) 4 77 42 00 70"
,listElement <<< infoRender $ Tuple "Courriel: " "gargantua@rabelais.fr"
,listElement <<< infoRender $ Tuple "Bureau: " "D1/10"
,listElement <<< infoRender $ Tuple "Appelation: " "Maître de conférences (EPA)"
,listElement <<< infoRender $ Tuple "Lieu: " "Saint-Etienne, 158 Cours Fauriel"
, listElement <<< infoRender $ Tuple "Entité, service: " "Mines Saint-Etienne SPIN -PTSI"
, listElement <<< infoRender $ Tuple "Téléphone: " "(+33) 4 77 42 00 70"
, listElement <<< infoRender $ Tuple "Courriel: " "gargantua@rabelais.fr"
, listElement <<< infoRender $ Tuple "Bureau: " "D1/10"
, listElement <<< infoRender $ Tuple "Appelation: " "Maître de conférences (EPA)"
, listElement <<< infoRender $ Tuple "Lieu: " "Saint-Etienne, 158 Cours Fauriel"
]
pbInfos :: ReactElement
......@@ -53,8 +53,8 @@ pbInfos =
ul [className "list-group"]
[
listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
,listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
,listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
, listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
, listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
]
render :: forall props. Render State props Action
......
......@@ -3,10 +3,9 @@ module Gargantext.Users.Types.Types where
import Brevets as B
import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM)
import Data.Date (Date)
import Data.Generic (class Generic)
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Network.HTTP.Affjax (AJAX)
import Prelude (id, void)
import Prelude (bind, id, pure, void, ($))
import Projects as PS
import Publications as P
import Tab as Tab
......@@ -80,16 +79,75 @@ performAction _ _ _ = void do
-- mail "pierre.demugnier@mines-paristech.fr"
-- actif "1"
type User =
{
newtype User =
User {
id :: Int,
typename :: Int,
userId :: Int,
parentId :: Int,
name :: String,
date :: Date,
date :: String,
hyperData :: HyperData
}
newtype HyperData =
HyperData
{
bureau :: String,
atel :: String,
fax :: String,
aprecision :: String,
service :: String,
service2 :: String,
groupe :: String,
lieu :: String,
pservice :: String,
date_modification :: String,
fonction :: String,
pfonction :: String,
url :: String,
prenom :: String,
nom :: String,
idutilentite :: String,
afonction :: String,
grprech :: String,
entite :: String,
entite2 :: String
}
type HyperData =
{}
instance decodeUserHyperData :: DecodeJson HyperData where
decodeJson json = do
obj <- decodeJson json
bureau <- obj .? "bureau"
atel <- obj .? "atel"
fax <- obj .? "fax"
aprecision <- obj .? "aprecision"
service <- obj .? "service"
service2 <- obj .? "service2"
groupe <- obj .? "groupe"
lieu <- obj .? "lieu"
pservice <- obj .? "pservice"
date_modification <- obj .? "date_modification"
fonction <- obj .? "fonction"
pfonction <- obj .? "pfonction"
url <- obj .? "url"
prenom <- obj .? "prenom"
nom <- obj .? "nom"
idutilentite <- obj .? "idutilentite"
afonction <- obj .? "afonction"
grprech <- obj .? "grprech"
entite <- obj .? "entite"
entite2 <- obj .? "entite2"
pure $ HyperData {bureau, atel, fax, aprecision, service, service2, groupe, lieu, pservice, date_modification, fonction, pfonction, url, prenom, nom, idutilentite, afonction, grprech, entite, entite2}
instance decodeUser :: DecodeJson User where
decodeJson json = do
obj <- decodeJson json
id <- obj .? "id"
typename <- obj .? "typename"
userId <- obj .? "userId"
parentId <- obj .? "parentId"
name <- obj .? "name"
date <- obj .? "date"
hyperData <- obj .? "hyperData"
pure $ User {id, typename, userId, parentId, name, date, hyperData}
module Users
(module Users.Types,
module Users.Specs)
where
import Users.Types
import Users.Specs
module Users.Actions
(module Users.Actions.API)
where
import Users.Actions.API
module Users.Actions.API
where
import Users.Types.Types
import Control.Monad.Aff (Aff, attempt, launchAff)
import Control.Monad.Aff.Class (liftAff)
import Control.Monad.Aff.Console (log)
import Data.Argonaut (decodeJson)
import Data.Either (Either(..))
import Data.HTTP.Method (Method(..))
import Data.Identity (Identity(..))
import Network.HTTP.Affjax (AJAX, affjax, defaultRequest, get)
import Prelude (pure, show, unit, bind, discard, (<<<), ($), (<>))
user userID = launchAff $ do
res <- get "http://localhost:8008/node/452146"
pure res
module Users.Specs
(module Users.Specs.Renders,
layoutUser)
where
import Users.Specs.Renders
import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM)
import Network.HTTP.Affjax (AJAX)
import Thermite (Spec, simpleSpec)
import Users.Types.Types (Action, State, performAction)
layoutUser :: forall props eff . Spec ( console :: CONSOLE
, ajax :: AJAX
, dom :: DOM
| eff
) State props Action
layoutUser = simpleSpec performAction render
module Users.Specs.Renders
where
import Control.Monad.Aff.Class (liftAff)
import Data.Tuple (Tuple(..))
import Prelude (($), (<<<))
import React (ReactElement)
import React.DOM (div, h4, li, span, text, ul)
import React.DOM.Props (_id, className)
import Thermite (Render)
import Users.Types.Types (Action, State)
infoRender :: forall props. Tuple String String -> Array ReactElement
infoRender (Tuple title content) =
[
span [className "font-weight-bold text-primary"] [text title],
span [className "pull-right"] [text content]
]
listElement :: forall props. Array ReactElement -> ReactElement
listElement = li [className "list-group-item justify-content-between"]
card :: forall props. String -> Array ReactElement -> Array ReactElement
card title elems =
[
div [className "card"]
[
div [className "card-header text-white bg-primary"]
[
h4 [] [text title]
],
div [className "card-body"]
elems
]
]
userInfos :: ReactElement
userInfos =
ul [className "list-group"]
[
listElement <<< infoRender $ Tuple "Fonction: " "Enseignant chercheur"
,listElement <<< infoRender $ Tuple "Entité, service: " "Mines Saint-Etienne SPIN -PTSI"
,listElement <<< infoRender $ Tuple "Téléphone: " "(+33) 4 77 42 00 70"
,listElement <<< infoRender $ Tuple "Courriel: " "gargantua@rabelais.fr"
,listElement <<< infoRender $ Tuple "Bureau: " "D1/10"
,listElement <<< infoRender $ Tuple "Appelation: " "Maître de conférences (EPA)"
,listElement <<< infoRender $ Tuple "Lieu: " "Saint-Etienne, 158 Cours Fauriel"
]
pbInfos :: ReactElement
pbInfos =
ul [className "list-group"]
[
listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
,listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
,listElement <<< infoRender $ Tuple "" "https://www.imt.fr/en/"
]
render :: forall props. Render State props Action
render dispatch _ state _ =
[
div [className "container-fluid"]
[
div [className "row", _id "user-page-info"]
[
div [className "row"]
[
div [className "col-md-8"]
$ card "Jean HEUDE" [userInfos]
]
]
]
]
module Users.Types
(module Users.Types.Types,
module Users.Types.Lens,
brevetSpec,
projectSpec,
facets
)
where
import Users.Types.Lens
import Users.Types.Types
import Brevets as B
import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM)
import Data.List (fromFoldable)
import Data.Tuple (Tuple(..))
import Network.HTTP.Affjax (AJAX)
import Prelude (($))
import Projects as PS
import Tab (tabs)
import Thermite (Spec, focus)
brevetSpec :: forall eff props. Spec (dom :: DOM, console::CONSOLE, ajax :: AJAX | eff) State props Action
brevetSpec = focus _brevetslens _brevetsAction B.brevetsSpec
projectSpec :: forall eff props. Spec (dom :: DOM, console :: CONSOLE, ajax :: AJAX | eff) State props Action
projectSpec = focus _projectslens _projectsAction PS.projets
facets :: forall eff props. Spec ( dom :: DOM, console :: CONSOLE, ajax :: AJAX| eff) State props Action
facets = tabs _tablens _tabAction $ fromFoldable
[ Tuple "Publications(12)" publicationSpec
, Tuple "Brevets (2)" brevetSpec
, Tuple "Projets IMT (5)" projectSpec
]
module Users.Types.Lens where
import Brevets as B
import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM)
import Data.Either (Either(..))
import Data.Lens (Lens', Prism', lens, prism)
import Network.HTTP.Affjax (AJAX)
import Projects as PS
import Publications as P
import Tab as Tab
import Thermite (Spec, focus)
import Users.Types.Types (State(..), Action(..))
_tablens :: Lens' State Tab.State
_tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
_tabAction :: Prism' Action Tab.Action
_tabAction = prism TabA \ action ->
case action of
TabA laction -> Right laction
_-> Left action
_publens :: Lens' State P.State
_publens = lens (\s -> s.publications) (\s ss -> s { publications= ss})
_pubAction :: Prism' Action P.Action
_pubAction = prism PublicationA \ action ->
case action of
PublicationA laction -> Right laction
_-> Left action
publicationSpec :: forall eff props. Spec (dom :: DOM, console :: CONSOLE, ajax :: AJAX | eff) State props Action
publicationSpec = focus _publens _pubAction P.publicationSpec
_brevetslens :: Lens' State B.State
_brevetslens = lens (\s -> s.brevets) (\s ss -> s {brevets = ss})
_brevetsAction :: Prism' Action B.Action
_brevetsAction = prism BrevetsA \ action ->
case action of
BrevetsA laction -> Right laction
_-> Left action
_projectslens :: Lens' State PS.State
_projectslens = lens (\s -> s.projects) (\s ss -> s {projects = ss})
_projectsAction :: Prism' Action PS.Action
_projectsAction = prism ProjectsA \ action ->
case action of
ProjectsA laction -> Right laction
_-> Left action
module Users.Types.Types where
import Brevets as B
import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM)
import Data.Date (Date)
import Data.Generic (class Generic)
import Network.HTTP.Affjax (AJAX)
import Prelude (id, void)
import Projects as PS
import Publications as P
import Tab as Tab
import Thermite (PerformAction, modifyState)
type State =
{ activeTab :: Int
, publications :: P.State
, brevets :: B.State
, projects :: PS.State
}
initialState :: State
initialState =
{ activeTab : 0
, publications : P.initialState
, brevets : B.initialState
, projects : PS.initialState
}
data Action
= NoOp
| PublicationA P.Action
| BrevetsA B.Action
| ProjectsA PS.Action
| TabA Tab.Action
performAction :: forall eff props. PerformAction ( console :: CONSOLE
, ajax :: AJAX
, dom :: DOM
| eff ) State props Action
performAction NoOp _ _ = void do
modifyState id
performAction _ _ _ = void do
modifyState id
-- id 452146
-- typename 41
-- userId 1
-- parentId 452132
-- name "Pierre DEMUGNIER"
-- date "2018-06-18T14:27:50.670952Z"
-- hyperdata
-- bureau "V.305"
-- atel ""
-- fax ""
-- aprecision ""
-- service2 null
-- groupe ""
-- service "ARMINES"
-- lieu "Paris"
-- pservice ""
-- date_modification "07/06/2018"
-- pfonction ""
-- fonction "Service Développement Partenarial - Chargé de Projet France & International"
-- url ""
-- statut null
-- prenom "Pierre"
-- idutilentite "1055"
-- afonction ""
-- grprech ""
-- nom "DEMUGNIER"
-- entite "Armines"
-- entite2 null
-- id "11002"
-- tel "01.40.51.93.66"
-- idutilsiecoles null
-- groupe2 null
-- sexe "1"
-- mail "pierre.demugnier@mines-paristech.fr"
-- actif "1"
type User =
{
id :: Int,
typename :: Int,
userId :: Int,
parentId :: Int,
name :: String,
date :: Date,
hyperData :: HyperData
}
type HyperData =
{}
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