Commit ad628cfe authored by Christopher League's avatar Christopher League 🖥

Work toward initial query form

parent e47f05e2
......@@ -11,7 +11,7 @@ module Handler.Home where
import Control.Lens ((^.))
import Data.Time.Clock (addUTCTime)
import Data.Time.Zones (utcToLocalTimeTZ)
import Data.Time.Zones.All (tzByLabel)
import Data.Time.Zones.All (tzByLabel, toTZName)
import Import
import qualified Network.Google as Google
import Network.Google.AppsCalendar (calendarListList, clItems,
......@@ -20,6 +20,38 @@ import Text.Julius (RawJS (..))
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..),
renderBootstrap3)
data QueryForm = QueryForm
{ queryLocation :: Location
-- , queryTimeZone :: TZLabel
}
locationOptions :: Handler (OptionList Location)
locationOptions = do
locs <- appLocations . appSettings <$> getYesod
let
mkOpt loc@Location{..} = Option locDescr loc (tshow locId)
readOpt i = find ((== i) . locId) locs
return $ OptionList (map mkOpt locs) (readMay >=> readOpt)
queryForm :: Maybe QueryForm -> Form QueryForm
queryForm defaultQ =
renderBootstrap3 BootstrapBasicForm $
QueryForm <$> areq (radioField locationOptions) "Location" (queryLocation <$> defaultQ)
-- <*> areq (selectField _) "
getHomeR :: Handler Html
getHomeR = do
AppSettings{..} <- appSettings <$> getYesod
let appLengths = [15, 20, 25] :: [Int]
defaultLength = 20
lengthRadios = zip appLengths (map (== defaultLength) appLengths)
let currentTz = decodeUtf8 (toTZName appDefaultTimeZone)
defaultQ = QueryForm <$> headMay appLocations
tzs = map (decodeUtf8 . toTZName) [minBound..maxBound]
(formWidget, formEnctype) <- generateFormPost $ queryForm defaultQ
defaultLayout
$(widgetFile "step1")
-- Define our data that will be used for creating the form.
data FileForm = FileForm
{ fileInfo :: FileInfo
......@@ -33,8 +65,8 @@ data FileForm = FileForm
-- The majority of the code you will write in Yesod lives in these handler
-- functions. You can spread them across multiple files if you are so
-- inclined, or create a single monolithic file.
getHomeR :: Handler Html
getHomeR = do
oldgetHomeR :: Handler Html
oldgetHomeR = do
(formWidget, formEnctype) <- generateFormPost sampleForm
let submission = Nothing :: Maybe FileForm
handlerName = "getHomeR" :: Text
......
......@@ -31,6 +31,16 @@ import Yesod.Default.Util (WidgetFileSettings,
widgetFileNoReload,
widgetFileReload)
data Location = Location
{ locId :: Int
, locSearch :: Text
, locDescr :: Text
} deriving (Show, Eq)
makeLocs :: [(Text,Text)] -> [Location]
makeLocs = zipWith mk [1..]
where mk i (s,d) = Location i s d
-- | Runtime settings to configure this application. These settings can be
-- loaded from various sources: defaults, environment variables, config files,
-- theoretically even a database.
......@@ -65,7 +75,7 @@ data AppSettings = AppSettings
, appAnalytics :: Maybe Text
-- ^ Google Analytics code
, appDefaultTimeZone :: TZLabel
, appLocations :: [(Text,Text)]
, appLocations :: [Location]
, appFreeCalendarId :: Text
, appBusyCalendarId :: Text
, appLookahead :: NominalDiffTime
......@@ -104,7 +114,7 @@ instance FromJSON AppSettings where
appCopyright <- o .: "copyright"
appAnalytics <- o .:? "analytics"
appDefaultTimeZone <- unwrapTZLabel <$> o .: "time-zone"
appLocations <- o .: "locations"
appLocations <- makeLocs <$> o .: "locations"
appFreeCalendarId <- o .: "free-calendar"
appBusyCalendarId <- o .: "busy-calendar"
appLookahead <- (7*24*60*60*) <$> o .: "look-ahead-weeks"
......
<!-- Static navbar -->
<nav .navbar.navbar-default.navbar-static-top>
<div .container>
<div .navbar-header>
<button type="button" .navbar-toggle.collapsed data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<div #navbar .collapse.navbar-collapse>
<ul .nav.navbar-nav>
$forall MenuItem label route _ <- navbarLeftFilteredMenuItems
<li :Just route == mcurrentRoute:.active>
<a href="@{route}">#{label}
<ul .nav.navbar-nav.navbar-right>
$forall MenuItem label route _ <- navbarRightFilteredMenuItems
<li :Just route == mcurrentRoute:.active>
<a href="@{route}">#{label}
<!-- Page Contents -->
<div .container>
......@@ -35,13 +14,10 @@
<div .alert.alert-info #message>#{msg}
$if (Just HomeR == mcurrentRoute)
^{widget}
$else
<div .container>
<div .row>
<div .col-md-12>
^{widget}
<div .container>
<div .row>
<div .col-md-12>
^{widget}
<!-- Footer -->
<footer .footer>
......
<h2>Book an appointment
<p style="line-height:2.5">
Show
<select>
<option>15 minute
<option>20 minute
<option>25 minute
slots using
<select>
<option>12-hour (AM/PM)
<option>24-hour
notation in
#{currentTz}
time zone:
<div .form-group>
$forall loc <- appLocations
<div .radio>
<label>
<input name=meetloc type=radio value=#{locId loc}>#{locDescr loc}
<p style="font-size:150%">
<span .glyphicon.glyphicon-off.fast-right-spinner>
/* step1.lucius -*- css -*- */
/* Glyphicons spinner from https://bootsnipp.com/snippets/djeAk */
.fast-right-spinner {
-webkit-animation: glyphicon-spin-r 1s infinite linear;
animation: glyphicon-spin-r 1s infinite linear;
}
@-webkit-keyframes glyphicon-spin-r {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@keyframes glyphicon-spin-r {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment