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
import Gargantext.Types (CTabNgramType(..), TermList)
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.Utils.Selection as Sel
...
...
src/Gargantext/Components/DocsTable.purs
View file @
97a4b906
...
...
@@ -27,6 +27,7 @@ import Gargantext.Prelude
import Gargantext.Components.Category (caroussel)
import Gargantext.Components.Category.Types (Category(..), decodeCategory)
import Gargantext.Components.DocsTable.Types
import Gargantext.Components.Table.Types as T
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Nodes.Texts.Types (SidePanelTriggers)
import Gargantext.Components.Table as T
...
...
@@ -361,7 +362,8 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
reload <- R.useState' 0
pure $ T.table
{ colNames
{ syncResetButton : [ H.div {} [] ]
, colNames
, container: T.defaultContainer { title: "Documents" }
, params
, rows: rows reload localCategories
...
...
src/Gargantext/Components/FacetsTable.purs
View file @
97a4b906
...
...
@@ -26,6 +26,7 @@ import Gargantext.Components.Category (CategoryQuery(..), putCategories)
import Gargantext.Components.Category.Types (Category(..), decodeCategory, favCategory)
import Gargantext.Components.Search
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Ends (url, Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(Search, NodeAPI))
...
...
@@ -304,7 +305,10 @@ pageCpt :: R.Component PageProps
pageCpt = R.hooksComponentWithModule thisModule "page" cpt
where
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
setParams f = setPath $ \p@{params: ps} -> p {params = f ps}
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
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.AutoUpdate (autoUpdateElt)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Components.Table.Types as T
import Gargantext.Components.NgramsTable.Components as NTC
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.NgramsTable.Loader (useLoaderWithCacheAPI)
...
...
@@ -319,21 +320,16 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, versioned: Versioned { data: initTable }
, withAutoUpdate } _ = do
let syncResetBtns = [ syncResetButtons
{ afterSync: chartsAfterSync
, ngramsLocalPatch
, performAction: performAction <<< CoreAction
}
]
pure $ R.fragment $
autoUpdate <>
syncResetBtns <>
[
autoUpdate <> [
H.h4 {style: {textAlign : "center"}}
[ H.span {className: "glyphicon glyphicon-hand-down"} []
, H.text "Extracted Terms"
]
, search
, T.table { colNames
, search ]
<> syncResetButton <>
[ T.table { syncResetButton
, colNames
, container: tableContainer { dispatch: performAction
, ngramsChildren
, ngramsParent
...
...
@@ -350,28 +346,30 @@ loadedNgramsTableCpt = R.hooksComponentWithModule thisModule "loadedNgramsTable"
, ngramsSelection
}
}
] <> syncResetBtns
] <> syncResetButton
where
chartsAfterSync _ = 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)
syncResetButton = syncResetBtns (chartsAfterSync path' asyncTasksRef nodeId treeReloadRef)
ngramsLocalPatch
performAction
autoUpdate :: Array R.Element
autoUpdate = if withAutoUpdate then
[ R2.buff $ autoUpdateElt {
duration: 5000
, effect: performAction $ CoreAction $ Synchronize { afterSync: chartsAfterSync }
} ]
[ R2.buff
$ autoUpdateElt
{ duration: 5000
, effect: performAction
$ CoreAction
$ Synchronize { afterSync: chartsAfterSync
path'
asyncTasksRef
nodeId
treeReloadRef
}
}
]
else []
setParentResetChildren :: Maybe NgramsTerm -> State -> State
...
...
@@ -747,3 +745,6 @@ sumOccurrences nt = sumOccChildren mempty
optps1 :: forall a. Show a => { desc :: String, mval :: Maybe a } -> R.Element
optps1 { desc, mval } = H.option { value: value } [H.text desc]
where value = maybe "" show mval
src/Gargantext/Components/NgramsTable/Components.purs
View file @
97a4b906
...
...
@@ -17,12 +17,7 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Components.NgramsTable.Core ( Action(..), Dispatch, NgramsElement, NgramsPatch(..)
, NgramsTable, NgramsTablePatch, NgramsTerm, Replace
, _NgramsElement, _NgramsRepoElement, _PatchMap, _children
, _list, _ngrams, _occurrences, ngramsTermText, replace
, singletonNgramsTablePatch, setTermListA
)
import Gargantext.Components.NgramsTable.Core
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as Tbl
import Gargantext.Types as T
...
...
@@ -30,7 +25,6 @@ import Gargantext.Utils.Reactix as R2
thisModule = "Gargantext.Components.NgramsTable.Components"
type SearchInputProps =
( key :: String -- to prevent refreshing & losing input
, onSearch :: String -> Effect Unit
...
...
@@ -71,8 +65,7 @@ searchInputCpt = R.hooksComponentWithModule thisModule "searchInput" cpt
}
type SelectionCheckboxProps =
(
allNgramsSelected :: Boolean
( allNgramsSelected :: Boolean
, dispatch :: Dispatch
, ngramsSelection :: Set NgramsTerm
)
...
...
@@ -137,8 +130,7 @@ type NgramsDepth = {ngrams :: NgramsTerm, depth :: Int}
type NgramsClick = NgramsDepth -> Maybe (Effect Unit)
type TreeProps =
(
ngramsClick :: NgramsClick
( ngramsClick :: NgramsClick
, ngramsDepth :: NgramsDepth
, ngramsEdit :: NgramsClick
, ngramsStyle :: Array DOM.Props
...
...
src/Gargantext/Components/NgramsTable/Core.purs
View file @
97a4b906
...
...
@@ -6,10 +6,9 @@ module Gargantext.Components.NgramsTable.Core
, NgramsRepoElement(..)
, _NgramsRepoElement
, ngramsRepoElementToNgramsElement
, NgramsPatch(..)
, NgramsTable(..)
, NgramsTablePatch
, NewElems
, NgramsPatch
, NgramsPatches
, _NgramsTable
, NgramsTerm
...
...
@@ -22,6 +21,8 @@ module Gargantext.Components.NgramsTable.Core
, VersionedNgramsPatches
, AsyncNgramsChartsUpdate
, VersionedNgramsTable
, NgramsTablePatch
, NgramsPatch(..)
, CoreState
, highlightNgrams
, initialPageParams
...
...
@@ -65,9 +66,13 @@ module Gargantext.Components.NgramsTable.Core
, coreDispatch
, isSingleNgramsTerm
, filterTermSize
-- Reset Button TODO put elsewhere this file is too big
, SyncResetButtonsProps
, syncResetButtons
, syncResetButtonsCpt
, chartsAfterSync
, syncResetBtns
)
where
...
...
@@ -113,7 +118,7 @@ import Data.Traversable (for, traverse_)
import Data.TraversableWithIndex (traverseWithIndex)
import Data.Tuple (Tuple(..), snd)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log
, log
2)
import Effect.Aff (Aff, launchAff_)
import Effect (Effect)
import Effect.Class (liftEffect)
...
...
@@ -127,10 +132,11 @@ import Partial.Unsafe (unsafePartial)
import Gargantext.AsyncTasks as GAT
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(..))
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)
thisModule :: String
...
...
@@ -138,6 +144,67 @@ thisModule = "Gargantext.Components.NgramsTable.Core"
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 =
{ nodeId :: Int
-- ^ This node can be a corpus or contact.
...
...
@@ -171,22 +238,8 @@ initialPageParams session nodeId listIds tabType =
where
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 (NormNgramsTerm t) = t
...
...
@@ -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.
Instead NgramsTable has a ngrams_scores map.
...
...
@@ -593,16 +626,6 @@ patchSetFromMap m = PatchSet { rem: Map.keys (Map.filter not m)
, add: Map.keys (Map.filter identity m) }
-- 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?
ngramsReplace :: Maybe NgramsRepoElement -> Maybe NgramsRepoElement -> NgramsPatch
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 eqPatchSetNgramsTerm :: Eq (PatchSet NgramsTerm)
-- TODO
invert :: forall a. a -> a
invert _ = unsafeThrow "invert: TODO"
instance semigroupNgramsPatch :: Semigroup NgramsPatch where
append (NgramsReplace p) (NgramsReplace q)
| p.patch_old /= q.patch_new = unsafeThrow "append/NgramsPatch: old != new"
...
...
@@ -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 (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
mempty = NgramsPatch { patch_children: mempty, patch_list: mempty }
...
...
@@ -670,7 +696,6 @@ applyNgramsPatch :: NgramsPatch -> Maybe NgramsRepoElement -> Maybe NgramsRepoEl
applyNgramsPatch (NgramsReplace {patch_new}) _ = patch_new
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 = PatchMap <<< Map.filter (\v -> v /= mempty)
...
...
@@ -756,8 +781,8 @@ applyPatchMap applyPatchValue (PatchMap pm) m =
where
go m (Tuple k pv) = Map.alter (applyPatchValue pv) k m
type NgramsPatches = PatchMap NgramsTerm NgramsPatch
type VersionedNgramsPatches = Versioned NgramsPatches
newtype AsyncNgramsChartsUpdate = AsyncNgramsChartsUpdate {
listId :: Maybe ListId
, tabType :: TabType
...
...
@@ -770,9 +795,7 @@ instance encodeAsyncNgramsChartsUpdate :: EncodeJson AsyncNgramsChartsUpdate whe
type NewElems = Map NgramsTerm TermList
-- TODO replace by NgramsPatches directly
type NgramsTablePatch = { ngramsPatches :: NgramsPatches }
----------------------------------------------------------------------------------
isEmptyNgramsTablePatch :: NgramsTablePatch -> Boolean
isEmptyNgramsTablePatch {ngramsPatches} = isEmptyPatchMap ngramsPatches
...
...
@@ -922,15 +945,6 @@ putNgramsPatches :: forall s. CoreParams s -> VersionedNgramsPatches -> Aff Vers
putNgramsPatches { listIds, nodeId, session, tabType } = put session putNgrams
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 props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsStagePatch
...
...
@@ -1074,6 +1088,9 @@ filterTermSize (Just MonoTerm) nt = isSingleNgramsTerm nt
filterTermSize (Just MultiTerm) nt = not $ isSingleNgramsTerm nt
filterTermSize _ _ = true
------------------------------------------------------------------------
-- | Reset Button
type SyncResetButtonsProps =
( afterSync :: Unit -> Aff Unit
, ngramsLocalPatch :: NgramsTablePatch
...
...
@@ -1112,3 +1129,53 @@ syncResetButtonsCpt = R.hooksComponentWithModule thisModule "syncResetButtons" c
, on: { click: synchronizeClick }
} [ 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)
import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types as CT
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Table as T
import Gargantext.Components.Table.Types as T
import Gargantext.Ends (url, Frontends)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(..))
...
...
@@ -149,7 +150,11 @@ pageCpt = R.hooksComponentWithModule thisModule "page" cpt
where
cpt { session, pagePath, frontends
, 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
path = fst pagePath
rows = (\c -> {
...
...
src/Gargantext/Components/Nodes/Lists/Tabs.purs
View file @
97a4b906
...
...
@@ -63,10 +63,11 @@ tabsCpt = R.hooksComponentWithModule thisModule "tabs" cpt
pure $ Tab.tabs { selected, tabs: tabs' }
where
tabs' = [ "Authors" /\ view Authors
tabs' = [ "Terms" /\ view Terms
, "Authors" /\ view Authors
, "Institutes" /\ view Institutes
, "Sources" /\ view Sources
, "Terms" /\ view Terms
]
]
view mode = ngramsView { appReload
, asyncTasksRef
, cacheState
...
...
src/Gargantext/Components/Table.purs
View file @
97a4b906
...
...
@@ -7,12 +7,15 @@ 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.Table.Types
import Gargantext.Components.Nodes.Lists.Types as NT
import Gargantext.Components.Search
import Gargantext.Utils.Reactix as R2
...
...
@@ -21,60 +24,6 @@ import Gargantext.Utils.Reactix (effectLink)
thisModule :: String
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 =
{ page :: Int
, pageSize :: PageSizes
...
...
@@ -174,7 +123,7 @@ table props = R.createElement tableCpt props []
tableCpt :: R.Component Props
tableCpt = R.hooksComponentWithModule thisModule "table" cpt
where
cpt {container, colNames, wrapColElts, totalRecords, rows, params} _ = do
cpt {container,
syncResetButton,
colNames, wrapColElts, totalRecords, rows, params} _ = do
let
state = paramsState $ fst params
ps = pageSizes2Int state.pageSize
...
...
@@ -187,11 +136,12 @@ tableCpt = R.hooksComponentWithModule thisModule "table" cpt
cs =
wrapColElts c $
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)]
_ -> [lnk (Just (ASC c)) (columnName c)]
pure $ container
{ pageSizeControl: sizeDD { params }
{ syncResetButton
, pageSizeControl: sizeDD { params }
, pageSizeDescription: textDescription state.page state.pageSize totalRecords
, paginationLinks: pagination params totalPages
, tableBody: map _.row $ A.fromFoldable rows
...
...
@@ -213,8 +163,9 @@ filterRows { params: { limit, offset, orderBy } } rs = newRs
newRs = Seq.take limit $ Seq.drop offset $ rs
defaultContainer :: {title :: String} -> Record TableContainerProps -> R.Element
defaultContainer {title} props = R.fragment
[ R2.row
defaultContainer {title} props = R.fragment $ props.syncResetButton <> controls
where
controls = [ R2.row
[ H.div {className: "col-md-4"} [ props.pageSizeDescription ]
, H.div {className: "col-md-4"} [ props.paginationLinks ]
, H.div {className: "col-md-4"} [ props.pageSizeControl ]
...
...
@@ -356,3 +307,11 @@ string2PageSize "50" = PS50
string2PageSize "100" = PS100
string2PageSize "200" = PS200
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