Commit b53c931d authored by Mael NICOLAS's avatar Mael NICOLAS

Refactoring so the code can be maintenable

parent 58c1fc40
module Forms.Users where
module Landing where
import Gargantext.Data.Landing
import Gargantext.Data.Lang
import Prelude hiding (div)
import Control.Monad.Cont.Trans (lift)
import Control.Monad.Eff.Console (CONSOLE)
import DOM (DOM)
import Gargantext.Lang.Landing.EnUS as En
import Gargantext.Lang.Landing.FrFR as Fr
import Network.HTTP.Affjax (AJAX)
import Prelude hiding (div)
import React (ReactElement)
import React.DOM (a, button, div, footer, h1, h3, hr, i, img, li, p, span, text, ul)
import React.DOM.Props (Props, _data, _id, aria, className, href, onClick, role, src, style, tabIndex, target, title)
import React (ReactElement)
import Routing.Hash.Aff (setHash)
import Thermite (PerformAction, Render, Spec, simpleSpec)
import Thermite as T
import Gargantext.Data.Landing
import Gargantext.Data.Lang
import Gargantext.Lang.Landing.EnUS as En
import Gargantext.Lang.Landing.FrFR as Fr
newtype State = State
{ userName :: String
, password :: String
......
......@@ -33,7 +33,7 @@ import SearchForm as S
import Tabview as TV
import Thermite (PerformAction, Render, Spec, _render, cotransform, defaultPerformAction, defaultRender, focus, modifyState, simpleSpec, withState)
import Unsafe.Coerce (unsafeCoerce)
import UserPage as UP
import Users.Info as UI
import GraphExplorer as GE
type E e = (dom :: DOM, ajax :: AJAX, console :: CONSOLE | e)
......@@ -45,7 +45,7 @@ type AppState =
, addCorpusState :: AC.State
, docViewState :: DV.State
, searchState :: S.State
, userPage :: UP.State
, userPage :: UI.State
, annotationdocumentView :: D.State
, ntreeView :: NT.State
, tabview :: TV.State
......@@ -64,7 +64,7 @@ initAppState =
, addCorpusState : AC.initialState
, docViewState : DV.tdata
, searchState : S.initialState
, userPage : UP.initialState
, userPage : UI.initialState
, annotationdocumentView : D.initialState
, ntreeView : NT.exampleTree
, tabview : TV.initialState
......@@ -83,7 +83,7 @@ data Action
| AddCorpusA AC.Action
| DocViewA DV.Action
| SearchA S.Action
| UserPageA UP.Action
| UserPageA UI.Action
| AnnotationDocumentViewA D.Action
| TreeViewA NT.Action
| TabViewA TV.Action
......@@ -180,11 +180,11 @@ _searchAction = prism SearchA \action ->
_-> Left action
_userPageState :: Lens' AppState UP.State
_userPageState :: Lens' AppState UI.State
_userPageState = lens (\s -> s.userPage) (\s ss -> s{userPage = ss})
_userPageAction :: Prism' Action UP.Action
_userPageAction :: Prism' Action UI.Action
_userPageAction = prism UserPageA \action ->
case action of
UserPageA caction -> Right caction
......@@ -264,7 +264,7 @@ pagesComponent s =
selectSpec Home = layout0 $ focus _landingState _landingAction (L.layoutLanding EN)
-- selectSpec AddCorpus = layout0 $ focus _addCorpusState _addCorpusAction AC.layoutAddcorpus
selectSpec DocView = layout0 $ focus _docViewState _docViewAction DV.layoutDocview
selectSpec UserPage = layout0 $ focus _userPageState _userPageAction UP.layoutUser
selectSpec UserPage = layout0 $ focus _userPageState _userPageAction UI.layoutUser
selectSpec (AnnotationDocumentView i) = layout0 $ focus _annotationdocumentviewState _annotationdocumentviewAction D.docview
selectSpec Tabview = layout0 $ focus _tabviewState _tabviewAction TV.tab1
-- To be removed
......@@ -574,7 +574,7 @@ dispatchAction dispatcher _ SearchView = do
dispatchAction dispatcher _ UserPage = do
_ <- dispatcher $ SetRoute $ UserPage
_ <- dispatcher $ UserPageA $ UP.NoOp
_ <- dispatcher $ UserPageA $ UI.NoOp
pure unit
dispatchAction dispatcher _ (AnnotationDocumentView i) = do
......
......@@ -59,7 +59,7 @@ routing =
where
tabview = Tabview <$ route "tabview"
documentView = AnnotationDocumentView <$> (route "documentView" *> int)
userPageRoute = UserPage <$ route "userPage"
userPageRoute = UserPage <$ (route "user" *> int)
searchRoute = SearchView <$ route "search"
docviewRoute = DocView <$ route "docView"
addcorpusRoute = AddCorpus <$ route "addCorpus"
......
module UserPage where
import Tab
import Brevets as B
import Control.Monad.Eff.Console (CONSOLE)
import DOM (DOM)
import Data.Either (Either(..))
import Data.Lens (Lens', Prism', lens, prism)
import Data.List (fromFoldable)
import Data.Tuple (Tuple(..))
import DocView as DV
import Network.HTTP.Affjax (AJAX)
import Prelude hiding (div)
import Projects as PS
import Publications as P
import React.DOM (a, div, h3, h5, h6, i, img, li, nav, small, span, table, tbody, td, text, th, thead, tr, ul)
import React.DOM.Props (_data, _id, aria, className, href, role, scope, src)
import Tab as Tab
import Thermite (PerformAction, Render, Spec, focus, modifyState, simpleSpec)
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
layoutUser :: forall props eff . Spec ( console :: CONSOLE
, ajax :: AJAX
, dom :: DOM
| eff
) State props Action
layoutUser = simpleSpec performAction render
where
render :: Render State props Action
render dispatch _ state _ =
[
div [className "container-fluid"]
[ div [className "row", _id "user-page-header"]
[ div [className "col-md-2"]
[ h3 [] [text "User Name"]
]
, div [className "col-md-8"] []
, div [className "col-md-2"]
[ span [] [text ""]
]
]
, div [className "row", _id "user-page-info"]
[
div [className "col-md-12"]
[ div [className "row"]
[ div [className "col-md-2"]
[ img [src "/images/Gargantextuel-212x300.jpg"] []
]
, div [className "col-md-1"] []
, div [className "col-md-8"]
[
ul [className "list-group"]
[
li [className "list-group-item justify-content-between"]
[ span [] [text "Fonction"]
, span [className "badge badge-default badge-pill"] [text "Enseignant chercheur"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Entité, service"]
, span [className "badge badge-default badge-pill"] [text "Mines Saint-Etienne SPIN -PTSI"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Téléphone"]
, span [className "badge badge-default badge-pill"] [text "(+33) 04 77 42 0070"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Courriel"]
, span [className "badge badge-default badge-pill"] [text "gargantua@rabelais.fr"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Bureau"]
, span [className "badge badge-default badge-pill"] [text "D1/10"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Apellation"]
, span [className "badge badge-default badge-pill"] [text "Maître de conférences (EPA)"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Lieu"]
, span [className "badge badge-default badge-pill"] [text "Saint-Etienne, 158 Cours Fauriel"]
]
]
]
]
]
]
, div [className "row",_id "user-page-footer"]
[ div [className "col-md-12"]
[]
]
]
]
_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
brevetSpec :: forall eff props. Spec (dom :: DOM, console::CONSOLE, ajax :: AJAX | eff) State props Action
brevetSpec = focus _brevetslens _brevetsAction B.brevetsSpec
_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
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.Info
(layoutUser,
brevetSpec,
projectSpec,
facets,
module Users.Types.Types,
module Users.Types.Lens
)
where
import Prelude hiding (div)
import Users.Types.Lens
import Users.Types.Types
import Brevets as B
import Control.Monad.Eff.Console (CONSOLE)
import DOM (DOM)
import Data.Either (Either(..))
import Data.Lens (Lens', Prism', lens, prism)
import Data.List (fromFoldable)
import Data.Tuple (Tuple(..))
import DocView as DV
import Network.HTTP.Affjax (AJAX)
import Projects as PS
import React.DOM (a, div, h3, h5, h6, i, img, li, nav, small, span, table, tbody, td, text, th, thead, tr, ul)
import React.DOM.Props (_data, _id, aria, className, href, role, scope, src)
import Tab (tabs)
import Thermite (PerformAction, Render, Spec, focus, modifyState, simpleSpec)
layoutUser :: forall props eff . Spec ( console :: CONSOLE
, ajax :: AJAX
, dom :: DOM
| eff
) State props Action
layoutUser = simpleSpec performAction render
where
render :: Render State props Action
render dispatch _ state _ =
[
div [className "container-fluid"]
[ div [className "row", _id "user-page-header"]
[ div [className "col-md-2"]
[ h3 [] [text "User Name"]
]
, div [className "col-md-8"] []
, div [className "col-md-2"]
[ span [] [text ""]
]
]
, div [className "row", _id "user-page-info"]
[
div [className "col-md-12"]
[ div [className "row"]
[ div [className "col-md-2"]
[ img [src "/images/Gargantextuel-212x300.jpg"] []
]
, div [className "col-md-1"] []
, div [className "col-md-8"]
[
ul [className "list-group"]
[
li [className "list-group-item justify-content-between"]
[ span [] [text "Fonction"]
, span [className "badge badge-default badge-pill"] [text "Enseignant chercheur"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Entité, service"]
, span [className "badge badge-default badge-pill"] [text "Mines Saint-Etienne SPIN -PTSI"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Téléphone"]
, span [className "badge badge-default badge-pill"] [text "(+33) 04 77 42 0070"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Courriel"]
, span [className "badge badge-default badge-pill"] [text "gargantua@rabelais.fr"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Bureau"]
, span [className "badge badge-default badge-pill"] [text "D1/10"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Apellation"]
, span [className "badge badge-default badge-pill"] [text "Maître de conférences (EPA)"]
]
, li [className "list-group-item justify-content-between"]
[ span [] [text "Lieu"]
, span [className "badge badge-default badge-pill"] [text "Saint-Etienne, 158 Cours Fauriel"]
]
]
]
]
]
]
, div [className "row",_id "user-page-footer"]
[ div [className "col-md-12"]
[]
]
]
]
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 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
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