Commit 30998d6f authored by Mael NICOLAS's avatar Mael NICOLAS

refactor, getting the info, need to do lenses

parent 350f3412
module Gargantext.Users.API module Gargantext.Users.API
where where
import Gargantext.Users.Types
import Control.Monad.Aff (Aff) import Control.Monad.Aff (Aff)
import Control.Monad.Aff.Console (CONSOLE) import Control.Monad.Aff.Console (CONSOLE, log)
import Data.Either (Either) import Control.Monad.Trans.Class (lift)
import DOM (DOM)
import Data.Either (Either(..))
import Data.Lens (set)
import Data.Maybe (Maybe(..))
import Gargantext.REST (get) import Gargantext.REST (get)
import Gargantext.Users (User)
import Network.HTTP.Affjax (AJAX) import Network.HTTP.Affjax (AJAX)
import Prelude (show, ($), (<>)) import Prelude (id, show, void, ($), (<>), bind)
import Thermite (PerformAction, modifyState)
user :: forall eff. Int -> Aff getUser :: forall eff. Int -> Aff
(console :: CONSOLE, ajax :: AJAX | eff) (Either String User) (console :: CONSOLE, ajax :: AJAX | eff) (Either String User)
user id = get $ "localhost:8008/node/" <> show id getUser id = get $ "localhost:8008/node/" <> show id
performAction :: forall eff props. PerformAction ( console :: CONSOLE
, ajax :: AJAX
, dom :: DOM
| eff ) State props Action
performAction NoOp _ _ = void do
modifyState id
performAction FetchUser _ _ = void do
value <- lift $ getUser 452145
let user = case value of
(Right user) -> Just user
_ -> Nothing
modifyState \state -> set _user user state
performAction _ _ _ = void do
modifyState id
...@@ -9,7 +9,8 @@ import Control.Monad.Aff.Console (CONSOLE) ...@@ -9,7 +9,8 @@ import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM) import DOM (DOM)
import Network.HTTP.Affjax (AJAX) import Network.HTTP.Affjax (AJAX)
import Thermite (Spec, simpleSpec) import Thermite (Spec, simpleSpec)
import Gargantext.Users.Types.Types (Action, State, performAction) import Gargantext.Users.Types (Action, State)
import Gargantext.Users.API (performAction)
layoutUser :: forall props eff . Spec ( console :: CONSOLE layoutUser :: forall props eff . Spec ( console :: CONSOLE
, ajax :: AJAX , ajax :: AJAX
......
module Gargantext.Users.Specs.Renders module Gargantext.Users.Specs.Renders
where where
import Control.Monad.Aff (attempt)
import Control.Monad.Aff.Class (liftAff) import Control.Monad.Aff.Class (liftAff)
import Data.Either (Either(..))
import Data.Generic (gShow)
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Prelude (($), (<<<)) import Gargantext.Users.API (getUser)
import Gargantext.Users.Types
import Prelude (show, ($), (<<<))
import React (ReactElement) import React (ReactElement)
import React.DOM (div, h4, li, span, text, ul) import React.DOM (div, h4, li, span, text, ul)
import React.DOM.Props (_id, className) import React.DOM.Props (_id, className)
import Thermite (Render) import Thermite (Render)
import Gargantext.Users.Types.Types (Action, State)
infoRender :: forall props. Tuple String String -> Array ReactElement infoRender :: forall props. Tuple String String -> Array ReactElement
...@@ -67,7 +72,9 @@ render dispatch _ state _ = ...@@ -67,7 +72,9 @@ render dispatch _ state _ =
div [className "row"] div [className "row"]
[ [
div [className "col-md-8"] div [className "col-md-8"]
$ card "Jean HEUDE" [userInfos] $ card (case state.user of (Just _) -> "Ok"
Nothing -> "Pas Ok")
[userInfos]
] ]
] ]
] ]
......
module Gargantext.Users.Types module Gargantext.Users.Types
(module Gargantext.Users.Types.Types, (module Gargantext.Users.Types.Types,
module Gargantext.Users.Types.Lens, module Gargantext.Users.Types.Lens,
module Gargantext.Users.Types.States,
brevetSpec, brevetSpec,
projectSpec, projectSpec,
facets facets
...@@ -9,6 +10,7 @@ module Gargantext.Users.Types ...@@ -9,6 +10,7 @@ module Gargantext.Users.Types
import Gargantext.Users.Types.Lens import Gargantext.Users.Types.Lens
import Gargantext.Users.Types.Types import Gargantext.Users.Types.Types
import Gargantext.Users.Types.States
import Brevets as B import Brevets as B
import Control.Monad.Aff.Console (CONSOLE) import Control.Monad.Aff.Console (CONSOLE)
......
...@@ -5,13 +5,17 @@ import Control.Monad.Aff.Console (CONSOLE) ...@@ -5,13 +5,17 @@ import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM) import DOM (DOM)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Lens (Lens', Prism', lens, prism) import Data.Lens (Lens', Prism', lens, prism)
import Data.Maybe (Maybe)
import Gargantext.Users.Types.States (Action(..), State)
import Gargantext.Users.Types.Types (User)
import Network.HTTP.Affjax (AJAX) import Network.HTTP.Affjax (AJAX)
import Projects as PS import Projects as PS
import Publications as P import Publications as P
import Tab as Tab import Tab as Tab
import Thermite (Spec, focus) import Thermite (Spec, focus)
import Gargantext.Users.Types.Types (State(..), Action(..))
_user :: Lens' State (Maybe User)
_user = lens (\s -> s.user) (\s ss -> s{user = ss})
_tablens :: Lens' State Tab.State _tablens :: Lens' State Tab.State
_tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss}) _tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
......
module Gargantext.Users.Types.States
where
import Brevets as B
import Data.Maybe (Maybe(..))
import Gargantext.Users.Types.Types (User)
import Projects as PS
import Publications as P
import Tab as Tab
data Action
= NoOp
| PublicationA P.Action
| BrevetsA B.Action
| ProjectsA PS.Action
| TabA Tab.Action
| FetchUser
type State =
{ activeTab :: Int
, publications :: P.State
, brevets :: B.State
, projects :: PS.State
, user :: Maybe User
}
initialState :: State
initialState =
{ activeTab : 0
, publications : P.initialState
, brevets : B.initialState
, projects : PS.initialState
, user: Nothing
}
module Gargantext.Users.Types.Types where module Gargantext.Users.Types.Types where
import Brevets as B
import Control.Monad.Aff.Console (CONSOLE)
import DOM (DOM)
import Data.Argonaut (class DecodeJson, decodeJson, (.?)) import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Network.HTTP.Affjax (AJAX) import Data.Generic (class Generic)
import Prelude (bind, id, pure, void, ($)) import Prelude (bind, pure, ($))
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"
newtype User = newtype User =
User { User {
......
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