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
97a4b906
Commit
97a4b906
authored
Dec 18, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] SyncResetButton in the table
parent
4aedec4a
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
289 additions
and
185 deletions
+289
-185
AnnotatedField.purs
src/Gargantext/Components/Annotation/AnnotatedField.purs
+2
-2
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+3
-1
FacetsTable.purs
src/Gargantext/Components/FacetsTable.purs
+5
-1
Sidebar.purs
src/Gargantext/Components/GraphExplorer/Sidebar.purs
+1
-1
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+29
-28
Components.purs
src/Gargantext/Components/NgramsTable/Components.purs
+3
-11
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+136
-69
Annuaire.purs
src/Gargantext/Components/Nodes/Annuaire.purs
+6
-1
Tabs.purs
src/Gargantext/Components/Nodes/Lists/Tabs.purs
+3
-2
Table.purs
src/Gargantext/Components/Table.purs
+28
-69
Types.purs
src/Gargantext/Components/Table/Types.purs
+73
-0
No files found.
src/Gargantext/Components/Annotation/AnnotatedField.purs
View file @
97a4b906
...
@@ -24,7 +24,7 @@ import Reactix.SyntheticEvent as E
...
@@ -24,7 +24,7 @@ import Reactix.SyntheticEvent as E
import Gargantext.Types (CTabNgramType(..), TermList)
import Gargantext.Types (CTabNgramType(..), TermList)
import Gargantext.Components.Annotation.Utils ( termBootstrapClass )
import Gargantext.Components.Annotation.Utils ( termBootstrapClass )
import Gargantext.Components.NgramsTable.Core
(NgramsTable, NgramsTerm, findNgramTermList, highlightNgrams, normNgram)
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.Annotation.Menu ( annotationMenu, MenuType(..) )
import Gargantext.Components.Annotation.Menu ( annotationMenu, MenuType(..) )
import Gargantext.Utils.Selection as Sel
import Gargantext.Utils.Selection as Sel
...
...
src/Gargantext/Components/DocsTable.purs
View file @
97a4b906
...
@@ -27,6 +27,7 @@ import Gargantext.Prelude
...
@@ -27,6 +27,7 @@ import Gargantext.Prelude
import Gargantext.Components.Category (caroussel)
import Gargantext.Components.Category (caroussel)
import Gargantext.Components.Category.Types (Category(..), decodeCategory)
import Gargantext.Components.Category.Types (Category(..), decodeCategory)
import Gargantext.Components.DocsTable.Types
import Gargantext.Components.DocsTable.Types
import Gargantext.Components.Table.Types as T
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Texts.Types (SidePanelTriggers)
import Gargantext.Components.Nodes.Texts.Types (SidePanelTriggers)
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
...
@@ -361,7 +362,8 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
...
@@ -361,7 +362,8 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
reload <- R.useState' 0
reload <- R.useState' 0
pure $ T.table
pure $ T.table
{ colNames
{ syncResetButton : [ H.div {} [] ]
, colNames
, container: T.defaultContainer { title: "Documents" }
, container: T.defaultContainer { title: "Documents" }
, params
, params
, rows: rows reload localCategories
, rows: rows reload localCategories
...
...
src/Gargantext/Components/FacetsTable.purs
View file @
97a4b906
...
@@ -26,6 +26,7 @@ import Gargantext.Components.Category (CategoryQuery(..), putCategories)
...
@@ -26,6 +26,7 @@ import Gargantext.Components.Category (CategoryQuery(..), putCategories)
import Gargantext.Components.Category.Types (Category(..), decodeCategory, favCategory)
import Gargantext.Components.Category.Types (Category(..), decodeCategory, favCategory)
import Gargantext.Components.Search
import Gargantext.Components.Search
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Ends (url, Frontends)
import Gargantext.Ends (url, Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(Search, NodeAPI))
import Gargantext.Routes (SessionRoute(Search, NodeAPI))
...
@@ -304,7 +305,10 @@ pageCpt :: R.Component PageProps
...
@@ -304,7 +305,10 @@ pageCpt :: R.Component PageProps
pageCpt = R.hooksComponentWithModule thisModule "page" cpt
pageCpt = R.hooksComponentWithModule thisModule "page" cpt
where
where
cpt {frontends, totalRecords, container, deletions, documents, session, path: path@({nodeId, listId, query} /\ setPath)} _ = do
cpt {frontends, totalRecords, container, deletions, documents, session, path: path@({nodeId, listId, query} /\ setPath)} _ = do
pure $ T.table { rows, container, colNames, totalRecords, params, wrapColElts }
pure $ T.table { syncResetButton : [ H.div {} [] ]
, rows, container, colNames
, totalRecords, params, wrapColElts
}
where
where
setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
params = (fst path).params /\ setParams
params = (fst path).params /\ setParams
...
...
src/Gargantext/Components/GraphExplorer/Sidebar.purs
View file @
97a4b906
src/Gargantext/Components/NgramsTable.purs
View file @
97a4b906
...
@@ -37,6 +37,7 @@ import Gargantext.Prelude
...
@@ -37,6 +37,7 @@ import Gargantext.Prelude
import Gargantext.AsyncTasks as GAT
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Components.Table.Types as T
import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
...
@@ -319,21 +320,16 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
...
@@ -319,21 +320,16 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, versioned: Versioned { data: initTable }
, versioned: Versioned { data: initTable }
, withAutoUpdate } _ = do
, withAutoUpdate } _ = do
let syncResetBtns = [ syncResetButtons
{ afterSync: chartsAfterSync
, ngramsLocalPatch
, performAction: performAction <<< CoreAction
}
]
pure $ R.fragment $
pure $ R.fragment $
autoUpdate <>
syncResetBtns <>
[
autoUpdate <> [
H.h4 {style: {textAlign : "center"}}
H.h4 {style: {textAlign : "center"}}
[ H.span {className: "glyphicon glyphicon-hand-down"} []
[ H.span {className: "glyphicon glyphicon-hand-down"} []
, H.text "Extracted Terms"
, H.text "Extracted Terms"
]
]
, search
, search ]
, T.table { colNames
<> syncResetButton <>
[ T.table { syncResetButton
, colNames
, container: tableContainer { dispatch: performAction
, container: tableContainer { dispatch: performAction
, ngramsChildren
, ngramsChildren
, ngramsParent
, ngramsParent
...
@@ -350,28 +346,30 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
...
@@ -350,28 +346,30 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, ngramsSelection
, ngramsSelection
}
}
}
}
] <> syncResetBtns
] <> syncResetButton
where
where
chartsAfterSync _ = do
task <- postNgramsChartsAsync path'
syncResetButton = syncResetBtns (chartsAfterSync path' asyncTasksRef nodeId treeReloadRef)
liftEffect $ do
ngramsLocalPatch
log2 "[chartsAfterSync] Synchronize task" task
performAction
case R.readRef asyncTasksRef of
Nothing -> log "[chartsAfterSync] asyncTasksRef is Nothing"
Just asyncTasks -> do
snd asyncTasks $ GAT.Insert nodeId task
case R.readRef treeReloadRef of
Nothing -> log "[chartsAfterSync] can't reload tree: ref empty"
Just treeReload -> do
snd treeReload $ (_ + 1)
-- snd appReload $ (_ + 1)
autoUpdate :: Array R.Element
autoUpdate :: Array R.Element
autoUpdate = if withAutoUpdate then
autoUpdate = if withAutoUpdate then
[ R2.buff $ autoUpdateElt {
[ R2.buff
duration: 5000
$ autoUpdateElt
, effect: performAction $ CoreAction $ Synchronize { afterSync: chartsAfterSync }
{ duration: 5000
} ]
, effect: performAction
$ CoreAction
$ Synchronize { afterSync: chartsAfterSync
path'
asyncTasksRef
nodeId
treeReloadRef
}
}
]
else []
else []
setParentResetChildren :: Maybe NgramsTerm -> State -> State
setParentResetChildren :: Maybe NgramsTerm -> State -> State
...
@@ -747,3 +745,6 @@ sumOccurrences nt = sumOccChildren mempty
...
@@ -747,3 +745,6 @@ sumOccurrences nt = sumOccChildren mempty
optps1 :: forall a. Show a => { desc :: String, mval :: Maybe a } -> R.Element
optps1 :: forall a. Show a => { desc :: String, mval :: Maybe a } -> R.Element
optps1 { desc, mval } = H.option { value: value } [H.text desc]
optps1 { desc, mval } = H.option { value: value } [H.text desc]
where value = maybe "" show mval
where value = maybe "" show mval
src/Gargantext/Components/NgramsTable/Components.purs
View file @
97a4b906
...
@@ -17,12 +17,7 @@ import Reactix as R
...
@@ -17,12 +17,7 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.NgramsTable.Core ( Action(..), Dispatch, NgramsElement, NgramsPatch(..)
import Gargantext.Components.NgramsTable.Core
, NgramsTable, NgramsTablePatch, NgramsTerm, Replace
, _NgramsElement, _NgramsRepoElement, _PatchMap, _children
, _list, _ngrams, _occurrences, ngramsTermText, replace
, singletonNgramsTablePatch, setTermListA
)
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as Tbl
import Gargantext.Components.Table as Tbl
import Gargantext.Types as T
import Gargantext.Types as T
...
@@ -30,7 +25,6 @@ import Gargantext.Utils.Reactix as R2
...
@@ -30,7 +25,6 @@ import Gargantext.Utils.Reactix as R2
thisModule = "Gargantext.Components.NgramsTable.Components"
thisModule = "Gargantext.Components.NgramsTable.Components"
type SearchInputProps =
type SearchInputProps =
( key :: String -- to prevent refreshing & losing input
( key :: String -- to prevent refreshing & losing input
, onSearch :: String -> Effect Unit
, onSearch :: String -> Effect Unit
...
@@ -71,8 +65,7 @@ searchInputCpt = R.hooksComponentWithModule thisModule "searchInput" cpt
...
@@ -71,8 +65,7 @@ searchInputCpt = R.hooksComponentWithModule thisModule "searchInput" cpt
}
}
type SelectionCheckboxProps =
type SelectionCheckboxProps =
(
( allNgramsSelected :: Boolean
allNgramsSelected :: Boolean
, dispatch :: Dispatch
, dispatch :: Dispatch
, ngramsSelection :: Set NgramsTerm
, ngramsSelection :: Set NgramsTerm
)
)
...
@@ -137,8 +130,7 @@ type NgramsDepth = {ngrams :: NgramsTerm, depth :: Int}
...
@@ -137,8 +130,7 @@ type NgramsDepth = {ngrams :: NgramsTerm, depth :: Int}
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
type TreeProps =
type TreeProps =
(
( ngramsClick :: NgramsClick
ngramsClick :: NgramsClick
, ngramsDepth :: NgramsDepth
, ngramsDepth :: NgramsDepth
, ngramsEdit :: NgramsClick
, ngramsEdit :: NgramsClick
, ngramsStyle :: Array DOM.Props
, ngramsStyle :: Array DOM.Props
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
97a4b906
...
@@ -6,10 +6,9 @@ module Gargantext.Components.NgramsTable.Core
...
@@ -6,10 +6,9 @@ module Gargantext.Components.NgramsTable.Core
, NgramsRepoElement(..)
, NgramsRepoElement(..)
, _NgramsRepoElement
, _NgramsRepoElement
, ngramsRepoElementToNgramsElement
, ngramsRepoElementToNgramsElement
, NgramsPatch(..)
, NgramsTable(..)
, NgramsTable(..)
, NgramsTablePatch
, NewElems
, NewElems
, NgramsPatch
, NgramsPatches
, NgramsPatches
, _NgramsTable
, _NgramsTable
, NgramsTerm
, NgramsTerm
...
@@ -22,6 +21,8 @@ module Gargantext.Components.NgramsTable.Core
...
@@ -22,6 +21,8 @@ module Gargantext.Components.NgramsTable.Core
, VersionedNgramsPatches
, VersionedNgramsPatches
, AsyncNgramsChartsUpdate
, AsyncNgramsChartsUpdate
, VersionedNgramsTable
, VersionedNgramsTable
, NgramsTablePatch
, NgramsPatch(..)
, CoreState
, CoreState
, highlightNgrams
, highlightNgrams
, initialPageParams
, initialPageParams
...
@@ -65,9 +66,13 @@ module Gargantext.Components.NgramsTable.Core
...
@@ -65,9 +66,13 @@ module Gargantext.Components.NgramsTable.Core
, coreDispatch
, coreDispatch
, isSingleNgramsTerm
, isSingleNgramsTerm
, filterTermSize
, filterTermSize
-- Reset Button TODO put elsewhere this file is too big
, SyncResetButtonsProps
, SyncResetButtonsProps
, syncResetButtons
, syncResetButtons
, syncResetButtonsCpt
, syncResetButtonsCpt
, chartsAfterSync
, syncResetBtns
)
)
where
where
...
@@ -113,7 +118,7 @@ import Data.Traversable (for, traverse_)
...
@@ -113,7 +118,7 @@ import Data.Traversable (for, traverse_)
import Data.TraversableWithIndex (traverseWithIndex)
import Data.TraversableWithIndex (traverseWithIndex)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log
, log
2)
import Effect.Aff (Aff, launchAff_)
import Effect.Aff (Aff, launchAff_)
import Effect (Effect)
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
...
@@ -127,10 +132,11 @@ import Partial.Unsafe (unsafePartial)
...
@@ -127,10 +132,11 @@ import Partial.Unsafe (unsafePartial)
import Gargantext.AsyncTasks as GAT
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get, post, put)
import Gargantext.Sessions (Session, get, post, put)
import Gargantext.Types (AsyncTaskType(..), AsyncTaskWithType(..), CTabNgramType(..), ListId, OrderBy(..), ScoreType(..), TabSubType(..), TabType(..), TermList(..), TermSize(..))
import Gargantext.Types (AsyncTaskType(..), AsyncTaskWithType(..), CTabNgramType(..), ListId, OrderBy(..), ScoreType(..), TabSubType(..), TabType(..), TermList(..), TermSize(..)
, ReloadS
)
import Gargantext.Utils.KarpRabin (indicesOfAny)
import Gargantext.Utils.KarpRabin (indicesOfAny)
thisModule :: String
thisModule :: String
...
@@ -138,6 +144,67 @@ thisModule = "Gargantext.Components.NgramsTable.Core"
...
@@ -138,6 +144,67 @@ thisModule = "Gargantext.Components.NgramsTable.Core"
type Endo a = a -> a
type Endo a = a -> a
-- | Main Types
type Version = Int
newtype Versioned a = Versioned
{ version :: Version
, data :: a
}
instance encodeJsonVersioned :: EncodeJson a => EncodeJson (Versioned a) where
encodeJson (Versioned {version, data: data_})
= "version" := version
~> "data" := data_
~> jsonEmptyObject
instance decodeJsonVersioned :: DecodeJson a => DecodeJson (Versioned a) where
decodeJson json = do
obj <- decodeJson json
version <- obj .: "version"
data_ <- obj .: "data"
pure $ Versioned {version, data: data_}
------------------------------------------------------------------------
-- TODO replace by NgramsPatches directly
type NgramsTablePatch = { ngramsPatches :: NgramsPatches }
newtype PatchMap k p = PatchMap (Map k p)
type NgramsPatches = PatchMap NgramsTerm NgramsPatch
data NgramsPatch
= NgramsReplace
{ patch_old :: Maybe NgramsRepoElement
, patch_new :: Maybe NgramsRepoElement
}
| NgramsPatch
{ patch_children :: PatchSet NgramsTerm
, patch_list :: Replace TermList
}
------------------------------------------------------------------------
newtype NgramsTerm = NormNgramsTerm String
derive instance genericNgramsTerm :: Generic NgramsTerm _
instance eqNgramsTerm :: Eq NgramsTerm where
eq = genericEq
instance ordNgramsTerm :: Ord NgramsTerm where
compare = genericCompare
instance showNgramsTerm :: Show NgramsTerm where
show = genericShow
instance encodeJsonNgramsTerm :: EncodeJson NgramsTerm where
encodeJson (NormNgramsTerm s) = encodeJson s
-- TODO we assume that the ngrams are already normalized.
instance decodeJsonNgramsTerm :: DecodeJson NgramsTerm where
decodeJson = map NormNgramsTerm <<< decodeJson
------------------------------------------------------------------------
type CoreParams s =
type CoreParams s =
{ nodeId :: Int
{ nodeId :: Int
-- ^ This node can be a corpus or contact.
-- ^ This node can be a corpus or contact.
...
@@ -171,22 +238,8 @@ initialPageParams session nodeId listIds tabType =
...
@@ -171,22 +238,8 @@ initialPageParams session nodeId listIds tabType =
where
where
params = T.initialParams { orderBy = Just (T.DESC $ T.ColumnName "Score") }
params = T.initialParams { orderBy = Just (T.DESC $ T.ColumnName "Score") }
newtype NgramsTerm = NormNgramsTerm String
derive instance genericNgramsTerm :: Generic NgramsTerm _
instance eqNgramsTerm :: Eq NgramsTerm where
eq = genericEq
instance ordNgramsTerm :: Ord NgramsTerm where
compare = genericCompare
instance showNgramsTerm :: Show NgramsTerm where
show = genericShow
instance encodeJsonNgramsTerm :: EncodeJson NgramsTerm where
encodeJson (NormNgramsTerm s) = encodeJson s
-- TODO we assume that the ngrams are already normalized.
instance decodeJsonNgramsTerm :: DecodeJson NgramsTerm where
decodeJson = map NormNgramsTerm <<< decodeJson
ngramsTermText :: NgramsTerm -> String
ngramsTermText :: NgramsTerm -> String
ngramsTermText (NormNgramsTerm t) = t
ngramsTermText (NormNgramsTerm t) = t
...
@@ -341,26 +394,6 @@ ngramsRepoElementToNgramsElement ngrams occurrences (NgramsRepoElement { childre
...
@@ -341,26 +394,6 @@ ngramsRepoElementToNgramsElement ngrams occurrences (NgramsRepoElement { childre
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
type Version = Int
newtype Versioned a = Versioned
{ version :: Version
, data :: a
}
instance encodeJsonVersioned :: EncodeJson a => EncodeJson (Versioned a) where
encodeJson (Versioned {version, data: data_})
= "version" := version
~> "data" := data_
~> jsonEmptyObject
instance decodeJsonVersioned :: DecodeJson a => DecodeJson (Versioned a) where
decodeJson json = do
obj <- decodeJson json
version <- obj .: "version"
data_ <- obj .: "data"
pure $ Versioned {version, data: data_}
{-
{-
NgramsRepoElement does not have the occurrences field.
NgramsRepoElement does not have the occurrences field.
Instead NgramsTable has a ngrams_scores map.
Instead NgramsTable has a ngrams_scores map.
...
@@ -593,16 +626,6 @@ patchSetFromMap m = PatchSet { rem: Map.keys (Map.filter not m)
...
@@ -593,16 +626,6 @@ patchSetFromMap m = PatchSet { rem: Map.keys (Map.filter not m)
, add: Map.keys (Map.filter identity m) }
, add: Map.keys (Map.filter identity m) }
-- TODO Map.partition would be nice here
-- TODO Map.partition would be nice here
data NgramsPatch
= NgramsReplace
{ patch_old :: Maybe NgramsRepoElement
, patch_new :: Maybe NgramsRepoElement
}
| NgramsPatch
{ patch_children :: PatchSet NgramsTerm
, patch_list :: Replace TermList
}
-- TODO shall we normalise as in replace? shall we make a type class Replaceable?
-- TODO shall we normalise as in replace? shall we make a type class Replaceable?
ngramsReplace :: Maybe NgramsRepoElement -> Maybe NgramsRepoElement -> NgramsPatch
ngramsReplace :: Maybe NgramsRepoElement -> Maybe NgramsRepoElement -> NgramsPatch
ngramsReplace patch_old patch_new = NgramsReplace {patch_old, patch_new}
ngramsReplace patch_old patch_new = NgramsReplace {patch_old, patch_new}
...
@@ -610,10 +633,6 @@ ngramsReplace patch_old patch_new = NgramsReplace {patch_old, patch_new}
...
@@ -610,10 +633,6 @@ ngramsReplace patch_old patch_new = NgramsReplace {patch_old, patch_new}
derive instance eqNgramsPatch :: Eq NgramsPatch
derive instance eqNgramsPatch :: Eq NgramsPatch
derive instance eqPatchSetNgramsTerm :: Eq (PatchSet NgramsTerm)
derive instance eqPatchSetNgramsTerm :: Eq (PatchSet NgramsTerm)
-- TODO
invert :: forall a. a -> a
invert _ = unsafeThrow "invert: TODO"
instance semigroupNgramsPatch :: Semigroup NgramsPatch where
instance semigroupNgramsPatch :: Semigroup NgramsPatch where
append (NgramsReplace p) (NgramsReplace q)
append (NgramsReplace p) (NgramsReplace q)
| p.patch_old /= q.patch_new = unsafeThrow "append/NgramsPatch: old != new"
| p.patch_old /= q.patch_new = unsafeThrow "append/NgramsPatch: old != new"
...
@@ -625,6 +644,13 @@ instance semigroupNgramsPatch :: Semigroup NgramsPatch where
...
@@ -625,6 +644,13 @@ instance semigroupNgramsPatch :: Semigroup NgramsPatch where
append (NgramsPatch p) (NgramsReplace q) = ngramsReplace q.patch_old (q.patch_new # _Just <<< _Newtype %~ applyNgramsPatch' p)
append (NgramsPatch p) (NgramsReplace q) = ngramsReplace q.patch_old (q.patch_new # _Just <<< _Newtype %~ applyNgramsPatch' p)
append (NgramsReplace p) (NgramsPatch q) = ngramsReplace (p.patch_old # _Just <<< _Newtype %~ applyNgramsPatch' (invert q)) p.patch_new
append (NgramsReplace p) (NgramsPatch q) = ngramsReplace (p.patch_old # _Just <<< _Newtype %~ applyNgramsPatch' (invert q)) p.patch_new
-- TODO
invert :: forall a. a -> a
invert _ = unsafeThrow "invert: TODO"
instance monoidNgramsPatch :: Monoid NgramsPatch where
instance monoidNgramsPatch :: Monoid NgramsPatch where
mempty = NgramsPatch { patch_children: mempty, patch_list: mempty }
mempty = NgramsPatch { patch_children: mempty, patch_list: mempty }
...
@@ -670,7 +696,6 @@ applyNgramsPatch :: NgramsPatch -> Maybe NgramsRepoElement -> Maybe NgramsRepoEl
...
@@ -670,7 +696,6 @@ applyNgramsPatch :: NgramsPatch -> Maybe NgramsRepoElement -> Maybe NgramsRepoEl
applyNgramsPatch (NgramsReplace {patch_new}) _ = patch_new
applyNgramsPatch (NgramsReplace {patch_new}) _ = patch_new
applyNgramsPatch (NgramsPatch p) m = m # _Just <<< _Newtype %~ applyNgramsPatch' p
applyNgramsPatch (NgramsPatch p) m = m # _Just <<< _Newtype %~ applyNgramsPatch' p
newtype PatchMap k p = PatchMap (Map k p)
fromMap :: forall k p. Ord k => Eq p => Monoid p => Map k p -> PatchMap k p
fromMap :: forall k p. Ord k => Eq p => Monoid p => Map k p -> PatchMap k p
fromMap = PatchMap <<< Map.filter (\v -> v /= mempty)
fromMap = PatchMap <<< Map.filter (\v -> v /= mempty)
...
@@ -756,8 +781,8 @@ applyPatchMap applyPatchValue (PatchMap pm) m =
...
@@ -756,8 +781,8 @@ applyPatchMap applyPatchValue (PatchMap pm) m =
where
where
go m (Tuple k pv) = Map.alter (applyPatchValue pv) k m
go m (Tuple k pv) = Map.alter (applyPatchValue pv) k m
type NgramsPatches = PatchMap NgramsTerm NgramsPatch
type VersionedNgramsPatches = Versioned NgramsPatches
type VersionedNgramsPatches = Versioned NgramsPatches
newtype AsyncNgramsChartsUpdate = AsyncNgramsChartsUpdate {
newtype AsyncNgramsChartsUpdate = AsyncNgramsChartsUpdate {
listId :: Maybe ListId
listId :: Maybe ListId
, tabType :: TabType
, tabType :: TabType
...
@@ -770,9 +795,7 @@ instance encodeAsyncNgramsChartsUpdate :: EncodeJson AsyncNgramsChartsUpdate whe
...
@@ -770,9 +795,7 @@ instance encodeAsyncNgramsChartsUpdate :: EncodeJson AsyncNgramsChartsUpdate whe
type NewElems = Map NgramsTerm TermList
type NewElems = Map NgramsTerm TermList
-- TODO replace by NgramsPatches directly
----------------------------------------------------------------------------------
type NgramsTablePatch = { ngramsPatches :: NgramsPatches }
isEmptyNgramsTablePatch :: NgramsTablePatch -> Boolean
isEmptyNgramsTablePatch :: NgramsTablePatch -> Boolean
isEmptyNgramsTablePatch {ngramsPatches} = isEmptyPatchMap ngramsPatches
isEmptyNgramsTablePatch {ngramsPatches} = isEmptyPatchMap ngramsPatches
...
@@ -922,15 +945,6 @@ putNgramsPatches :: forall s. CoreParams s -> VersionedNgramsPatches -> Aff Vers
...
@@ -922,15 +945,6 @@ putNgramsPatches :: forall s. CoreParams s -> VersionedNgramsPatches -> Aff Vers
putNgramsPatches { listIds, nodeId, session, tabType } = put session putNgrams
putNgramsPatches { listIds, nodeId, session, tabType } = put session putNgrams
where putNgrams = PutNgrams tabType (head listIds) Nothing (Just nodeId)
where putNgrams = PutNgrams tabType (head listIds) Nothing (Just nodeId)
postNgramsChartsAsync :: forall s. CoreParams s -> Aff AsyncTaskWithType
postNgramsChartsAsync { listIds, nodeId, session, tabType } = do
task <- post session putNgramsAsync acu
pure $ AsyncTaskWithType { task, typ: UpdateNgramsCharts }
where
acu = AsyncNgramsChartsUpdate { listId: head listIds
, tabType }
putNgramsAsync = PostNgramsChartsAsync (Just nodeId)
syncPatches :: forall p s. CoreParams p -> R.State (CoreState s) -> (Unit -> Aff Unit) -> Effect Unit
syncPatches :: forall p s. CoreParams p -> R.State (CoreState s) -> (Unit -> Aff Unit) -> Effect Unit
syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsStagePatch
, ngramsStagePatch
...
@@ -1074,6 +1088,9 @@ filterTermSize (Just MonoTerm) nt = isSingleNgramsTerm nt
...
@@ -1074,6 +1088,9 @@ filterTermSize (Just MonoTerm) nt = isSingleNgramsTerm nt
filterTermSize (Just MultiTerm) nt = not $ isSingleNgramsTerm nt
filterTermSize (Just MultiTerm) nt = not $ isSingleNgramsTerm nt
filterTermSize _ _ = true
filterTermSize _ _ = true
------------------------------------------------------------------------
-- | Reset Button
type SyncResetButtonsProps =
type SyncResetButtonsProps =
( afterSync :: Unit -> Aff Unit
( afterSync :: Unit -> Aff Unit
, ngramsLocalPatch :: NgramsTablePatch
, ngramsLocalPatch :: NgramsTablePatch
...
@@ -1112,3 +1129,53 @@ syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" c
...
@@ -1112,3 +1129,53 @@ syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" c
, on: { click: synchronizeClick }
, on: { click: synchronizeClick }
} [ H.text "Sync" ]
} [ H.text "Sync" ]
]
]
type ResetButton = (Unit -> Aff Unit)
-> { ngramsPatches :: PatchMap NgramsTerm NgramsPatch }
-> (Action -> Effect Unit)
-> Array R.Element
syncResetBtns :: ResetButton
syncResetBtns chartsAfterSync' ngramsLocalPatch performAction = [ syncResetButtons
{ afterSync: chartsAfterSync'
, ngramsLocalPatch
, performAction: performAction <<< CoreAction
}
]
chartsAfterSync :: forall props discard.
{ listIds :: Array Int
, nodeId :: Int
, session :: Session
, tabType :: TabType
| props
}
-> R.Ref (Maybe GAT.Reductor)
-> Int
-> R.Ref (Maybe ReloadS)
-> discard
-> Aff Unit
chartsAfterSync path' asyncTasksRef nodeId treeReloadRef _ = do
task <- postNgramsChartsAsync path'
liftEffect $ do
log2 "[chartsAfterSync] Synchronize task" task
case R.readRef asyncTasksRef of
Nothing -> log "[chartsAfterSync] asyncTasksRef is Nothing"
Just asyncTasks -> do
snd asyncTasks $ GAT.Insert nodeId task
case R.readRef treeReloadRef of
Nothing -> log "[chartsAfterSync] can't reload tree: ref empty"
Just treeReload -> do
snd treeReload $ (_ + 1)
-- snd appReload $ (_ + 1)
postNgramsChartsAsync :: forall s. CoreParams s -> Aff AsyncTaskWithType
postNgramsChartsAsync { listIds, nodeId, session, tabType } = do
task <- post session putNgramsAsync acu
pure $ AsyncTaskWithType { task, typ: UpdateNgramsCharts }
where
acu = AsyncNgramsChartsUpdate { listId: head listIds
, tabType }
putNgramsAsync = PostNgramsChartsAsync (Just nodeId)
src/Gargantext/Components/Nodes/Annuaire.purs
View file @
97a4b906
...
@@ -17,6 +17,7 @@ import Gargantext.Components.NgramsTable.Loader (clearCache)
...
@@ -17,6 +17,7 @@ import Gargantext.Components.NgramsTable.Loader (clearCache)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Ends (url, Frontends)
import Gargantext.Ends (url, Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Routes (SessionRoute(..))
...
@@ -149,7 +150,11 @@ pageCpt = R.hooksComponentWithModule thisModule "page" cpt
...
@@ -149,7 +150,11 @@ pageCpt = R.hooksComponentWithModule thisModule "page" cpt
where
where
cpt { session, pagePath, frontends
cpt { session, pagePath, frontends
, table: ({count: totalRecords, docs})} _ = do
, table: ({count: totalRecords, docs})} _ = do
pure $ T.table { rows, params, container, colNames, totalRecords, wrapColElts }
pure $ T.table { syncResetButton : [ H.div {} [] ]
, rows, params, container
, colNames, totalRecords
, wrapColElts
}
where
where
path = fst pagePath
path = fst pagePath
rows = (\c -> {
rows = (\c -> {
...
...
src/Gargantext/Components/Nodes/Lists/Tabs.purs
View file @
97a4b906
...
@@ -63,10 +63,11 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
...
@@ -63,10 +63,11 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
pure $ Tab.tabs { selected, tabs: tabs' }
pure $ Tab.tabs { selected, tabs: tabs' }
where
where
tabs' = [ "Authors" /\ view Authors
tabs' = [ "Terms" /\ view Terms
, "Authors" /\ view Authors
, "Institutes" /\ view Institutes
, "Institutes" /\ view Institutes
, "Sources" /\ view Sources
, "Sources" /\ view Sources
, "Terms" /\ view Terms
]
]
view mode = ngramsView { appReload
view mode = ngramsView { appReload
, asyncTasksRef
, asyncTasksRef
, cacheState
, cacheState
...
...
src/Gargantext/Components/Table.purs
View file @
97a4b906
...
@@ -7,12 +7,15 @@ import Data.Generic.Rep.Show (genericShow)
...
@@ -7,12 +7,15 @@ import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Sequence as Seq
import Data.Sequence as Seq
import Data.Tuple (fst, snd)
import Data.Tuple (fst, snd)
import Effect.Aff (Aff, launchAff_)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect (Effect)
import Gargantext.Sessions (Session, get)
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
import Gargantext.Components.Table.Types
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Search
import Gargantext.Components.Search
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
...
@@ -21,60 +24,6 @@ import Gargantext.Utils.Reactix (effectLink)
...
@@ -21,60 +24,6 @@ import Gargantext.Utils.Reactix (effectLink)
thisModule :: String
thisModule :: String
thisModule = "Gargantext.Components.Table"
thisModule = "Gargantext.Components.Table"
type TableContainerProps =
( pageSizeControl :: R.Element
, pageSizeDescription :: R.Element
, paginationLinks :: R.Element
, tableHead :: R.Element
, tableBody :: Array R.Element
)
type Row = { row :: R.Element, delete :: Boolean }
type Rows = Seq.Seq Row
type OrderBy = Maybe (OrderByDirection ColumnName)
type Params = { limit :: Int
, offset :: Int
, orderBy :: OrderBy
, searchType :: SearchType
}
newtype ColumnName = ColumnName String
derive instance genericColumnName :: Generic ColumnName _
instance showColumnName :: Show ColumnName where
show = genericShow
derive instance eqColumnName :: Eq ColumnName
columnName :: ColumnName -> String
columnName (ColumnName c) = c
data OrderByDirection a = ASC a | DESC a
derive instance genericOrderByDirection :: Generic (OrderByDirection a) _
instance showOrderByDirection :: Show a => Show (OrderByDirection a) where
show = genericShow
derive instance eqOrderByDirection :: Eq a => Eq (OrderByDirection a)
orderByToForm :: OrderByDirection ColumnName -> String
orderByToForm (ASC (ColumnName x)) = x <> "Asc"
orderByToForm (DESC (ColumnName x)) = x <> "Desc"
type Props =
( colNames :: Array ColumnName
, container :: Record TableContainerProps -> R.Element
, params :: R.State Params
, rows :: Rows
, totalRecords :: Int
, wrapColElts :: ColumnName -> Array R.Element -> Array R.Element
-- ^ Use `const identity` as a default behavior.
)
type State =
type State =
{ page :: Int
{ page :: Int
, pageSize :: PageSizes
, pageSize :: PageSizes
...
@@ -174,7 +123,7 @@ table props = R.createElement tableCpt props []
...
@@ -174,7 +123,7 @@ table props = R.createElement tableCpt props []
tableCpt :: R.Component Props
tableCpt :: R.Component Props
tableCpt = R.hooksComponentWithModule thisModule "table" cpt
tableCpt = R.hooksComponentWithModule thisModule "table" cpt
where
where
cpt {container, colNames, wrapColElts, totalRecords, rows, params} _ = do
cpt {container,
syncResetButton,
colNames, wrapColElts, totalRecords, rows, params} _ = do
let
let
state = paramsState $ fst params
state = paramsState $ fst params
ps = pageSizes2Int state.pageSize
ps = pageSizes2Int state.pageSize
...
@@ -187,11 +136,12 @@ tableCpt = R.hooksComponentWithModule thisModule "table" cpt
...
@@ -187,11 +136,12 @@ tableCpt = R.hooksComponentWithModule thisModule "table" cpt
cs =
cs =
wrapColElts c $
wrapColElts c $
case state.orderBy of
case state.orderBy of
Just (ASC d) | c == d -> [lnk (Just (DESC c)) "ASC ", lnk Nothing (columnName c)]
Just (ASC d) | c == d -> [lnk (Just (DESC c)) "ASC "
, lnk Nothing (columnName c)]
Just (DESC d) | c == d -> [lnk (Just (ASC c)) "DESC ", lnk Nothing (columnName c)]
Just (DESC d) | c == d -> [lnk (Just (ASC c)) "DESC ", lnk Nothing (columnName c)]
_ -> [lnk (Just (ASC c)) (columnName c)]
_ -> [lnk (Just (ASC c)) (columnName c)]
pure $ container
pure $ container
{ pageSizeControl: sizeDD { params }
{ syncResetButton
, pageSizeControl: sizeDD { params }
, pageSizeDescription: textDescription state.page state.pageSize totalRecords
, pageSizeDescription: textDescription state.page state.pageSize totalRecords
, paginationLinks: pagination params totalPages
, paginationLinks: pagination params totalPages
, tableBody: map _.row $ A.fromFoldable rows
, tableBody: map _.row $ A.fromFoldable rows
...
@@ -213,8 +163,9 @@ filterRows { params: { limit, offset, orderBy } } rs = newRs
...
@@ -213,8 +163,9 @@ filterRows { params: { limit, offset, orderBy } } rs = newRs
newRs = Seq.take limit $ Seq.drop offset $ rs
newRs = Seq.take limit $ Seq.drop offset $ rs
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer {title} props = R.fragment
defaultContainer {title} props = R.fragment $ props.syncResetButton <> controls
[ R2.row
where
controls = [ R2.row
[ H.div {className: "col-md-4"} [ props.pageSizeDescription ]
[ H.div {className: "col-md-4"} [ props.pageSizeDescription ]
, H.div {className: "col-md-4"} [ props.paginationLinks ]
, H.div {className: "col-md-4"} [ props.paginationLinks ]
, H.div {className: "col-md-4"} [ props.pageSizeControl ]
, H.div {className: "col-md-4"} [ props.pageSizeControl ]
...
@@ -356,3 +307,11 @@ string2PageSize "50" = PS50
...
@@ -356,3 +307,11 @@ string2PageSize "50" = PS50
string2PageSize "100" = PS100
string2PageSize "100" = PS100
string2PageSize "200" = PS200
string2PageSize "200" = PS200
string2PageSize _ = PS10
string2PageSize _ = PS10
src/Gargantext/Components/Table/Types.purs
0 → 100644
View file @
97a4b906
module Gargantext.Components.Table.Types where
import Prelude
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Sequence as Seq
import Data.Tuple (fst, snd)
import Effect.Aff (Aff, launchAff_)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Gargantext.Sessions (Session, get)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Search
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix (effectLink)
import Data.Generic.Rep (class Generic)
type Params = { limit :: Int
, offset :: Int
, orderBy :: OrderBy
, searchType :: SearchType
}
type OrderBy = Maybe (OrderByDirection ColumnName)
data OrderByDirection a = ASC a | DESC a
derive instance genericOrderByDirection :: Generic (OrderByDirection a) _
instance showOrderByDirection :: Show a => Show (OrderByDirection a) where
show = genericShow
derive instance eqOrderByDirection :: Eq a => Eq (OrderByDirection a)
orderByToForm :: OrderByDirection ColumnName -> String
orderByToForm (ASC (ColumnName x)) = x <> "Asc"
orderByToForm (DESC (ColumnName x)) = x <> "Desc"
newtype ColumnName = ColumnName String
derive instance genericColumnName :: Generic ColumnName _
instance showColumnName :: Show ColumnName where
show = genericShow
derive instance eqColumnName :: Eq ColumnName
columnName :: ColumnName -> String
columnName (ColumnName c) = c
type Props =
( syncResetButton :: Array R.Element
, colNames :: Array ColumnName
, container :: Record TableContainerProps -> R.Element
, params :: R.State Params
, rows :: Rows
, totalRecords :: Int
, wrapColElts :: ColumnName -> Array R.Element -> Array R.Element
-- ^ Use `const identity` as a default behavior.
)
type TableContainerProps =
( syncResetButton :: Array R.Element
, pageSizeControl :: R.Element
, pageSizeDescription :: R.Element
, paginationLinks :: R.Element
, tableHead :: R.Element
, tableBody :: Array R.Element
)
type Row = { row :: R.Element, delete :: Boolean }
type Rows = Seq.Seq Row
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