From 94fcd0cf59f94dd29ab171f0875bd25af65fd527 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 8 Aug 2012 16:06:01 -0400 Subject: add routes to pause/start/cancel transfers This commit includes a paydown on technical debt incurred two years ago, when I didn't know that it was bad to make custom Read and Show instances for types. As the routes need Read and Show for Transfer, which includes a Key, and deriving my own Read instance of key was not practical, I had to finally clean that up. So the compact Key read and show functions are now file2key and key2file, and Read and Show are now derived instances. Changed all code that used the old instances, compiler checked. (There were a few places, particularly in Command.Unused, and the test suite where the Show instance continue to be used for legitimate comparisons; ie show key_x == show key_y (though really in a bloom filter)) --- Assistant/WebApp.hs | 5 +++++ Assistant/WebApp/DashBoard.hs | 36 ++++++++++++++++++++++++++++++++++-- Assistant/WebApp/routes | 4 ++++ 3 files changed, 43 insertions(+), 2 deletions(-) (limited to 'Assistant') diff --git a/Assistant/WebApp.hs b/Assistant/WebApp.hs index aa0834535..5bb2339b3 100644 --- a/Assistant/WebApp.hs +++ b/Assistant/WebApp.hs @@ -19,6 +19,7 @@ import Assistant.Alert import Utility.NotificationBroadcaster import Utility.WebApp import Utility.Yesod +import Logs.Transfer import Yesod import Yesod.Static @@ -154,6 +155,10 @@ instance PathPiece AlertId where toPathPiece = pack . show fromPathPiece = readish . unpack +instance PathPiece Transfer where + toPathPiece = pack . show + fromPathPiece = readish . unpack + {- Adds the auth parameter as a hidden field on a form. Must be put into - every form. -} webAppFormAuthToken :: Widget diff --git a/Assistant/WebApp/DashBoard.hs b/Assistant/WebApp/DashBoard.hs index 8e526fb1d..57d789831 100644 --- a/Assistant/WebApp/DashBoard.hs +++ b/Assistant/WebApp/DashBoard.hs @@ -42,13 +42,18 @@ transfersDisplay warnNoScript = do queued <- liftIO $ getTransferQueue $ transferQueue webapp let ident = "transfers" autoUpdate ident NotifierTransfersR (10 :: Int) (10 :: Int) - let transfers = current ++ queued + let transfers = current ++ queued ++ dummy if null transfers then ifM (lift $ showIntro <$> getWebAppState) ( introDisplay ident , $(widgetFile "dashboard/transfers") ) else $(widgetFile "dashboard/transfers") + where + dummy = [(t, i), (t, i)] + t = Transfer Download (UUID "00000000-0000-0000-0000-000000000001") k + k = Types.Key.Key "foo" "bar" Nothing Nothing + i = TransferInfo Nothing Nothing Nothing Nothing Nothing Nothing {- Called by client to get a display of currently in process transfers. - @@ -98,7 +103,10 @@ postFileBrowserR = void openFileBrowser {- Used by non-javascript browsers, where clicking on the link actually - opens this page, so we redirect back to the referrer. -} getFileBrowserR :: Handler () -getFileBrowserR = whenM openFileBrowser $ do +getFileBrowserR = whenM openFileBrowser $ redirectBack + +redirectBack :: Handler () +redirectBack = do clearUltDest setUltDestReferer redirectUltDest HomeR @@ -130,3 +138,27 @@ openFileBrowser = do #else cmd = "xdg-open" #endif + +{- Transfer controls. The GET is done in noscript mode and redirects back + - to the referring page. The POST is called by javascript. -} +getPauseTransferR :: Transfer -> Handler () +getPauseTransferR t = pauseTransfer t >> redirectBack +postPauseTransferR :: Transfer -> Handler () +postPauseTransferR t = pauseTransfer t +getStartTransferR :: Transfer -> Handler () +getStartTransferR t = startTransfer t >> redirectBack +postStartTransferR :: Transfer -> Handler () +postStartTransferR t = startTransfer t +getCancelTransferR :: Transfer -> Handler () +getCancelTransferR t = cancelTransfer t >> redirectBack +postCancelTransferR :: Transfer -> Handler () +postCancelTransferR t = cancelTransfer t + +pauseTransfer :: Transfer -> Handler () +pauseTransfer t = liftIO $ putStrLn "pause" + +startTransfer :: Transfer -> Handler () +startTransfer t = liftIO $ putStrLn "start" + +cancelTransfer :: Transfer -> Handler () +cancelTransfer t = liftIO $ putStrLn "cancel" diff --git a/Assistant/WebApp/routes b/Assistant/WebApp/routes index 60f56cf14..e3e7daf87 100644 --- a/Assistant/WebApp/routes +++ b/Assistant/WebApp/routes @@ -15,4 +15,8 @@ /closealert/#AlertId CloseAlert GET /filebrowser FileBrowserR GET POST +/transfer/pause/#Transfer PauseTransferR GET POST +/transfer/start/#Transfer StartTransferR GET POST +/transfer/cancel/#Transfer CancelTransferR GET POST + /static StaticR Static getStatic -- cgit v1.2.3