Commit e467737c authored by Alexandre Delanoë's avatar Alexandre Delanoë

[ANNUAIRE] page main config.

parent b39bf39a
module Gargantext.Pages.Corpus.Annuaire where module Gargantext.Pages.Corpus.Annuaire where
import Prelude import Prelude
import React.DOM (div, h1, text)
import Thermite (Render, Spec, simpleSpec, defaultPerformAction)
import Data.Array (concat)
import Data.Traversable (foldl)
import Control.Monad.Trans.Class (lift)
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, p, text)
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)
render :: Render {} {} Void import Gargantext.Utils.DecodeMaybe ((.?|))
render dispatch _ state _ = [h1 [] [text "Annuaire"]] import Data.Argonaut (class DecodeJson, decodeJson, (.?))
layoutAnnuaire :: Spec {} {} Void
layoutAnnuaire = simpleSpec defaultPerformAction render
defaultAnnuaire :: AnnuaireTable
defaultAnnuaire = AnnuaireTable {annuaireTable : [IndividuRow {id: 0, name :"nothing, error"}] }
toRows :: AnnuaireTable -> Array IndividuRow
toRows (AnnuaireTable {annuaireTable : default}) = default
render :: Render State {} Action
render dispatch _ state _ = [ h1 [] [text "Annuaire 2"]
, p [] [text $ foldl (<>) " "
$ map (\(IndividuRow {id:_,name:n}) -> n)
$ maybe (toRows defaultAnnuaire) toRows state.annuaire]
]
layoutAnnuaire :: Spec State {} Action
layoutAnnuaire = simpleSpec performAction render
------------------------------------------------------------------------------
newtype IndividuRow = IndividuRow { id :: Int
, name :: String
}
newtype AnnuaireTable = AnnuaireTable { annuaireTable :: Array IndividuRow}
instance decodeIndividuRow :: DecodeJson IndividuRow where
decodeJson json = do
obj <- decodeJson json
id <- obj .? "id"
name <- obj .? "name"
pure $ IndividuRow { id : id, name : name}
instance decodeAnnuaireTable :: DecodeJson AnnuaireTable where
decodeJson json = do
obj <- decodeJson json
annuaire' <- obj .? "annuaire"
pure $ AnnuaireTable { annuaireTable : annuaire'}
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
getAnnuaire :: Int -> Aff (Either String AnnuaireTable)
getAnnuaire id = get $ toUrl Back Children id
--data Action performAction :: PerformAction State {} Action
-- = LoadData performAction (Load aId) _ _ = do
eitherAnnuaire <- lift $ getAnnuaire aId
_ <- case eitherAnnuaire of
(Right annuaire') -> void $ modifyState $ _annuaire ?~ annuaire'
(Left err) -> do
liftEffect $ log err
liftEffect <<< log $ "Fetching annuaire..."
performAction _ _ _ = pure unit
------------------------------------------------------------------------------
------------------------------------------------------------------------------
type State = { annuaire :: Maybe AnnuaireTable}
initialState :: State
initialState = { annuaire : Nothing }
data Action
= Load Int
-- | ChangePageSize PageSizes -- | ChangePageSize PageSizes
-- | ChangePage Int -- | ChangePage Int
-- ------------------------------------------------------------------------------
_annuaire :: Lens' State (Maybe AnnuaireTable)
_annuaire = lens (\s -> s.annuaire) (\s ss -> s{annuaire = ss})
------------------------------------------------------------------------------
------------------------------------------------------------------------------
...@@ -12,6 +12,7 @@ import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE ...@@ -12,6 +12,7 @@ import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE
-- import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG -- import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG
import Gargantext.Pages.Corpus.User.Users as U import Gargantext.Pages.Corpus.User.Users as U
import Gargantext.Pages.Corpus.Annuaire as Annuaire
-- import Gargantext.Pages.Home as L -- import Gargantext.Pages.Home as L
-- import Gargantext.Pages.Layout.Specs.Search as S -- import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Router (Routes(..)) import Gargantext.Router (Routes(..))
...@@ -48,7 +49,8 @@ dispatchAction dispatcher _ (UserPage id) = do ...@@ -48,7 +49,8 @@ dispatchAction dispatcher _ (UserPage id) = do
dispatcher $ UserPageA $ U.FetchUser id dispatcher $ UserPageA $ U.FetchUser id
dispatchAction dispatcher _ (Annuaire id) = do dispatchAction dispatcher _ (Annuaire id) = do
dispatcher $ SetRoute $ Annuaire id dispatcher $ SetRoute $ Annuaire id
dispatcher $ AnnuaireAction $ Annuaire.Load id
dispatchAction dispatcher _ (Folder id) = do dispatchAction dispatcher _ (Folder id) = do
dispatcher $ SetRoute $ Folder id dispatcher $ SetRoute $ Folder id
......
-- | Module Description
module Gargantext.Pages.Layout.Actions where module Gargantext.Pages.Layout.Actions where
import Prelude hiding (div) import Prelude hiding (div)
import Control.Monad.Cont.Trans (lift) import Control.Monad.Cont.Trans (lift)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Lens (Prism', prism) import Data.Lens (Prism', prism)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Console (log) import Effect.Console (log)
import Gargantext.Components.Login as LN import Gargantext.Components.Login as LN
import Gargantext.Components.Modals.Modal (modalShow) import Gargantext.Components.Modals.Modal (modalShow)
import Gargantext.Components.Tree as Tree import Gargantext.Components.Tree as Tree
import Gargantext.Pages.Corpus.Doc.Annotation as D import Gargantext.Pages.Corpus.Doc.Annotation as D
import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV
import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE
import Gargantext.Pages.Corpus.User.Users as U import Gargantext.Pages.Corpus.User.Users as U
import Gargantext.Pages.Layout.Specs.AddCorpus as AC import Gargantext.Pages.Corpus.Annuaire as Annuaire
import Gargantext.Pages.Layout.Specs.Search as S import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Pages.Layout.States (AppState) import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Router (Routes) import Gargantext.Pages.Layout.States (AppState)
import Thermite (PerformAction, modifyState) import Gargantext.Router (Routes)
import Thermite (PerformAction, modifyState)
------------------------------------------------------------------------
data Action data Action
= Initialize = Initialize
...@@ -29,10 +33,11 @@ data Action ...@@ -29,10 +33,11 @@ data Action
| DocViewA DV.Action | DocViewA DV.Action
| SearchA S.Action | SearchA S.Action
| UserPageA U.Action | UserPageA U.Action
| DocAnnotationViewA D.Action | DocAnnotationViewA D.Action
| TreeViewA Tree.Action | TreeViewA Tree.Action
| GraphExplorerA GE.Action | GraphExplorerA GE.Action
| Search String | Search String
| AnnuaireAction Annuaire.Action
| Go | Go
| ShowLogin | ShowLogin
| ShowAddcorpus | ShowAddcorpus
...@@ -62,9 +67,7 @@ performAction Initialize _ state = void do ...@@ -62,9 +67,7 @@ performAction Initialize _ state = void do
_ <- liftEffect $ log "loading Initial nodes" _ <- liftEffect $ log "loading Initial nodes"
case state.initialized of case state.initialized of
false -> do false -> do
lnodes <- lift $ Tree.loadDefaultNode lnodes <- lift $ Tree.loadDefaultNode
case lnodes of case lnodes of
Left err -> do Left err -> do
pure unit pure unit
...@@ -88,14 +91,15 @@ performAction Initialize _ state = void do ...@@ -88,14 +91,15 @@ performAction Initialize _ state = void do
_ -> do _ -> do
pure unit pure unit
performAction (LoginA _) _ _ = pure unit performAction (LoginA _) _ _ = pure unit
performAction (AddCorpusA _) _ _ = pure unit performAction (AddCorpusA _) _ _ = pure unit
performAction (DocViewA _) _ _ = pure unit performAction (DocViewA _) _ _ = pure unit
performAction (SearchA _) _ _ = pure unit performAction (SearchA _) _ _ = pure unit
performAction (UserPageA _) _ _ = pure unit performAction (UserPageA _) _ _ = pure unit
performAction (DocAnnotationViewA _) _ _ = pure unit performAction (DocAnnotationViewA _) _ _ = pure unit
performAction (TreeViewA _) _ _ = pure unit performAction (TreeViewA _) _ _ = pure unit
performAction (GraphExplorerA _) _ _ = pure unit performAction (GraphExplorerA _) _ _ = pure unit
performAction (AnnuaireAction _) _ _ = pure unit
---------------------------------------------------------- ----------------------------------------------------------
...@@ -129,6 +133,12 @@ _userPageAction = prism UserPageA \action -> ...@@ -129,6 +133,12 @@ _userPageAction = prism UserPageA \action ->
UserPageA caction -> Right caction UserPageA caction -> Right caction
_-> Left action _-> Left action
_annuaireAction :: Prism' Action Annuaire.Action
_annuaireAction = prism AnnuaireAction \action ->
case action of
AnnuaireAction a -> Right a
_ -> Left action
_docAnnotationViewAction :: Prism' Action D.Action _docAnnotationViewAction :: Prism' Action D.Action
_docAnnotationViewAction = prism DocAnnotationViewA \action -> _docAnnotationViewAction = prism DocAnnotationViewA \action ->
case action of case action of
......
...@@ -20,10 +20,10 @@ import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE ...@@ -20,10 +20,10 @@ import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE
import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG
import Gargantext.Pages.Corpus.User.Users as U import Gargantext.Pages.Corpus.User.Users as U
import Gargantext.Pages.Home as L import Gargantext.Pages.Home as L
import Gargantext.Pages.Layout.Actions (Action(..), _addCorpusAction, _docAnnotationViewAction, _docViewAction, _graphExplorerAction, _loginAction, _searchAction, _treeAction, _userPageAction, performAction) import Gargantext.Pages.Layout.Actions (Action(..), _addCorpusAction, _docAnnotationViewAction, _docViewAction, _graphExplorerAction, _loginAction, _searchAction, _treeAction, _userPageAction, performAction, _annuaireAction)
import Gargantext.Pages.Layout.Specs.AddCorpus as AC import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Pages.Layout.Specs.Search as S import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Pages.Layout.States (AppState, _addCorpusState, _docAnnotationViewState, _docViewState, _graphExplorerState, _loginState, _searchState, _treeState, _userPageState) import Gargantext.Pages.Layout.States (AppState, _addCorpusState, _docAnnotationViewState, _docViewState, _graphExplorerState, _loginState, _searchState, _treeState, _userPageState, _annuaireState)
import Gargantext.Router (Routes(..)) import Gargantext.Router (Routes(..))
import React (ReactElement) import React (ReactElement)
import React.DOM (a, button, div, footer, hr', img, input, li, p, span, text, ul) import React.DOM (a, button, div, footer, hr', img, input, li, p, span, text, ul)
...@@ -67,7 +67,7 @@ pagesComponent s = ...@@ -67,7 +67,7 @@ pagesComponent s =
selectSpec NGramsTable = layout0 $ noState NG.ngramsTableSpec selectSpec NGramsTable = layout0 $ noState NG.ngramsTableSpec
selectSpec PGraphExplorer = focus _graphExplorerState _graphExplorerAction GE.specOld selectSpec PGraphExplorer = focus _graphExplorerState _graphExplorerAction GE.specOld
selectSpec Dashboard = layout0 $ noState Dsh.layoutDashboard selectSpec Dashboard = layout0 $ noState Dsh.layoutDashboard
selectSpec (Annuaire i) = layout0 $ noState A.layoutAnnuaire selectSpec (Annuaire i) = layout0 $ focus _annuaireState _annuaireAction A.layoutAnnuaire
selectSpec (Folder i) = layout0 $ noState F.layoutFolder selectSpec (Folder i) = layout0 $ noState F.layoutFolder
-- selectSpec _ = simpleSpec defaultPerformAction defaultRender -- selectSpec _ = simpleSpec defaultPerformAction defaultRender
......
...@@ -2,17 +2,18 @@ module Gargantext.Pages.Layout.States where ...@@ -2,17 +2,18 @@ module Gargantext.Pages.Layout.States where
import Prelude hiding (div) import Prelude hiding (div)
import Data.Lens (Lens', lens) import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(Just)) import Data.Maybe (Maybe(Just))
import Gargantext.Components.Login as LN import Gargantext.Components.Login as LN
import Gargantext.Components.Tree as Tree import Gargantext.Components.Tree as Tree
import Gargantext.Pages.Corpus.Doc.Annotation as D import Gargantext.Pages.Corpus.Doc.Annotation as D
import Gargantext.Pages.Corpus.Annuaire as Annuaire
import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV
import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE
import Gargantext.Pages.Corpus.User.Users as U import Gargantext.Pages.Corpus.User.Users as U
import Gargantext.Pages.Layout.Specs.AddCorpus as AC import Gargantext.Pages.Layout.Specs.AddCorpus as AC
import Gargantext.Pages.Layout.Specs.Search as S import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Router (Routes(..)) import Gargantext.Router (Routes(..))
type AppState = type AppState =
{ currentRoute :: Maybe Routes { currentRoute :: Maybe Routes
...@@ -22,6 +23,7 @@ type AppState = ...@@ -22,6 +23,7 @@ type AppState =
, searchState :: S.State , searchState :: S.State
, userPageState :: U.State , userPageState :: U.State
, docAnnotationState :: D.State , docAnnotationState :: D.State
, annuaireState :: Annuaire.State
, ntreeState :: Tree.State , ntreeState :: Tree.State
, search :: String , search :: String
, showLogin :: Boolean , showLogin :: Boolean
...@@ -40,6 +42,7 @@ initAppState = ...@@ -40,6 +42,7 @@ initAppState =
, userPageState : U.initialState , userPageState : U.initialState
, docAnnotationState : D.initialState , docAnnotationState : D.initialState
, ntreeState : Tree.exampleTree , ntreeState : Tree.exampleTree
, annuaireState : Annuaire.initialState
, search : "" , search : ""
, showLogin : false , showLogin : false
, showCorpus : false , showCorpus : false
...@@ -63,6 +66,9 @@ _searchState = lens (\s -> s.searchState) (\s ss -> s{searchState = ss}) ...@@ -63,6 +66,9 @@ _searchState = lens (\s -> s.searchState) (\s ss -> s{searchState = ss})
_userPageState :: Lens' AppState U.State _userPageState :: Lens' AppState U.State
_userPageState = lens (\s -> s.userPageState) (\s ss -> s{userPageState = ss}) _userPageState = lens (\s -> s.userPageState) (\s ss -> s{userPageState = ss})
_annuaireState :: Lens' AppState Annuaire.State
_annuaireState = lens (\s -> s.annuaireState) (\s ss -> s{annuaireState = ss})
_docAnnotationViewState :: Lens' AppState D.State _docAnnotationViewState :: Lens' AppState D.State
_docAnnotationViewState = lens (\s -> s.docAnnotationState) (\s ss -> s{docAnnotationState = ss}) _docAnnotationViewState = lens (\s -> s.docAnnotationState) (\s ss -> s{docAnnotationState = ss})
......
...@@ -54,7 +54,7 @@ routing = ...@@ -54,7 +54,7 @@ routing =
Login <$ route "login" Login <$ route "login"
<|> Tabview <$ route "tabview" <|> Tabview <$ route "tabview"
<|> DocAnnotation <$> (route "document" *> int) <|> DocAnnotation <$> (route "document" *> int)
<|> UserPage <$> (route "user" *> int) <|> UserPage <$> (route "user" *> int)
<|> SearchView <$ route "search" <|> SearchView <$ route "search"
<|> DocView <$ route "docView" <|> DocView <$ route "docView"
<|> AddCorpus <$ route "addCorpus" <|> AddCorpus <$ route "addCorpus"
...@@ -63,7 +63,7 @@ routing = ...@@ -63,7 +63,7 @@ routing =
<|> NGramsTable <$ route "ngrams" <|> NGramsTable <$ route "ngrams"
<|> Dashboard <$ route "dashboard" <|> Dashboard <$ route "dashboard"
<|> Annuaire <$> (route "annuaire" *> int) <|> Annuaire <$> (route "annuaire" *> int)
<|> Folder <$> (route "folder" *> int) <|> Folder <$> (route "folder" *> int)
<|> Home <$ lit "" <|> Home <$ lit ""
where where
route str = lit "" *> lit str route str = lit "" *> lit str
......
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