From a6525d754911775e8b049a69d1cfa748d688ab1d Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Wed, 17 Feb 2016 16:43:23 +0000 Subject: [PATCH] Add people and person pages --- config/routes | 19 ++++++++++-- src/Application.hs | 1 + src/Foundation.hs | 1 + src/Handler/Home.hs | 1 - src/Handler/Person.hs | 52 +++++++++++++++++++++++++++++++++ templates/default-layout.hamlet | 23 +++++++++++++++ templates/homepage.hamlet | 33 ++++++++++++++------- templates/people.hamlet | 23 +++++++++++++++ templates/person.hamlet | 23 +++++++++++++++ vervis.cabal | 2 ++ 10 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 src/Handler/Person.hs create mode 100644 templates/people.hamlet create mode 100644 templates/person.hamlet diff --git a/config/routes b/config/routes index ed840f6..d085c3f 100644 --- a/config/routes +++ b/config/routes @@ -12,10 +12,25 @@ -- with this software. If not, see -- . -/static StaticR Static appStatic -/auth AuthR Auth getAuth +-- ---------------------------------------------------------------------------- +-- Yesod misc +-- ---------------------------------------------------------------------------- +/static StaticR Static appStatic /favicon.ico FaviconR GET /robots.txt RobotsR GET +-- ---------------------------------------------------------------------------- +-- User signup and login +-- ---------------------------------------------------------------------------- + +/auth AuthR Auth getAuth + +-- ---------------------------------------------------------------------------- +-- Everything else... +-- ---------------------------------------------------------------------------- + / HomeR GET + +/p PeopleR GET +/p/#Text PersonR GET diff --git a/src/Application.hs b/src/Application.hs index 2ca3ce1..7477d2b 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -51,6 +51,7 @@ import System.Log.FastLogger (defaultBufSize, newStdoutLoggerSet, -- Don't forget to add new modules to your cabal file! import Handler.Common import Handler.Home +import Handler.Person -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/src/Foundation.hs b/src/Foundation.hs index fd5a9c5..2243033 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -88,6 +88,7 @@ instance Yesod App where defaultLayout widget = do master <- getYesod mmsg <- getMessage + mperson <- maybeAuth -- We break up the default layout into two components: -- default-layout is the contents of the body tag, and diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index 80850f4..1182d05 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -52,7 +52,6 @@ getHomeR = do dt <- lastChange path ago <- timeAgo dt return (sharer, project, repo, ago) - mp <- maybeAuth defaultLayout $ do setTitle "Welcome to Vervis!" $(widgetFile "homepage") diff --git a/src/Handler/Person.hs b/src/Handler/Person.hs new file mode 100644 index 0000000..3149c13 --- /dev/null +++ b/src/Handler/Person.hs @@ -0,0 +1,52 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +module Handler.Person + ( getPeopleR + , getPersonR + ) +where + +import Import hiding ((==.)) +--import Prelude + +import Text.Blaze (text) +import Database.Esqueleto +--import Model +--import Yesod.Core (Handler) + +getPeopleR :: Handler Html +getPeopleR = do + people <- runDB $ select $ from $ \ (sharer, person) -> do + where_ $ sharer ^. SharerId ==. person ^. PersonIdent + orderBy [asc $ sharer ^. SharerIdent] + return $ sharer ^. SharerIdent + defaultLayout $ do + setTitle "Vervis > People" + $(widgetFile "people") + +getPersonR :: Text -> Handler Html +getPersonR ident = do + people <- runDB $ select $ from $ \ (sharer, person) -> do + where_ $ + sharer ^. SharerIdent ==. val ident &&. + sharer ^. SharerId ==. person ^. PersonIdent + return person + case people of + [] -> notFound + p:ps -> defaultLayout $ do + let mperson = if null ps then Just p else Nothing + setTitle $ text $ "Vervis > People > " <> ident + $(widgetFile "person") diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index 3701e3c..e4080c2 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -1,3 +1,26 @@ +$# This file is part of Vervis. +$# +$# Written in 2016 by fr33domlover . +$# +$# ♡ Copying is an act of love. Please copy, reuse and share. +$# +$# The author(s) have dedicated all copyright and related and neighboring +$# rights to this software to the public domain worldwide. This software is +$# distributed without any warranty. +$# +$# You should have received a copy of the CC0 Public Domain Dedication along +$# with this software. If not, see +$# . + +$maybe Entity _pid person <- mperson +

+ You are logged in as #{personLogin person}. + Log out. +$nothing +

+ You are not logged in. + Log in. + $maybe msg <- mmsg

#{msg} ^{widget} diff --git a/templates/homepage.hamlet b/templates/homepage.hamlet index fd2cf1d..7c7f9ff 100644 --- a/templates/homepage.hamlet +++ b/templates/homepage.hamlet @@ -1,18 +1,25 @@ +$# This file is part of Vervis. +$# +$# Written in 2016 by fr33domlover . +$# +$# ♡ Copying is an act of love. Please copy, reuse and share. +$# +$# The author(s) have dedicated all copyright and related and neighboring +$# rights to this software to the public domain worldwide. This software is +$# distributed without any warranty. +$# +$# You should have received a copy of the CC0 Public Domain Dedication along +$# with this software. If not, see +$# . +

Vervis

Vervis is hopefully going to be, eventually, a decentralized project hosting - platform. At the time of writing (2016-02-14), it is a simple scaffolded - Yesod web application which displays a table of Git repositories. + platform. It's still in early development, but hopefully making progress + fast. -$maybe Entity _pid person <- mp -

- You are logged in as #{personLogin person}. - Log out. -$nothing -

- You are not logged in. - Log in. +

Repos $forall (sharer, proj, repo, ago) <- rows @@ -21,3 +28,9 @@ $nothing
#{proj} #{repo} #{ago} + +

People + +

+ See + people. diff --git a/templates/people.hamlet b/templates/people.hamlet new file mode 100644 index 0000000..571e3bf --- /dev/null +++ b/templates/people.hamlet @@ -0,0 +1,23 @@ +$# This file is part of Vervis. +$# +$# Written in 2016 by fr33domlover . +$# +$# ♡ Copying is an act of love. Please copy, reuse and share. +$# +$# The author(s) have dedicated all copyright and related and neighboring +$# rights to this software to the public domain worldwide. This software is +$# distributed without any warranty. +$# +$# You should have received a copy of the CC0 Public Domain Dedication along +$# with this software. If not, see +$# . + +

Vervis > People + +

+ These are the people registered in this Vervis instance. + +