Commit 9221aec4 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-doc-table-columns' of...

Merge branch 'dev-doc-table-columns' of ssh://gitlab.iscpif.fr:20022/gargantext/purescript-gargantext into dev-doc-table-columns
parents e50d6c48 9f8bdd93
...@@ -10,7 +10,6 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson ...@@ -10,7 +10,6 @@ import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson
import Data.Array (drop, take, (:), filter) import Data.Array (drop, take, (:), filter)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
import Data.HTTP.Method (Method(..)) import Data.HTTP.Method (Method(..))
import Data.Lens import Data.Lens
...@@ -41,6 +40,7 @@ import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, ...@@ -41,6 +40,7 @@ import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType,
import Gargantext.Config.REST (get, put, post, deleteWithBody, delete) import Gargantext.Config.REST (get, put, post, deleteWithBody, delete)
import Gargantext.Components.Loader2 (useLoader) import Gargantext.Components.Loader2 (useLoader)
import Gargantext.Components.Node (NodePoly(..)) import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Search.Types (Category(..), CategoryQuery(..), favCategory, trashCategory, decodeCategory, putCategories)
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Utils.DecodeMaybe ((.|)) import Gargantext.Utils.DecodeMaybe ((.|))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -50,26 +50,6 @@ import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_ ...@@ -50,26 +50,6 @@ import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState_
type NodeID = Int type NodeID = Int
type TotalRecords = Int type TotalRecords = Int
data Category = Trash | Normal | Favorite
derive instance genericFavorite :: Generic Category _
instance showCategory :: Show Category where
show = genericShow
instance eqCategory :: Eq Category where
eq = genericEq
instance encodeJsonCategory :: EncodeJson Category where
encodeJson Trash = encodeJson 0
encodeJson Normal = encodeJson 1
encodeJson Favorite = encodeJson 2
favCategory :: Category -> Category
favCategory Normal = Favorite
favCategory Trash = Favorite
favCategory Favorite = Normal
trashCategory :: Category -> Category
trashCategory Normal = Trash
trashCategory Trash = Normal
trashCategory Favorite = Trash
type Props = type Props =
{ nodeId :: Int { nodeId :: Int
...@@ -143,12 +123,6 @@ instance decodeHyperdata :: DecodeJson Hyperdata where ...@@ -143,12 +123,6 @@ instance decodeHyperdata :: DecodeJson Hyperdata where
pub_year <- obj .? "publication_year" pub_year <- obj .? "publication_year"
pure $ Hyperdata { title,source, pub_year} pure $ Hyperdata { title,source, pub_year}
decodeCategory :: Int -> Category
decodeCategory 0 = Trash
decodeCategory 1 = Normal
decodeCategory 2 = Favorite
decodeCategory _ = Normal
instance decodeResponse :: DecodeJson Response where instance decodeResponse :: DecodeJson Response where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
...@@ -397,24 +371,6 @@ searchResults :: SearchQuery -> Aff Int ...@@ -397,24 +371,6 @@ searchResults :: SearchQuery -> Aff Int
searchResults squery = post "http://localhost:8008/count" unit searchResults squery = post "http://localhost:8008/count" unit
-- TODO -- TODO
newtype CategoryQuery = CategoryQuery {
nodeIds :: Array Int
, category :: Category
}
instance encodeJsonCategoryQuery :: EncodeJson CategoryQuery where
encodeJson (CategoryQuery post) =
"ntc_nodesId" := post.nodeIds
~> "ntc_category" := encodeJson post.category
~> jsonEmptyObject
categoryUrl :: Int -> String
categoryUrl nodeId = toUrl Back Node (Just nodeId) <> "/category"
putCategories :: Int -> CategoryQuery -> Aff (Array Int)
putCategories nodeId = put $ categoryUrl nodeId
documentsUrl :: Int -> String documentsUrl :: Int -> String
documentsUrl nodeId = toUrl Back Node (Just nodeId) <> "/documents" documentsUrl nodeId = toUrl Back Node (Just nodeId) <> "/documents"
......
...@@ -29,6 +29,7 @@ import Gargantext.Prelude ...@@ -29,6 +29,7 @@ import Gargantext.Prelude
import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, toUrl) import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, toUrl)
import Gargantext.Config.REST (put, post, deleteWithBody) import Gargantext.Config.REST (put, post, deleteWithBody)
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
import Gargantext.Components.Search.Types (Category(..), CategoryQuery(..), favCategory, trashCategory, decodeCategory, putCategories)
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
import Gargantext.Utils (toggleSet) import Gargantext.Utils (toggleSet)
import Gargantext.Utils.DecodeMaybe ((.|)) import Gargantext.Utils.DecodeMaybe ((.|))
...@@ -83,9 +84,9 @@ initialState = ...@@ -83,9 +84,9 @@ initialState =
} }
data Action data Action
= MarkFavorites (Array Int) = MarkCategory Category (Array Int)
| ToggleDocumentToDelete Int | ToggleDocumentToDelete Int
| Trash | TrashDocuments
newtype Pair = Pair newtype Pair = Pair
{ id :: Int { id :: Int
...@@ -106,9 +107,9 @@ newtype DocumentsView ...@@ -106,9 +107,9 @@ newtype DocumentsView
, score :: Int , score :: Int
, pairs :: Array Pair , pairs :: Array Pair
, delete :: Boolean , delete :: Boolean
, category :: Category
} }
derive instance genericDocumentsView :: Generic DocumentsView _ derive instance genericDocumentsView :: Generic DocumentsView _
instance showDocumentsView :: Show DocumentsView where instance showDocumentsView :: Show DocumentsView where
...@@ -118,7 +119,7 @@ newtype Response = Response ...@@ -118,7 +119,7 @@ newtype Response = Response
{ id :: Int { id :: Int
, created :: String , created :: String
, hyperdata :: Hyperdata , hyperdata :: Hyperdata
, favorite :: Boolean , category :: Category
, ngramCount :: Int , ngramCount :: Int
-- , date :: String -- , date :: String
-- , score :: Int -- , score :: Int
...@@ -174,7 +175,7 @@ instance decodeResponse :: DecodeJson Response where ...@@ -174,7 +175,7 @@ instance decodeResponse :: DecodeJson Response where
hyperdata <- obj .? "hyperdata" hyperdata <- obj .? "hyperdata"
favorite <- obj .? "favorite" favorite <- obj .? "favorite"
ngramCount <- obj .? "ngramCount" ngramCount <- obj .? "ngramCount"
pure $ Response { id, created, hyperdata, favorite, ngramCount } pure $ Response { id, created, hyperdata, category: decodeCategory favorite, ngramCount }
-- | Filter -- | Filter
-- TODO: unused -- TODO: unused
...@@ -194,12 +195,12 @@ layoutDocview :: Spec State Props Action ...@@ -194,12 +195,12 @@ layoutDocview :: Spec State Props Action
layoutDocview = simpleSpec performAction render layoutDocview = simpleSpec performAction render
where where
performAction :: PerformAction State Props Action performAction :: PerformAction State Props Action
performAction (MarkFavorites nids) {nodeId} _ = performAction (MarkCategory category nids) {nodeId} _ =
void $ lift $ putFavorites nodeId (FavoriteQuery {favorites: nids}) void $ lift $ putCategories nodeId $ CategoryQuery {nodeIds: nids, category: favCategory category}
--TODO add array of delete rows here --TODO add array of delete rows here
performAction (ToggleDocumentToDelete nid) _ _ = performAction (ToggleDocumentToDelete nid) _ _ =
modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete} modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete}
performAction Trash {nodeId} {documentIdsToDelete} = do performAction TrashDocuments {nodeId} {documentIdsToDelete} = do
void $ lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents: Set.toUnfoldable documentIdsToDelete}) void $ lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents: Set.toUnfoldable documentIdsToDelete})
modifyState_ \{documentIdsToDelete, documentIdsDeleted} -> modifyState_ \{documentIdsToDelete, documentIdsDeleted} ->
{ documentIdsToDelete: mempty { documentIdsToDelete: mempty
...@@ -229,7 +230,7 @@ layoutDocview = simpleSpec performAction render ...@@ -229,7 +230,7 @@ layoutDocview = simpleSpec performAction render
] ]
, div [className "col-md-12"] , div [className "col-md-12"]
[ button [ style {backgroundColor: "peru", padding : "9px", color : "white", border : "white", float: "right"} [ button [ style {backgroundColor: "peru", padding : "9px", color : "white", border : "white", float: "right"}
, onClick $ (\_ -> dispatch Trash) , onClick $ (\_ -> dispatch TrashDocuments)
] ]
[ i [className "glyphitem glyphicon glyphicon-trash", style {marginRight : "9px"}] [] [ i [className "glyphitem glyphicon glyphicon-trash", style {marginRight : "9px"}] []
, text "Trash it !" , text "Trash it !"
...@@ -245,12 +246,12 @@ layoutDocviewGraph :: Spec State Props Action ...@@ -245,12 +246,12 @@ layoutDocviewGraph :: Spec State Props Action
layoutDocviewGraph = simpleSpec performAction render layoutDocviewGraph = simpleSpec performAction render
where where
performAction :: PerformAction State Props Action performAction :: PerformAction State Props Action
performAction (MarkFavorites nids) {nodeId} _ = performAction (MarkCategory category nids) {nodeId} _ =
void $ lift $ putFavorites nodeId (FavoriteQuery {favorites: nids}) void $ lift $ putCategories nodeId $ CategoryQuery {nodeIds: nids, category: favCategory category}
--TODO add array of delete rows here --TODO add array of delete rows here
performAction (ToggleDocumentToDelete nid) _ _ = performAction (ToggleDocumentToDelete nid) _ _ =
modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete} modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete}
performAction Trash {nodeId} {documentIdsToDelete} = do performAction TrashDocuments {nodeId} {documentIdsToDelete} = do
void $ lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents: Set.toUnfoldable documentIdsToDelete}) void $ lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents: Set.toUnfoldable documentIdsToDelete})
modifyState_ \{documentIdsToDelete, documentIdsDeleted} -> modifyState_ \{documentIdsToDelete, documentIdsDeleted} ->
{ documentIdsToDelete: mempty { documentIdsToDelete: mempty
...@@ -275,7 +276,7 @@ layoutDocviewGraph = simpleSpec performAction render ...@@ -275,7 +276,7 @@ layoutDocviewGraph = simpleSpec performAction render
, container , container
} }
, button [ style {backgroundColor: "peru", padding : "9px", color : "white", border : "white", float: "right"} , button [ style {backgroundColor: "peru", padding : "9px", color : "white", border : "white", float: "right"}
, onClick $ (\_ -> dispatch Trash) , onClick $ (\_ -> dispatch TrashDocuments)
] ]
[ i [className "glyphitem glyphicon glyphicon-trash", style {marginRight : "9px"}] [] [ i [className "glyphitem glyphicon glyphicon-trash", style {marginRight : "9px"}] []
, text "Trash it !" , text "Trash it !"
...@@ -303,7 +304,7 @@ loadPage {nodeId, listId, query, params: {limit, offset, orderBy}} = do ...@@ -303,7 +304,7 @@ loadPage {nodeId, listId, query, params: {limit, offset, orderBy}} = do
res2corpus :: Response -> DocumentsView res2corpus :: Response -> DocumentsView
res2corpus (Response { id, created: date, ngramCount: score res2corpus (Response { id, created: date, ngramCount: score
, hyperdata: Hyperdata {title, source} , hyperdata: Hyperdata {title, source}
-- favorite TODO , category
}) = }) =
DocumentsView DocumentsView
{ id { id
...@@ -313,6 +314,7 @@ loadPage {nodeId, listId, query, params: {limit, offset, orderBy}} = do ...@@ -313,6 +314,7 @@ loadPage {nodeId, listId, query, params: {limit, offset, orderBy}} = do
, score , score
, pairs: [] , pairs: []
, delete: false , delete: false
, category
} }
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
...@@ -363,7 +365,7 @@ renderPage loaderDispatch { totalRecords, dispatch, container ...@@ -363,7 +365,7 @@ renderPage loaderDispatch { totalRecords, dispatch, container
] ]
where where
-- TODO: how to interprete other scores? -- TODO: how to interprete other scores?
gi 0 = "glyphicon glyphicon-star-empty" gi Favorite = "glyphicon glyphicon-star-empty"
gi _ = "glyphicon glyphicon-star" gi _ = "glyphicon glyphicon-star"
isChecked id = Set.member id documentIdsToDelete isChecked id = Set.member id documentIdsToDelete
isDeleted (DocumentsView {id}) = Set.member id documentIdsDeleted isDeleted (DocumentsView {id}) = Set.member id documentIdsDeleted
...@@ -371,7 +373,7 @@ renderPage loaderDispatch { totalRecords, dispatch, container ...@@ -371,7 +373,7 @@ renderPage loaderDispatch { totalRecords, dispatch, container
| id > 1 = [a [href (toUrl Front NodeContact (Just id)), target "blank"] [text label]] | id > 1 = [a [href (toUrl Front NodeContact (Just id)), target "blank"] [text label]]
| otherwise = [text label] | otherwise = [text label]
comma = span [] [text ", "] comma = span [] [text ", "]
rows = (\(DocumentsView {id,score,title,source,date,pairs,delete}) -> rows = (\(DocumentsView {id,score,title,source,date,pairs,delete,category}) ->
let let
strikeIfDeleted strikeIfDeleted
| delete = [style {textDecoration : "line-through"}] | delete = [style {textDecoration : "line-through"}]
...@@ -379,8 +381,8 @@ renderPage loaderDispatch { totalRecords, dispatch, container ...@@ -379,8 +381,8 @@ renderPage loaderDispatch { totalRecords, dispatch, container
in in
{ row: { row:
[ div [] [ div []
[ a [ className $ gi score [ a [ className $ gi category
, onClick $ const $ dispatch $ MarkFavorites [id] , onClick $ const $ dispatch $ MarkCategory category [id]
] [] ] []
] ]
-- TODO show date: Year-Month-Day only -- TODO show date: Year-Month-Day only
...@@ -405,15 +407,6 @@ pageLoader props = React.createElement pageLoaderClass props [] ...@@ -405,15 +407,6 @@ pageLoader props = React.createElement pageLoaderClass props []
--------------------------------------------------------- ---------------------------------------------------------
newtype FavoriteQuery = FavoriteQuery
{ favorites :: Array Int
}
instance encodeJsonFQuery :: EncodeJson FavoriteQuery where
encodeJson (FavoriteQuery post)
= "favorites" := post.favorites
~> jsonEmptyObject
newtype DeleteDocumentQuery = DeleteDocumentQuery newtype DeleteDocumentQuery = DeleteDocumentQuery
{ {
documents :: Array Int documents :: Array Int
...@@ -425,11 +418,5 @@ instance encodeJsonDDQuery :: EncodeJson DeleteDocumentQuery where ...@@ -425,11 +418,5 @@ instance encodeJsonDDQuery :: EncodeJson DeleteDocumentQuery where
= "documents" := post.documents = "documents" := post.documents
~> jsonEmptyObject ~> jsonEmptyObject
putFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
putFavorites nodeId = put (toUrl Back Node (Just nodeId) <> "/favorites")
deleteFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
deleteFavorites nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/favorites")
deleteDocuments :: Int -> DeleteDocumentQuery -> Aff (Array Int) deleteDocuments :: Int -> DeleteDocumentQuery -> Aff (Array Int)
deleteDocuments nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/documents") deleteDocuments nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/documents")
...@@ -2,8 +2,11 @@ module Gargantext.Components.Search.Types where ...@@ -2,8 +2,11 @@ module Gargantext.Components.Search.Types where
import Control.Monad.Cont.Trans (lift) import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>), encodeJson) import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>), encodeJson)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Array (head) import Data.Array (head)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.Tuple (Tuple) import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
...@@ -14,7 +17,8 @@ import Thermite (PerformAction, modifyState) ...@@ -14,7 +17,8 @@ import Thermite (PerformAction, modifyState)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Types (class ToQuery) import Gargantext.Types (class ToQuery)
import Gargantext.Config.REST (post) import Gargantext.Config (End(..), NodeType(..), Path(..), toUrl)
import Gargantext.Config.REST (post, put)
import Gargantext.Components.Modals.Modal (modalHide) import Gargantext.Components.Modals.Modal (modalHide)
import Gargantext.Pages.Layout.Specs.AddCorpus.States (Response, State) import Gargantext.Pages.Layout.Specs.AddCorpus.States (Response, State)
import Gargantext.Utils (id) import Gargantext.Utils (id)
...@@ -96,3 +100,51 @@ instance encodeJsonSearchQuery :: EncodeJson SearchQuery where ...@@ -96,3 +100,51 @@ instance encodeJsonSearchQuery :: EncodeJson SearchQuery where
~> "corpus_id" := fromMaybe 0 corpus_id ~> "corpus_id" := fromMaybe 0 corpus_id
~> "files_id" := files_id ~> "files_id" := files_id
~> jsonEmptyObject ~> jsonEmptyObject
data Category = Trash | Normal | Favorite
derive instance genericFavorite :: Generic Category _
instance showCategory :: Show Category where
show = genericShow
instance eqCategory :: Eq Category where
eq = genericEq
instance encodeJsonCategory :: EncodeJson Category where
encodeJson Trash = encodeJson 0
encodeJson Normal = encodeJson 1
encodeJson Favorite = encodeJson 2
favCategory :: Category -> Category
favCategory Normal = Favorite
favCategory Trash = Favorite
favCategory Favorite = Normal
trashCategory :: Category -> Category
trashCategory Normal = Trash
trashCategory Trash = Normal
trashCategory Favorite = Trash
decodeCategory :: Int -> Category
decodeCategory 0 = Trash
decodeCategory 1 = Normal
decodeCategory 2 = Favorite
decodeCategory _ = Normal
newtype CategoryQuery = CategoryQuery {
nodeIds :: Array Int
, category :: Category
}
instance encodeJsonCategoryQuery :: EncodeJson CategoryQuery where
encodeJson (CategoryQuery post) =
"ntc_nodesId" := post.nodeIds
~> "ntc_category" := encodeJson post.category
~> jsonEmptyObject
categoryUrl :: Int -> String
categoryUrl nodeId = toUrl Back Node (Just nodeId) <> "/category"
putCategories :: Int -> CategoryQuery -> Aff (Array Int)
putCategories nodeId = put $ categoryUrl nodeId
...@@ -4,7 +4,6 @@ import Prelude hiding (div) ...@@ -4,7 +4,6 @@ import Prelude hiding (div)
import Data.Lens (view) import Data.Lens (view)
import Data.List (fromFoldable) import Data.List (fromFoldable)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Config (TabType(..), TabSubType(..))
import Gargantext.Components.GraphExplorer.Types (GraphSideCorpus(..)) import Gargantext.Components.GraphExplorer.Types (GraphSideCorpus(..))
import Gargantext.Components.FacetsTable (TextQuery, docViewSpec) import Gargantext.Components.FacetsTable (TextQuery, docViewSpec)
import Gargantext.Components.Table as T import Gargantext.Components.Table as T
......
...@@ -10,7 +10,6 @@ import Gargantext.Pages.Corpus.Graph as GE ...@@ -10,7 +10,6 @@ import Gargantext.Pages.Corpus.Graph as GE
-- import Gargantext.Pages.Corpus.Tabs.Terms.NgramsTable as NG -- import Gargantext.Pages.Corpus.Tabs.Terms.NgramsTable as NG
-- import Gargantext.Pages.Home as L -- import Gargantext.Pages.Home as L
-- import Gargantext.Pages.Layout.Specs.Search as S
import Gargantext.Router (Routes(..)) import Gargantext.Router (Routes(..))
dispatchAction :: forall ignored m. dispatchAction :: forall ignored m.
......
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