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
Show 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)
------------------------------------------------------------------------
import Gargantext.Prelude
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.Node (NodePoly(..))
import Gargantext.Components.Table as T
...
...
@@ -56,25 +56,23 @@ type Props =
}
type State =
{ documentIdsToDelete :: Set Int
, documentIdsDeleted :: Set Int
{ documentIdsDeleted :: Set Int
, localFavorites :: Map Int Boolean
}
initialState :: State
initialState =
{ documentIdsToDelete: mempty
, documentIdsDeleted: mempty
{ documentIdsDeleted: mempty
, localFavorites: mempty
}
_documentIdsToDelete = prop (SProxy :: SProxy "documentIdsToDelete")
_documentIdsDeleted = prop (SProxy :: SProxy "documentIdsDeleted")
_localFavorites = prop (SProxy :: SProxy "localFavorites")
data Action
= MarkFavorites Int Boolean
| ToggleDocumentToDelete Int
-- | ToggleDocumentToDelete Int
| ToggleDeleteDocument Int
| Trash
newtype DocumentsView
...
...
@@ -165,15 +163,16 @@ layoutDocview = simpleSpec performAction render
performAction (MarkFavorites nid fav) {nodeId} _ = do
modifyState_ $ _localFavorites <<< at nid ?~ fav
void $ lift $ if fav
then putFavorites nodeId (FavoriteQuery {favorites: [nid]})
else deleteFavorites nodeId (FavoriteQuery {favorites: [nid]})
performAction (ToggleDocumentToDelete nid) _ _ =
modifyState_ \state -> state {documentIdsToDelete = toggleSet nid state.documentIdsToDelete}
performAction Trash {nodeId} {documentIdsToDelete} = do
void $ lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents: Set.toUnfoldable documentIdsToDelete})
modifyState_ $
(_documentIdsToDelete .~ mempty) >>>
(_documentIdsDeleted <>~ documentIdsToDelete)
then putFavorites nodeId $ FavoriteQuery {favorites: [nid]}
else deleteFavorites nodeId $ FavoriteQuery {favorites: [nid]}
performAction (ToggleDeleteDocument nid) {nodeId} {documentIdsDeleted} = do
modifyState_ $ _ {documentIdsDeleted = toggleSet nid documentIdsDeleted}
void $ lift $ if (Set.member nid documentIdsDeleted)
then deleteDocuments nodeId $ DocumentQuery {documents: [nid]}
else putDocuments nodeId $ DocumentQuery {documents: [nid]}
performAction Trash {nodeId} {documentIdsDeleted} = do
ids <- lift $ deleteAllDocuments nodeId
modifyState_ $ _ {documentIdsDeleted = Set.union documentIdsDeleted $ Set.fromFoldable ids}
render :: Render State Props Action
render dispatch {nodeId, tabType, listId, corpusId, totalRecords, chart} deletionState _ =
...
...
@@ -271,7 +270,7 @@ renderPage :: forall props path.
(Loader.Action PageParams)
renderPage _ _ {loaded: Nothing} _ = [] -- TODO loading spinner
renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
, deletionState: {documentIds
ToDelete, documentIds
Deleted, localFavorites}}
, deletionState: {documentIdsDeleted, localFavorites}}
{currentPath: {nodeId, tabType}, loaded: Just res} _ =
[ T.tableElt
{ rows
...
...
@@ -291,32 +290,31 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
where
gi true = "glyphicon glyphicon-star"
gi false = "glyphicon glyphicon-star-empty"
toDelete (DocumentsView {_id}) = Set.member _id documentIdsToDelete
isDeleted (DocumentsView {_id}) = Set.member _id documentIdsDeleted
isFavorite {_id,fav} = maybe fav identity (localFavorites ^. at _id)
corpusDocument (Just corpusId) = R.CorpusDocument corpusId
corpusDocument _ = R.Document
rows = (\(DocumentsView r) ->
let isFav = isFavorite r
toDel = toDelete
$ DocumentsView r in
isDel = isDeleted
$ DocumentsView r in
{ row:
[ div []
[ a [ className $ gi isFav
, if
to
Del then style {textDecoration : "line-through"}
, if
is
Del then style {textDecoration : "line-through"}
else style {textDecoration : "none"}
, onClick $ (\_-> dispatch $ MarkFavorites r._id (not isFav))
] []
]
, input [ _type "checkbox"
, checked
to
Del
, onClick $ (\_ -> dispatch $ ToggleD
ocumentToDelete
r._id)
, checked
is
Del
, onClick $ (\_ -> dispatch $ ToggleD
eleteDocument
r._id)
]
-- TODO show date: Year-Month-Day only
, if
to
Del then
, if
is
Del then
div [ style {textDecoration : "line-through"}][text (show r.date)]
else
div [ ][text (show r.date)]
, if
to
Del then
, if
is
Del then
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, style {textDecoration : "line-through"}
, target "_blank"
...
...
@@ -324,11 +322,10 @@ renderPage loaderDispatch { totalRecords, dispatch, listId, corpusId
else
a [ href (toLink $ (corpusDocument corpusId) listId r._id)
, target "_blank" ] [ text r.title ]
, if
to
Del then
, if
is
Del then
div [style {textDecoration : "line-through"}] [ text r.source]
else
div [] [ text r.source]
]
, delete: true
}) <$> filter (not <<< isDeleted) res
...
...
@@ -372,7 +369,8 @@ searchResults squery = post "http://localhost:8008/count" unit
newtype FavoriteQuery = FavoriteQuery
{ favorites :: Array Int
{
favorites :: Array Int
}
instance encodeJsonFQuery :: EncodeJson FavoriteQuery where
...
...
@@ -380,25 +378,37 @@ instance encodeJsonFQuery :: EncodeJson FavoriteQuery where
= "favorites" := post.favorites
~> jsonEmptyObject
newtype DeleteDocumentQuery = DeleteDocumentQuery
favoritesUrl :: Int -> String
favoritesUrl nodeId = toUrl Back Node (Just nodeId) <> "/favorites"
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
encodeJson (D
eleteD
ocumentQuery post)
instance encodeJsonDDQuery :: EncodeJson DocumentQuery where
encodeJson (DocumentQuery post)
= "documents" := post.documents
~> jsonEmptyObject
putFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
putFavorites nodeId = put (toUrl Back Node (Just nodeId) <> "/favorites")
documentsUrl :: Int -> String
documentsUrl nodeId = toUrl Back Node (Just nodeId) <> "/documents"
deleteFavorites :: Int -> FavoriteQuery -> Aff (Array Int)
deleteFavorites nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/favorites")
putDocuments :: Int -> DocumentQuery -> Aff (Array Int)
putDocuments nodeId = put $ documentsUrl nodeId
deleteDocuments :: Int -> DocumentQuery -> Aff (Array Int)
deleteDocuments nodeId = deleteWithBody $ documentsUrl nodeId
delete
Documents :: Int -> DeleteDocumentQuery
-> Aff (Array Int)
delete
Documents nodeId = deleteWithBody (toUrl Back Node (Just nodeId) <> "/documents")
delete
AllDocuments :: Int
-> Aff (Array Int)
delete
AllDocuments nodeId = delete $ documentsUrl nodeId
-- TODO: not optimal but Data.Set lacks some function (Set.alter)
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