show who's working
This commit is contained in:
parent
104500869e
commit
ed0e956dbc
@ -7,12 +7,26 @@ import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, bfs)
|
|||||||
import Handler.TagUtils
|
import Handler.TagUtils
|
||||||
|
|
||||||
import Handler.Tables
|
import Handler.Tables
|
||||||
|
import Handler.Shared
|
||||||
|
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
import Data.Time.LocalTime
|
import Data.Time.LocalTime
|
||||||
|
|
||||||
|
import Data.Text
|
||||||
|
|
||||||
import qualified Yesod.Table as Table
|
import qualified Yesod.Table as Table
|
||||||
|
|
||||||
|
data AchievementInfo = AchievementInfo {
|
||||||
|
achievementInfoName :: Text,
|
||||||
|
achievementInfoDescription :: Maybe Text,
|
||||||
|
achievementInfoPoints :: Int,
|
||||||
|
achievementInfoDeadline :: UTCTime,
|
||||||
|
achievementInfoMaxWinners :: Maybe Int,
|
||||||
|
achievementInfoWorkingOn :: [Entity User],
|
||||||
|
achievementInfoCurrentUser :: Maybe (Entity User) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getAchievementsR :: Handler Html
|
getAchievementsR :: Handler Html
|
||||||
getAchievementsR = do
|
getAchievementsR = do
|
||||||
(formWidget, formEnctype) <- generateFormPost achievementForm
|
(formWidget, formEnctype) <- generateFormPost achievementForm
|
||||||
@ -42,6 +56,8 @@ postAchievementsR = do
|
|||||||
|
|
||||||
doAchievements mUser formWidget formEnctype = do
|
doAchievements mUser formWidget formEnctype = do
|
||||||
achievements <- runDB $ selectList [] [Asc AchievementName]
|
achievements <- runDB $ selectList [] [Asc AchievementName]
|
||||||
|
mUser <- maybeAuth
|
||||||
|
achievementInfos <- runDB $ mapM (getAchievementInfo mUser) achievements
|
||||||
|
|
||||||
tagsAvailableAsJSON <- runDB $ getAvailableTagsAsJSON
|
tagsAvailableAsJSON <- runDB $ getAvailableTagsAsJSON
|
||||||
|
|
||||||
@ -49,13 +65,30 @@ doAchievements mUser formWidget formEnctype = do
|
|||||||
setTitle "Achievements"
|
setTitle "Achievements"
|
||||||
$(widgetFile "achievements")
|
$(widgetFile "achievements")
|
||||||
|
|
||||||
achievementsTable :: Table.Table App (Entity Achievement)
|
getAchievementInfo mUser (Entity achievementId achievement) = do
|
||||||
|
es <- selectList [WorkingOnAchievement ==. achievementId] []
|
||||||
|
let userIds = Import.map (workingOnUser . entityVal) es
|
||||||
|
users <- mapM get404 userIds
|
||||||
|
|
||||||
|
return $ AchievementInfo {
|
||||||
|
achievementInfoName = achievementName achievement,
|
||||||
|
achievementInfoDescription = achievementDescription achievement,
|
||||||
|
achievementInfoPoints = achievementPoints achievement,
|
||||||
|
achievementInfoDeadline = achievementDeadline achievement,
|
||||||
|
achievementInfoMaxWinners = achievementMaxWinners achievement,
|
||||||
|
achievementInfoWorkingOn = Import.map (\(i,v) -> Entity i v) $ Import.zip userIds users,
|
||||||
|
achievementInfoCurrentUser = mUser }
|
||||||
|
|
||||||
|
achievementsTable :: Table.Table App (AchievementInfo)
|
||||||
achievementsTable = mempty
|
achievementsTable = mempty
|
||||||
++ Table.text "achievement" (\(Entity _ achievement) -> achievementName achievement)
|
++ Table.text "achievement" achievementInfoName
|
||||||
++ Table.text "description" (\(Entity _ achievement) -> (fromMaybe (""::Text) (achievementDescription achievement)))
|
++ Table.text "description" (fromMaybe (""::Text) . achievementInfoDescription)
|
||||||
++ Table.int "points" (\(Entity _ achievement) -> achievementPoints achievement)
|
++ Table.int "points" achievementInfoPoints
|
||||||
++ timestampCell "deadline" (\(Entity _ achievement) -> achievementDeadline achievement)
|
++ timestampCell "deadline" achievementInfoDeadline
|
||||||
++ Table.string "max submitters" (\(Entity _ achievement) -> formatMaxSubmitters $ achievementMaxWinners achievement)
|
++ Table.string "max submitters" (formatMaxSubmitters . achievementInfoMaxWinners)
|
||||||
|
++ Table.text "who's working on it?" (formatSubmitters . achievementInfoWorkingOn)
|
||||||
|
|
||||||
|
formatSubmitters userEnts = Data.Text.intercalate ", " $ Import.map (formatSubmitter . entityVal) userEnts
|
||||||
|
|
||||||
formatMaxSubmitters :: Maybe Int -> String
|
formatMaxSubmitters :: Maybe Int -> String
|
||||||
formatMaxSubmitters Nothing = "no limit"
|
formatMaxSubmitters Nothing = "no limit"
|
||||||
|
@ -95,4 +95,8 @@ AchievementTag
|
|||||||
achievement AchievementId
|
achievement AchievementId
|
||||||
tag TagId
|
tag TagId
|
||||||
UniqueAchievementTag achievement tag
|
UniqueAchievementTag achievement tag
|
||||||
|
WorkingOn
|
||||||
|
achievement AchievementId
|
||||||
|
user UserId
|
||||||
|
UniqueWorkingOnAchievementUser achievement user
|
||||||
-- By default this file is used in Model.hs (which is imported by Foundation.hs)
|
-- By default this file is used in Model.hs (which is imported by Foundation.hs)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<h1>Achievements
|
<h1>Achievements
|
||||||
|
|
||||||
^{Table.buildBootstrap achievementsTable achievements}
|
^{Table.buildBootstrap achievementsTable achievementInfos}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user