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