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