= return $ Just $ ResourceDef {
resUsesNativeThread = False
, resIsGreedy = True
- , resGet = Just $ handleGet env (toPageName path)
+ , resGet = Just $ handleGet env (toPageName path)
, resHead = Nothing
, resPost = Nothing
- , resPut = Just $ handlePut env (toPageName path)
- , resDelete = Nothing
+ , resPut = Just $ handlePut env (toPageName path)
+ , resDelete = Just $ handleDelete env (toPageName path)
}
where
toPageName :: [String] -> PageName
-> do page <- parseXmlizedPage -< (name, tree)
status <- putPageA (envStorage env) -< page
returnA -< setStatus status
+
+
+handleDelete :: Environment -> PageName -> Resource ()
+handleDelete env name
+ = do status <- deletePage (envStorage env) name
+ setStatus status
, getPage
, putPage
+ , deletePage
, getPageA
, putPageA
+ , deletePageA
, searchPages
return st
+deletePage :: MonadIO m => Storage -> PageName -> m StatusCode
+deletePage sto name
+ = liftIO $ do st <- deletePage' (stoRepository sto) name
+ syncIndex sto
+ return st
+
+
getPageA :: ArrowIO a => Storage -> a (PageName, Maybe RevNum) (Maybe Page)
getPageA = arrIO2 . getPage
putPageA = arrIO . putPage
+deletePageA :: ArrowIO a => Storage -> a PageName StatusCode
+deletePageA = arrIO . deletePage
+
+
searchPages :: MonadIO m => Storage -> Condition -> m [(PageName, RevNum)]
searchPages sto cond
= liftIO $
module Rakka.Storage.Impl
( getPage'
, putPage'
+ , deletePage'
, startIndexManager
)
where
putPage' = putPageIntoRepository
+deletePage' :: Repository -> PageName -> IO StatusCode
+deletePage' = deletePageFromRepository
+
+
findAllPages :: Repository -> RevNum -> IO (Set PageName)
findAllPages _ 0 = findAllDefaultPages
findAllPages repos rev = do reposPages <- findAllPagesInRevision repos rev
, findChangedPagesAtRevision
, loadPageInRepository
, putPageIntoRepository
+ , deletePageFromRepository
)
where
-> do fs <- getRepositoryFS repos
rev <- getYoungestRev fs
doReposTxn repos
- rev
- "[Rakka]"
- (Just "Automatic commit by Rakka for page creation")
- $ do createPage name
- updatePage name
+ rev
+ "[Rakka]"
+ (Just "Automatic commit by Rakka for page creation")
+ $ do createPage name
+ updatePage name
case ret of
Left _ -> return Conflict
Right _ -> return Created
encodeFlag False = Nothing
+deletePageFromRepository :: Repository -> PageName -> IO StatusCode
+deletePageFromRepository repos name
+ = filterSvnError $
+ do let path = mkPagePath name
+ fs <- getRepositoryFS repos
+ rev <- getYoungestRev fs
+ exists <- withRevision fs rev $ isFile path
+ if exists then
+ do doReposTxn repos
+ rev
+ "[Rakka]"
+ (Just "Automatic commit by Rakka for page deleting")
+ $ do deleteEntry path
+ deleteEmptyParentDirectories path
+ return NoContent
+ else
+ return NotFound
+ where
+ deleteEmptyParentDirectories :: FilePath -> Txn ()
+ deleteEmptyParentDirectories path
+ = do let parentPath = takeDirectory path
+ contents <- getDirEntries parentPath
+ when (null contents)
+ $ do deleteEntry parentPath
+ deleteEmptyParentDirectories parentPath
+
+
filterSvnError :: IO a -> IO a
filterSvnError f = catchDyn f rethrow
where
= $.INPUT({type: "button", value: "Delete this page"});
$(btnDelete).click(function () {
- throw new Error("FIXME: not implemented yet");
+ if (window.confirm("Do you really want to delete this page?")) {
+ Rakka.deletePage(pageName);
+ }
});
var updateTRContent = function () {
$area.text("Error: " + req.status + " " + req.statusText);
}
});
-};
\ No newline at end of file
+};
+
+Rakka.deletePage = function (pageName) {
+ var url = Rakka.baseURI + encodeURI(pageName);
+ $.ajax({
+ type : "DELETE",
+ url : url,
+ success : function () {
+ window.location.replace(url);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+
+ var $area = Rakka.switchScreen();
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ });
+};