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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
93b6d5dc
Commit
93b6d5dc
authored
Oct 10, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CHORE] Intances of Sessions (compiling but not tested with load/save sessions yet).
parent
97d89bae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
11 deletions
+88
-11
Ends.purs
src/Gargantext/Ends.purs
+20
-1
Sessions.purs
src/Gargantext/Sessions.purs
+52
-8
Types.purs
src/Gargantext/Types.purs
+16
-2
No files found.
src/Gargantext/Ends.purs
View file @
93b6d5dc
...
...
@@ -3,7 +3,8 @@ module Gargantext.Ends
-- ( )
where
import Prelude (class Eq, class Show, identity, show, ($), (<>))
import Prelude (class Eq, class Show, identity, show, ($), (<>), bind, pure)
import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJson, (:=), (~>), jsonEmptyObject, (.:))
import Data.Foldable (foldMap)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
...
...
@@ -45,6 +46,24 @@ instance showBackend :: Show Backend where
instance toUrlBackendString :: ToUrl Backend String where
toUrl = backendUrl
-- JSON instances
instance encodeJsonBackend :: EncodeJson Backend where
encodeJson (Backend {name, baseUrl, prePath, version})
= "name" := name
~> "baseUrl" := baseUrl
~> "prePath" := prePath
~> "version" := show version
~> jsonEmptyObject
instance decodeJsonBackend :: DecodeJson Backend where
decodeJson json = do
obj <- decodeJson json
name <- obj .: "objet"
baseUrl <- obj .: "baseUrl"
prePath <- obj .: "prePath"
version <- obj .: "version"
pure $ Backend {name, baseUrl, prePath, version}
-- | Encapsulates the data needed to construct a url to a frontend
-- | server (either for the app or static content)
newtype Frontend = Frontend
...
...
src/Gargantext/Sessions.purs
View file @
93b6d5dc
-- | A module for authenticating to create sessions and handling them
module Gargantext.Sessions where
import Prelude (class Eq, class Show, Unit, const, otherwise, pure, show, unit, ($), (*>), (<*), (<$>), (<>), (==), (/=), (>>=), (<<<))
import Prelude (class Eq, class Show, Unit, const, otherwise, pure, show, unit, ($), (*>), (<*), (<$>), (<>), (==), (/=), (>>=), (<<<), bind)
import Data.Argonaut ( class DecodeJson, decodeJson, class EncodeJson, encodeJson, (:=), (~>), jsonEmptyObject, (.:), Json, fromArray)
import Data.Array as A
import Data.Traversable (traverse)
import DOM.Simple.Console (log2)
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
...
...
@@ -33,6 +35,9 @@ newtype Session = Session
, token :: String
, treeId :: Int }
------------------------------------------------------------------------
-- | Main instances
derive instance genericSession :: Generic Session _
instance eqSession :: Eq Session where
...
...
@@ -56,6 +61,27 @@ sessionId = SessionId <<< show
instance toUrlSessionString :: ToUrl Session String where
toUrl = sessionUrl
--------------------
-- | JSON instances
instance encodeJsonSession :: EncodeJson Session where
encodeJson (Session {backend, username, token, treeId})
= "backend" := encodeJson backend
~> "username" := username
~> "token" := token
~> "treeId" := treeId
~> jsonEmptyObject
instance decodeJsonSession :: DecodeJson Session where
decodeJson json = do
obj <- decodeJson json
backend <- obj .: "backend"
username <- obj .: "username"
token <- obj .: "token"
treeId <- obj .: "treeId"
pure $ Session { backend, username, token, treeId}
------------------------------------------------------------------------
newtype Sessions = Sessions (Seq Session)
derive instance genericSessions :: Generic Sessions _
...
...
@@ -63,6 +89,23 @@ derive instance genericSessions :: Generic Sessions _
instance eqSessions :: Eq Sessions where
eq = genericEq
instance decodeJsonSessions :: DecodeJson Sessions where
decodeJson json = do
ss <- decodeSessions' json
pure (Sessions (Seq.fromFoldable ss))
where
decodeSessions' :: Json -> Either String (Array Session)
decodeSessions' json = decodeJson json >>= traverse decodeJson
instance encodeJsonSessions :: EncodeJson Sessions where
encodeJson (Sessions ss) = "sessions" := (encodeSessions ss)
~> jsonEmptyObject
where
encodeSessions :: Seq Session -> Json
encodeSessions ss = fromArray $ encodeJson <$> (Seq.toUnfoldable ss)
unSessions :: Sessions -> Array Session
unSessions (Sessions s) = A.fromFoldable s
...
...
@@ -125,13 +168,14 @@ null (Sessions seq) = Seq.null seq
-- | Will attempt to load saved sessions from localstorage. should log if decoding fails
loadSessions :: Effect Sessions
loadSessions = pure empty
-- loadSessions = window >>= localStorage >>= getItem "auths" >>= traverse decode
-- where
-- decode :: String -> Effect (Maybe Sessions)
-- decode = ret <<< runExcept <<< decodeJSON
-- ret (Right v) = pure $ Just v
-- ret (Left e) = log2 "Error reading serialised sessions:" e *> pure (Malformed e)
{-
loadSessions = window >>= localStorage >>= getItem "auths" >>= traverse decode
where
decode :: String -> Effect (Maybe Sessions)
decode = ret <<< runExcept <<< decodeJson
ret (Right v) = pure $ Just v
ret (Left e) = log2 "Error reading serialised sessions:" e *> pure (Malformed e)
-}
saveSessions :: Sessions -> Effect Sessions
saveSessions sessions = effect *> pure sessions
where
...
...
src/Gargantext/Types.purs
View file @
93b6d5dc
...
...
@@ -282,17 +282,31 @@ instance showOrderBy :: Show OrderBy where
show = genericShow
------------------------------------------------------------
data ApiVersion = V10 | V11
-- V0 is the dummy case (impossible)
data ApiVersion = V0 | V10 | V11
instance showApiVersion :: Show ApiVersion where
show V0 = "v0"
show V10 = "v1.0"
show V11 = "v1.1"
------------------------------------------------------------
instance eqApiVersion :: Eq ApiVersion where
eq V10 V10 = true
eq V11 V11 = true
eq _ _ = false
instance encodeJsonApiVersion :: EncodeJson ApiVersion where
encodeJson v = encodeJson (show v)
instance decodeJsonApiVersion :: DecodeJson ApiVersion where
decodeJson json = do
v <- decodeJson json
case v of
"v1.0" -> pure V10
"v1.1" -> pure V11
_ -> pure V0
------------------------------------------------------------
data CTabNgramType = CTabTerms | CTabSources | CTabAuthors | CTabInstitutes
derive instance eqCTabNgramType :: Eq CTabNgramType
...
...
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