[adding functionality for happs consultants/happs jobs thomashartman1@gmail.com**20080916095257] hunk ./src/Controller.hs 43 - , exactdir "/tutorial/users" viewAllUsers + -- , exactdir "/tutorial/users" viewAllUsers + , exactdir "/tutorial/consultants" viewConsultants + , exactdir "/tutorial/jobs" viewJobs hunk ./src/Controller.hs 48 - , dir "actions" [ - dir "login" [ methodSP POST $ withData loginPage ] - , dir "newuser" [ methodSP POST $ withData newUserPage ] - , dir "logout" [ logoutPage ] - , dir "accountsettings" [ methodSP POST $ withData accountSettingsPage ] - ] - , dir "users" userProfile + , dir "actions" $ + [ dir "login" [ methodSP POST $ withData loginPage ] + , dir "newuser" [ methodSP POST $ withData newUserPage ] + ] ++ loggedInActions + , dir "users" (userProfile "viewprofile") + , dir "consultants" (userProfile "viewconsultantprofile") -- placeholder, currently just shows all users hunk ./src/Controller.hs 58 +-- to do: add check that that user is logged in +-- http://localhost:5001/tutorial/accountsettings should be an error if not logged in. +loggedInActions = [ dir "logout" [ logoutPage ] + , dir "accountsettings" [ methodSP POST $ withData accountSettingsPage ] ] hunk ./src/Controller.hs 63 +-- placeholder +viewConsultants = [ ServerPartT $ \rq -> do + consultants <- query ListUsers + let url = rqURL $ rq + consultantlist = paintVList (makeListLink url) consultants + tutlayoutReq rq [("consultantList", consultantlist)] "consultants" + ] + +-- placeholder +viewJobs = [ ServerPartT $ \rq -> do + users <- query ListUsers + let url = rqURL rq + joblist = paintVList (makeListLink url) users + tutlayoutReq rq [("jobList", joblist)] "jobs" + ] + +-- this could go in view +-- better yet, use StringTemplate machinery. +paintVList f users = intercalate "
" . map f $ users +makeListLink url x = "" ++ x ++ "" hunk ./src/Controller.hs 84 +{- hunk ./src/Controller.hs 92 +-} hunk ./src/Controller.hs 94 +consultantProfile = userProfile hunk ./src/Controller.hs 96 -userProfile = [ ServerPartT $ \rq -> do +userProfile template = [ ServerPartT $ \rq -> do hunk ./src/Controller.hs 100 + errW msg rq = ( tutlayoutReq rq [("errormsgProfile", msg)] ) template + tutlay rq u = tutlayoutReq rq [("username",username u)] template + -- template = "viewprofile" hunk ./src/Controller.hs 108 - hunk ./src/Controller.hs 109 - where errW msg rq = ( tutlayoutReq rq [("errormsgProfile", msg)] ) "viewprofile" - tutlay rq u = tutlayoutReq rq [("username",username u), ("password", password u)] "viewprofile" hunk ./templates/home.st 11 -
You also get all the goodness +
You also get all the goodness hunk ./templates/home.st 14 -$!
I created this tutorial to popularize the use of my favorite language, haskell, in web applications.
!$ +Unfortunately, the documentation for HAppS is +cringeworthy. +So bad that honestly I wouldn't know where to start to fix it. +
+ ++Instead of tackling the documentation probablem directly, I decided to create an easy-to-install demo project +that included clear step-by-step instructions for getting from zero to final product. + +My hope is simply that that this material will tempt more people to try HAppS out. +With enough users, I believe the documentation and other "batteries not included" issues that +HAppS currently has will simply cease to matter, as the gaps get plugged in a gradual way. + +$! +I created this project, the Real +World HAppS Tutorial, to popularize the use of haskell, with HAppS, in web applications. +!$ +
+ hunk ./templates/menubar.st 11 - | tutorial users + | happs consultants + | happs jobs hunk ./templates/menubar.st 19 -- -$ userList $ + rmfile ./templates/users.st addfile ./templates/viewconsultantprofile.st hunk ./templates/viewconsultantprofile.st 1 - +