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
loadPage :: PagePath -> Aff (Array DocumentsView)
loadPage {session, nodeId, listId, query, params: {limit, offset, orderBy, searchType}} = do
let p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId)
searchResult <- post session p $ SearchQuery {query: concat query, expected:searchType}
pure $ res2view searchResult
where
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc
convOrderBy (T.ASC (T.ColumnName "Title")) = TitleAsc
convOrderBy (T.DESC (T.ColumnName "Title")) = TitleDesc
convOrderBy (T.ASC (T.ColumnName "Source")) = SourceAsc
convOrderBy (T.DESC (T.ColumnName "Source")) = SourceDesc
convOrderBy _ = DateAsc -- TODO
res2view :: SearchResult -> Array DocumentsView
res2view (SearchResultDoc {docs}) = map toView docs
let
convOrderBy (T.ASC (T.ColumnName "Date")) = DateAsc
convOrderBy (T.DESC (T.ColumnName "Date")) = DateDesc
convOrderBy (T.ASC (T.ColumnName "Title")) = TitleAsc
convOrderBy (T.DESC (T.ColumnName "Title")) = TitleDesc
convOrderBy (T.ASC (T.ColumnName "Source")) = SourceAsc
convOrderBy (T.DESC (T.ColumnName "Source")) = SourceDesc
convOrderBy _ = DateAsc -- TODO
p = Search { listId, offset, limit, orderBy: convOrderBy <$> orderBy } (Just nodeId)
SearchResult {result} <- post session p $ SearchQuery {query: concat query, expected:searchType}
pure $ case result of
SearchResultDoc {docs} -> docs2view docs
SearchResultContact {contacts} -> contacts2view contacts
errMessage -> err2view errMessage
docs2view :: Array Document -> Array DocumentsView
docs2view docs = map toView docs
where
toView :: Document -> DocumentsView
toView (Document { id
toView (
Document { id
, created: date
, hyperdata:
Hyperdata
Document { authors
, hyperdata:
HyperdataRow
Document { authors
, title
, source
, publication_year
...
...
@@ -223,7 +227,7 @@ res2view (SearchResultDoc {docs}) = map toView docs
, publication_month: fromMaybe 1 publication_month
, publication_day : fromMaybe 1 publication_day
}
res2view (SearchResultContact {contacts})
= map toView contacts
contacts2view contacts
= map toView contacts
where
toView :: Contact -> DocumentsView
toView (Contact { id
...
...
@@ -248,7 +252,22 @@ res2view (SearchResultContact {contacts}) = map toView contacts
, 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
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
data SearchResult = SearchResultDoc { docs :: Array Document}
| SearchResultContact { contacts :: Array Contact }
-- | SearchNoResult { message :: String }
data SearchResult = SearchResult { result :: SearchResultTypes }
derive instance eqSearchResult :: Eq SearchResult
derive instance genericSearchResult :: Generic SearchResult _
...
...
@@ -55,13 +54,31 @@ instance decodeJsonSearchResult :: Argonaut.DecodeJson SearchResult where
instance encodeJsonSearchResult :: Argonaut.EncodeJson SearchResult where
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 =
Document { id :: Int
, created :: String
, title :: String
, hyperdata :: HyperdataDocument
, hyperdata :: Hyperdata
Row
Document
, category :: Int
, score :: Int
}
...
...
@@ -75,41 +92,43 @@ instance decodeJsonDocument :: Argonaut.DecodeJson Document where
instance encodeJsonDocument :: Argonaut.EncodeJson Document where
encodeJson = genericSumEncodeJson
-----------
------------------------------------------------------------------------
data Hyperdata
Document =
HyperdataDocument { bdd :: Maybe String
, doi :: Maybe String
, url :: Maybe String
, uniqId :: Maybe String
, uniqIdBdd :: Maybe String
, page :: Maybe Int
, title :: Maybe String
, authors :: Maybe String
, institutes :: Maybe String
, source :: Maybe String
, abstract :: Maybe String
, publication_date :: Maybe String
, publication_year :: Maybe Int
, publication_month :: Maybe Int
, publication_day :: Maybe Int
, publication_hour :: Maybe Int
, publication_minute :: Maybe Int
, publication_second :: Maybe Int
, language_iso2 :: Maybe String
}
derive instance eqHyperdata
Document :: Eq Hyperdata
Document
derive instance genericHyperdata
Document :: Generic Hyperdata
Document _
instance showHyperdata
Document :: Show Hyperdata
Document where
newtype HyperdataRow
Document =
Hyperdata
Row
Document { bdd :: Maybe String
, doi :: Maybe String
, url :: Maybe String
, uniqId :: Maybe String
, uniqIdBdd :: Maybe String
, page :: Maybe Int
, title :: Maybe String
, authors :: Maybe String
, institutes :: Maybe String
, source :: Maybe String
, abstract :: Maybe String
, publication_date :: Maybe String
, publication_year :: Maybe Int
, publication_month :: Maybe Int
, publication_day :: Maybe Int
, publication_hour :: Maybe Int
, publication_minute :: Maybe Int
, publication_second :: Maybe Int
, language_iso2 :: Maybe String
}
derive instance eqHyperdata
RowDocument :: Eq HyperdataRow
Document
derive instance genericHyperdata
RowDocument :: Generic HyperdataRow
Document _
instance showHyperdata
RowDocument :: Show HyperdataRow
Document where
show = genericShow
instance decodeJsonHyperdata
Document :: Argonaut.DecodeJson Hyperdata
Document where
instance decodeJsonHyperdata
RowDocument :: Argonaut.DecodeJson HyperdataRow
Document where
decodeJson = genericSumDecodeJson
instance encodeJsonHyperdata
Document :: Argonaut.EncodeJson Hyperdata
Document where
instance encodeJsonHyperdata
RowDocument :: Argonaut.EncodeJson HyperdataRow
Document where
encodeJson = genericSumEncodeJson
------------------------------------------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
data Contact =
Contact { id :: Int
, 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