Skip to content

Commit 1ef6661

Browse files
committed
more
1 parent 21e7b1c commit 1ef6661

File tree

3 files changed

+62
-24
lines changed

3 files changed

+62
-24
lines changed

src/Handler/Admin.hs

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ data AbstractTypeForm =
4949
, abstractTypeFormDuration :: Word64
5050
} deriving Show
5151

52-
mkAbstractTypeForm :: Maybe Text -> Maybe Int -> Form AbstractTypeForm
52+
-- TODO have this function take abstract type and make a form for editing
53+
-- not sure if this should include the ID(?) probably not
54+
-- - seems like the id is not used in the "new" form
55+
-- so we don't need Entitity AbsTyp, only AbsTyp
56+
mkAbstractTypeForm' :: AbstractType -> Form AbstractTypeForm
57+
mkAbstractTypeForm' at = mkAbstractTypeForm (Just $ abstractTypeName at) (Just $ (unpackTalkDuration . abstractTypeDuration) at)
58+
59+
mkAbstractTypeForm :: Maybe Text -> Maybe Word64 -> Form AbstractTypeForm
5360
mkAbstractTypeForm atName atDuration =
5461
renderDivs $
5562
AbstractTypeForm
@@ -91,6 +98,27 @@ renderConferenceAbstractTypes conf@(Entity conferenceId _)
9198
<li>^{renderAbstractTypeEdit conferenceId abstractType}
9299
|]
93100

101+
renderConferenceAbstractType ::
102+
Entity Conference
103+
-> Entity AbstractType
104+
-> Widget
105+
-> Handler Html
106+
renderConferenceAbstractType conf@(Entity conferenceId _)
107+
abstractType@(Entity abstractTypeId _) abstractTypeFormWidget = do
108+
baseLayout Nothing $ do
109+
setTitle "Conference Abstract Type"
110+
[whamlet|
111+
<article .grid-container>
112+
<div .medium-3 .cell>
113+
^{renderConferenceWidget conf}
114+
<div .medium-3 .cell>
115+
<h1> Edit abstract type
116+
<div>
117+
<form method="POST" action=@{ConferenceAbstractTypeR conferenceId abstractTypeId }>
118+
^{abstractTypeFormWidget}
119+
<input .button type="submit" value="Create">
120+
|]
121+
94122
getConferenceAbstractTypesR :: ConferenceId -> Handler Html
95123
getConferenceAbstractTypesR conferenceId = do
96124
(_, _, _, conference) <-
@@ -114,28 +142,34 @@ postConferenceAbstractTypesR conferenceId = do
114142
renderConferenceAbstractTypes conference abstractTypes abstractTypeFormWidget
115143
_ -> error "bluhhh"
116144

145+
-- TODO finish making this handler
117146
getConferenceAbstractTypeR :: ConferenceId -> AbstractTypeId -> Handler Html
118147
getConferenceAbstractTypeR conferenceId abstractTypeId = do
119-
-- (_, _, _, conference) <-
120-
-- requireOwnerForConference conferenceId
121-
abstractType <- runDB $ getAbstractType abstractTypeId
122-
(abstractTypeFormWidget, _) <- generateFormPost abstractTypeForm
123-
renderConferenceAbstractTypes conference abstractTypes abstractTypeFormWidget
124-
125-
postConferenceAbstractTypeR :: ConferenceId -> AbstractTypeId -> Handler Html
126-
postConferenceAbstractTypeR conferenceId abstractTypeId = do
127148
(_, _, _, conference) <-
128149
requireOwnerForConference conferenceId
129-
((result, abstractTypeFormWidget), _) <- runFormPost abstractTypeForm
130-
case result of
131-
FormSuccess (AbstractTypeForm name duration) -> do
132-
abstractTypes <- runDB $ do
133-
void $
134-
insertEntity $
135-
AbstractType (entityKey conference) name (makeTalkDuration duration)
136-
getAbstractTypes (entityKey conference)
137-
renderConferenceAbstractTypes conference abstractTypes abstractTypeFormWidget
138-
_ -> error "bluhhh"
150+
abstractType <- runDBOr404 $ getAbstractTypeByConferenceAndId conferenceId abstractTypeId
151+
(abstractTypeFormWidget, _) <- generateFormPost (mkAbstractTypeForm' (entityVal abstractType))
152+
renderConferenceAbstractType conference abstractType abstractTypeFormWidget
153+
154+
155+
-- TODO make this after building the form
156+
postConferenceAbstractTypeR :: ConferenceId -> AbstractTypeId -> Handler Html
157+
postConferenceAbstractTypeR conferenceId abstractTypeId = undefined
158+
159+
-- postConferenceAbstractTypeR :: ConferenceId -> AbstractTypeId -> Handler Html
160+
-- postConferenceAbstractTypeR conferenceId abstractTypeId = do
161+
-- (_, _, _, conference) <-
162+
-- requireOwnerForConference conferenceId
163+
-- ((result, abstractTypeFormWidget), _) <- runFormPost abstractTypeForm
164+
-- case result of
165+
-- FormSuccess (AbstractTypeForm name duration) -> do
166+
-- abstractTypes <- runDB $ do
167+
-- void $
168+
-- insertEntity $
169+
-- AbstractType (entityKey conference) name (makeTalkDuration duration)
170+
-- getAbstractTypes (entityKey conference)
171+
-- renderConferenceAbstractTypes conference abstractTypes abstractTypeFormWidget
172+
-- _ -> error "bluhhh"
139173

140174
renderAbstractTypeEdit :: ConferenceId -> Entity AbstractType -> Widget
141175
renderAbstractTypeEdit confId (Entity atId (AbstractType _ name td)) =

src/Model/API.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,13 @@ getAbstractTypes :: ConferenceId -> DB [Entity AbstractType]
323323
getAbstractTypes conferenceId =
324324
getRecsByField AbstractTypeConference conferenceId
325325

326-
getAbstractType :: AbstractTypeId -> DB [Entity AbstractType]
327-
getAbstractType abstractTypeId =
328-
getRecsByField AbstractTypeId abstractTypeId
326+
getAbstractTypeByConferenceAndId :: ConferenceId -> AbstractTypeId -> DB (Maybe (Entity AbstractType))
327+
getAbstractTypeByConferenceAndId confId atId =
328+
selectFirst $
329+
from $ \(abstractType) -> do
330+
where_ (abstractType ^. AbstractTypeConference ==. val confId)
331+
where_ (abstractType ^. AbstractTypeId ==. val atId)
332+
pure abstractType
329333

330334
getAbstractsForConference :: ConferenceId
331335
-> DB [(Entity Abstract, Entity AbstractType)]

src/Model/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ renderMarkdown (Markdown md) = do
118118
Left err -> throwIO (PandocRenderingFailed err md)
119119
(Right html) -> return html
120120

121-
newtype ConferenceSlug =
121+
newtype ConferenceSlug =
122122
ConferenceSlug { unConferenceSlug :: Text }
123123
deriving (Eq, Show, Read, PathPiece, PersistField, PersistFieldSql)
124124

@@ -130,5 +130,5 @@ makeConferenceSlug = ConferenceSlug
130130
defaultConferenceSlug :: Text -> ConferenceSlug
131131
defaultConferenceSlug = makeConferenceSlug . filter ( /= ' ')
132132

133-
displayConferenceSlug :: ConferenceSlug -> Text
133+
displayConferenceSlug :: ConferenceSlug -> Text
134134
displayConferenceSlug = decodeUtf8 . urlEncode False . encodeUtf8 . unConferenceSlug

0 commit comments

Comments
 (0)