Commit f5f6efec authored by Sudhir Kumar's avatar Sudhir Kumar

added code for deleting multiple documents

parent 54d7b3fe
...@@ -8,7 +8,7 @@ import Affjax.ResponseFormat (printResponseFormatError) ...@@ -8,7 +8,7 @@ import Affjax.ResponseFormat (printResponseFormatError)
import Affjax.ResponseFormat as ResponseFormat import Affjax.ResponseFormat as ResponseFormat
import Control.Monad.Cont.Trans (lift) import Control.Monad.Cont.Trans (lift)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, jsonEmptyObject, (.?), (:=), (~>)) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, jsonEmptyObject, (.?), (:=), (~>))
import Data.Array (take, drop) import Data.Array (cons, drop, take, (:))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
...@@ -41,7 +41,7 @@ import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState, ...@@ -41,7 +41,7 @@ import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState,
type State = type State =
{ documents :: DocumentsView { documents :: DocumentsView
, deleteRows :: Boolean , deleteRows :: Boolean
, deleteRowId :: Int , deleteRowId :: Array Int
} }
...@@ -52,7 +52,7 @@ data Action ...@@ -52,7 +52,7 @@ data Action
| Trash | Trash
performAction :: PerformAction State Props Action performAction :: PerformAction State Props Action
performAction (SendFavorites nid) _ _ = void $ do performAction (SendFavorites nid) {path : nodeId} _ = void $ do
s' <- lift $ favorites nid (FavoriteQuery {favorites : [nid]}) s' <- lift $ favorites nid (FavoriteQuery {favorites : [nid]})
case s' of case s' of
...@@ -63,10 +63,10 @@ performAction (SendFavorites nid) _ _ = void $ do ...@@ -63,10 +63,10 @@ performAction (SendFavorites nid) _ _ = void $ do
performAction (DeleteDocuments nid) _ _ = void $ do performAction (DeleteDocuments nid) _ _ = void $ do
_ <- liftEffect $ log $ show nid _ <- liftEffect $ log $ show nid
modifyState \state -> state {deleteRowId = nid, deleteRows = true} modifyState \state -> state {deleteRowId = ( cons nid []), deleteRows = true}
performAction (Trash) _ state = void $ do performAction Trash {path:nodeId} state = void $ do
s' <- lift $ deleteDocuments state.deleteRowId (DeleteDocumentQuery {documents : [state.deleteRowId]}) s' <- lift $ deleteDocuments nodeId (DeleteDocumentQuery {documents : state.deleteRowId})
case s' of case s' of
Left err -> do Left err -> do
_ <- liftEffect $ log err _ <- liftEffect $ log err
...@@ -341,9 +341,9 @@ deleteFavorites nodeId reqbody= do ...@@ -341,9 +341,9 @@ deleteFavorites nodeId reqbody= do
deleteDocuments :: Int -> DeleteDocumentQuery -> Aff (Either String Unit) deleteDocuments :: Int -> DeleteDocumentQuery -> Aff (Either String Unit)
deleteDocuments ddid reqbody= do deleteDocuments nodeId reqbody= do
res <- request $ defaultRequest res <- request $ defaultRequest
{ url = "http://localhost:8008/api/v1.0/annuaire/"<>show ddid<>"/documents" { url = "http://localhost:8008/api/v1.0/annuaire/"<>show nodeId <>"/documents"
, responseFormat = ResponseFormat.json , responseFormat = ResponseFormat.json
, method = Left DELETE , method = Left DELETE
, headers = [] , headers = []
......
...@@ -12,12 +12,13 @@ type State = ...@@ -12,12 +12,13 @@ type State =
, activeTab :: Int , activeTab :: Int
} }
initialState :: State initialState :: State
initialState = initialState =
{ docsView : { docsView :
{ documents : D.sampleData' { documents : D.sampleData'
, deleteRows : false , deleteRows : false
, deleteRowId : 1 , deleteRowId : []
} }
, ngramsView : {} -- N.initialState , ngramsView : {} -- N.initialState
, activeTab : 0 , activeTab : 0
......
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