Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
b54293bf
Commit
b54293bf
authored
Oct 11, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUG] State is overwritten before changing the page.
parent
dccaa33a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
32 deletions
+60
-32
Config.purs
src/Gargantext/Config.purs
+9
-5
Annuaire.purs
src/Gargantext/Pages/Annuaire.purs
+1
-1
Corpus.purs
src/Gargantext/Pages/Corpus.purs
+6
-7
Documents.purs
src/Gargantext/Pages/Corpus/Tabs/Documents.purs
+41
-17
Layout.purs
src/Gargantext/Pages/Layout.purs
+3
-2
No files found.
src/Gargantext/Config.purs
View file @
b54293bf
...
...
@@ -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
...
...
src/Gargantext/Pages/Annuaire.purs
View file @
b54293bf
...
...
@@ -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
...
...
src/Gargantext/Pages/Corpus.purs
View file @
b54293bf
...
...
@@ -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
...
...
src/Gargantext/Pages/Corpus/Tabs/Documents.purs
View file @
b54293bf
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 : PS10
0
, 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
...
...
src/Gargantext/Pages/Layout.purs
View file @
b54293bf
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment