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
06b9d6d5
Commit
06b9d6d5
authored
Feb 19, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Dashboard] store charts in dashboard node, not corpus one
parent
5fa8954a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
43 deletions
+86
-43
Dashboard.purs
src/Gargantext/Components/Nodes/Corpus/Dashboard.purs
+15
-16
Types.purs
src/Gargantext/Components/Nodes/Corpus/Types.purs
+9
-27
Types.purs
src/Gargantext/Components/Nodes/Dashboard/Types.purs
+62
-0
No files found.
src/Gargantext/Components/Nodes/Corpus/Dashboard.purs
View file @
06b9d6d5
...
@@ -14,9 +14,8 @@ import Reactix.DOM.HTML as H
...
@@ -14,9 +14,8 @@ import Reactix.DOM.HTML as H
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Nodes.Corpus (loadCorpusWithChildAndReload, saveCorpus)
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Components.Nodes.
Corpus.Types (getCorpusInfo, updateHyperdataCharts, CorpusInfo(..), Hyperdata(..))
import Gargantext.Components.Nodes.
Dashboard.Types as DT
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reactix as R2
import Gargantext.Sessions (Session)
import Gargantext.Sessions (Session)
...
@@ -37,25 +36,25 @@ dashboardLayoutCpt = R.hooksComponent "G.C.N.C.D.dashboardLayout" cpt
...
@@ -37,25 +36,25 @@ dashboardLayoutCpt = R.hooksComponent "G.C.N.C.D.dashboardLayout" cpt
cpt params@{nodeId, session} _ = do
cpt params@{nodeId, session} _ = do
reload <- R.useState' 0
reload <- R.useState' 0
useLoader {nodeId, reload: fst reload, session} loadCorpusWithChildAndReload $
useLoader {nodeId, reload: fst reload, session} DT.loadDashboardWithReload $
\corpusData@{corpusId, defaultListId, corpusNode: NodePoly poly} -> do
\dashboardData@{hyperdata: DT.Hyperdata h, parentId} -> do
let { name, date, hyperdata : Hyperdata h} = poly
let { charts } = h
let CorpusInfo {authors, charts, desc, query} = getCorpusInfo h.fields
dashboardLayoutLoaded { charts
dashboardLayoutLoaded { charts
, corpusId
, corpusId
: parentId
, defaultListId
, defaultListId
: 0
, key: show $ fst reload
, key: show $ fst reload
, nodeId
, nodeId
, onChange: onChange
corpusId reload (
Hyperdata h)
, onChange: onChange
nodeId reload (DT.
Hyperdata h)
, session }
, session }
where
where
onChange :: NodeID -> R.State Int -> Hyperdata -> Array P.PredefinedChart -> Effect Unit
onChange :: NodeID -> R.State Int ->
DT.
Hyperdata -> Array P.PredefinedChart -> Effect Unit
onChange
corpusId (_ /\ setReload) h
charts = do
onChange
nodeId (_ /\ setReload) (DT.Hyperdata h)
charts = do
launchAff_ do
launchAff_ do
saveCorpus $ { hyperdata: updateHyperdataCharts h charts
DT.saveDashboard {
, nodeId: corpusId
hyperdata: DT.Hyperdata $ h { charts = charts }
, session }
, nodeId
, session }
liftEffect $ setReload $ (+) 1
liftEffect $ setReload $ (+) 1
type LoadedProps =
type LoadedProps =
...
@@ -98,8 +97,8 @@ dashboardLayoutLoadedCpt = R.hooksComponent "G.C.N.C.D.dashboardLayoutLoaded" cp
...
@@ -98,8 +97,8 @@ dashboardLayoutLoadedCpt = R.hooksComponent "G.C.N.C.D.dashboardLayoutLoaded" cp
type PredefinedChartProps =
type PredefinedChartProps =
(
(
c
orpusId :: NodeID
c
hart :: P.PredefinedChart
, c
hart :: P.PredefinedChart
, c
orpusId :: NodeID
, defaultListId :: Int
, defaultListId :: Int
, onChange :: P.PredefinedChart -> Effect Unit
, onChange :: P.PredefinedChart -> Effect Unit
, onRemove :: Unit -> Effect Unit
, onRemove :: Unit -> Effect Unit
...
...
src/Gargantext/Components/Nodes/Corpus/Types.purs
View file @
06b9d6d5
...
@@ -57,7 +57,6 @@ data FieldType =
...
@@ -57,7 +57,6 @@ data FieldType =
}
}
| JSON {
| JSON {
authors :: Author
authors :: Author
, charts :: Array P.PredefinedChart
, desc :: Description
, desc :: Description
, query :: Query
, query :: Query
, tag :: Tag
, tag :: Tag
...
@@ -77,31 +76,19 @@ isJSON (Field {typ}) = isJSON' typ
...
@@ -77,31 +76,19 @@ isJSON (Field {typ}) = isJSON' typ
getCorpusInfo :: List.List FTField -> CorpusInfo
getCorpusInfo :: List.List FTField -> CorpusInfo
getCorpusInfo as = case List.head (List.filter isJSON as) of
getCorpusInfo as = case List.head (List.filter isJSON as) of
Just (Field {typ: JSON {authors, charts, desc, query, title}}) -> CorpusInfo { title
Just (Field {typ: JSON {authors, desc, query, title}}) -> CorpusInfo { title
, desc
, desc
, query
, query
, authors
, authors
, charts
, totalRecords: 0
, totalRecords: 0
}
}
_ -> CorpusInfo { title:"Empty"
_ -> CorpusInfo { title:"Empty"
, desc:""
, desc:""
, query:""
, query:""
, authors:""
, authors:""
, charts: []
, totalRecords: 0
, totalRecords: 0
}
}
updateHyperdataCharts :: Hyperdata -> Array P.PredefinedChart -> Hyperdata
updateHyperdataCharts (Hyperdata h@{fields}) charts = Hyperdata $ h { fields = updateFieldsCharts fields charts }
updateFieldsCharts :: List.List FTField -> Array P.PredefinedChart -> List.List FTField
updateFieldsCharts List.Nil _ = List.Nil
updateFieldsCharts fs [] = fs
updateFieldsCharts ((Field f@{typ: JSON j@{charts}}):as) pcharts = (Field $ f { typ = JSON $ j { charts = pcharts } }):as
updateFieldsCharts (a@(Field {typ: _}):as) pcharts = a:(updateFieldsCharts as pcharts)
derive instance genericFieldType :: Generic FieldType _
derive instance genericFieldType :: Generic FieldType _
instance eqFieldType :: Eq FieldType where
instance eqFieldType :: Eq FieldType where
eq = genericEq
eq = genericEq
...
@@ -120,12 +107,11 @@ instance decodeFTField :: DecodeJson (Field FieldType) where
...
@@ -120,12 +107,11 @@ instance decodeFTField :: DecodeJson (Field FieldType) where
pure $ Haskell {haskell, tag}
pure $ Haskell {haskell, tag}
"JSON" -> do
"JSON" -> do
authors <- data_ .: "authors"
authors <- data_ .: "authors"
charts <- data_ .: "charts"
desc <- data_ .: "desc"
desc <- data_ .: "desc"
query <- data_ .: "query"
query <- data_ .: "query"
tag <- data_ .: "tag"
tag <- data_ .: "tag"
title <- data_ .: "title"
title <- data_ .: "title"
pure $ JSON {authors,
charts,
desc, query, tag, title}
pure $ JSON {authors, desc, query, tag, title}
"Markdown" -> do
"Markdown" -> do
tag <- data_ .: "tag"
tag <- data_ .: "tag"
text <- data_ .: "text"
text <- data_ .: "text"
...
@@ -147,9 +133,8 @@ instance encodeFieldType :: EncodeJson FieldType where
...
@@ -147,9 +133,8 @@ instance encodeFieldType :: EncodeJson FieldType where
"haskell" := haskell
"haskell" := haskell
~> "tag" := "HaskellField"
~> "tag" := "HaskellField"
~> jsonEmptyObject
~> jsonEmptyObject
encodeJson (JSON {authors,
charts,
desc, query, tag, title}) =
encodeJson (JSON {authors, desc, query, tag, title}) =
"authors" := authors
"authors" := authors
~> "charts" := charts
~> "desc" := desc
~> "desc" := desc
~> "query" := query
~> "query" := query
~> "tag" := "JsonField"
~> "tag" := "JsonField"
...
@@ -171,7 +156,6 @@ defaultJSON :: FieldType
...
@@ -171,7 +156,6 @@ defaultJSON :: FieldType
defaultJSON = JSON defaultJSON'
defaultJSON = JSON defaultJSON'
defaultJSON' = {
defaultJSON' = {
authors: ""
authors: ""
, charts: []
, desc: ""
, desc: ""
, query: ""
, query: ""
, tag: "JSONField"
, tag: "JSONField"
...
@@ -195,7 +179,6 @@ newtype CorpusInfo =
...
@@ -195,7 +179,6 @@ newtype CorpusInfo =
CorpusInfo
CorpusInfo
{ title :: String
{ title :: String
, authors :: String
, authors :: String
, charts :: Array P.PredefinedChart
, desc :: String
, desc :: String
, query :: String
, query :: String
, totalRecords :: Int }
, totalRecords :: Int }
...
@@ -207,9 +190,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
...
@@ -207,9 +190,8 @@ instance decodeCorpusInfo :: DecodeJson CorpusInfo where
desc <- obj .: "desc"
desc <- obj .: "desc"
query <- obj .: "query"
query <- obj .: "query"
authors <- obj .: "authors"
authors <- obj .: "authors"
charts <- obj .: "charts"
let totalRecords = 47361 -- TODO
let totalRecords = 47361 -- TODO
pure $ CorpusInfo {title, authors,
charts,
desc, query, totalRecords}
pure $ CorpusInfo {title, authors, desc, query, totalRecords}
type CorpusData = { corpusId :: Int
type CorpusData = { corpusId :: Int
, corpusNode :: NodePoly Hyperdata -- CorpusInfo
, corpusNode :: NodePoly Hyperdata -- CorpusInfo
...
...
src/Gargantext/Components/Nodes/Dashboard/Types.purs
0 → 100644
View file @
06b9d6d5
module Gargantext.Components.Nodes.Dashboard.Types where
import Data.Maybe (Maybe(..))
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, (.:), (.:?), (:=), (~>), jsonEmptyObject)
import Data.Maybe (Maybe)
import Effect.Aff (Aff)
import Gargantext.Prelude
import Gargantext.Components.Nodes.Corpus.Chart.Predefined as P
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, get, put)
import Gargantext.Types (NodeType(..))
type Preferences = Maybe String
newtype Hyperdata =
Hyperdata
{
charts :: Array P.PredefinedChart
, preferences :: Preferences
}
instance decodeHyperdata :: DecodeJson Hyperdata where
decodeJson json = do
obj <- decodeJson json
charts <- obj .: "charts"
preferences <- obj .:? "preferences"
pure $ Hyperdata {charts, preferences}
instance encodeHyperdata :: EncodeJson Hyperdata where
encodeJson (Hyperdata {charts, preferences}) = do
"charts" := charts
~> "preferences" := preferences
~> jsonEmptyObject
type LoadProps = (
nodeId :: Int
, session :: Session
)
loadDashboard' :: Record LoadProps -> Aff DashboardData
loadDashboard' {nodeId, session} = get session $ NodeAPI Node (Just nodeId) ""
-- Just to make reloading effective
loadDashboardWithReload :: {reload :: Int | LoadProps} -> Aff DashboardData
loadDashboardWithReload {nodeId, session} = loadDashboard' {nodeId, session}
type SaveProps = (
hyperdata :: Hyperdata
| LoadProps
)
saveDashboard :: Record SaveProps -> Aff Unit
saveDashboard {hyperdata, nodeId, session} = do
id_ <- (put session (NodeAPI Node (Just nodeId) "") hyperdata) :: Aff Int
pure unit
type DashboardData = {
id :: Int
, hyperdata :: Hyperdata
, parentId :: Int
}
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