Commit 4bb618e2 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Corpus] Facets added.

parent 898dae3c
......@@ -5,7 +5,10 @@ import Prelude hiding (div)
import Control.Monad.Trans.Class (lift)
import Data.Maybe (Maybe(..), maybe)
import Data.Lens (Lens', Prism', lens, prism, (?~))
import Data.List (fromFoldable)
import Data.Either (Either(..))
import Data.Tuple (Tuple(..))
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Effect.Aff (Aff)
......@@ -14,14 +17,11 @@ import Effect.Console (log)
import React.DOM (div, h3, hr, i, p, text)
import React.DOM.Props (className, style)
import Thermite ( Render, Spec, PerformAction
import Thermite ( Render, Spec, PerformAction, focus, hide
, defaultPerformAction, simpleSpec, modifyState)
--------------------------------------------------------
import Gargantext.Config (toUrl, NodeType(..), End(..))
import Gargantext.Config.REST (get)
import Gargantext.Components.Charts.Options.ECharts (chart)
import Gargantext.Pages.Corpus.Doc.Facets.Dashboard (globalPublis)
import Gargantext.Pages.Corpus.Doc.Facets (pureTab1)
---------------------------------------------------------
-- Facets
import Gargantext.Pages.Corpus.Doc.Facets.Documents as D
......@@ -31,18 +31,79 @@ import Gargantext.Pages.Corpus.Doc.Facets.Terms as T
import Gargantext.Components.Tab as Tab
-------------------------------------------------------------------
type State = { info :: Maybe (NodePoly CorpusInfo)
-- , docview :: D.state
-- , authorview :: A.State
-- , sourceview :: S.State
-- , termsview :: T.State
-- , activeTab :: Int
, docsView :: D.State
, authorsView :: A.State
, sourcesView :: S.State
, termsView :: T.State
, activeTab :: Int
}
initialState :: State
initialState = { info : Nothing }
initialState = { info : Nothing
, docsView : D.initialState
, authorsView : A.initialState
, sourcesView : S.initialState
, termsView : T.initialState
, activeTab : 0
}
------------------------------------------------------------------------
_info :: Lens' State (Maybe (NodePoly CorpusInfo))
_info = lens (\s -> s.info) (\s ss -> s{info = ss})
_doclens :: Lens' State D.State
_doclens = lens (\s -> s.docsView) (\s ss -> s {docsView = ss})
_authorlens :: Lens' State A.State
_authorlens = lens (\s -> s.authorsView) (\s ss -> s {authorsView = ss})
_sourcelens :: Lens' State S.State
_sourcelens = lens (\s -> s.sourcesView) (\s ss -> s {sourcesView = ss})
_termslens :: Lens' State T.State
_termslens = lens (\s -> s.termsView) (\s ss -> s {termsView = ss})
_tablens :: Lens' State Tab.State
_tablens = lens (\s -> s.activeTab) (\s ss -> s {activeTab = ss})
------------------------------------------------------------------------
data Action = Load Int
| DocviewA D.Action
| AuthorviewA A.Action
| SourceviewA S.Action
| TermsviewA T.Action
| TabViewA Tab.Action
_docAction :: Prism' Action D.Action
_docAction = prism DocviewA \ action ->
case action of
DocviewA laction -> Right laction
_-> Left action
_authorAction :: Prism' Action A.Action
_authorAction = prism AuthorviewA \ action ->
case action of
AuthorviewA laction -> Right laction
_-> Left action
_sourceAction :: Prism' Action S.Action
_sourceAction = prism SourceviewA \ action ->
case action of
SourceviewA laction -> Right laction
_-> Left action
_termsAction :: Prism' Action T.Action
_termsAction = prism TermsviewA \ action ->
case action of
TermsviewA laction -> Right laction
_-> Left action
_tabAction :: Prism' Action Tab.Action
_tabAction = prism TabViewA \ action ->
case action of
TabViewA laction -> Right laction
_-> Left action
------------------------------------------------------------------------
newtype NodePoly a = NodePoly { id :: Int
, typename :: Int
, userId :: Int
......@@ -111,7 +172,7 @@ instance decodeNode :: (DecodeJson a) => DecodeJson (NodePoly a) where
------------------------------------------------------------------------
layout :: Spec State {} Action
layout = corpusSpec -- <> pureTab1
layout = corpusSpec <> facets
corpusSpec :: Spec State {} Action
corpusSpec = simpleSpec performAction render
......@@ -152,7 +213,6 @@ corpusSpec = simpleSpec performAction render
------------------------------------------------------------------------
performAction :: PerformAction State {} Action
performAction (Load nId) _ _ = do
eitherInfo <- lift $ getNode nId
......@@ -166,14 +226,30 @@ performAction _ _ _ = pure unit
getNode :: Int -> Aff (Either String (NodePoly CorpusInfo))
getNode id = get $ toUrl Back Node id
_info :: Lens' State (Maybe (NodePoly CorpusInfo))
_info = lens (\s -> s.info) (\s ss -> s{info = ss})
------------------------------------------------------------------------
-- Tabs
-- Facets
------------------------------------------------------------------------
facets :: Spec State {} Action
facets = hide initialState statefulFacets
statefulFacets :: Spec State {} Action
statefulFacets =
Tab.tabs _tablens _tabAction $ fromFoldable [ Tuple "Doc View" docPageSpec
, Tuple "Author View" authorPageSpec
, Tuple "Source View" sourcePageSpec
, Tuple "Terms View" termsPageSpec
]
docPageSpec :: Spec State {} Action
docPageSpec = focus _doclens _docAction D.layoutDocview
authorPageSpec :: Spec State {} Action
authorPageSpec = focus _authorlens _authorAction A.authorspec'
sourcePageSpec :: Spec State {} Action
sourcePageSpec = focus _sourcelens _sourceAction S.sourcespec'
termsPageSpec :: Spec State {} Action
termsPageSpec = focus _termslens _termsAction T.termSpec'
......@@ -10,7 +10,7 @@ import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = D.State
initialState :: State
initialState = D.tdata
initialState = D.initialState
type Action = D.Action
......
......@@ -21,6 +21,11 @@ import Gargantext.Config (NodeType(..), toUrl, End(..))
import Gargantext.Config.REST (get)
import Gargantext.Utils.DecodeMaybe ((.|))
------------------------------------------------------------------------
import Gargantext.Components.Charts.Options.ECharts (chart)
import Gargantext.Pages.Corpus.Doc.Facets.Dashboard (globalPublis)
------------------------------------------------------------------------
import React (ReactElement)
import React.DOM (a, b, b', br', div, input, option, select, span, table, tbody, td, text, th, thead, tr, p)
import React.DOM.Props (_type, className, href, onChange, onClick, scope, selected, value)
......@@ -51,7 +56,7 @@ data Action
type State = CorpusTableData
type CorpusTableData = TableData CorpusView
type CorpusTableData = TableData DocumentsView
newtype TableData a
= TableData
......@@ -66,8 +71,8 @@ newtype TableData a
-- , tree :: FTree
}
newtype CorpusView
= CorpusView
newtype DocumentsView
= DocumentsView
{ _id :: Int
, url :: String
, date :: String
......@@ -78,9 +83,9 @@ newtype CorpusView
}
derive instance genericCorpus :: Generic CorpusView _
derive instance genericCorpus :: Generic DocumentsView _
instance showCorpus :: Show CorpusView where
instance showCorpus :: Show DocumentsView where
show = genericShow
......@@ -150,8 +155,8 @@ layoutDocview = simpleSpec performAction render
render dispatch _ state@(TableData d) _ =
[ div [className "container1"]
[ div [className "row"]
[
div [className "col-md-12"]
[ chart globalPublis
, div [className "col-md-12"]
[ p [] []
, div [] [ text " Filter ", input []]
, br'
......@@ -186,12 +191,12 @@ performAction (LoadData n) _ _ = do
res <- lift $ loadPage n
case res of
Left err -> do
_ <- liftEffect $ log $ show err
_ <- liftEffect $ log $ show "Error: loading page documents"
_ <- liftEffect $ log $ show $ "Error: loading page documents:" <> show err
pure unit
Right resData -> do
_ <- liftEffect $ log $ show "OK: loading page documents"
void $ modifyState $ const resData
_ <- liftEffect $ log $ show "OK: loading page documents."
_ <- modifyState $ const resData
pure unit
loadPage :: Int -> Aff (Either String CorpusTableData)
......@@ -210,9 +215,9 @@ loadPage n = do
_ <- liftEffect $ log $ show $ map (\({ row: r, delete :_}) -> show r) ((\(TableData docs') -> docs'.rows) docs)
pure $ Right docs
where
res2corpus :: Array Response -> Array CorpusView
res2corpus :: Array Response -> Array DocumentsView
res2corpus rs = map (\(Response r) ->
CorpusView { _id : r.cid
DocumentsView { _id : r.cid
, url : ""
, date : r.created
, title : (\(Hyperdata hr) -> hr.title) r.hyperdata
......@@ -222,7 +227,7 @@ loadPage n = do
}) rs
toTableData :: Array CorpusView -> CorpusTableData
toTableData :: Array DocumentsView -> CorpusTableData
toTableData ds = TableData
{ rows : map (\d -> { row : d , delete : false}) ds
, totalPages : 474
......@@ -234,25 +239,25 @@ loadPage n = do
---------------------------------------------------------
sampleData' :: CorpusView
sampleData' = CorpusView {_id : 1, url : "", date : "date3", title : "title", source : "source", fav : false, ngramCount : 1}
sampleData' :: DocumentsView
sampleData' = DocumentsView {_id : 1, url : "", date : "date3", title : "title", source : "source", fav : false, ngramCount : 1}
sampleData :: Array CorpusView
sampleData :: Array DocumentsView
--sampleData = replicate 10 sampleData'
sampleData = map (\(Tuple t s) -> CorpusView {_id : 1, url : "", date : "2017", title: t, source: s, fav : false, ngramCount : 10}) sampleDocuments
sampleData = map (\(Tuple t s) -> DocumentsView {_id : 1, url : "", date : "2017", title: t, source: s, fav : false, ngramCount : 10}) sampleDocuments
sampleDocuments :: Array (Tuple String String)
sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"]
data' :: Array CorpusView -> Array {row :: CorpusView, delete :: Boolean}
data' :: Array DocumentsView -> Array {row :: DocumentsView, delete :: Boolean}
data' = map {row : _, delete : false}
sdata :: Array { row :: CorpusView, delete :: Boolean }
sdata :: Array { row :: DocumentsView, delete :: Boolean }
sdata = data' sampleData
tdata :: TableData CorpusView
tdata = TableData
initialState :: TableData DocumentsView
initialState = TableData
{ rows : sdata
, totalPages : 10
, currentPage : 1
......@@ -263,8 +268,8 @@ tdata = TableData
}
showRow :: {row :: CorpusView, delete :: Boolean} -> ReactElement
showRow {row : (CorpusView c), delete} =
showRow :: {row :: DocumentsView, delete :: Boolean} -> ReactElement
showRow {row : (DocumentsView c), delete} =
tr []
[ td [] [div [className $ fa <> "fa-star"][]]
-- TODO show date: Year-Month-Day only
......
......@@ -11,7 +11,7 @@ type State = D.State
initialState :: D.State
initialState = D.tdata
initialState = D.initialState
type Action = D.Action
......
......@@ -18,7 +18,7 @@ type State =
initialState :: State
initialState =
{ docview : DV.tdata
{ docview : DV.initialState
, authorview : AV.initialState
, sourceview : SV.initialState
, termsview : TV.initialState
......
......@@ -12,7 +12,7 @@ type State = D.State
initialState :: D.State
initialState = D.tdata
initialState = D.initialState
type Action = D.Action
......
......@@ -8,7 +8,7 @@ import Gargantext.Pages.Layout.Specs.AddCorpus as AC
-- import Gargantext.Pages.Corpus.Doc.Annotation as D
import Gargantext.Pages.Corpus as Corpus
import Gargantext.Pages.Corpus.Doc.Facets.Documents as DV
import Gargantext.Pages.Corpus.Doc.Facets.Documents as D
import Gargantext.Pages.Corpus.Doc.Facets.Graph as GE
-- import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsTable as NG
......@@ -38,11 +38,12 @@ dispatchAction dispatcher _ AddCorpus = do
dispatchAction dispatcher _ (DocView n) = do
dispatcher $ SetRoute (DocView n)
dispatcher $ DocViewA $ DV.LoadData n
dispatcher $ DocViewA $ D.LoadData n
dispatchAction dispatcher _ (Corpus n) = do
dispatcher $ SetRoute $ Corpus n
dispatcher $ CorpusAction $ Corpus.Load n
dispatcher $ DocViewA $ D.LoadData n
dispatchAction dispatcher _ SearchView = do
dispatcher $ SetRoute SearchView
......
......@@ -41,7 +41,7 @@ initAppState =
, corpus : Corpus.initialState
, loginState : LN.initialState
, addCorpusState : AC.initialState
, docViewState : DV.tdata
, docViewState : DV.initialState
, searchState : S.initialState
, userPageState : U.initialState
, docAnnotationState : D.initialState
......
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