From aa5b2f1c3c54e84156b6a5a38f226fa12d81607f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 11 Oct 2013 00:45:46 -0400 Subject: [PATCH] basic fsck form UI --- Assistant/WebApp/Configurators/Fsck.hs | 57 +++++++++++++++++++++++- Assistant/WebApp/routes | 2 +- templates/configurators/fsck.hamlet | 14 ++++++ templates/configurators/fsck/form.hamlet | 9 ++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 templates/configurators/fsck.hamlet create mode 100644 templates/configurators/fsck/form.hamlet diff --git a/Assistant/WebApp/Configurators/Fsck.hs b/Assistant/WebApp/Configurators/Fsck.hs index 1c88f7f7f2..bc43eeb26a 100644 --- a/Assistant/WebApp/Configurators/Fsck.hs +++ b/Assistant/WebApp/Configurators/Fsck.hs @@ -10,8 +10,61 @@ module Assistant.WebApp.Configurators.Fsck where +import qualified Data.Map as M +import qualified Data.Text as T +import qualified Text.Hamlet as Hamlet + import Assistant.WebApp.Common +import Types.ScheduledActivity +import Utility.HumanTime +import Utility.Scheduled + +fsckForm :: ScheduledActivity -> Hamlet.Html -> MkMForm ScheduledActivity +fsckForm (ScheduledSelfFsck (Schedule r t) d) msg = do + (durationRes, durationView) <- mreq intField "" (Just $ durationSeconds d `quot` 60 ) + (timeRes, timeView) <- mreq (selectFieldList times) "" (Just t) + (recurranceRes, recurranceView) <- mreq (selectFieldList recurrances) "" (Just r) + let form = do + webAppFormAuthToken + $(widgetFile "configurators/fsck/form") + let formresult = ScheduledSelfFsck + <$> (Schedule <$> recurranceRes <*> timeRes) + <*> (Duration <$> durationRes) + return (formresult, form) + where + times :: [(Text, ScheduledTime)] + times = ensurevalue t (T.pack $ fromScheduledTime t) $ + map (\x -> (T.pack $ fromScheduledTime x, x)) $ + AnyTime : map (\h -> SpecificTime h 0) [0..23] + recurrances :: [(Text, Recurrance)] + recurrances = ensurevalue r (T.pack $ fromRecurrance r) $ + [ ("every day", Daily) + , ("every Sunday", Weekly 1) + , ("every Monday", Weekly 2) + , ("every Tuesday", Weekly 3) + , ("every Wednesday", Weekly 4) + , ("every Thursday", Weekly 5) + , ("every Friday", Weekly 6) + , ("every Saturday", Weekly 7) + , ("on the 1st of the month", Monthly 1) + , ("mid-month", Monthly 15) + , ("once a year", Yearly 1) + , ("twice a year", (Divisible 6 $ Monthly 1)) + , ("quarterly", (Divisible 4 $ Monthly 1)) + ] + ensurevalue v desc l = case M.lookup v (M.fromList $ map (\(x,y) -> (y,x)) l) of + Just _ -> l + Nothing -> (desc, v) : l +fsckForm (ScheduledRemoteFsck u s d) _msg = error "TODO" + +defaultFsck :: ScheduledActivity +defaultFsck = ScheduledSelfFsck (Schedule Daily AnyTime) (Duration $ 60*60) getConfigFsckR :: Handler Html -getConfigFsckR = page "Consistency checks" (Just Configuration) $ do - error "TODO" +getConfigFsckR = postConfigFsckR +postConfigFsckR :: Handler Html +postConfigFsckR = page "Consistency checks" (Just Configuration) $ do + ((res, form), enctype) <- liftH $ runFormPost $ fsckForm defaultFsck + case res of + FormSuccess s -> error "TODO" + _ -> $(widgetFile "configurators/fsck") diff --git a/Assistant/WebApp/routes b/Assistant/WebApp/routes index 3b44c03136..e942b41e1c 100644 --- a/Assistant/WebApp/routes +++ b/Assistant/WebApp/routes @@ -19,7 +19,7 @@ /config/xmpp/for/self XMPPConfigForPairSelfR GET POST /config/xmpp/for/frield XMPPConfigForPairFriendR GET POST /config/xmpp/needcloudrepo/#UUID NeedCloudRepoR GET -/config/fsck ConfigFsckR GET +/config/fsck ConfigFsckR GET POST /config/addrepository AddRepositoryR GET /config/repository/new NewRepositoryR GET POST diff --git a/templates/configurators/fsck.hamlet b/templates/configurators/fsck.hamlet new file mode 100644 index 0000000000..3e2d60a6bb --- /dev/null +++ b/templates/configurators/fsck.hamlet @@ -0,0 +1,14 @@ +
+

+ Consistency checks +

+ Checking the contents of a repository periodically will ensure that # + your data is in good shape. Any problems that are detected will # + be automatically fixed. +

+ Running the consistency check involves reading all the files in the # + repository, which can take a long time if it's large. Running just a # + little at a time will eventually check the whole repository. +

+

+ ^{form} diff --git a/templates/configurators/fsck/form.hamlet b/templates/configurators/fsck/form.hamlet new file mode 100644 index 0000000000..3ae62709a8 --- /dev/null +++ b/templates/configurators/fsck/form.hamlet @@ -0,0 +1,9 @@ +#{msg} +

+

+ Check this repository for # + ^{fvInput durationView} minutes # + starting at ^{fvInput timeView} + ^{fvInput recurranceView} +