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)
import React.DOM.Props (Props, className, href, onClick)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Gargantext.Config (NodeType(..), toUrl, readNodeType, End(..), ApiVersion)
type Name = String
type Open = Boolean
type URL = String
......@@ -53,8 +55,6 @@ toggleNode sid (NTree (LNode {id, name, nodeType, open}) ary) =
where
nopen = if sid == id then not open else open
------------------------------------------------------------------------
-- Realistic Tree for the UI
......@@ -115,7 +115,7 @@ toHtml d (NTree (LNode {id, name, nodeType, open}) []) =
[
li []
[
a [ href "#"]
a [ href (toUrl Front (readNodeType nodeType) id)]
( [ text (name <> " ")
] <> nodeOptionsView false
)
......@@ -125,7 +125,8 @@ toHtml d (NTree (LNode {id, name, nodeType, open}) ary) =
ul [ ]
[ li [] $
( [ a [onClick $ (\e-> d $ ToggleFolder id)] [i [fldr open] []]
, text $ " " <> name <> " "
, a [ href (toUrl Front (readNodeType nodeType) id )]
[ text $ " " <> name <> " " ]
] <> nodeOptionsCorp false <>
if open then
map (toHtml d) ary
......@@ -161,7 +162,7 @@ instance decodeJsonFTree :: DecodeJson (NTree LNode) where
loadDefaultNode :: Aff (Either String (NTree LNode))
loadDefaultNode = do
res <- request $ defaultRequest
{ url = "http://localhost:8008/tree/1"
{ url = toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, method = Left GET
, headers = []
......@@ -182,7 +183,7 @@ loadDefaultNode = do
renameNode :: Aff (Either String (Int)) --- need to change return type herre
renameNode = do
res <- request $ defaultRequest
{ url = "http://localhost:8008/tree/1"
{ url = toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, method = Left PUT
, headers = []
......@@ -203,7 +204,7 @@ renameNode = do
deleteNode :: Aff (Either String (Int))
deleteNode = do
res <- request $ defaultRequest
{ url = "http://localhost:8008/tree/1"
{ url = toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, method = Left DELETE
, headers = []
......@@ -225,7 +226,7 @@ deleteNode = do
deleteNodes :: String -> Aff (Either String Int)
deleteNodes reqbody = do
res <- request $ defaultRequest
{ url = "http://localhost:8008/tree"
{ url = toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, method = Left DELETE
, headers = []
......@@ -246,7 +247,7 @@ deleteNodes reqbody = do
createNode :: String -> Aff (Either String (Int))
createNode reqbody= do
res <- request $ defaultRequest
{ url = "http://localhost:8008/tree"
{ url = toUrl Back Tree 1
, responseFormat = ResponseFormat.json
, method = Left POST
, headers = []
......
......@@ -5,15 +5,15 @@ developpement is : toUrl.
* Example usage:
- 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)
- 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)
- 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)
-}
module Gargantext.Config where
......@@ -27,14 +27,20 @@ import Data.Maybe (maybe)
import Data.Tuple (Tuple(..))
------------------------------------------------------------
-- | Versions wille used later after the release
-- data ApiVersion = V1
-- | Versions will used later after the release
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
data Mode = Mock | Dev | Prod
config :: FrontEndConfig
config = mkConfig Mock
config = mkConfig Dev V10
mkAdress :: Mode -> String
mkAdress Mock = "localhost"
......@@ -55,48 +61,67 @@ mkProto Prod = "https://"
urlConfig :: Map NodeType Url
urlConfig = DM.fromFoldable [ Tuple UserPage "user"
, easy Corpus
, easy Project
, easy Document
, easy Annuaire
, easy Individu
, easy Tree
]
where
easy :: NodeType -> Tuple NodeType Url
easy n = Tuple n (show n)
------------------------------------------------------------
type FrontEndConfig = { proto :: String
, port :: Int
, address :: String
, urls :: Map NodeType Url
type FrontEndConfig = { proto :: String
, port :: Int
, address :: String
, apiVersion :: ApiVersion
, urls :: Map NodeType Url
}
mkConfig :: Mode -> FrontEndConfig
mkConfig mode = { proto : mkProto mode
, address : mkAdress mode
, port : mkPort mode
, urls : urlConfig
}
mkConfig :: Mode -> ApiVersion -> FrontEndConfig
mkConfig mode v = { proto : mkProto mode
, address : mkAdress mode
, port : mkPort mode
, apiVersion : v
, urls : urlConfig
}
------------------------------------------------------------
------------------------------------------------------------
-- | Main function to use in the Front-End developpement
-- for more complex urls, use urlConfig and smart constructors
toUrl :: NodeType -> Id -> Url
toUrl nt i = config.proto <> config.address <> ":" <> show config.port <> "/" <> path
toUrl :: End -> NodeType -> Id -> Url
toUrl end nt i = config.proto <> config.address <> ":" <> show config.port <> end' <> path
where
end' = case end of
Back -> "/api/" <> show config.apiVersion <> "/"
Front -> "/"
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 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
show UserPage = "userPage"
show UserPage = "user"
show Corpus = "corpus"
show Document = "document"
show Annuaire = "annuaire"
show Individu = "individu"
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
compare n1 n2 = compare (show n1) (show n2)
......@@ -104,4 +129,3 @@ instance ordNodeType :: Ord NodeType where
instance eqNodeType :: Eq NodeType where
eq n1 n2 = eq (show n1) (show n2)
------------------------------------------------------------
------------------------------------------------------------
......@@ -32,11 +32,11 @@ instance showRoutes :: Show Routes where
show Login = "Login"
show AddCorpus = "AddCorpus"
show DocView = "DocView"
show SearchView = "SearchView"
show (UserPage i) = "UserPage"
show (DocAnnotation i)= "DocumentView"
show SearchView = "Search"
show (UserPage i) = "User"
show (DocAnnotation i)= "Document"
show Tabview = "Tabview"
show CorpusAnalysis = "corpus"
show CorpusAnalysis = "Corpus"
show PGraphExplorer = "graphExplorer"
show NGramsTable = "NGramsTable"
show Dashboard = "Dashboard"
......@@ -49,7 +49,7 @@ routing :: Match Routes
routing =
Login <$ route "login"
<|> Tabview <$ route "tabview"
<|> DocAnnotation <$> (route "documentView" *> int)
<|> DocAnnotation <$> (route "document" *> int)
<|> UserPage <$> (route "user" *> int)
<|> SearchView <$ route "search"
<|> 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