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

Merge branch 'dev-demo2' of...

Merge branch 'dev-demo2' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev-demo2
parents 52efc212 0dfc506b
...@@ -47,13 +47,11 @@ type TextQuery = Array (Array String) ...@@ -47,13 +47,11 @@ type TextQuery = Array (Array String)
newtype SearchQuery = SearchQuery newtype SearchQuery = SearchQuery
{ query :: TextQuery { query :: TextQuery
, id :: Int
} }
instance encodeJsonSearchQuery :: EncodeJson SearchQuery where instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
encodeJson (SearchQuery post) encodeJson (SearchQuery post)
= "query" := post.query !! 0 -- TODO anoe = "query" := post.query !! 0 -- TODO anoe
~> "corpus_id" := post.id
~> jsonEmptyObject ~> jsonEmptyObject
newtype SearchResults = SearchResults { results :: Array Response } newtype SearchResults = SearchResults { results :: Array Response }
...@@ -117,10 +115,13 @@ instance showDocumentsView :: Show DocumentsView where ...@@ -117,10 +115,13 @@ instance showDocumentsView :: Show DocumentsView where
newtype Response = Response newtype Response = Response
{ id :: Int { id :: Int
, date :: String , created :: String
, hyperdata :: Hyperdata , hyperdata :: Hyperdata
, score :: Int , favorite :: Boolean
, pairs :: Array Pair , ngramCount :: Int
-- , date :: String
-- , score :: Int
-- , pairs :: Array Pair
} }
...@@ -135,15 +136,6 @@ newtype Hyperdata = Hyperdata ...@@ -135,15 +136,6 @@ newtype Hyperdata = Hyperdata
-- title <- obj .? "title" -- title <- obj .? "title"
-- source <- obj .? "source" -- source <- obj .? "source"
-- pure $ Hyperdata { title,source } -- pure $ Hyperdata { title,source }
--instance decodeResponse :: DecodeJson Response where
-- decodeJson json = do
-- obj <- decodeJson json
-- cid <- obj .? "id"
-- created <- obj .? "created"
-- favorite <- obj .? "favorite"
-- ngramCount <- obj .? "ngramCount"
-- hyperdata <- obj .? "hyperdata"
-- pure $ Response { cid, created, favorite, ngramCount, hyperdata }
instance decodePair :: DecodeJson Pair where instance decodePair :: DecodeJson Pair where
...@@ -160,6 +152,7 @@ instance decodeHyperdata :: DecodeJson Hyperdata where ...@@ -160,6 +152,7 @@ instance decodeHyperdata :: DecodeJson Hyperdata where
source <- obj .| "source" source <- obj .| "source"
pure $ Hyperdata { title,source } pure $ Hyperdata { title,source }
{-
instance decodeResponse :: DecodeJson Response where instance decodeResponse :: DecodeJson Response where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
...@@ -170,8 +163,17 @@ instance decodeResponse :: DecodeJson Response where ...@@ -170,8 +163,17 @@ instance decodeResponse :: DecodeJson Response where
hyperdata <- obj .? "hyperdata" hyperdata <- obj .? "hyperdata"
pairs <- obj .? "pairs" pairs <- obj .? "pairs"
pure $ Response { id, date, score, hyperdata, pairs } pure $ Response { id, date, score, hyperdata, pairs }
-}
instance decodeResponse :: DecodeJson Response where
decodeJson json = do
obj <- decodeJson json
id <- obj .? "id"
created <- obj .? "created"
hyperdata <- obj .? "hyperdata"
favorite <- obj .? "favorite"
ngramCount <- obj .? "ngramCount"
pure $ Response { id, created, hyperdata, favorite, ngramCount }
-- | Filter -- | Filter
-- TODO: unused -- TODO: unused
...@@ -294,12 +296,13 @@ loadPage :: PageParams -> Aff (Array DocumentsView) ...@@ -294,12 +296,13 @@ loadPage :: PageParams -> Aff (Array DocumentsView)
loadPage {nodeId, query, params: {limit, offset, orderBy}} = do loadPage {nodeId, query, params: {limit, offset, orderBy}} = do
logs "loading documents page: loadPage with Offset and limit" logs "loading documents page: loadPage with Offset and limit"
let url = toUrl Back (Search { offset, limit, orderBy: convOrderBy <$> orderBy }) (Just nodeId) let url = toUrl Back (Search { offset, limit, orderBy: convOrderBy <$> orderBy }) (Just nodeId)
SearchResults res <- post url $ SearchQuery {id: nodeId, query} SearchResults res <- post url $ SearchQuery {query}
pure $ res2corpus <$> res.results pure $ res2corpus <$> res.results
where where
res2corpus :: Response -> DocumentsView res2corpus :: Response -> DocumentsView
res2corpus (Response { id, date, score, pairs res2corpus (Response { id, created: date, ngramCount: score
, hyperdata: Hyperdata {title, source} , hyperdata: Hyperdata {title, source}
-- favorite TODO
}) = }) =
DocumentsView DocumentsView
{ id { id
...@@ -307,8 +310,8 @@ loadPage {nodeId, query, params: {limit, offset, orderBy}} = do ...@@ -307,8 +310,8 @@ loadPage {nodeId, query, params: {limit, offset, orderBy}} = do
, title , title
, source , source
, score , score
, pairs , pairs: []
, delete : false , delete: false
} }
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc
......
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