2012-09-18 21:50:07 +00:00
|
|
|
{- git-annex assistant webapp switching to other repos
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-09-18 21:50:07 +00:00
|
|
|
-
|
2012-09-24 18:48:47 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-09-18 21:50:07 +00:00
|
|
|
-}
|
|
|
|
|
2013-06-05 01:02:09 +00:00
|
|
|
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
|
2012-09-18 21:50:07 +00:00
|
|
|
|
|
|
|
module Assistant.WebApp.OtherRepos where
|
|
|
|
|
|
|
|
import Assistant.Common
|
|
|
|
import Assistant.WebApp.Types
|
2013-01-03 20:34:57 +00:00
|
|
|
import Assistant.WebApp.Page
|
2013-04-23 15:38:52 +00:00
|
|
|
import Config.Files
|
2013-01-03 20:34:57 +00:00
|
|
|
import Utility.Yesod
|
2013-11-23 19:50:17 +00:00
|
|
|
import Assistant.Restart
|
2012-09-18 21:50:07 +00:00
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
getRepositorySwitcherR :: Handler Html
|
2013-01-03 20:34:57 +00:00
|
|
|
getRepositorySwitcherR = page "Switch repository" Nothing $ do
|
|
|
|
repolist <- liftIO listOtherRepos
|
|
|
|
$(widgetFile "control/repositoryswitcher")
|
|
|
|
|
|
|
|
listOtherRepos :: IO [(String, String)]
|
|
|
|
listOtherRepos = do
|
2013-03-03 21:07:27 +00:00
|
|
|
dirs <- readAutoStartFile
|
2013-01-03 20:34:57 +00:00
|
|
|
pwd <- getCurrentDirectory
|
2014-02-28 23:16:49 +00:00
|
|
|
gooddirs <- filterM isrepo $
|
2013-03-03 21:07:27 +00:00
|
|
|
filter (\d -> not $ d `dirContains` pwd) dirs
|
2013-01-09 22:59:45 +00:00
|
|
|
names <- mapM relHome gooddirs
|
|
|
|
return $ sort $ zip names gooddirs
|
2014-02-28 23:16:49 +00:00
|
|
|
where
|
|
|
|
isrepo d = doesDirectoryExist (d </> ".git")
|
2013-01-03 20:34:57 +00:00
|
|
|
|
2013-06-27 05:15:28 +00:00
|
|
|
getSwitchToRepositoryR :: FilePath -> Handler Html
|
2012-09-18 21:50:07 +00:00
|
|
|
getSwitchToRepositoryR repo = do
|
2013-06-11 04:06:06 +00:00
|
|
|
liftIO $ addAutoStartFile repo -- make this the new default repo
|
global webapp redirects, to finish upgrades
When an automatic upgrade completes, or when the user clicks on the upgrade
button in one webapp, but also has it open in another browser window/tab,
we have a problem: The current web server is going to stop running in
minutes, but there is no way to send a redirect to the web browser to the
new url.
To solve this, used long polling, so the webapp is always listening for
urls it should redirect to. This allows globally redirecting every open
webapp. Works great! Tested with 2 web browsers with 2 tabs each.
May be useful for other purposes later too, dunno.
The overhead is 2 http requests per page load in the webapp. Due to yesod's
speed, this does not seem to noticibly delay it. Only 1 of the requests
could possibly block the page load, the other is async.
2013-11-23 18:47:38 +00:00
|
|
|
redirect =<< liftIO (newAssistantUrl repo)
|