Commit 9264eae1 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Annuaire] Back connection ok.

parent aa8be585
...@@ -28,17 +28,16 @@ type State = { info :: Maybe AnnuaireInfo ...@@ -28,17 +28,16 @@ type State = { info :: Maybe AnnuaireInfo
, table :: Maybe AnnuaireTable , table :: Maybe AnnuaireTable
} }
initialState :: State
initialState = { info : Nothing, table : Nothing }
type Offset = Int type Offset = Int
type Limit = Int type Limit = Int
data Action data Action = Load Int
= Load Int
-- | ChangePageSize PageSizes -- | ChangePageSize PageSizes
-- | ChangePage Int -- | ChangePage Int
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
initialState :: State
initialState = { info : Nothing, table : Nothing }
defaultAnnuaireTable :: AnnuaireTable defaultAnnuaireTable :: AnnuaireTable
defaultAnnuaireTable = AnnuaireTable { annuaireTable : [Nothing] } defaultAnnuaireTable = AnnuaireTable { annuaireTable : [Nothing] }
...@@ -51,7 +50,7 @@ defaultAnnuaireInfo = AnnuaireInfo { id : 0 ...@@ -51,7 +50,7 @@ defaultAnnuaireInfo = AnnuaireInfo { id : 0
, date : "" , date : ""
, hyperdata : "" , hyperdata : ""
} }
------------------------------------------------------------------------------
toRows :: AnnuaireTable -> Array (Maybe User) toRows :: AnnuaireTable -> Array (Maybe User)
toRows (AnnuaireTable a) = a.annuaireTable toRows (AnnuaireTable a) = a.annuaireTable
...@@ -81,7 +80,8 @@ render dispatch _ state _ = [ div [className "row"] ...@@ -81,7 +80,8 @@ render dispatch _ state _ = [ div [className "row"]
$ maybe (toRows defaultAnnuaireTable) toRows state.table] $ maybe (toRows defaultAnnuaireTable) toRows state.table]
] ]
where where
(AnnuaireInfo info) = maybe defaultAnnuaireInfo identity state.info (AnnuaireInfo info) = maybe defaultAnnuaireInfo identity state.info
(AnnuaireTable table) = maybe defaultAnnuaireTable identity state.table
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
newtype AnnuaireInfo = AnnuaireInfo { id :: Int newtype AnnuaireInfo = AnnuaireInfo { id :: Int
...@@ -116,20 +116,14 @@ instance decodeAnnuaireInfo :: DecodeJson AnnuaireInfo where ...@@ -116,20 +116,14 @@ instance decodeAnnuaireInfo :: DecodeJson AnnuaireInfo where
newtype AnnuaireTable = AnnuaireTable { annuaireTable :: Array (Maybe User)} 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 rows <- decodeJson json
annuaire' <- obj .? "annuaire" pure $ AnnuaireTable { annuaireTable : rows}
pure $ AnnuaireTable { annuaireTable : annuaire'}
------------------------------------------------------------------------
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 :: PerformAction State {} Action
performAction (Load aId) _ _ = do performAction (Load aId) _ _ = do
eitherTable <- lift $ getTable aId eitherTable <- lift $ getTable aId
liftEffect $ log "Feching Table"
_ <- case eitherTable of _ <- case eitherTable of
(Right table') -> void $ modifyState $ _table ?~ table' (Right table') -> void $ modifyState $ _table ?~ table'
(Left err) -> do (Left err) -> do
...@@ -143,6 +137,12 @@ performAction (Load aId) _ _ = do ...@@ -143,6 +137,12 @@ performAction (Load aId) _ _ = do
liftEffect <<< log $ "Fetching annuaire page..." liftEffect <<< log $ "Fetching annuaire page..."
performAction _ _ _ = pure unit performAction _ _ _ = pure unit
------------------------------------------------------------------------
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
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
_table :: Lens' State (Maybe AnnuaireTable) _table :: Lens' State (Maybe AnnuaireTable)
_table = lens (\s -> s.table) (\s ss -> s{table = ss}) _table = lens (\s -> s.table) (\s ss -> s{table = ss})
......
...@@ -83,7 +83,6 @@ derive instance genericCorpus :: Generic CorpusView _ ...@@ -83,7 +83,6 @@ derive instance genericCorpus :: Generic CorpusView _
instance showCorpus :: Show CorpusView where instance showCorpus :: Show CorpusView where
show = genericShow show = genericShow
newtype Response = Response newtype Response = Response
{ cid :: Int { cid :: Int
, created :: String , created :: String
...@@ -92,7 +91,6 @@ newtype Response = Response ...@@ -92,7 +91,6 @@ newtype Response = Response
, ngramCount :: Int , ngramCount :: Int
} }
newtype Hyperdata = Hyperdata newtype Hyperdata = Hyperdata
{ title :: String { title :: String
, source :: String , source :: String
...@@ -200,16 +198,17 @@ performAction (LoadData n) _ _ = do ...@@ -200,16 +198,17 @@ performAction (LoadData n) _ _ = do
loadPage :: Int -> Aff (Either String CorpusTableData) loadPage :: Int -> Aff (Either String CorpusTableData)
loadPage n = do loadPage n = do
res <- get $ toUrl Back Children n res <- get $ toUrl Back Children n
-- TODO: offset and limit
-- 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: loading page documents"
_ <- 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)
_ <- liftEffect $ log $ show "Ok: loading page documents"
_ <- liftEffect $ log $ show $ map (\({ row: r, delete :_}) -> show r) ((\(TableData docs') -> docs'.rows) docs) _ <- liftEffect $ log $ show $ map (\({ row: r, delete :_}) -> show r) ((\(TableData docs') -> docs'.rows) docs)
_ <- liftEffect $ log $ show "loading page documents"
pure $ Right docs pure $ Right docs
where where
res2corpus :: Array Response -> Array CorpusView res2corpus :: Array Response -> Array CorpusView
......
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