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
122
Issues
122
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
gargantext
purescript-gargantext
Commits
e8ade662
Commit
e8ade662
authored
Jan 26, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dashboard] some code editor fixes
parent
954a886c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
40 deletions
+88
-40
CodeEditor.purs
src/Gargantext/Components/CodeEditor.purs
+1
-0
Corpus.purs
src/Gargantext/Components/Nodes/Corpus.purs
+10
-10
Dashboard.purs
src/Gargantext/Components/Nodes/Corpus/Dashboard.purs
+76
-29
Reload.purs
src/Gargantext/Utils/Reload.purs
+1
-1
No files found.
src/Gargantext/Components/CodeEditor.purs
View file @
e8ade662
...
@@ -24,6 +24,7 @@ import Gargantext.Prelude
...
@@ -24,6 +24,7 @@ import Gargantext.Prelude
import Gargantext.Utils.HighlightJS as HLJS
import Gargantext.Utils.HighlightJS as HLJS
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
thisModule :: String
thisModule = "Gargantext.Components.CodeEditor"
thisModule = "Gargantext.Components.CodeEditor"
type Code = String
type Code = String
...
...
src/Gargantext/Components/Nodes/Corpus.purs
View file @
e8ade662
...
@@ -105,7 +105,7 @@ corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
...
@@ -105,7 +105,7 @@ corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
, H.div {}
, H.div {}
[ fieldsCodeEditor { fields: fieldsS
[ fieldsCodeEditor { fields: fieldsS
, nodeId
, nodeId
, session } ]
, session }
[]
]
, H.div { className: "row" }
, H.div { className: "row" }
[ H.div { className: "btn btn-secondary"
[ H.div { className: "btn btn-secondary"
, on: { click: onClickAdd fieldsS }
, on: { click: onClickAdd fieldsS }
...
@@ -139,14 +139,14 @@ type FieldsCodeEditorProps =
...
@@ -139,14 +139,14 @@ type FieldsCodeEditorProps =
| LoadProps
| LoadProps
)
)
fieldsCodeEditor :: R
ecord FieldsCodeEditorProps -> R.Element
fieldsCodeEditor :: R
2.Component FieldsCodeEditorProps
fieldsCodeEditor
props = R.createElement fieldsCodeEditorCpt props []
fieldsCodeEditor
= R.createElement el
where
where
fieldsCodeEditorCpt
:: R.Component FieldsCodeEditorProps
el
:: R.Component FieldsCodeEditorProps
fieldsCodeEditorCpt
= R.hooksComponentWithModule thisModule "fieldsCodeEditorCpt" cpt
el
= R.hooksComponentWithModule thisModule "fieldsCodeEditorCpt" cpt
cpt {nodeId, fields: fS@(fields /\ _), session} _ = do
cpt {nodeId, fields: fS@(fields /\ _), session} _ = do
masterKey <-
R.useState' 0
masterKey <-
GUR.new
pure $ H.div {} $ List.toUnfoldable (editors masterKey)
pure $ H.div {} $ List.toUnfoldable (editors masterKey)
where
where
...
@@ -170,13 +170,13 @@ fieldsCodeEditor props = R.createElement fieldsCodeEditorCpt props []
...
@@ -170,13 +170,13 @@ fieldsCodeEditor props = R.createElement fieldsCodeEditorCpt props []
List.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields
List.modifyAt idx (\(Tuple _ (Field f)) -> Tuple idx (Field $ f { typ = typ })) fields
onMoveDown :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveDown :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveDown
(_ /\ setMasterKey) (fs
/\ setFields) idx _ = do
onMoveDown
masterKey (_
/\ setFields) idx _ = do
setMasterKey $ (+) 1
GUR.bump masterKey
setFields $ recomputeIndices <<< (GDA.swapList idx (idx + 1))
setFields $ recomputeIndices <<< (GDA.swapList idx (idx + 1))
onMoveUp :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveUp :: GUR.ReloadS -> R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onMoveUp
(_ /\ setMasterKey)
(_ /\ setFields) idx _ = do
onMoveUp
masterKey
(_ /\ setFields) idx _ = do
setMasterKey $ (+) 1
GUR.bump masterKey
setFields $ recomputeIndices <<< (GDA.swapList idx (idx - 1))
setFields $ recomputeIndices <<< (GDA.swapList idx (idx - 1))
onRemove :: R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
onRemove :: R.State FTFieldsWithIndex -> Index -> Unit -> Effect Unit
...
...
src/Gargantext/Components/Nodes/Corpus/Dashboard.purs
View file @
e8ade662
module Gargantext.Components.Nodes.Corpus.Dashboard where
module Gargantext.Components.Nodes.Corpus.Dashboard where
import DOM.Simple.Console (log2)
import Gargantext.Components.Nodes.Types
import Gargantext.Prelude
import DOM.Simple.Console (log, log2)
import Data.Array as A
import Data.Array as A
import Data.List as List
import Data.List as List
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Maybe (Maybe(..), fromMaybe)
...
@@ -9,19 +12,16 @@ import Data.Tuple.Nested ((/\))
...
@@ -9,19 +12,16 @@ import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Reactix as R
import Reactix.DOM.HTML as H
import Gargantext.Components.Nodes.Corpus (fieldsCodeEditor)
import Gargantext.Components.Nodes.Corpus (fieldsCodeEditor)
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.Dashboard.Types as DT
import Gargantext.Components.Nodes.Dashboard.Types as DT
import Gargantext.Components.Nodes.Types
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Prelude
import Gargantext.Sessions (Session, sessionId)
import Gargantext.Sessions (Session, sessionId)
import Gargantext.Types (NodeID)
import Gargantext.Types (NodeID)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
import Gargantext.Utils.Reload as GUR
import Reactix as R
import Reactix.DOM.HTML as H
thisModule :: String
thisModule :: String
thisModule = "Gargantext.Components.Nodes.Corpus.Dashboard"
thisModule = "Gargantext.Components.Nodes.Corpus.Dashboard"
...
@@ -68,10 +68,11 @@ dashboardLayoutWithKey = R.createElement dashboardLayoutWithKeyCpt
...
@@ -68,10 +68,11 @@ dashboardLayoutWithKey = R.createElement dashboardLayoutWithKeyCpt
, onChange: onChange nodeId reload (DT.Hyperdata h)
, onChange: onChange nodeId reload (DT.Hyperdata h)
, session } []
, session } []
where
where
onChange :: NodeID -> GUR.ReloadS -> DT.Hyperdata -> Array P.PredefinedChart -> Effect Unit
onChange :: NodeID -> GUR.ReloadS -> DT.Hyperdata -> { charts :: Array P.PredefinedChart
onChange nodeId' reload (DT.Hyperdata h) charts = do
, fields :: List.List FTField } -> Effect Unit
onChange nodeId' reload (DT.Hyperdata h) { charts, fields } = do
launchAff_ do
launchAff_ do
DT.saveDashboard { hyperdata: DT.Hyperdata $ h { charts = charts }
DT.saveDashboard { hyperdata: DT.Hyperdata $ h { charts = charts
, fields = fields
}
, nodeId:nodeId'
, nodeId:nodeId'
, session }
, session }
liftEffect $ GUR.bump reload
liftEffect $ GUR.bump reload
...
@@ -82,7 +83,8 @@ type LoadedProps =
...
@@ -82,7 +83,8 @@ type LoadedProps =
, defaultListId :: Int
, defaultListId :: Int
, fields :: List.List FTField
, fields :: List.List FTField
, key :: String
, key :: String
, onChange :: Array P.PredefinedChart -> Effect Unit
, onChange :: { charts :: Array P.PredefinedChart
, fields :: List.List FTField } -> Effect Unit
| Props
| Props
)
)
...
@@ -93,6 +95,49 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
...
@@ -93,6 +95,49 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
dashboardLayoutLoadedCpt = R.hooksComponentWithModule thisModule "dashboardLayoutLoaded" cpt
dashboardLayoutLoadedCpt = R.hooksComponentWithModule thisModule "dashboardLayoutLoaded" cpt
cpt props@{ charts, corpusId, defaultListId, fields, nodeId, onChange, session } _ = do
cpt props@{ charts, corpusId, defaultListId, fields, nodeId, onChange, session } _ = do
pure $ H.div {}
[ H.div { className: "row" }
[ H.div { className: "col-12" }
([ H.h1 {} [ H.text "Board" ]
, H.p {} [ H.text "Summary of all your charts here" ]
] <> chartsEls <> [addNew])
]
, dashboardCodeEditor { fields
, nodeId
, onChange: \fs -> onChange { charts, fields: fs }
, session } []
]
where
addNew = H.div { className: "row" } [
H.span { className: "btn btn-secondary"
, on: { click: onClickAddChart }} [ H.span { className: "fa fa-plus" } [] ]
]
where
onClickAddChart _ = onChange { charts: A.cons P.CDocsHistogram charts
, fields }
chartsEls = A.mapWithIndex chartIdx charts
chartIdx idx chart =
renderChart { chart, corpusId, defaultListId, onChange: onChangeChart, onRemove, session } []
where
onChangeChart c = do
onChange { charts: fromMaybe charts (A.modifyAt idx (\_ -> c) charts)
, fields }
onRemove _ = onChange { charts: fromMaybe charts $ A.deleteAt idx charts
, fields }
type CodeEditorProps =
( fields :: List.List FTField
, onChange :: List.List FTField -> Effect Unit
| Props
)
dashboardCodeEditor :: R2.Component CodeEditorProps
dashboardCodeEditor = R.createElement el
where
el :: R.Component CodeEditorProps
el = R.hooksComponentWithModule thisModule "dashboardCodeEditor" cpt
cpt props@{ fields, nodeId, onChange, session } _ = do
let fieldsWithIndex = List.mapWithIndex (\idx -> \t -> Tuple idx t) fields
let fieldsWithIndex = List.mapWithIndex (\idx -> \t -> Tuple idx t) fields
fieldsS <- R.useState' fieldsWithIndex
fieldsS <- R.useState' fieldsWithIndex
fieldsRef <- R.useRef fields
fieldsRef <- R.useRef fields
...
@@ -105,18 +150,20 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
...
@@ -105,18 +150,20 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
R.setRef fieldsRef fields
R.setRef fieldsRef fields
snd fieldsS $ const fieldsWithIndex
snd fieldsS $ const fieldsWithIndex
pure $
H.div {}
pure $
R.fragment
[ H.div { className: "row" }
[ H.div { className: "row" }
[ H.div { className: "col-12" }
[ H.div { className: "btn btn-secondary " <> (saveEnabled fieldsWithIndex fieldsS)
([ H.h1 {} [ H.text "Board" ]
, on: { click: onClickSave fieldsS }
, H.p {} [ H.text "Summary of all your charts here" ]
}
] <> chartsEls <> [addNew])
[ H.span { className: "fa fa-floppy-o" } [ ]
]
]
]
, H.div { className: "row" }
, H.div { className: "row" }
[ H.div { className: "col-12" }
[ H.div { className: "col-12" }
[ fieldsCodeEditor { fields: fieldsS
[ fieldsCodeEditor { fields: fieldsS
, nodeId
, nodeId
, session } ]
, session} []
]
]
]
, H.div { className: "row" }
, H.div { className: "row" }
[ H.div { className: "btn btn-secondary"
[ H.div { className: "btn btn-secondary"
...
@@ -127,19 +174,18 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
...
@@ -127,19 +174,18 @@ dashboardLayoutLoaded = R.createElement dashboardLayoutLoadedCpt
]
]
]
]
where
where
addNew = H.div { className: "row" } [
saveEnabled :: FTFieldsWithIndex -> R.State FTFieldsWithIndex -> String
H.span { className: "btn btn-secondary"
saveEnabled fs (fsS /\ _) = if fs == fsS then "disabled" else "enabled"
, on: { click: onClickAddChart }} [ H.span { className: "fa fa-plus" } [] ]
]
onClickSave :: forall e. R.State FTFieldsWithIndex -> e -> Effect Unit
where
onClickSave (fields /\ _) _ = do
onClickAddChart _ = onChange $ A.cons P.CDocsHistogram charts
log "[dashboardCodeEditor] saving (TODO)"
chartsEls = A.mapWithIndex chartIdx charts
onChange $ snd <$> fields
chartIdx idx chart =
-- launchAff_ do
renderChart { chart, corpusId, defaultListId, onChange: onChangeChart, onRemove, session } []
-- saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS}
where
-- , nodeId
onChangeChart c = do
-- , session }
onChange $ fromMaybe charts (A.modifyAt idx (\_ -> c) charts)
onRemove _ = onChange $ fromMaybe charts $ A.deleteAt idx charts
onClickAddField :: forall e. R.State FTFieldsWithIndex -> e -> Effect Unit
onClickAddField :: forall e. R.State FTFieldsWithIndex -> e -> Effect Unit
onClickAddField (_ /\ setFieldsS) _ = do
onClickAddField (_ /\ setFieldsS) _ = do
setFieldsS $ \fieldsS -> List.snoc fieldsS $ Tuple (List.length fieldsS) defaultField
setFieldsS $ \fieldsS -> List.snoc fieldsS $ Tuple (List.length fieldsS) defaultField
...
@@ -168,6 +214,7 @@ renderChart = R.createElement renderChartCpt
...
@@ -168,6 +214,7 @@ renderChart = R.createElement renderChartCpt
, on: { change: onSelectChange }
, on: { change: onSelectChange }
} (option <$> P.allPredefinedCharts)
} (option <$> P.allPredefinedCharts)
]
]
, H.div { className: "col-9" } []
, H.div { className: "col-1" }
, H.div { className: "col-1" }
[ H.span { className: "btn btn-danger"
[ H.span { className: "btn btn-danger"
, on: { click: onRemoveClick }} [ H.span { className: "fa fa-trash" } [] ]
, on: { click: onRemoveClick }} [ H.span { className: "fa fa-trash" } [] ]
...
...
src/Gargantext/Utils/Reload.purs
View file @
e8ade662
module Gargantext.Utils.Reload where
module Gargantext.Utils.Reload where
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple.Nested((/\))
import Data.Tuple.Nested
((/\))
import Effect (Effect)
import Effect (Effect)
import Reactix as R
import Reactix as R
...
...
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