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
11f5e8ff
Commit
11f5e8ff
authored
Jul 23, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DocTable] remove docs immediately
parent
dfb8f679
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
40 deletions
+50
-40
DocsTable.purs
src/Gargantext/Components/DocsTable.purs
+50
-40
No files found.
src/Gargantext/Components/DocsTable.purs
View file @
11f5e8ff
...
@@ -30,7 +30,7 @@ import React (ReactClass, ReactElement, Children)
...
@@ -30,7 +30,7 @@ import React (ReactClass, ReactElement, Children)
------------------------------------------------------------------------
------------------------------------------------------------------------
import Gargantext.Prelude
import Gargantext.Prelude
import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, toUrl, toLink)
import Gargantext.Config (End(..), NodeType(..), OrderBy(..), Path(..), TabType, toUrl, toLink)
import Gargantext.Config.REST (get, put, post, deleteWithBody)
import Gargantext.Config.REST (get, put, post, deleteWithBody
, delete
)
import Gargantext.Components.Loader as Loader
import Gargantext.Components.Loader as Loader
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Components.Table as T
import Gargantext.Components.Table as T
...
@@ -56,25 +56,23 @@ type Props =
...
@@ -56,25 +56,23 @@ type Props =
}
}
type State =
type State =
{ documentIdsToDelete :: Set Int
{ documentIdsDeleted :: Set Int
, documentIdsDeleted :: Set Int
, localFavorites :: Map Int Boolean
, localFavorites :: Map Int Boolean
}
}
initialState :: State
initialState :: State
initialState =
initialState =
{ documentIdsToDelete: mempty
{ documentIdsDeleted: mempty
, documentIdsDeleted: mempty
, localFavorites: mempty
, localFavorites: mempty
}
}
_documentIdsToDelete = prop (SProxy :: SProxy "documentIdsToDelete")
_documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted")
_documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted")
_localFavorites = prop (SProxy :: SProxy "localFavorites")
_localFavorites = prop (SProxy :: SProxy "localFavorites")
data Action
data Action
= MarkFavorites Int Boolean
= MarkFavorites Int Boolean
| ToggleDocumentToDelete Int
-- | ToggleDocumentToDelete Int
| ToggleDeleteDocument Int
| Trash
| Trash
newtype DocumentsView
newtype DocumentsView
...
@@ -165,15 +163,16 @@ layoutDocview = simpleSpec performAction render
...
@@ -165,15 +163,16 @@ layoutDocview = simpleSpec performAction render
performAction (MarkFavorites nid fav) {nodeId} _ = do
performAction (MarkFavorites nid fav) {nodeId} _ = do
modifyState_ $ _localFavorites <<< at nid ?~ fav
modifyState_ $ _localFavorites <<< at nid ?~ fav
void $ lift $ if fav
void $ lift $ if fav
then putFavorites nodeId (FavoriteQuery {favorites: [nid]})
then putFavorites nodeId $ FavoriteQuery {favorites: [nid]}
else deleteFavorites nodeId (FavoriteQuery {favorites: [nid]})
else deleteFavorites nodeId $ FavoriteQuery {favorites: [nid]}
performAction (ToggleDocumentToDelete nid) _ _ =
performAction (ToggleDeleteDocument nid) {nodeId} {documentIdsDeleted} = do
modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete}
modifyState_ $ _ {documentIdsDeleted = toggleSet nid documentIdsDeleted}
performAction Trash {nodeId} {documentIdsToDelete} = do
void $ lift $ if (Set.member nid documentIdsDeleted)
void $ lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents: Set.toUnfoldable documentIdsToDelete})
then deleteDocuments nodeId $ DocumentQuery {documents: [nid]}
modifyState_ $
else putDocuments nodeId $ DocumentQuery {documents: [nid]}
(_documentIdsToDelete .~ mempty) >>>
performAction Trash {nodeId} {documentIdsDeleted} = do
(_documentIdsDeleted <>~ documentIdsToDelete)
ids <- lift $ deleteAllDocuments nodeId
modifyState_ $ _ {documentIdsDeleted = Set.union documentIdsDeleted $ Set.fromFoldable ids}
render :: Render State Props Action
render :: Render State Props Action
render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} deletionState _ =
render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} deletionState _ =
...
@@ -271,7 +270,7 @@ renderPage :: forall props path.
...
@@ -271,7 +270,7 @@ renderPage :: forall props path.
(Loader.Action PageParams)
(Loader.Action PageParams)
renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner
renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner
renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
, deletionState: {documentIds
ToDelete, documentIds
Deleted, localFavorites}}
, deletionState: {documentIdsDeleted, localFavorites}}
{currentPath: {nodeId, tabType}, loaded: Just res} _ =
{currentPath: {nodeId, tabType}, loaded: Just res} _ =
[ T.tableElt
[ T.tableElt
{ rows
{ rows
...
@@ -291,32 +290,31 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
...
@@ -291,32 +290,31 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
where
where
gi true = "glyphicon glyphicon-star"
gi true = "glyphicon glyphicon-star"
gi false = "glyphicon glyphicon-star-empty"
gi false = "glyphicon glyphicon-star-empty"
toDelete (DocumentsView {_id}) = Set.member _id documentIdsToDelete
isDeleted (DocumentsView {_id}) = Set.member _id documentIdsDeleted
isDeleted (DocumentsView {_id}) = Set.member _id documentIdsDeleted
isFavorite {_id,fav} = maybe fav identity (localFavorites ^. at _id)
isFavorite {_id,fav} = maybe fav identity (localFavorites ^. at _id)
corpusDocument (Just corpusId) = R.CorpusDocument corpusId
corpusDocument (Just corpusId) = R.CorpusDocument corpusId
corpusDocument _ = R.Document
corpusDocument _ = R.Document
rows = (\(DocumentsView r) ->
rows = (\(DocumentsView r) ->
let isFav = isFavorite r
let isFav = isFavorite r
toDel = toDelete
$ DocumentsView r in
isDel = isDeleted
$ DocumentsView r in
{ row:
{ row:
[ div []
[ div []
[ a [ className $ gi isFav
[ a [ className $ gi isFav
, if
to
Del then style {textDecoration : "line-through"}
, if
is
Del then style {textDecoration : "line-through"}
else style {textDecoration : "none"}
else style {textDecoration : "none"}
, onClick $ (\_-> dispatch $ MarkFavorites r._id (not isFav))
, onClick $ (\_-> dispatch $ MarkFavorites r._id (not isFav))
] []
] []
]
]
, input [ _type "checkbox"
, input [ _type "checkbox"
, checked
to
Del
, checked
is
Del
, onClick $ (\_ -> dispatch $ ToggleD
ocumentToDelete
r._id)
, onClick $ (\_ -> dispatch $ ToggleD
eleteDocument
r._id)
]
]
-- TODO show date: Year-Month-Day only
-- TODO show date: Year-Month-Day only
, if
to
Del then
, if
is
Del then
div [ style {textDecoration : "line-through"}][text (show r.date)]
div [ style {textDecoration : "line-through"}][text (show r.date)]
else
else
div [ ][text (show r.date)]
div [ ][text (show r.date)]
, if
to
Del then
, if
is
Del then
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, style {textDecoration : "line-through"}
, style {textDecoration : "line-through"}
, target "_blank"
, target "_blank"
...
@@ -324,11 +322,10 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
...
@@ -324,11 +322,10 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
else
else
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, target "_blank" ] [ text r.title ]
, target "_blank" ] [ text r.title ]
, if
to
Del then
, if
is
Del then
div [style {textDecoration : "line-through"}] [ text r.source]
div [style {textDecoration : "line-through"}] [ text r.source]
else
else
div [] [ text r.source]
div [] [ text r.source]
]
]
, delete: true
, delete: true
}) <$> filter (not <<< isDeleted) res
}) <$> filter (not <<< isDeleted) res
...
@@ -372,33 +369,46 @@ searchResults squery = post "http://localhost:8008/count" unit
...
@@ -372,33 +369,46 @@ searchResults squery = post "http://localhost:8008/count" unit
newtype FavoriteQuery = FavoriteQuery
newtype FavoriteQuery = FavoriteQuery
{ favorites :: Array Int
{
}
favorites :: Array Int
}
instance encodeJsonFQuery :: EncodeJson FavoriteQuery where
instance encodeJsonFQuery :: EncodeJson FavoriteQuery where
encodeJson (FavoriteQuery post)
encodeJson (FavoriteQuery post)
= "favorites" := post.favorites
= "favorites" := post.favorites
~> jsonEmptyObject
~> jsonEmptyObject
newtype DeleteDocumentQuery = DeleteDocumentQuery
favoritesUrl :: Int -> String
{
favoritesUrl nodeId = toUrl Back Node (Just nodeId) <> "/favorites"
documents :: Array Int
}
putFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
putFavorites nodeId = put $ favoritesUrl nodeId
deleteFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
deleteFavorites nodeId = deleteWithBody $ favoritesUrl nodeId
newtype DocumentQuery = DocumentQuery
{
documents :: Array Int
}
instance encodeJsonDDQuery :: EncodeJson D
eleteD
ocumentQuery where
instance encodeJsonDDQuery :: EncodeJson DocumentQuery where
encodeJson (D
eleteD
ocumentQuery post)
encodeJson (DocumentQuery post)
= "documents" := post.documents
= "documents" := post.documents
~> jsonEmptyObject
~> jsonEmptyObject
putFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
documentsUrl :: Int -> String
putFavorites nodeId = put (toUrl Back Node (Just nodeId) <> "/favorites")
documentsUrl nodeId = toUrl Back Node (Just nodeId) <> "/documents"
deleteFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
putDocuments :: Int -> DocumentQuery -> Aff (Array Int)
deleteFavorites nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/favorites")
putDocuments nodeId = put $ documentsUrl nodeId
deleteDocuments :: Int -> DocumentQuery -> Aff (Array Int)
deleteDocuments nodeId = deleteWithBody $ documentsUrl nodeId
delete
Documents :: Int -> DeleteDocumentQuery
-> Aff (Array Int)
delete
AllDocuments :: Int
-> Aff (Array Int)
delete
Documents nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/documents")
delete
AllDocuments nodeId = delete $ documentsUrl nodeId
-- TODO: not optimal but Data.Set lacks some function (Set.alter)
-- TODO: not optimal but Data.Set lacks some function (Set.alter)
toggleSet :: forall a. Ord a => a -> Set a -> Set a
toggleSet :: forall a. Ord a => a -> Set a -> Set a
...
...
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