feat(course-teaser): unpolished version of course-teaser for course list
This commit is contained in:
parent
8a49979ecc
commit
ea5d54b213
@ -48,11 +48,11 @@ import Generics.Deriving.Monoid (memptydefault, mappenddefault)
|
|||||||
|
|
||||||
|
|
||||||
-- NOTE: Outdated way to use dbTable; see ProfileDataR Handler for a more recent method.
|
-- NOTE: Outdated way to use dbTable; see ProfileDataR Handler for a more recent method.
|
||||||
type CourseTableData = DBRow (Entity Course, Int, Bool, Entity School)
|
type CourseTableData = DBRow (Entity Course, Int, Bool, Entity School, [Entity User])
|
||||||
|
|
||||||
colCourse :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colCourse :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colCourse = sortable (Just "course") (i18nCell MsgCourse)
|
colCourse = sortable (Just "course") (i18nCell MsgCourse)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } ->
|
||||||
anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR)
|
anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR)
|
||||||
[whamlet|_{courseName}|]
|
[whamlet|_{courseName}|]
|
||||||
|
|
||||||
@ -63,14 +63,14 @@ colCourse = sortable (Just "course") (i18nCell MsgCourse)
|
|||||||
|
|
||||||
colDescription :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colDescription :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colDescription = sortable Nothing mempty
|
colDescription = sortable Nothing mempty
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } ->
|
||||||
case courseDescription of
|
case courseDescription of
|
||||||
Nothing -> mempty
|
Nothing -> mempty
|
||||||
(Just descr) -> cell $ modal (toWidget $ hasComment True) (Right $ toWidget descr)
|
(Just descr) -> cell $ modal (toWidget $ hasComment True) (Right $ toWidget descr)
|
||||||
|
|
||||||
colCShort :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colCShort :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colCShort = sortable (Just "cshort") (i18nCell MsgCourseShort)
|
colCShort = sortable (Just "cshort") (i18nCell MsgCourseShort)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } ->
|
||||||
anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR) [whamlet|_{courseShorthand}|]
|
anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR) [whamlet|_{courseShorthand}|]
|
||||||
|
|
||||||
-- colCShortDescr :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
-- colCShortDescr :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
@ -89,39 +89,39 @@ colCShort = sortable (Just "cshort") (i18nCell MsgCourseShort)
|
|||||||
|
|
||||||
colTerm :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colTerm :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colTerm = sortable (Just "term") (i18nCell MsgTerm)
|
colTerm = sortable (Just "term") (i18nCell MsgTerm)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } ->
|
||||||
anchorCell (TermCourseListR courseTerm) [whamlet|#{courseTerm}|]
|
anchorCell (TermCourseListR courseTerm) [whamlet|#{courseTerm}|]
|
||||||
|
|
||||||
colSchool :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colSchool :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colSchool = sortable (Just "school") (i18nCell MsgCourseSchool)
|
colSchool = sortable (Just "school") (i18nCell MsgCourseSchool)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, Entity _ School{..}) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, Entity _ School{..}, _) } ->
|
||||||
anchorCell (TermSchoolCourseListR courseTerm courseSchool) [whamlet|_{schoolName}|]
|
anchorCell (TermSchoolCourseListR courseTerm courseSchool) [whamlet|_{schoolName}|]
|
||||||
|
|
||||||
colSchoolShort :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colSchoolShort :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colSchoolShort = sortable (Just "schoolshort") (i18nCell MsgCourseSchoolShort)
|
colSchoolShort = sortable (Just "schoolshort") (i18nCell MsgCourseSchoolShort)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, Entity _ School{..}) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, Entity _ School{..}, _) } ->
|
||||||
anchorCell (TermSchoolCourseListR courseTerm courseSchool) [whamlet|_{schoolShorthand}|]
|
anchorCell (TermSchoolCourseListR courseTerm courseSchool) [whamlet|_{schoolShorthand}|]
|
||||||
|
|
||||||
colRegFrom :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colRegFrom :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colRegFrom = sortable (Just "register-from") (i18nCell MsgRegisterFrom)
|
colRegFrom = sortable (Just "register-from") (i18nCell MsgRegisterFrom)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } ->
|
||||||
maybe mempty dateTimeCell courseRegisterFrom
|
maybe mempty dateTimeCell courseRegisterFrom
|
||||||
-- cell $ traverse (formatTime SelFormatDateTime) courseRegisterFrom >>= maybe mempty toWidget
|
-- cell $ traverse (formatTime SelFormatDateTime) courseRegisterFrom >>= maybe mempty toWidget
|
||||||
|
|
||||||
colRegTo :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colRegTo :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colRegTo = sortable (Just "register-to") (i18nCell MsgRegisterTo)
|
colRegTo = sortable (Just "register-to") (i18nCell MsgRegisterTo)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _) } ->
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } ->
|
||||||
maybe mempty dateTimeCell courseRegisterTo
|
maybe mempty dateTimeCell courseRegisterTo
|
||||||
|
|
||||||
colMembers :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colMembers :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colMembers = sortable (Just "members") (i18nCell MsgCourseMembers)
|
colMembers = sortable (Just "members") (i18nCell MsgCourseMembers)
|
||||||
$ \DBRow{ dbrOutput=(Entity _ Course{..}, currentParticipants, _, _) } -> i18nCell $ case courseCapacity of
|
$ \DBRow{ dbrOutput=(Entity _ Course{..}, currentParticipants, _, _, _) } -> i18nCell $ case courseCapacity of
|
||||||
Nothing -> MsgCourseMembersCount currentParticipants
|
Nothing -> MsgCourseMembersCount currentParticipants
|
||||||
Just limit -> MsgCourseMembersCountLimited currentParticipants limit
|
Just limit -> MsgCourseMembersCountLimited currentParticipants limit
|
||||||
|
|
||||||
colRegistered :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
colRegistered :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a)
|
||||||
colRegistered = sortable (Just "registered") (i18nCell MsgRegistered)
|
colRegistered = sortable (Just "registered") (i18nCell MsgRegistered)
|
||||||
$ \DBRow{ dbrOutput=(_, _, registered, _) } -> tickmarkCell registered
|
$ \DBRow{ dbrOutput=(_, _, registered, _, _) } -> tickmarkCell registered
|
||||||
|
|
||||||
type CourseTableExpr = E.SqlExpr (Entity Course) `E.InnerJoin` E.SqlExpr (Entity School)
|
type CourseTableExpr = E.SqlExpr (Entity Course) `E.InnerJoin` E.SqlExpr (Entity School)
|
||||||
|
|
||||||
@ -146,8 +146,14 @@ makeCourseTable whereClause colChoices psValidator = do
|
|||||||
let registered = course2Registered muid qin
|
let registered = course2Registered muid qin
|
||||||
E.where_ $ whereClause (course, participants, registered)
|
E.where_ $ whereClause (course, participants, registered)
|
||||||
return (course, participants, registered, school)
|
return (course, participants, registered, school)
|
||||||
|
lecturerQuery cid (user `E.InnerJoin` lecturer) = do
|
||||||
|
E.on $ user E.^. UserId E.==. lecturer E.^. LecturerUser
|
||||||
|
E.where_ $ E.val cid E.==. lecturer E.^. LecturerCourse
|
||||||
|
return user
|
||||||
dbtProj :: DBRow _ -> MaybeT (ReaderT SqlBackend (HandlerT UniWorX IO)) CourseTableData
|
dbtProj :: DBRow _ -> MaybeT (ReaderT SqlBackend (HandlerT UniWorX IO)) CourseTableData
|
||||||
dbtProj = traverse $ \(course, E.Value participants, E.Value registered, school) -> return (course, participants, registered, school)
|
dbtProj = traverse $ \(course, E.Value participants, E.Value registered, school) -> do
|
||||||
|
lecturerList <- lift $ E.select $ E.from $ lecturerQuery $ entityKey course
|
||||||
|
return (course, participants, registered, school, lecturerList)
|
||||||
snd <$> dbTable psValidator DBTable
|
snd <$> dbTable psValidator DBTable
|
||||||
{ dbtSQLQuery
|
{ dbtSQLQuery
|
||||||
, dbtRowKey = \(course `E.InnerJoin` _) -> course E.^. CourseId
|
, dbtRowKey = \(course `E.InnerJoin` _) -> course E.^. CourseId
|
||||||
@ -205,8 +211,8 @@ makeCourseTable whereClause colChoices psValidator = do
|
|||||||
]
|
]
|
||||||
, dbtStyle = def
|
, dbtStyle = def
|
||||||
{ dbsFilterLayout = defaultDBSFilterLayout
|
{ dbsFilterLayout = defaultDBSFilterLayout
|
||||||
-- DBSTCourse :: Lens' r (Entity Course) -> Traversal' r (Entity User) -> Lens' r Bool -> DBSTemplateMode r
|
-- DBSTCourse :: Lens' r (Entity Course) -> Traversal' r ([Entity User]) -> Lens' r Bool -> DBSTemplateMode r
|
||||||
, dbsCellTemplate = DBSTCourse (_dbrOutput . _1) ignored (_dbrOutput . _3)
|
, dbsCellTemplate = DBSTCourse (_dbrOutput . _1) (_dbrOutput . _5) (_dbrOutput . _3)
|
||||||
-- ^ course lens ^ lecturers traversal ^ isRegistered lens
|
-- ^ course lens ^ lecturers traversal ^ isRegistered lens
|
||||||
}
|
}
|
||||||
, dbtParams = def
|
, dbtParams = def
|
||||||
|
|||||||
@ -391,7 +391,7 @@ data DBStyle r = DBStyle
|
|||||||
, dbsCellTemplate :: DBSTemplateMode r
|
, dbsCellTemplate :: DBSTemplateMode r
|
||||||
}
|
}
|
||||||
|
|
||||||
data DBSTemplateMode r = DBSTDefault | DBSTCourse (Lens' r (Entity Course)) (Traversal' r (Entity User)) (Lens' r Bool)
|
data DBSTemplateMode r = DBSTDefault | DBSTCourse (Lens' r (Entity Course)) (Traversal' r [Entity User]) (Lens' r Bool)
|
||||||
|
|
||||||
instance Default (DBStyle r) where
|
instance Default (DBStyle r) where
|
||||||
def = DBStyle
|
def = DBStyle
|
||||||
@ -853,7 +853,7 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db
|
|||||||
|
|
||||||
wRows <- forM (zip [0..length rows] rows) $ \(cid, row') -> let
|
wRows <- forM (zip [0..length rows] rows) $ \(cid, row') -> let
|
||||||
Course{..} = row' ^. c . _entityVal
|
Course{..} = row' ^. c . _entityVal
|
||||||
lecturerUsers = toListOf l row'
|
lecturerUsers = row' ^. l
|
||||||
courseLecturers = userSurname . entityVal <$> lecturerUsers
|
courseLecturers = userSurname . entityVal <$> lecturerUsers
|
||||||
isRegistered = row' ^. r
|
isRegistered = row' ^. r
|
||||||
courseSchoolName = unSchoolKey courseSchool
|
courseSchoolName = unSchoolKey courseSchool
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<div .course-teaser :isRegistered:.course-teaser--registered #courseteaser-#{courseId} tabindex='1'>
|
<div .course-teaser :isRegistered:.course-teaser__registered #courseteaser-#{courseId} tabindex='1'>
|
||||||
<div .course-teaser__chevron>
|
<div .course-teaser__chevron>
|
||||||
<div .course-teaser__shorthand>_{courseShorthand}
|
<div .course-teaser__shorthand>_{courseShorthand}
|
||||||
<div .course-teaser__title>
|
<div .course-teaser__title>
|
||||||
@ -11,14 +11,13 @@
|
|||||||
$forall lecturer <- courseLecturers
|
$forall lecturer <- courseLecturers
|
||||||
<li>
|
<li>
|
||||||
#{lecturer}
|
#{lecturer}
|
||||||
<div .course-teaser__duedate-label>_{MsgRegisterTo}
|
|
||||||
$maybe regTo <- courseRegisterTo
|
$maybe regTo <- courseRegisterTo
|
||||||
|
<div .course-teaser__duedate-label>_{MsgRegisterTo}
|
||||||
<div .course-teaser__duedate-value>^{formatTimeW SelFormatDateTime regTo}
|
<div .course-teaser__duedate-value>^{formatTimeW SelFormatDateTime regTo}
|
||||||
$nothing
|
$nothing
|
||||||
<div .course-teaser__school-label>_{MsgCourseSchool}
|
<div .course-teaser__school-label>_{MsgCourseSchool}
|
||||||
<div .course-teaser__school-value>_{courseSchoolName}
|
<div .course-teaser__school-value>_{courseSchoolName}
|
||||||
<div .course-teaser__description>
|
$maybe desc <- courseDescription
|
||||||
$maybe desc <- courseDescription
|
<div .course-teaser__description-label>_{MsgCourseDescription}
|
||||||
#{desc}
|
<div .course-teaser__description-value>#{desc}
|
||||||
$nothing
|
$nothing
|
||||||
_{MsgNoCourseDescription}
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var COURSE_TEASER_EXPANDED_CLASS = 'course--expanded';
|
var COURSE_TEASER_EXPANDED_CLASS = 'course-teaser__expanded';
|
||||||
var COURSE_TEASER_CHEVRON_CLASS = 'course-chevron';
|
var COURSE_TEASER_CHEVRON_CLASS = 'course-teaser__chevron';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var courseTeaserId = #{String courseId};
|
var courseTeaserId = #{String courseId};
|
||||||
|
|||||||
@ -91,7 +91,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* description */
|
/* description */
|
||||||
.course-teaser__description {
|
.course-teaser__description-value {
|
||||||
grid-column: 2;
|
grid-column: 2;
|
||||||
color: var(--color-fontsec);
|
color: var(--color-fontsec);
|
||||||
}
|
}
|
||||||
@ -111,13 +111,14 @@
|
|||||||
.course-teaser__school-value,
|
.course-teaser__school-value,
|
||||||
.course-teaser__duedate-label,
|
.course-teaser__duedate-label,
|
||||||
.course-teaser__duedate-value,
|
.course-teaser__duedate-value,
|
||||||
.course-teaser__description,
|
.course-teaser__description-label,
|
||||||
|
.course-teaser__description-value,
|
||||||
.course-teaser__registration {
|
.course-teaser__registration {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* registered courses */
|
/* registered courses */
|
||||||
.course-teaser--registered {
|
.course-teaser__registered {
|
||||||
|
|
||||||
.course-teaser__registration {
|
.course-teaser__registration {
|
||||||
display: block;
|
display: block;
|
||||||
@ -125,7 +126,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* expanded courses */
|
/* expanded courses */
|
||||||
.course-teaser--expanded {
|
.course-teaser__expanded {
|
||||||
max-height: 1000px;
|
max-height: 1000px;
|
||||||
|
|
||||||
.course-teaser__chevron::before {
|
.course-teaser__chevron::before {
|
||||||
@ -136,7 +137,8 @@
|
|||||||
.course-teaser__school-value,
|
.course-teaser__school-value,
|
||||||
.course-teaser__duedate-label,
|
.course-teaser__duedate-label,
|
||||||
.course-teaser__duedate-value,
|
.course-teaser__duedate-value,
|
||||||
.course-teaser__description {
|
.course-teaser__description-label,
|
||||||
|
.course-teaser__description-value {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user