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

[BUG] State is overwritten before changing the page.

parent dccaa33a
......@@ -98,7 +98,7 @@ endPathUrl Back c nt i = pathUrl c.back nt i
endPathUrl Front c nt i = pathUrl c.front nt i
pathUrl :: Config -> NodeType -> Id -> UrlPath
pathUrl c Children i = pathUrl c Node i <> "/" <> show Children
pathUrl c (Children o l) i = pathUrl c Node i <> "/" <> show (Children o l)
pathUrl c nt i = c.prePath <> urlConfig nt <> "/" <> show i
------------------------------------------------------------
toUrl :: End -> NodeType -> Id -> Url
......@@ -110,7 +110,7 @@ toUrl e nt i = doUrl base path params
------------------------------------------------------------
data NodeType = NodeUser
| Annuaire
| Children
| Children Offset Limit
| Corpus
| CorpusV3
| Dashboard
......@@ -123,6 +123,10 @@ data NodeType = NodeUser
| Tree
data End = Back | Front
type Id = Int
type Limit = Int
type Offset = Int
------------------------------------------------------------
data ApiVersion = V10 | V11
instance showApiVersion :: Show ApiVersion where
......@@ -132,7 +136,7 @@ instance showApiVersion :: Show ApiVersion where
------------------------------------------------------------
urlConfig :: NodeType -> Url
urlConfig Annuaire = show Annuaire
urlConfig Children = show Children
urlConfig (Children o l) = show (Children o l)
urlConfig Corpus = show Corpus
urlConfig CorpusV3 = show CorpusV3
urlConfig Dashboard = show Dashboard
......@@ -147,7 +151,6 @@ urlConfig Tree = show Tree
------------------------------------------------------------
instance showNodeType :: Show NodeType where
show Annuaire = "annuaire"
show Children = "children"
show Corpus = "corpus"
show CorpusV3 = "corpus"
show Dashboard = "dashboard"
......@@ -159,12 +162,13 @@ instance showNodeType :: Show NodeType where
show Node = "node"
show NodeUser = "user"
show Tree = "tree"
show (Children o l) = "children?offset=" <> show o <> "&limit=" <> show l
-- | TODO : where is the Read Class ?
-- instance readNodeType :: Read NodeType where
readNodeType :: String -> NodeType
readNodeType "Annuaire" = Annuaire
readNodeType "Children" = Children
readNodeType "Children" = (Children 0 0)
readNodeType "Dashboard" = Dashboard
readNodeType "Document" = Url_Document
readNodeType "Folder" = Folder
......
......@@ -192,7 +192,7 @@ instance decodeAnnuaireTable :: DecodeJson AnnuaireTable where
pure $ AnnuaireTable { annuaireTable : rows}
------------------------------------------------------------------------
getTable :: Int -> Aff (Either String AnnuaireTable)
getTable id = get $ toUrl Back Children id
getTable id = get $ toUrl Back (Children 0 10) id
getInfo :: Int -> Aff (Either String AnnuaireInfo)
getInfo id = get $ toUrl Back Node id
......
......@@ -68,8 +68,8 @@ _tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
------------------------------------------------------------------------
data HeaderAction = Load Int
data Action = HeaderA HeaderAction
| DocviewA D.Action
data Action = HeaderA HeaderAction
| DocviewA D.Action
| AuthorviewA A.Action
| SourceviewA S.Action
| TermsviewA T.Action
......@@ -191,7 +191,6 @@ corpusHeaderSpec = simpleSpec performAction render
}
= maybe corpusInfoDefault identity state.info
------------------------------------------------------------------------
performAction :: PerformAction HeaderState {} HeaderAction
performAction (Load nId) _ _ = do
......@@ -210,10 +209,10 @@ getNode id = get $ toUrl Back Node id
------------------------------------------------------------------------
facets :: Spec State {} Action
facets =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec
, Tuple "Authors" authorPageSpec
, Tuple "Sources" sourcePageSpec
, Tuple "Terms" termsPageSpec
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Documents" docPageSpec
, Tuple "Authors" authorPageSpec
, Tuple "Sources" sourcePageSpec
, Tuple "Terms" termsPageSpec
]
docPageSpec :: Spec State {} Action
......
module Gargantext.Pages.Corpus.Tabs.Documents where
import Data.Maybe (Maybe(..))
import Affjax (defaultRequest, printResponseFormatError, request)
import Affjax.ResponseFormat as ResponseFormat
import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.?), (:=), (~>))
import Data.Array (filter)
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
......@@ -19,7 +21,7 @@ import Thermite (PerformAction, Render, Spec, modifyState, defaultPerformAction,
import Unsafe.Coerce (unsafeCoerce)
------------------------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Config (NodeType(..), toUrl, End(..))
import Gargantext.Config (NodeType(..), toUrl, End(..), Limit, Offset)
import Gargantext.Config.REST (get)
import Gargantext.Utils.DecodeMaybe ((.|))
import Gargantext.Components.Charts.Options.ECharts (chart)
......@@ -34,7 +36,8 @@ import Gargantext.Pages.Corpus.Dashboard (globalPublis)
-- TODO: When a pagination link is clicked, reload data.
data Action
= LoadData Int
= UpdateNodeId Int
| LoadData Int
| ChangePageSize PageSizes
| ChangePage Int
......@@ -52,7 +55,9 @@ newtype TableData a
, pageSize :: PageSizes
, totalRecords :: Int
, title :: String
-- , tree :: FTree
, nodeId :: Maybe Int -- /!\ When changing the pages of the Table, NodeId
-- is needed to reload Data (other solution is using
-- NodeId as a parameter
}
newtype DocumentsView
......@@ -169,10 +174,19 @@ layoutDocview = simpleSpec performAction render
fa false = "far "
performAction :: PerformAction State {} Action
performAction (LoadData n) _ _ = do
performAction (UpdateNodeId nId) _ _ = do
void $ modifyState \(TableData td) -> TableData $ td { nodeId = (Just nId) }
logs $ "writing NodeId" <> show nId
performAction (LoadData n) props state@(TableData table) = do
logs "loading documents page"
res <- lift $ loadPage n
logs table.nodeId
let limit = pageSizes2Int table.pageSize
let offset = limit * (table.currentPage +1)
res <- lift $ loadPage n offset limit
case res of
Left err -> do
_ <- logs $ "Error: loading page documents:" <> show err
......@@ -182,20 +196,29 @@ performAction (LoadData n) _ _ = do
_ <- modifyState $ const resData
pure unit
performAction (ChangePageSize ps) _ _ =
performAction (ChangePageSize ps) props state@(TableData table) = do
void $ modifyState $ changePageSize ps
performAction (ChangePage p) _ _ =
void $ modifyState \(TableData td) -> TableData
$ td { currentPage = p }
logs table.nodeId
performAction (LoadData nId) props state
where
nId = case table.nodeId of
Nothing -> 0
(Just n) -> n
performAction (ChangePage p) props state@(TableData table) = do
void $ modifyState \(TableData td) -> TableData $ td { currentPage = p }
logs table.nodeId
performAction (LoadData nId) props state
where
nId = case table.nodeId of
Nothing -> 0
(Just n)-> n
loadPage :: Int -> Aff (Either String CorpusTableData)
loadPage n = do
loadPage :: Int -> Offset -> Limit -> Aff (Either String CorpusTableData)
loadPage n o l = do
logs "loading documents page: loadPage"
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 $ toUrl Back (Children o l) n
case res of
Left err -> do
_ <- logs "Err: loading page documents"
......@@ -225,9 +248,10 @@ loadPage n = do
{ rows : map (\d -> { row : d , delete : false}) ds
, totalPages : 474
, currentPage : 1
, pageSize : PS100
, pageSize : PS10
, totalRecords : 47361
, title : "Documents"
, nodeId : Nothing
}
---------------------------------------------------------
......@@ -257,6 +281,7 @@ initialState = TableData
, pageSize : PS10
, totalRecords : 100
, title : "Documents"
, nodeId : Nothing
-- , tree : exampleTree
}
......@@ -277,7 +302,6 @@ showTable {title, pageSize, currentPage, totalRecords, totalPages} dispatch colN
]
]
--------------------------------------------------------------
-- | Action
-- ChangePageSize
......
......@@ -38,8 +38,9 @@ dispatchAction dispatcher _ AddCorpus = do
dispatchAction dispatcher _ (Corpus n) = do
dispatcher $ SetRoute $ Corpus n
dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatcher $ CorpusAction $ Corpus.DocviewA $ D.LoadData n
dispatcher $ CorpusAction $ Corpus.DocviewA $ D.UpdateNodeId n
dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatcher $ CorpusAction $ Corpus.DocviewA $ D.LoadData n
dispatchAction dispatcher _ SearchView = do
dispatcher $ SetRoute SearchView
......
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