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

[PAGES] Corpus Documents are not loaded.

parent b1ff0afb
......@@ -9,7 +9,8 @@ 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 React.DOM (div, h1, h3, hr, i, p, text)
import React.DOM.Props (className, style)
import Thermite (Render, Spec
, simpleSpec, defaultPerformAction
, PerformAction, modifyState)
......@@ -18,73 +19,134 @@ import Effect.Aff (Aff)
import Gargantext.Config (toUrl, NodeType(..), End(..))
import Gargantext.Config.REST (get)
import Gargantext.Pages.Corpus.User.Users.Types.Types (User(..))
import Gargantext.Utils.DecodeMaybe ((.?|))
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
------------------------------------------------------------------------------
type State = { info :: Maybe AnnuaireInfo
, table :: Maybe AnnuaireTable
}
defaultAnnuaire :: AnnuaireTable
defaultAnnuaire = AnnuaireTable {annuaireTable : [IndividuRow {id: 0, name :"nothing, error"}] }
toRows :: AnnuaireTable -> Array IndividuRow
toRows (AnnuaireTable {annuaireTable : default}) = default
initialState :: State
initialState = { info : Nothing, table : Nothing }
type Offset = Int
type Limit = Int
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]
]
data Action
= Load Int
-- | ChangePageSize PageSizes
-- | ChangePage Int
------------------------------------------------------------------------------
defaultAnnuaireTable :: AnnuaireTable
defaultAnnuaireTable = AnnuaireTable { annuaireTable : [Nothing] }
defaultAnnuaireInfo :: AnnuaireInfo
defaultAnnuaireInfo = AnnuaireInfo { id : 0
, typename : 0
, userId : 0
, parentId : 0
, name : ""
, date : ""
, hyperdata : ""
}
toRows :: AnnuaireTable -> Array (Maybe User)
toRows (AnnuaireTable a) = a.annuaireTable
layoutAnnuaire :: Spec State {} Action
layoutAnnuaire = simpleSpec performAction render
------------------------------------------------------------------------------
newtype IndividuRow = IndividuRow { id :: Int
, name :: String
}
newtype AnnuaireTable = AnnuaireTable { annuaireTable :: Array IndividuRow}
render :: Render State {} Action
render dispatch _ state _ = [ div [className "row"]
[ div [className "col-md-3"] [ h3 [] [text info.name] ]
, div [className "col-md-9"] [ hr [style {height : "2px",backgroundColor : "black"}] ]
]
, div [className "row"] [ div [className "jumbotron1", style {padding : "12px 0px 20px 12px"}]
[ div [ className "col-md-8 content"]
[ p [] [ i [className "fa fa-globe"] []
, text info.name
]
]
, div [ className "col-md-4 content"]
[ p [] [ i [className "fa fa-calendar"] []
, text info.date
]
]
]
]
, p [] [text $ foldl (<>) " "
$ map (maybe "Nothing" (\(User u) -> show u.name))
$ maybe (toRows defaultAnnuaireTable) toRows state.table]
]
where
(AnnuaireInfo info) = maybe defaultAnnuaireInfo identity state.info
instance decodeIndividuRow :: DecodeJson IndividuRow where
------------------------------------------------------------------------------
newtype AnnuaireInfo = AnnuaireInfo { id :: Int
, typename :: Int
, userId :: Int
, parentId :: Int
, name :: String
, date :: String
, hyperdata :: String
}
instance decodeAnnuaireInfo :: DecodeJson AnnuaireInfo where
decodeJson json = do
obj <- decodeJson json
id <- obj .? "id"
name <- obj .? "name"
pure $ IndividuRow { id : id, name : name}
id <- obj .? "id"
typename <- obj .? "typename"
userId <- obj .? "userId"
parentId <- obj .? "parentId"
name <- obj .? "name"
date <- obj .? "date"
hyperdata <- obj .? "hyperdata"
pure $ AnnuaireInfo { id : id
, typename : typename
, userId : userId
, parentId : parentId
, name : name
, date : date
, hyperdata: hyperdata
}
newtype AnnuaireTable = AnnuaireTable { annuaireTable :: Array (Maybe User)}
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
------------------------------------------------------------------------
getTable :: Int -> Aff (Either String AnnuaireTable)
getTable id = get $ toUrl Back Children id
getInfo :: Int -> Aff (Either String AnnuaireInfo)
getInfo id = get $ toUrl Back Node id
------------------------------------------------------------------------
performAction :: PerformAction State {} Action
performAction (Load aId) _ _ = do
eitherAnnuaire <- lift $ getAnnuaire aId
_ <- case eitherAnnuaire of
(Right annuaire') -> void $ modifyState $ _annuaire ?~ annuaire'
eitherTable <- lift $ getTable aId
_ <- case eitherTable of
(Right table') -> void $ modifyState $ _table ?~ table'
(Left err) -> do
liftEffect $ log err
liftEffect <<< log $ "Fetching annuaire..."
performAction _ _ _ = pure unit
------------------------------------------------------------------------------
------------------------------------------------------------------------------
type State = { annuaire :: Maybe AnnuaireTable}
initialState :: State
initialState = { annuaire : Nothing }
eitherInfo <- lift $ getInfo aId
_ <- case eitherInfo of
(Right info') -> void $ modifyState $ _info ?~ info'
(Left err) -> do
liftEffect $ log err
data Action
= Load Int
-- | ChangePageSize PageSizes
-- | ChangePage Int
------------------------------------------------------------------------------
_annuaire :: Lens' State (Maybe AnnuaireTable)
_annuaire = lens (\s -> s.annuaire) (\s ss -> s{annuaire = ss})
liftEffect <<< log $ "Fetching annuaire page..."
performAction _ _ _ = pure unit
------------------------------------------------------------------------------
_table :: Lens' State (Maybe AnnuaireTable)
_table = lens (\s -> s.table) (\s ss -> s{table = ss})
_info :: Lens' State (Maybe AnnuaireInfo)
_info = lens (\s -> s.info) (\s ss -> s{info = ss})
------------------------------------------------------------------------------
......@@ -45,7 +45,7 @@ import Unsafe.Coerce (unsafeCoerce)
-- Right now it doesn't make sense to reload mock data.
data Action
= LoadData
= LoadData Int
| ChangePageSize PageSizes
| ChangePage Int
......@@ -185,20 +185,26 @@ performAction (ChangePageSize ps) _ _ = void $ modifyState $ changePageSize ps
performAction (ChangePage p) _ _ = void $ modifyState \(TableData td) -> TableData $ td { currentPage = p }
performAction LoadData _ _ = do
res <- lift $ loadPage
performAction (LoadData n) _ _ = do
res <- lift $ loadPage n
case res of
Left err -> pure unit
Right resData -> void $ modifyState $ const resData
Left err -> do
_ <- liftEffect $ log $ show err
_ <- liftEffect $ log $ show "Error: loading page documents"
pure unit
Right resData -> do
_ <- liftEffect $ log $ show "OK: loading page documents"
void $ modifyState $ const resData
loadPage :: Aff (Either String CorpusTableData)
loadPage = do
res <- get $ toUrl Back Children 452132
loadPage :: Int -> Aff (Either String CorpusTableData)
loadPage n = do
res <- get $ toUrl Back Children n
-- res <- get "http://localhost:8008/corpus/472764/facet/documents/table?offset=0&limit=10"
case res of
Left err -> do
_ <- liftEffect $ log $ show err
_ <- liftEffect $ log $ show "loading page documents"
pure $ Left $ show err
Right resData -> do
let docs = toTableData (res2corpus $ resData)
......
......@@ -35,9 +35,9 @@ dispatchAction dispatcher _ AddCorpus = do
dispatcher $ SetRoute AddCorpus
dispatcher $ AddCorpusA AC.LoadDatabaseDetails
dispatchAction dispatcher _ DocView = do
dispatcher $ SetRoute DocView
dispatcher $ DocViewA $ DV.LoadData
dispatchAction dispatcher _ (DocView n) = do
dispatcher $ SetRoute (DocView n)
dispatcher $ DocViewA $ DV.LoadData n
dispatchAction dispatcher _ SearchView = do
dispatcher $ SetRoute SearchView
......
......@@ -58,7 +58,7 @@ pagesComponent s =
selectSpec Login = focus _loginState _loginAction LN.renderSpec
selectSpec Home = layout0 $ noState (L.layoutLanding EN)
selectSpec AddCorpus = layout0 $ focus _addCorpusState _addCorpusAction AC.layoutAddcorpus
selectSpec DocView = layout0 $ focus _docViewState _docViewAction DV.layoutDocview
selectSpec (DocView i) = layout0 $ focus _docViewState _docViewAction DV.layoutDocview
selectSpec (UserPage i) = layout0 $ focus _userPageState _userPageAction U.layoutUser
selectSpec (DocAnnotation i) = layout0 $ focus _docAnnotationViewState _docAnnotationViewAction D.docview
selectSpec Tabview = layout0 $ noState TV.pureTab1
......
......@@ -17,7 +17,7 @@ data Routes
= Home
| Login
| AddCorpus
| DocView
| DocView Int
| SearchView
| UserPage Int
| DocAnnotation Int
......@@ -33,7 +33,7 @@ data Routes
instance showRoutes :: Show Routes where
show Login = "Login"
show AddCorpus = "AddCorpus"
show DocView = "DocView"
show (DocView i) = "DocView"
show SearchView = "Search"
show (UserPage i) = "User"
show (DocAnnotation i)= "Document"
......@@ -56,7 +56,7 @@ routing =
<|> DocAnnotation <$> (route "document" *> int)
<|> UserPage <$> (route "user" *> int)
<|> SearchView <$ route "search"
<|> DocView <$ route "docView"
<|> DocView <$> (route "docView" *> int)
<|> AddCorpus <$ route "addCorpus"
<|> CorpusAnalysis <$ route "corpus"
<|> PGraphExplorer <$ route "graph"
......
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