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

[Config] version of api Back|Front End datatype.

parent 771c3b98
...@@ -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 = []
......
...@@ -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,9 +61,11 @@ mkProto Prod = "https://" ...@@ -55,9 +61,11 @@ 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
...@@ -66,37 +74,54 @@ urlConfig = DM.fromFoldable [ Tuple UserPage "user" ...@@ -66,37 +74,54 @@ urlConfig = DM.fromFoldable [ Tuple UserPage "user"
type FrontEndConfig = { proto :: String type FrontEndConfig = { proto :: String
, port :: Int , port :: Int
, address :: String , address :: String
, apiVersion :: ApiVersion
, urls :: Map NodeType Url , 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
, apiVersion : v
, urls : urlConfig , 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 "errorSubPath" 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 = "userPage" 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)
------------------------------------------------------------ ------------------------------------------------------------
------------------------------------------------------------
...@@ -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 = "SearchView" show SearchView = "Search"
show (UserPage i) = "UserPage" show (UserPage i) = "User"
show (DocAnnotation i)= "DocumentView" show (DocAnnotation i)= "Document"
show Tabview = "Tabview" show Tabview = "Tabview"
show CorpusAnalysis = "corpus" show CorpusAnalysis = "Corpus"
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 "documentView" *> 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"
......
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