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