Commit ea9ca36a authored by Alexandre Delanoë's avatar Alexandre Delanoë

[REST] toUrl Children.

parent 15ee6d9c
...@@ -94,6 +94,7 @@ endPathUrl Back c nt i = pathUrl c.back nt i ...@@ -94,6 +94,7 @@ endPathUrl Back c nt i = pathUrl c.back nt i
endPathUrl Front c nt i = pathUrl c.front nt i endPathUrl Front c nt i = pathUrl c.front nt i
pathUrl :: Config -> NodeType -> Id -> UrlPath pathUrl :: Config -> NodeType -> Id -> UrlPath
pathUrl c Children i = pathUrl c Node i <> "/" <> show Children
pathUrl c nt i = c.prePath <> urlConfig nt <> "/" <> show i pathUrl c nt i = c.prePath <> urlConfig nt <> "/" <> show i
------------------------------------------------------------ ------------------------------------------------------------
toUrl :: End -> NodeType -> Id -> Url toUrl :: End -> NodeType -> Id -> Url
...@@ -105,14 +106,16 @@ toUrl e nt i = doUrl base path params ...@@ -105,14 +106,16 @@ toUrl e nt i = doUrl base path params
------------------------------------------------------------ ------------------------------------------------------------
data NodeType = NodeUser data NodeType = NodeUser
| Annuaire | Annuaire
| Children
| Corpus | Corpus
| Dashboard | Dashboard
| Document | Document
| Error
| Folder | Folder
| Graph | Graph
| Individu | Individu
| Node
| Tree | Tree
| Error
data End = Back | Front data End = Back | Front
type Id = Int type Id = Int
------------------------------------------------------------ ------------------------------------------------------------
...@@ -123,41 +126,47 @@ instance showApiVersion :: Show ApiVersion where ...@@ -123,41 +126,47 @@ instance showApiVersion :: Show ApiVersion where
------------------------------------------------------------ ------------------------------------------------------------
------------------------------------------------------------ ------------------------------------------------------------
urlConfig :: NodeType -> Url urlConfig :: NodeType -> Url
urlConfig NodeUser = show NodeUser
urlConfig Annuaire = show Annuaire urlConfig Annuaire = show Annuaire
urlConfig Children = show Children
urlConfig Corpus = show Corpus urlConfig Corpus = show Corpus
urlConfig Dashboard = show Dashboard urlConfig Dashboard = show Dashboard
urlConfig Document = show Document urlConfig Document = show Document
urlConfig Error = show Error
urlConfig Folder = show Folder urlConfig Folder = show Folder
urlConfig Graph = show Graph urlConfig Graph = show Graph
urlConfig Individu = show Individu urlConfig Individu = show Individu
urlConfig Node = show Node
urlConfig NodeUser = show NodeUser
urlConfig Tree = show Tree urlConfig Tree = show Tree
urlConfig Error = show Error
------------------------------------------------------------ ------------------------------------------------------------
instance showNodeType :: Show NodeType where instance showNodeType :: Show NodeType where
show NodeUser = "user"
show Annuaire = "annuaire" show Annuaire = "annuaire"
show Children = "children"
show Corpus = "corpus" show Corpus = "corpus"
show Dashboard = "dashboard" show Dashboard = "dashboard"
show Document = "document" show Document = "document"
show Error = "ErrorNodeType"
show Folder = "folder" show Folder = "folder"
show Graph = "graph" show Graph = "graph"
show Individu = "individu" show Individu = "individu"
show Node = "node"
show NodeUser = "user"
show Tree = "tree" show Tree = "tree"
show Error = "ErrorNodeType"
-- | TODO : where is the Read Class ? -- | TODO : where is the Read Class ?
-- instance readNodeType :: Read NodeType where -- instance readNodeType :: Read NodeType where
readNodeType :: String -> NodeType readNodeType :: String -> NodeType
readNodeType "NodeUser" = NodeUser
readNodeType "NodeCorpus" = Corpus
readNodeType "Annuaire" = Annuaire readNodeType "Annuaire" = Annuaire
readNodeType "Children" = Children
readNodeType "Dashboard" = Dashboard readNodeType "Dashboard" = Dashboard
readNodeType "Document" = Document readNodeType "Document" = Document
readNodeType "Folder" = Folder
readNodeType "Graph" = Graph readNodeType "Graph" = Graph
readNodeType "Individu" = Individu readNodeType "Individu" = Individu
readNodeType "Node" = Node
readNodeType "NodeCorpus" = Corpus
readNodeType "NodeUser" = NodeUser
readNodeType "Tree" = Tree readNodeType "Tree" = Tree
readNodeType "Folder" = Folder
readNodeType _ = Error readNodeType _ = Error
------------------------------------------------------------ ------------------------------------------------------------
instance ordNodeType :: Ord NodeType where instance ordNodeType :: Ord NodeType where
......
...@@ -11,3 +11,12 @@ render dispatch _ state _ = [h1 [] [text "Annuaire"]] ...@@ -11,3 +11,12 @@ render dispatch _ state _ = [h1 [] [text "Annuaire"]]
layoutAnnuaire :: Spec {} {} Void layoutAnnuaire :: Spec {} {} Void
layoutAnnuaire = simpleSpec defaultPerformAction render layoutAnnuaire = simpleSpec defaultPerformAction render
------------------------------------------------------------------------------
--data Action
-- = LoadData
-- | ChangePageSize PageSizes
-- | ChangePage Int
--
...@@ -16,17 +16,17 @@ import Effect (Effect) ...@@ -16,17 +16,17 @@ import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Console (log) import Effect.Console (log)
import Gargantext.Config (NodeType(..), toUrl, End(Back))
import Gargantext.Config.REST (get) import Gargantext.Config.REST (get)
import Gargantext.Utils.DecodeMaybe ((.|)) import Gargantext.Utils.DecodeMaybe ((.|))
import React (ReactElement) 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 (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) import React.DOM.Props (_type, className, href, onChange, onClick, scope, selected, value)
import Thermite (PerformAction, Render, Spec, modifyState, defaultPerformAction, simpleSpec) import Thermite (PerformAction, Render, Spec, modifyState, defaultPerformAction, simpleSpec)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
p'' :: ReactElement
p'' = p [] []
--main :: forall e. Eff (dom:: DOM, console :: CONSOLE, ajax :: AJAX | e) Unit --main :: forall e. Eff (dom:: DOM, console :: CONSOLE, ajax :: AJAX | e) Unit
--main = do --main = do
-- case createReactSpec layoutDocview tdata of -- case createReactSpec layoutDocview tdata of
...@@ -38,11 +38,11 @@ p'' = p [] [] ...@@ -38,11 +38,11 @@ p'' = p [] []
-- TODO: Pagination Details are not available from the BackEnd -- TODO: Pagination Details are not available from the BackEnd
-- TODO: PageSize Change manually sets the totalPages, need to get from backend and reload the data -- TODO: PageSize Change manually sets the totalPages, need to get from backend and reload the data
-- TODO: Search is pending -- TODO: Search is pending
-- TODO: Delete is pending
-- TODO: Fav is pending -- TODO: Fav is pending
-- TODO: Sort is Pending -- TODO: Sort is Pending
-- TODO: Filter is Pending -- TODO: Filter is Pending
-- TODO: When a pagination link is clicked, reload data. Right now it doesn't make sense to reload mock data. -- TODO: When a pagination link is clicked, reload data.
-- Right now it doesn't make sense to reload mock data.
data Action data Action
= LoadData = LoadData
...@@ -51,7 +51,7 @@ data Action ...@@ -51,7 +51,7 @@ data Action
type State = CorpusTableData type State = CorpusTableData
type CorpusTableData = TableData Corpus type CorpusTableData = TableData CorpusView
newtype TableData a newtype TableData a
= TableData = TableData
...@@ -66,8 +66,8 @@ newtype TableData a ...@@ -66,8 +66,8 @@ newtype TableData a
-- , tree :: FTree -- , tree :: FTree
} }
newtype Corpus newtype CorpusView
= Corpus = CorpusView
{ _id :: Int { _id :: Int
, url :: String , url :: String
, date :: String , date :: String
...@@ -78,10 +78,9 @@ newtype Corpus ...@@ -78,10 +78,9 @@ newtype Corpus
} }
derive instance genericCorpus :: Generic CorpusView _
derive instance genericCorpus :: Generic Corpus _ instance showCorpus :: Show CorpusView where
instance showCorpus :: Show Corpus where
show = genericShow show = genericShow
...@@ -116,7 +115,6 @@ newtype Hyperdata = Hyperdata ...@@ -116,7 +115,6 @@ newtype Hyperdata = Hyperdata
-- pure $ Response { cid, created, favorite, ngramCount, hyperdata } -- pure $ Response { cid, created, favorite, ngramCount, hyperdata }
instance decodeHyperdata :: DecodeJson Hyperdata where instance decodeHyperdata :: DecodeJson Hyperdata where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
...@@ -154,7 +152,7 @@ layoutDocview = simpleSpec performAction render ...@@ -154,7 +152,7 @@ layoutDocview = simpleSpec performAction render
[ div [className "row"] [ div [className "row"]
[ [
div [className "col-md-12"] div [className "col-md-12"]
[ p'' [ p [] []
, div [] [ text " Filter ", input []] , div [] [ text " Filter ", input []]
, br' , br'
, div [className "row"] , div [className "row"]
...@@ -196,7 +194,7 @@ performAction LoadData _ _ = do ...@@ -196,7 +194,7 @@ performAction LoadData _ _ = do
loadPage :: Aff (Either String CorpusTableData) loadPage :: Aff (Either String CorpusTableData)
loadPage = do loadPage = do
res <- get "http://localhost:8008/node/452132/children" res <- get $ toUrl Back Children 452132
-- res <- get "http://localhost:8008/corpus/472764/facet/documents/table?offset=0&limit=10" -- res <- get "http://localhost:8008/corpus/472764/facet/documents/table?offset=0&limit=10"
case res of case res of
Left err -> do Left err -> do
...@@ -208,9 +206,9 @@ loadPage = do ...@@ -208,9 +206,9 @@ loadPage = do
_ <- liftEffect $ log $ show "loading" _ <- liftEffect $ log $ show "loading"
pure $ Right docs pure $ Right docs
where where
res2corpus :: Array Response -> Array Corpus res2corpus :: Array Response -> Array CorpusView
res2corpus rs = map (\(Response r) -> res2corpus rs = map (\(Response r) ->
Corpus { _id : r.cid CorpusView { _id : r.cid
, url : "" , url : ""
, date : r.created , date : r.created
, title : (\(Hyperdata hr) -> hr.title) r.hyperdata , title : (\(Hyperdata hr) -> hr.title) r.hyperdata
...@@ -220,7 +218,7 @@ loadPage = do ...@@ -220,7 +218,7 @@ loadPage = do
}) rs }) rs
toTableData :: Array Corpus -> CorpusTableData toTableData :: Array CorpusView -> CorpusTableData
toTableData ds = TableData toTableData ds = TableData
{ rows : map (\d -> { row : d , delete : false}) ds { rows : map (\d -> { row : d , delete : false}) ds
, totalPages : 474 , totalPages : 474
...@@ -233,12 +231,12 @@ loadPage = do ...@@ -233,12 +231,12 @@ loadPage = do
--------------------------------------------------------- ---------------------------------------------------------
sampleData' :: Corpus sampleData' :: CorpusView
sampleData' = Corpus {_id : 1, url : "", date : "date3", title : "title", source : "source", fav : false, ngramCount : 1} sampleData' = CorpusView {_id : 1, url : "", date : "date3", title : "title", source : "source", fav : false, ngramCount : 1}
-- --
sampleData :: Array Corpus sampleData :: Array CorpusView
--sampleData = replicate 10 sampleData' --sampleData = replicate 10 sampleData'
sampleData = map (\(Tuple t s) -> Corpus {_id : 1, url : "", date : "2017", title: t, source: s, fav : false, ngramCount : 10}) sampleDocuments sampleData = map (\(Tuple t s) -> CorpusView {_id : 1, url : "", date : "2017", title: t, source: s, fav : false, ngramCount : 10}) sampleDocuments
sampleDocuments :: Array (Tuple String String) 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"] 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"]
...@@ -246,14 +244,14 @@ sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal d ...@@ -246,14 +244,14 @@ sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal d
data' :: Array Corpus -> Array {row :: Corpus, delete :: Boolean} data' :: Array CorpusView -> Array {row :: CorpusView, delete :: Boolean}
data' = map {row : _, delete : false} data' = map {row : _, delete : false}
sdata :: Array { row :: Corpus, delete :: Boolean } sdata :: Array { row :: CorpusView, delete :: Boolean }
sdata = data' sampleData sdata = data' sampleData
tdata :: TableData Corpus tdata :: TableData CorpusView
tdata = TableData tdata = TableData
{ rows : sdata { rows : sdata
, totalPages : 10 , totalPages : 10
...@@ -265,8 +263,8 @@ tdata = TableData ...@@ -265,8 +263,8 @@ tdata = TableData
} }
showRow :: {row :: Corpus, delete :: Boolean} -> ReactElement showRow :: {row :: CorpusView, delete :: Boolean} -> ReactElement
showRow {row : (Corpus c), delete} = showRow {row : (CorpusView c), delete} =
tr [] tr []
[ td [] [div [className $ fa <> "fa-star"][]] [ td [] [div [className $ fa <> "fa-star"][]]
-- TODO show date: Year-Month-Day only -- TODO show date: Year-Month-Day only
......
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