diff --git a/Assistant/Threads/WebApp.hs b/Assistant/Threads/WebApp.hs index a91a198e9f..58e7de1f69 100644 --- a/Assistant/Threads/WebApp.hs +++ b/Assistant/Threads/WebApp.hs @@ -25,6 +25,7 @@ import Assistant.WebApp.Configurators.AWS import Assistant.WebApp.Configurators.WebDAV import Assistant.WebApp.Configurators.XMPP import Assistant.WebApp.Documentation +import Assistant.WebApp.Control import Assistant.WebApp.OtherRepos import Assistant.Types.ThreadedMonad import Utility.WebApp diff --git a/Assistant/WebApp.hs b/Assistant/WebApp.hs index c311cb21dd..b7165d5238 100644 --- a/Assistant/WebApp.hs +++ b/Assistant/WebApp.hs @@ -25,7 +25,9 @@ inFirstRun = isNothing . relDir <$> getYesod newWebAppState :: IO (TMVar WebAppState) newWebAppState = do - otherrepos <- listOtherRepos + cwd <- getCurrentDirectory + otherrepos <- filter (\p -> not (snd p `dirContains` cwd)) + <$> listRepos atomically $ newTMVar $ WebAppState { showIntro = True , otherRepos = otherrepos } @@ -101,14 +103,13 @@ redirectBack = do setUltDestReferer redirectUltDest HomeR -{- List of other known repsitories, and link to add a new one. -} -otherReposWidget :: Widget -otherReposWidget = do +controlMenu :: Widget +controlMenu = do repolist <- lift $ otherRepos <$> getWebAppState - $(widgetFile "otherrepos") + $(widgetFile "controlmenu") -listOtherRepos :: IO [(String, String)] -listOtherRepos = do +listRepos :: IO [(String, String)] +listRepos = do f <- autoStartFile dirs <- nub <$> ifM (doesFileExist f) ( lines <$> readFile f, return []) names <- mapM relHome dirs diff --git a/Assistant/WebApp/Control.hs b/Assistant/WebApp/Control.hs new file mode 100644 index 0000000000..f87b22941f --- /dev/null +++ b/Assistant/WebApp/Control.hs @@ -0,0 +1,28 @@ +{- git-annex assistant webapp control + - + - Copyright 2012 Joey Hess + - + - Licensed under the GNU AGPL version 3 or higher. + -} + +{-# LANGUAGE CPP, TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings, RankNTypes #-} + +module Assistant.WebApp.Control where + +import Assistant.WebApp.Common + +import Control.Concurrent +import System.Posix (getProcessID, signalProcess, sigTERM) + +getShutdownR :: Handler RepHtml +getShutdownR = page "Shutdown" Nothing $ + $(widgetFile "control/shutdown") + +getShutdownConfirmedR :: Handler RepHtml +getShutdownConfirmedR = page "Shutdown" Nothing $ do + {- Wait 2 seconds before shutting down, to give the web page time + - to display. -} + void $ liftIO $ forkIO $ do + threadDelay 2000000 + signalProcess sigTERM =<< getProcessID + $(widgetFile "control/shutdownconfirmed") diff --git a/Assistant/WebApp/routes b/Assistant/WebApp/routes index 1760d79c45..c41e886429 100644 --- a/Assistant/WebApp/routes +++ b/Assistant/WebApp/routes @@ -5,6 +5,9 @@ /about/license LicenseR GET /about/repogroups RepoGroupR GET +/shutdown ShutdownR GET +/shutdown/confirm ShutdownConfirmedR GET + /config ConfigurationR GET /config/repository RepositoriesR GET /config/xmpp XMPPR GET diff --git a/debian/changelog b/debian/changelog index 4697600216..39707c6c27 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +git-annex (3.20130103) UNRELEASED; urgency=low + + * webapp: Add UI to stop assistant. + + -- Joey Hess Thu, 03 Jan 2013 14:58:45 -0400 + git-annex (3.20130102) unstable; urgency=low * direct, indirect: New commands, that switch a repository to and from diff --git a/doc/assistant/controlmenu.png b/doc/assistant/controlmenu.png new file mode 100644 index 0000000000..397dbe93bd Binary files /dev/null and b/doc/assistant/controlmenu.png differ diff --git a/templates/control/shutdown.hamlet b/templates/control/shutdown.hamlet new file mode 100644 index 0000000000..a1a9d72df2 --- /dev/null +++ b/templates/control/shutdown.hamlet @@ -0,0 +1,8 @@ +
+

+ Shutdown daemon? +

+ + Confirm shutdown + + Keep running diff --git a/templates/control/shutdownconfirmed.hamlet b/templates/control/shutdownconfirmed.hamlet new file mode 100644 index 0000000000..18270f588c --- /dev/null +++ b/templates/control/shutdownconfirmed.hamlet @@ -0,0 +1,2 @@ +

+ Shutting down... diff --git a/templates/otherrepos.hamlet b/templates/controlmenu.hamlet similarity index 55% rename from templates/otherrepos.hamlet rename to templates/controlmenu.hamlet index f1738f2f0d..4fab8beedb 100644 --- a/templates/otherrepos.hamlet +++ b/templates/controlmenu.hamlet @@ -2,9 +2,11 @@ $forall (name, path) <- repolist
  • - #{name} + #{name} $if not (null repolist)
  • - Add another repository + Add another repository + + Shut down diff --git a/templates/page.hamlet b/templates/page.hamlet index a42b374c85..1f88a69c94 100644 --- a/templates/page.hamlet +++ b/templates/page.hamlet @@ -16,7 +16,7 @@ Current Repository: #{reldir} - ^{otherReposWidget} + ^{controlMenu} $nothing