diff --git a/src/Vervis/Handler/Project.hs b/src/Vervis/Handler/Project.hs index 88a0b01..ec9fe11 100644 --- a/src/Vervis/Handler/Project.hs +++ b/src/Vervis/Handler/Project.hs @@ -21,23 +21,35 @@ module Vervis.Handler.Project ) where -import Vervis.Import hiding ((==.)) ---import Prelude +import Prelude + +import Data.Maybe (fromMaybe) +import Data.Text (Text) +import Database.Persist +import Text.Blaze.Html (Html) +import Yesod.Auth (requireAuth) +import Yesod.Core (defaultLayout) +import Yesod.Core.Handler (redirect, setMessage) +import Yesod.Form.Functions (runFormPost) +import Yesod.Form.Types (FormResult (..)) +import Yesod.Persist.Core (runDB, getBy404) + +import qualified Database.Esqueleto as E -import Text.Blaze.Html (toHtml) -import Database.Esqueleto ---import Model ---import Yesod.Core (Handler) import Vervis.Form.Project +import Vervis.Foundation +import Vervis.Model +import Vervis.Model.Repo +import Vervis.Settings getProjectsR :: Text -> Handler Html getProjectsR ident = do - projects <- runDB $ select $ from $ \ (sharer, project) -> do - where_ $ - sharer ^. SharerIdent ==. val ident &&. - sharer ^. SharerId ==. project ^. ProjectSharer - orderBy [asc $ project ^. ProjectIdent] - return $ project ^. ProjectIdent + projects <- runDB $ E.select $ E.from $ \ (sharer, project) -> do + E.where_ $ + sharer E.^. SharerIdent E.==. E.val ident E.&&. + sharer E.^. SharerId E.==. project E.^. ProjectSharer + E.orderBy [E.asc $ project E.^. ProjectIdent] + return $ project E.^. ProjectIdent defaultLayout $(widgetFile "project/list") postProjectsR :: Text -> Handler Html @@ -65,9 +77,10 @@ getProjectNewR ident = do defaultLayout $(widgetFile "project/new") getProjectR :: Text -> Text -> Handler Html -getProjectR user proj = do - project <- runDB $ do - Entity sid _s <- getBy404 $ UniqueSharerIdent user - Entity _pid p <- getBy404 $ UniqueProject proj sid - return p +getProjectR shar proj = do + (project, repos) <- runDB $ do + Entity sid _s <- getBy404 $ UniqueSharerIdent shar + Entity pid p <- getBy404 $ UniqueProject proj sid + rs <- selectList [RepoProject ==. Just pid] [Asc RepoIdent] + return (p, rs) defaultLayout $(widgetFile "project/one") diff --git a/templates/project/list.hamlet b/templates/project/list.hamlet index 703e6bc..c014ddb 100644 --- a/templates/project/list.hamlet +++ b/templates/project/list.hamlet @@ -15,6 +15,6 @@ $# .

These are projects shared by #{ident}.