#{display cid}|]
+
+makeCorrectionsTable whereClause colChoices = do
+ let tableData :: E.InnerJoin (E.InnerJoin (E.SqlExpr (Entity Course))
+ (E.SqlExpr (Entity Sheet )))
+ (E.SqlExpr (Entity Submission))
+ -> E.SqlQuery _
+ tableData (course `E.InnerJoin` sheet `E.InnerJoin` submission) = do
+ E.on $ sheet E.^. SheetId E.==. submission E.^. SubmissionSheet
+ E.on $ course E.^. CourseId E.==. sheet E.^. SheetCourse
+ E.where_ $ whereClause (course,sheet,submission)
+ let crse = ( course E.^. CourseName :: E.SqlExpr (E.Value Text)
+ , course E.^. CourseShorthand
+ , course E.^. CourseTerm
+ , course E.^. CourseSchool :: E.SqlExpr (E.Value SchoolId)
+ )
+ return (submission, sheet, crse)
+ dbTable def $ DBTable
+ { dbtSQLQuery = tableData
+ , dbtColonnade = colChoices
+ , dbtSorting = [ ( "term"
+ , SortColumn $ \(course `E.InnerJoin` _ `E.InnerJoin` _ ) -> course E.^. CourseTerm
+ )
+ , ( "course"
+ , SortColumn $ \(course `E.InnerJoin` _ `E.InnerJoin` _ ) -> course E.^. CourseShorthand
+ )
+ -- TODO
+ ]
+ , dbtFilter = mempty {- [ ( "term"
+ , FilterColumn $ \(course `E.InnerJoin` _ `E.InnerJoin` _ ) tids -> if
+ | Set.null tids -> E.val True :: E.SqlExpr (E.Value Bool)
+ | otherwise -> course E.^. CourseTerm `E.in_` E.valList (Set.toList tids)
+ )
+ ] -}
+ , dbtAttrs = tableDefault
+ , dbtIdent = "corrections" :: Text
+ }
+
+
+getCorrectionsR :: Handler Html
+getCorrectionsR = do
+ uid <- requireAuthId
+ let whereClause = ratedBy uid
+ displayColumns = mconcat
+ [ dbRow
+ , colTerm
+ , colCourse
+ , colSheet
+ , colSubmissionLink
+ ] -- Continue here
+ table <- makeCorrectionsTable whereClause displayColumns
+ defaultLayout $ do
+ setTitleI MsgCourseCorrectionsTitle
+ $(widgetFile "corrections")
+
+getCourseCorrectionsR :: TermId -> Text -> Handler Html
+getCourseCorrectionsR tid csh = do
+ cid <- runDB $ getBy404 $ CourseTermShort tid csh
+ let whereClause = courseIs $ entityKey cid
+ displayColumns = mconcat
+ [ dbRow
+ , colSheet
+ , colCorrector
+ , colSubmissionLink
+ ] -- Continue here
+ table <- makeCorrectionsTable whereClause displayColumns
+ defaultLayout $ do
+ setTitleI MsgCorrectionsTitle
+ $(widgetFile "corrections")
+
+
diff --git a/src/Handler/Term.hs b/src/Handler/Term.hs
index 229aeda10..d847acbd3 100644
--- a/src/Handler/Term.hs
+++ b/src/Handler/Term.hs
@@ -52,7 +52,7 @@ getTermShowR = do
$else
#{termToText termName}
|]
- , sortable (Just "lecture-start") "Beginn Vorlesungen" $ \(Entity _ Term{..},_) ->
+ , sortable (Just "lecture-start") (i18nCell MsgLectureStart) $ \(Entity _ Term{..},_) ->
stringCell $ formatTimeGerWD termLectureStart
, sortable (Just "lecture-end") "Ende Vorlesungen" $ \(Entity _ Term{..},_) ->
stringCell $ formatTimeGerWD termLectureEnd
diff --git a/src/Handler/Utils/Table.hs b/src/Handler/Utils/Table.hs
index bb1f621fd..478bd58ff 100644
--- a/src/Handler/Utils/Table.hs
+++ b/src/Handler/Utils/Table.hs
@@ -35,9 +35,6 @@ numberColonnade = headed "Nr" (fromString.show)
pairColonnade :: (Functor h) => Colonnade h a c -> Colonnade h b c -> Colonnade h (a,b) c
pairColonnade a b = mconcat [ lmap fst a, lmap snd b]
-i18nCell :: RenderMessage site a => a -> Cell site
-i18nCell msg = cell [whamlet|_{msg}|]
-
-- Table Modification
encodeHeadedWidgetTableNumbered :: Attribute -> Colonnade Headed a (WidgetT site IO ()) -> [a] -> WidgetT site IO ()
@@ -94,3 +91,5 @@ headedRowSelector toExternal fromExternal attrs colonnade tdata = do
return ( catMaybes <$> collectResult selectionResults
, encodeCellTable attrs (pairColonnade selColonnade colonnade) (zip [0..] tdata)
)
+
+
diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs
index fff153338..4203f4029 100644
--- a/src/Handler/Utils/Table/Pagination.hs
+++ b/src/Handler/Utils/Table/Pagination.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE NoImplicitPrelude
, ExistentialQuantification
, RecordWildCards
+ , NamedFieldPuns
, OverloadedStrings
, TemplateHaskell
, QuasiQuotes
@@ -18,14 +19,14 @@
module Handler.Utils.Table.Pagination
( SortColumn(..), SortDirection(..)
, FilterColumn(..), IsFilterColumn
- , DBRow(..), DBOutput
+ , DBRow(..), dbRow, DBOutput
, DBTable(..), IsDBTable(..)
, PaginationSettings(..)
, PSValidator(..)
, Sortable(..), sortable
, dbTable
, widgetColonnade, formColonnade
- , textCell, stringCell, anchorCell
+ , textCell, stringCell, i18nCell, anchorCell
, formCell, DBFormResult, getDBFormResult
) where
@@ -55,6 +56,7 @@ import qualified Data.Map as Map
import Data.Profunctor (lmap)
import Colonnade hiding (bool, fromMaybe, singleton)
+import qualified Colonnade (singleton)
import Colonnade.Encode
import Text.Hamlet (hamletFile)
@@ -112,6 +114,9 @@ data DBRow r = DBRow
, dbrOutput :: r
}
+dbRow :: (Headedness h, IsDBTable m a) => Colonnade h (DBRow r) (DBCell m a)
+dbRow = Colonnade.singleton (headednessPure $ textCell MsgNrColumn) $ \DBRow{ dbrIndex } -> textCell $ tshow dbrIndex
+
class DBOutput r r' where
dbProj :: r -> r'
@@ -331,8 +336,9 @@ formColonnade :: (Headedness h, Monoid a)
-> Colonnade h r (DBCell (RWST (Maybe (Env, FileEnv), UniWorX, [Lang]) Enctype Ints (HandlerT UniWorX IO)) (FormResult a))
formColonnade = id
-textCell, stringCell :: (RenderMessage UniWorX msg, IsDBTable m a) => msg -> DBCell m a
+textCell, stringCell, i18nCell :: (RenderMessage UniWorX msg, IsDBTable m a) => msg -> DBCell m a
stringCell = textCell
+i18nCell = textCell
textCell msg = cell [whamlet|_{msg}|]
anchorCell :: IsDBTable m a
diff --git a/src/Utils/Common.hs b/src/Utils/Common.hs
index 3b0d537b8..8583ccf86 100644
--- a/src/Utils/Common.hs
+++ b/src/Utils/Common.hs
@@ -16,7 +16,7 @@ import Language.Haskell.TH
-- Tuples --
------------
-
+-- Alternatively uses lenses: "^. _3" projects the 3rd component of an n-tuple for any n >=3, requires import Control.Lens
projNI :: Int -> Int -> ExpQ -- generic projection gives I-th element of N-tuple, i.e. snd3 = $(projNI 3 2) --ghci -fth
-- $(projN n m) :: (t1,..,tn) -> tm (for m<=n)
projNI n i = lamE [pat] rhs
diff --git a/templates/corrections.hamlet b/templates/corrections.hamlet
new file mode 100644
index 000000000..2d2943787
--- /dev/null
+++ b/templates/corrections.hamlet
@@ -0,0 +1,2 @@
+
+ ^{table}
diff --git a/templates/table/colonnade.hamlet b/templates/table/colonnade.hamlet
index dc27d91ce..147cdebc7 100644
--- a/templates/table/colonnade.hamlet
+++ b/templates/table/colonnade.hamlet
@@ -4,7 +4,8 @@ $newline never
$forall widget <- wHeaders'
- ^{widget} $# cell/header.hamlet
+ $# cell/header.hamlet
+ ^{widget}
$nothing
$if null wRows
@@ -15,4 +16,5 @@ $newline never
$forall row <- wRows
$forall widget <- row
- ^{widget} $# cell/body.hamlet
+ $# cell/body.hamlet
+ ^{widget}