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
32d99abb
Commit
32d99abb
authored
Jul 28, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[API] Generics for Document only (WIP)
parent
077646e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
50 deletions
+88
-50
FacetsTable.purs
src/Gargantext/Components/FacetsTable.purs
+38
-19
Search.purs
src/Gargantext/Components/Search.purs
+50
-31
No files found.
src/Gargantext/Components/FacetsTable.purs
View file @
32d99abb
...
@@ -181,26 +181,30 @@ initialPagePath {session, nodeId, listId, query} = {session, nodeId, listId, que
...
@@ -181,26 +181,30 @@ initialPagePath {session, nodeId, listId, query} = {session, nodeId, listId, que
loadPage :: PagePath -> Aff (Array DocumentsView)
loadPage :: PagePath -> Aff (Array DocumentsView)
loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searchType}} = do
loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searchType}} = do
let p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId)
let
searchResult <- post session p $ SearchQuery {query: concat query, expected:searchType}
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
pure $ res2view searchResult
convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc
where
convOrderBy (T.ASC (T.ColumnName "Title")) = TitleAsc
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
convOrderBy (T.DESC (T.ColumnName "Title")) = TitleDesc
convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc
convOrderBy (T.ASC (T.ColumnName "Source")) = SourceAsc
convOrderBy (T.ASC (T.ColumnName "Title")) = TitleAsc
convOrderBy (T.DESC (T.ColumnName "Source")) = SourceDesc
convOrderBy (T.DESC (T.ColumnName "Title")) = TitleDesc
convOrderBy _ = DateAsc -- TODO
convOrderBy (T.ASC (T.ColumnName "Source")) = SourceAsc
convOrderBy (T.DESC (T.ColumnName "Source")) = SourceDesc
p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId)
convOrderBy _ = DateAsc -- TODO
SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:searchType}
pure $ case result of
res2view :: SearchResult -> Array DocumentsView
SearchResultDoc {docs} -> docs2view docs
res2view (SearchResultDoc {docs}) = map toView docs
SearchResultContact {contacts} -> contacts2view contacts
errMessage -> err2view errMessage
docs2view :: Array Document -> Array DocumentsView
docs2view docs = map toView docs
where
where
toView :: Document -> DocumentsView
toView :: Document -> DocumentsView
toView (Document { id
toView (
Document { id
, created: date
, created: date
, hyperdata:
Hyperdata
Document { authors
, hyperdata:
HyperdataRow
Document { authors
, title
, title
, source
, source
, publication_year
, publication_year
...
@@ -223,7 +227,7 @@ res2view (SearchResultDoc {docs}) = map toView docs
...
@@ -223,7 +227,7 @@ res2view (SearchResultDoc {docs}) = map toView docs
, publication_month: fromMaybe 1 publication_month
, publication_month: fromMaybe 1 publication_month
, publication_day : fromMaybe 1 publication_day
, publication_day : fromMaybe 1 publication_day
}
}
res2view (SearchResultContact {contacts})
= map toView contacts
contacts2view contacts
= map toView contacts
where
where
toView :: Contact -> DocumentsView
toView :: Contact -> DocumentsView
toView (Contact { id
toView (Contact { id
...
@@ -248,7 +252,22 @@ res2view (SearchResultContact {contacts}) = map toView contacts
...
@@ -248,7 +252,22 @@ res2view (SearchResultContact {contacts}) = map toView contacts
, publication_day: 1
, publication_day: 1
}
}
-- res2view (SearchNoResult {message}) = map toView contacts
err2view message =
[DocumentsView { id: 1
, date: "2020-01-01"
, title : "SearchNoResult"
, source: "Source"
, score: 1
, authors: "Authors"
, category: decodeCategory 1
, pairs: []
, delete: false
, publication_year: 2020
, publication_month: 10
, publication_day: 1
}
]
...
...
src/Gargantext/Components/Search.purs
View file @
32d99abb
...
@@ -42,9 +42,8 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where
...
@@ -42,9 +42,8 @@ instance encodeJsonSearchQuery :: Argonaut.EncodeJson SearchQuery where
encodeJson = genericSumEncodeJson
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
------------------------------------------------------------------------
data SearchResult = SearchResultDoc { docs :: Array Document}
| SearchResultContact { contacts :: Array Contact }
data SearchResult = SearchResult { result :: SearchResultTypes }
-- | SearchNoResult { message :: String }
derive instance eqSearchResult :: Eq SearchResult
derive instance eqSearchResult :: Eq SearchResult
derive instance genericSearchResult :: Generic SearchResult _
derive instance genericSearchResult :: Generic SearchResult _
...
@@ -55,13 +54,31 @@ instance decodeJsonSearchResult :: Argonaut.DecodeJson SearchResult where
...
@@ -55,13 +54,31 @@ instance decodeJsonSearchResult :: Argonaut.DecodeJson SearchResult where
instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where
instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where
encodeJson = genericSumEncodeJson
encodeJson = genericSumEncodeJson
data SearchResultTypes =
SearchResultContact { contacts :: Array Contact }
| SearchNoResult { message :: String }
| SearchResultDoc { docs :: Array Document}
derive instance eqSearchResultTypes :: Eq SearchResultTypes
derive instance genericSearchResultTypes :: Generic SearchResultTypes _
instance showSearchResultTypes :: Show SearchResultTypes where
show = genericShow
instance decodeJsonSearchResultTypes :: Argonaut.DecodeJson SearchResultTypes where
decodeJson = genericSumDecodeJson
instance encodeJsonSearchResultTypes :: Argonaut.EncodeJson SearchResultTypes where
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
------------------------------------------------------------------------
data Document =
data Document =
Document { id :: Int
Document { id :: Int
, created :: String
, created :: String
, title :: String
, title :: String
, hyperdata :: HyperdataDocument
, hyperdata :: Hyperdata
Row
Document
, category :: Int
, category :: Int
, score :: Int
, score :: Int
}
}
...
@@ -75,41 +92,43 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where
...
@@ -75,41 +92,43 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where
instance encodeJsonDocument :: Argonaut.EncodeJson Document where
instance encodeJsonDocument :: Argonaut.EncodeJson Document where
encodeJson = genericSumEncodeJson
encodeJson = genericSumEncodeJson
-----------
------------------------------------------------------------------------
------------------------------------------------------------------------
data Hyperdata
Document =
newtype HyperdataRow
Document =
HyperdataDocument { bdd :: Maybe String
Hyperdata
Row
Document { bdd :: Maybe String
, doi :: Maybe String
, doi :: Maybe String
, url :: Maybe String
, url :: Maybe String
, uniqId :: Maybe String
, uniqId :: Maybe String
, uniqIdBdd :: Maybe String
, uniqIdBdd :: Maybe String
, page :: Maybe Int
, page :: Maybe Int
, title :: Maybe String
, title :: Maybe String
, authors :: Maybe String
, authors :: Maybe String
, institutes :: Maybe String
, institutes :: Maybe String
, source :: Maybe String
, source :: Maybe String
, abstract :: Maybe String
, abstract :: Maybe String
, publication_date :: Maybe String
, publication_date :: Maybe String
, publication_year :: Maybe Int
, publication_year :: Maybe Int
, publication_month :: Maybe Int
, publication_month :: Maybe Int
, publication_day :: Maybe Int
, publication_day :: Maybe Int
, publication_hour :: Maybe Int
, publication_hour :: Maybe Int
, publication_minute :: Maybe Int
, publication_minute :: Maybe Int
, publication_second :: Maybe Int
, publication_second :: Maybe Int
, language_iso2 :: Maybe String
, language_iso2 :: Maybe String
}
}
derive instance eqHyperdata
Document :: Eq Hyperdata
Document
derive instance eqHyperdata
RowDocument :: Eq HyperdataRow
Document
derive instance genericHyperdata
Document :: Generic Hyperdata
Document _
derive instance genericHyperdata
RowDocument :: Generic HyperdataRow
Document _
instance showHyperdata
Document :: Show Hyperdata
Document where
instance showHyperdata
RowDocument :: Show HyperdataRow
Document where
show = genericShow
show = genericShow
instance decodeJsonHyperdata
Document :: Argonaut.DecodeJson Hyperdata
Document where
instance decodeJsonHyperdata
RowDocument :: Argonaut.DecodeJson HyperdataRow
Document where
decodeJson = genericSumDecodeJson
decodeJson = genericSumDecodeJson
instance encodeJsonHyperdata
Document :: Argonaut.EncodeJson Hyperdata
Document where
instance encodeJsonHyperdata
RowDocument :: Argonaut.EncodeJson HyperdataRow
Document where
encodeJson = genericSumEncodeJson
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
data Contact =
data Contact =
Contact { id :: Int
Contact { id :: Int
, created :: String
, created :: String
...
...
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