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
Show 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
...
@@ -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
...
...
src/Gargantext/Pages/Annuaire.purs
View file @
b54293bf
...
@@ -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
...
...
src/Gargantext/Pages/Corpus.purs
View file @
b54293bf
...
@@ -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
...
...
src/Gargantext/Pages/Corpus/Tabs/Documents.purs
View file @
b54293bf
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 : PS10
0
, 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
...
...
src/Gargantext/Pages/Layout.purs
View file @
b54293bf
...
@@ -38,6 +38,7 @@ dispatchAction dispatcher _ AddCorpus = do
...
@@ -38,6 +38,7 @@ 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.DocviewA $ D.UpdateNodeId n
dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatcher $ CorpusAction $ Corpus.HeaderA $ Corpus.Load n
dispatcher $ CorpusAction $ Corpus.DocviewA $ D.LoadData n
dispatcher $ CorpusAction $ Corpus.DocviewA $ D.LoadData n
...
...
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