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
ba53e379
Commit
ba53e379
authored
Sep 24, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Config] version of api Back|Front End datatype.
parent
771c3b98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
36 deletions
+61
-36
Tree.purs
src/Gargantext/Components/Tree.purs
+10
-9
Config.purs
src/Gargantext/Config.purs
+46
-22
Router.purs
src/Gargantext/Router.purs
+5
-5
No files found.
src/Gargantext/Components/Tree.purs
View file @
ba53e379
...
@@ -21,6 +21,8 @@ import React.DOM (a, div, i, li, text, ul)
...
@@ -21,6 +21,8 @@ import React.DOM (a, div, i, li, text, ul)
import React.DOM.Props (Props, className, href, onClick)
import React.DOM.Props (Props, className, href, onClick)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Gargantext.Config (NodeType(..), toUrl, readNodeType, End(..), ApiVersion)
type Name = String
type Name = String
type Open = Boolean
type Open = Boolean
type URL = String
type URL = String
...
@@ -53,8 +55,6 @@ toggleNode sid (NTree (LNode {id, name, nodeType, open}) ary) =
...
@@ -53,8 +55,6 @@ toggleNode sid (NTree (LNode {id, name, nodeType, open}) ary) =
where
where
nopen = if sid == id then not open else open
nopen = if sid == id then not open else open
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Realistic Tree for the UI
-- Realistic Tree for the UI
...
@@ -115,7 +115,7 @@ toHtml d (NTree (LNode {id, name, nodeType, open}) []) =
...
@@ -115,7 +115,7 @@ toHtml d (NTree (LNode {id, name, nodeType, open}) []) =
[
[
li []
li []
[
[
a [ href
"#"
]
a [ href
(toUrl Front (readNodeType nodeType) id)
]
( [ text (name <> " ")
( [ text (name <> " ")
] <> nodeOptionsView false
] <> nodeOptionsView false
)
)
...
@@ -125,7 +125,8 @@ toHtml d (NTree (LNode {id, name, nodeType, open}) ary) =
...
@@ -125,7 +125,8 @@ toHtml d (NTree (LNode {id, name, nodeType, open}) ary) =
ul [ ]
ul [ ]
[ li [] $
[ li [] $
( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []]
( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []]
, text $ " " <> name <> " "
, a [ href (toUrl Front (readNodeType nodeType) id )]
[ text $ " " <> name <> " " ]
] <> nodeOptionsCorp false <>
] <> nodeOptionsCorp false <>
if open then
if open then
map (toHtml d) ary
map (toHtml d) ary
...
@@ -161,7 +162,7 @@ instance decodeJsonFTree :: DecodeJson (NTree LNode) where
...
@@ -161,7 +162,7 @@ instance decodeJsonFTree :: DecodeJson (NTree LNode) where
loadDefaultNode :: Aff (Either String (NTree LNode))
loadDefaultNode :: Aff (Either String (NTree LNode))
loadDefaultNode = do
loadDefaultNode = do
res <- request $ defaultRequest
res <- request $ defaultRequest
{ url =
"http://localhost:8008/tree/1"
{ url =
toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, responseFormat = ResponseFormat.json
, method = Left GET
, method = Left GET
, headers = []
, headers = []
...
@@ -182,7 +183,7 @@ loadDefaultNode = do
...
@@ -182,7 +183,7 @@ loadDefaultNode = do
renameNode :: Aff (Either String (Int)) --- need to change return type herre
renameNode :: Aff (Either String (Int)) --- need to change return type herre
renameNode = do
renameNode = do
res <- request $ defaultRequest
res <- request $ defaultRequest
{ url =
"http://localhost:8008/tree/1"
{ url =
toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, responseFormat = ResponseFormat.json
, method = Left PUT
, method = Left PUT
, headers = []
, headers = []
...
@@ -203,7 +204,7 @@ renameNode = do
...
@@ -203,7 +204,7 @@ renameNode = do
deleteNode :: Aff (Either String (Int))
deleteNode :: Aff (Either String (Int))
deleteNode = do
deleteNode = do
res <- request $ defaultRequest
res <- request $ defaultRequest
{ url =
"http://localhost:8008/tree/1"
{ url =
toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, responseFormat = ResponseFormat.json
, method = Left DELETE
, method = Left DELETE
, headers = []
, headers = []
...
@@ -225,7 +226,7 @@ deleteNode = do
...
@@ -225,7 +226,7 @@ deleteNode = do
deleteNodes :: String -> Aff (Either String Int)
deleteNodes :: String -> Aff (Either String Int)
deleteNodes reqbody = do
deleteNodes reqbody = do
res <- request $ defaultRequest
res <- request $ defaultRequest
{ url =
"http://localhost:8008/tree"
{ url =
toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, responseFormat = ResponseFormat.json
, method = Left DELETE
, method = Left DELETE
, headers = []
, headers = []
...
@@ -246,7 +247,7 @@ deleteNodes reqbody = do
...
@@ -246,7 +247,7 @@ deleteNodes reqbody = do
createNode :: String -> Aff (Either String (Int))
createNode :: String -> Aff (Either String (Int))
createNode reqbody= do
createNode reqbody= do
res <- request $ defaultRequest
res <- request $ defaultRequest
{ url =
"http://localhost:8008/tree"
{ url =
toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, responseFormat = ResponseFormat.json
, method = Left POST
, method = Left POST
, headers = []
, headers = []
...
...
src/Gargantext/Config.purs
View file @
ba53e379
...
@@ -5,15 +5,15 @@ developpement is : toUrl.
...
@@ -5,15 +5,15 @@ developpement is : toUrl.
* Example usage:
* Example usage:
- for Mock config:
- for Mock config:
- toUrl Corpus 3 == "http://localhost:2015/corpus/3"
- toUrl
Front
Corpus 3 == "http://localhost:2015/corpus/3"
- (this mode supposes you have the mock haskell backend running)
- (this mode supposes you have the mock haskell backend running)
- for Dev config:
- for Dev config:
- toUrl Corpus 3 == "http://localhost:8008/corpus/3"
- toUrl
Front
Corpus 3 == "http://localhost:8008/corpus/3"
- (this mode supposes you have the dev haskell backend running)
- (this mode supposes you have the dev haskell backend running)
- for Prod config:
- for Prod config:
- toUrl Corpus 3 == "https://gargantext.org:8080/corpus/3"
- toUrl
Front
Corpus 3 == "https://gargantext.org:8080/corpus/3"
- (this mode supposes you have a prod haskell backend running on the specified url)
- (this mode supposes you have a prod haskell backend running on the specified url)
-}
-}
module Gargantext.Config where
module Gargantext.Config where
...
@@ -27,14 +27,20 @@ import Data.Maybe (maybe)
...
@@ -27,14 +27,20 @@ import Data.Maybe (maybe)
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..))
------------------------------------------------------------
------------------------------------------------------------
-- | Versions wille used later after the release
-- | Versions will used later after the release
-- data ApiVersion = V1
data ApiVersion = V10 | V11
instance showApiVersion :: Show ApiVersion where
show V10 = "v1.0"
show V11 = "v1.1"
data End = Back | Front
-- | Main options of the configuration
-- | Main options of the configuration
data Mode = Mock | Dev | Prod
data Mode = Mock | Dev | Prod
config :: FrontEndConfig
config :: FrontEndConfig
config = mkConfig
Mock
config = mkConfig
Dev V10
mkAdress :: Mode -> String
mkAdress :: Mode -> String
mkAdress Mock = "localhost"
mkAdress Mock = "localhost"
...
@@ -55,48 +61,67 @@ mkProto Prod = "https://"
...
@@ -55,48 +61,67 @@ mkProto Prod = "https://"
urlConfig :: Map NodeType Url
urlConfig :: Map NodeType Url
urlConfig = DM.fromFoldable [ Tuple UserPage "user"
urlConfig = DM.fromFoldable [ Tuple UserPage "user"
, easy Corpus
, easy Corpus
, easy Project
, easy Document
, easy Document
, easy Annuaire
, easy Annuaire
, easy Individu
, easy Individu
, easy Tree
]
]
where
where
easy :: NodeType -> Tuple NodeType Url
easy :: NodeType -> Tuple NodeType Url
easy n = Tuple n (show n)
easy n = Tuple n (show n)
------------------------------------------------------------
------------------------------------------------------------
type FrontEndConfig = { proto :: String
type FrontEndConfig = { proto :: String
, port :: Int
, port :: Int
, address :: String
, address :: String
, urls :: Map NodeType Url
, apiVersion :: ApiVersion
, urls :: Map NodeType Url
}
}
mkConfig :: Mode -> FrontEndConfig
mkConfig :: Mode -> ApiVersion -> FrontEndConfig
mkConfig mode = { proto : mkProto mode
mkConfig mode v = { proto : mkProto mode
, address : mkAdress mode
, address : mkAdress mode
, port : mkPort mode
, port : mkPort mode
, urls : urlConfig
, apiVersion : v
}
, urls : urlConfig
}
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
-- | Main function to use in the Front-End developpement
-- | Main function to use in the Front-End developpement
-- for more complex urls, use urlConfig and smart constructors
-- for more complex urls, use urlConfig and smart constructors
toUrl :: NodeType -> Id -> Url
toUrl ::
End ->
NodeType -> Id -> Url
toUrl
nt i = config.proto <> config.address <> ":" <> show config.port <> "/"
<> path
toUrl
end nt i = config.proto <> config.address <> ":" <> show config.port <> end'
<> path
where
where
end' = case end of
Back -> "/api/" <> show config.apiVersion <> "/"
Front -> "/"
path = subPath <> "/" <> show i
path = subPath <> "/" <> show i
subPath = maybe "error" identity (DM.lookup nt config.urls)
subPath = maybe "error
SubPath
" identity (DM.lookup nt config.urls)
------------------------------------------------------------
------------------------------------------------------------
type Url = String
type Url = String
type Id = Int
type Id = Int
------------------------------------------------------------
------------------------------------------------------------
data NodeType = UserPage | Corpus | Document | Annuaire | Individu | Project
data NodeType = UserPage | Corpus | Document | Annuaire | Individu | Project
| Tree | Error
------------------------------------------------------------
------------------------------------------------------------
instance showNodeType :: Show NodeType where
instance showNodeType :: Show NodeType where
show UserPage = "user
Page
"
show UserPage = "user"
show Corpus = "corpus"
show Corpus = "corpus"
show Document = "document"
show Document = "document"
show Annuaire = "annuaire"
show Annuaire = "annuaire"
show Individu = "individu"
show Individu = "individu"
show Project = "project"
show Project = "project"
show Tree = "tree"
show Error = "errNodeType"
readNodeType :: String -> NodeType
readNodeType "NodeUser" = UserPage
readNodeType "NodeCorpus" = Corpus
readNodeType "Document" = Document
readNodeType "Annuaire" = Annuaire
readNodeType "Individu" = Individu
readNodeType "Project" = Project
readNodeType "Tree" = Tree
readNodeType _ = Error
instance ordNodeType :: Ord NodeType where
instance ordNodeType :: Ord NodeType where
compare n1 n2 = compare (show n1) (show n2)
compare n1 n2 = compare (show n1) (show n2)
...
@@ -104,4 +129,3 @@ instance ordNodeType :: Ord NodeType where
...
@@ -104,4 +129,3 @@ instance ordNodeType :: Ord NodeType where
instance eqNodeType :: Eq NodeType where
instance eqNodeType :: Eq NodeType where
eq n1 n2 = eq (show n1) (show n2)
eq n1 n2 = eq (show n1) (show n2)
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
src/Gargantext/Router.purs
View file @
ba53e379
...
@@ -32,11 +32,11 @@ instance showRoutes :: Show Routes where
...
@@ -32,11 +32,11 @@ instance showRoutes :: Show Routes where
show Login = "Login"
show Login = "Login"
show AddCorpus = "AddCorpus"
show AddCorpus = "AddCorpus"
show DocView = "DocView"
show DocView = "DocView"
show SearchView = "Search
View
"
show SearchView = "Search"
show (UserPage i) = "User
Page
"
show (UserPage i) = "User"
show (DocAnnotation i)= "Document
View
"
show (DocAnnotation i)= "Document"
show Tabview = "Tabview"
show Tabview = "Tabview"
show CorpusAnalysis = "
c
orpus"
show CorpusAnalysis = "
C
orpus"
show PGraphExplorer = "graphExplorer"
show PGraphExplorer = "graphExplorer"
show NGramsTable = "NGramsTable"
show NGramsTable = "NGramsTable"
show Dashboard = "Dashboard"
show Dashboard = "Dashboard"
...
@@ -49,7 +49,7 @@ routing :: Match Routes
...
@@ -49,7 +49,7 @@ routing :: Match Routes
routing =
routing =
Login <$ route "login"
Login <$ route "login"
<|> Tabview <$ route "tabview"
<|> Tabview <$ route "tabview"
<|> DocAnnotation <$> (route "document
View
" *> int)
<|> DocAnnotation <$> (route "document" *> int)
<|> UserPage <$> (route "user" *> int)
<|> UserPage <$> (route "user" *> int)
<|> SearchView <$ route "search"
<|> SearchView <$ route "search"
<|> DocView <$ route "docView"
<|> DocView <$ route "docView"
...
...
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