Commit bc3b4ada authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[list] chart update button

parent ddd234e0
...@@ -11,7 +11,7 @@ import Gargantext.Sessions (Session) ...@@ -11,7 +11,7 @@ import Gargantext.Sessions (Session)
type MetricsLoadViewProps a = ( type MetricsLoadViewProps a = (
getMetrics :: Session -> Record Path -> Aff a getMetrics :: Session -> Record Path -> Aff a
, loaded :: R.State Int -> a -> R.Element , loaded :: Session -> Record Path -> R.State Int -> a -> R.Element
| MetricsProps | MetricsProps
) )
...@@ -23,4 +23,4 @@ metricsLoadViewCpt = R.hooksComponent "G.C.N.C.C.metricsLoadView" cpt ...@@ -23,4 +23,4 @@ metricsLoadViewCpt = R.hooksComponent "G.C.N.C.C.metricsLoadView" cpt
where where
cpt {getMetrics, loaded, path, reload, session} _ = do cpt {getMetrics, loaded, path, reload, session} _ = do
useLoader path (getMetrics session) $ \l -> useLoader path (getMetrics session) $ \l ->
loaded reload l loaded session path reload l
...@@ -5,6 +5,7 @@ import Data.Argonaut (class DecodeJson, decodeJson, (.:)) ...@@ -5,6 +5,7 @@ import Data.Argonaut (class DecodeJson, decodeJson, (.:))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis') import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
import Gargantext.Components.Charts.Options.Series (seriesBarD1) import Gargantext.Components.Charts.Options.Series (seriesBarD1)
...@@ -65,5 +66,10 @@ histoCpt = R.hooksComponent "G.C.N.C.C.H.histo" cpt ...@@ -65,5 +66,10 @@ histoCpt = R.hooksComponent "G.C.N.C.C.H.histo" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded, path, reload, session} pure $ metricsLoadView {getMetrics, loaded, path, reload, session}
loaded :: R.State Int -> HistoMetrics -> R.Element loaded :: Session -> Record Path -> R.State Int -> HistoMetrics -> R.Element
loaded setReload loaded = U.reloadButtonWrap setReload $ chart $ chartOptions loaded loaded session path reload loaded =
H.div {} [
U.reloadButton reload
, U.chartUpdateButton { chartType: Histo, path, reload, session }
, chart $ chartOptions loaded
]
...@@ -101,5 +101,6 @@ metricsCpt = R.hooksComponent "G.C.N.C.C.M.metrics" cpt ...@@ -101,5 +101,6 @@ metricsCpt = R.hooksComponent "G.C.N.C.C.M.metrics" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded, path, reload, session} pure $ metricsLoadView {getMetrics, loaded, path, reload, session}
loaded :: R.State Int -> Loaded -> R.Element loaded :: Session -> Record Path -> R.State Int -> Loaded -> R.Element
loaded setReload loaded = U.reloadButtonWrap setReload $ chart $ scatterOptions loaded loaded _session _path setReload loaded =
U.reloadButtonWrap setReload $ chart $ scatterOptions loaded
...@@ -86,8 +86,9 @@ pieCpt = R.hooksComponent "G.C.N.C.C.P.pie" cpt ...@@ -86,8 +86,9 @@ pieCpt = R.hooksComponent "G.C.N.C.C.P.pie" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded: loadedPie, path, reload, session} pure $ metricsLoadView {getMetrics, loaded: loadedPie, path, reload, session}
loadedPie :: R.State Int -> HistoMetrics -> R.Element loadedPie :: Session -> Record Path -> R.State Int -> HistoMetrics -> R.Element
loadedPie setReload loaded = U.reloadButtonWrap setReload $ chart $ chartOptionsPie loaded loadedPie _session _path setReload loaded =
U.reloadButtonWrap setReload $ chart $ chartOptionsPie loaded
bar :: Record Props -> R.Element bar :: Record Props -> R.Element
...@@ -100,5 +101,6 @@ barCpt = R.hooksComponent "LoadedMetricsBar" cpt ...@@ -100,5 +101,6 @@ barCpt = R.hooksComponent "LoadedMetricsBar" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded: loadedBar, path, reload, session} pure $ metricsLoadView {getMetrics, loaded: loadedBar, path, reload, session}
loadedBar :: R.State Int -> Loaded -> R.Element loadedBar :: Session -> Record Path -> R.State Int -> Loaded -> R.Element
loadedBar setReload loaded = U.reloadButtonWrap setReload $ chart $ chartOptionsBar loaded loadedBar _session _path setReload loaded =
U.reloadButtonWrap setReload $ chart $ chartOptionsBar loaded
...@@ -61,8 +61,9 @@ treeCpt = R.hooksComponent "G.C.N.C.C.T.tree" cpt ...@@ -61,8 +61,9 @@ treeCpt = R.hooksComponent "G.C.N.C.C.T.tree" cpt
reload <- R.useState' 0 reload <- R.useState' 0
pure $ metricsLoadView {getMetrics, loaded, path, reload, session} pure $ metricsLoadView {getMetrics, loaded, path, reload, session}
loaded :: R.State Int -> Loaded -> R.Element loaded :: Session -> Record Path -> R.State Int -> Loaded -> R.Element
loaded setReload loaded = loaded _session _path reload loaded =
H.div {} H.div {} [
[ U.reloadButton setReload U.reloadButton reload
, chart (scatterOptions loaded) ] , chart (scatterOptions loaded)
]
module Gargantext.Components.Nodes.Corpus.Chart.Utils where module Gargantext.Components.Nodes.Corpus.Chart.Utils where
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import Effect (Effect)
import Effect.Uncurried (mkEffectFn1) import Effect.Uncurried (mkEffectFn1)
import Reactix as R 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.Nodes.Corpus.Chart.Types (Path)
import Gargantext.Sessions (Session)
import Gargantext.Types as T
reloadButtonWrap :: R.State Int -> R.Element -> R.Element reloadButtonWrap :: R.State Int -> R.Element -> R.Element
reloadButtonWrap setReload el = H.div {} [ reloadButtonWrap setReload el = H.div {} [
...@@ -14,7 +19,35 @@ reloadButtonWrap setReload el = H.div {} [ ...@@ -14,7 +19,35 @@ reloadButtonWrap setReload el = H.div {} [
] ]
reloadButton :: R.State Int -> R.Element reloadButton :: R.State Int -> R.Element
reloadButton (_ /\ setReload) = H.a {className, onClick, title: "Reload"} [] reloadButton (_ /\ setReload) = H.a { className
, on: { click: onClick }
, title: "Reload" } []
where where
className = "reload-btn glyphicon glyphicon-refresh" className = "reload-btn fa fa-refresh"
onClick = mkEffectFn1 $ \_ -> setReload $ \r -> r + 1 onClick _ = setReload $ (_ + 1)
type ChartUpdateButtonProps = (
chartType :: T.ChartType
, path :: Record Path
, reload :: R.State Int
, session :: Session
)
chartUpdateButton :: Record ChartUpdateButtonProps -> R.Element
chartUpdateButton p = R.createElement chartUpdateButtonCpt p []
chartUpdateButtonCpt :: R.Component ChartUpdateButtonProps
chartUpdateButtonCpt = R.hooksComponent "G.C.N.C.C.U.chartUpdateButton" cpt
where
cpt { path: { chartType, corpusId, listId, tabType }, reload: (_ /\ setReload), session } _ = do
R.useEffect' $ do
log2 "[chartUpdateButton] tabType" tabType
pure $ H.a { className: "chart-update-button fa fa-database"
, on: { click: onClick }
, title: "Update chart data" } []
where
onClick :: forall a. a -> Effect Unit
onClick _ = do
setReload $ (_ + 1)
...@@ -118,6 +118,8 @@ sessionPath (R.Tab t i) = sessionPath (R.NodeAPI Node i (showTabType ...@@ -118,6 +118,8 @@ sessionPath (R.Tab t i) = sessionPath (R.NodeAPI Node i (showTabType
sessionPath (R.Children n o l s i) = sessionPath (R.NodeAPI Node i ("children?type=" <> show n <> offsetUrl o <> limitUrl l <> orderUrl s)) sessionPath (R.Children n o l s i) = sessionPath (R.NodeAPI Node i ("children?type=" <> show n <> offsetUrl o <> limitUrl l <> orderUrl s))
sessionPath (R.NodeAPI Phylo pId p) = "phyloscape?nodeId=" <> (show $ fromMaybe 0 pId) <> p sessionPath (R.NodeAPI Phylo pId p) = "phyloscape?nodeId=" <> (show $ fromMaybe 0 pId) <> p
sessionPath (R.RecomputeNgrams nt nId lId) = "node/" <> (show nId) <> "/ngrams/recompute?list=" <> (show lId) <> "&ngramsType=" <> (show nt) sessionPath (R.RecomputeNgrams nt nId lId) = "node/" <> (show nId) <> "/ngrams/recompute?list=" <> (show lId) <> "&ngramsType=" <> (show nt)
sessionPath (R.RecomputeListChart Histo nId lId) = "node/" <> (show nId) <> "/chart?list=" <> (show lId)
sessionPath (R.RecomputeListChart _ nId lId) = "node/" <> (show nId) <> "/recompute-chart?list=" <> (show lId)
sessionPath (R.GraphAPI gId p) = "graph/" <> (show gId) <> "/" <> p sessionPath (R.GraphAPI gId p) = "graph/" <> (show gId) <> "/" <> p
sessionPath (R.GetNgrams opts i) = sessionPath (R.GetNgrams opts i) =
base opts.tabType base opts.tabType
......
...@@ -3,7 +3,7 @@ module Gargantext.Routes where ...@@ -3,7 +3,7 @@ module Gargantext.Routes where
import Prelude import Prelude
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Gargantext.Types (ChartOpts, CorpusMetricOpts, CTabNgramType, Id, Limit, ListId, NgramsGetOpts, NodeType, Offset, OrderBy, SearchOpts, SessionId, TabSubType, TabType, TermList, NgramsGetTableAllOpts) import Gargantext.Types (ChartOpts, ChartType, CorpusMetricOpts, CTabNgramType, Id, Limit, ListId, NgramsGetOpts, NodeType, Offset, OrderBy, SearchOpts, SessionId, TabSubType, TabType, TermList, NgramsGetTableAllOpts)
data AppRoute data AppRoute
= Home = Home
...@@ -37,6 +37,7 @@ data SessionRoute ...@@ -37,6 +37,7 @@ data SessionRoute
| PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id) | PutNgrams TabType (Maybe ListId) (Maybe TermList) (Maybe Id)
-- ^ This name is not good. In particular this URL is used both in PUT and POST. -- ^ This name is not good. In particular this URL is used both in PUT and POST.
| RecomputeNgrams (TabSubType CTabNgramType) Id ListId | RecomputeNgrams (TabSubType CTabNgramType) Id ListId
| RecomputeListChart ChartType Id ListId
| NodeAPI NodeType (Maybe Id) String | NodeAPI NodeType (Maybe Id) String
| GraphAPI Id String | GraphAPI Id String
| ListsRoute ListId | ListsRoute ListId
......
module Gargantext.Types where msession path reload = H.div {} []odule Gargantext.Types where
import Prelude import Prelude
......
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