chore(course-teaser): widget template case distinction in DBStyle
First stub of case distinction on template widget name in DBStyle
This commit is contained in:
parent
9fb9540bf7
commit
25efa947c6
@ -33,6 +33,7 @@ module Handler.Utils.Table.Pagination
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Handler.Utils.Table.Pagination.Types
|
import Handler.Utils.Table.Pagination.Types
|
||||||
|
import Handler.Utils.Table.Pagination.Utils (getTableWidget)
|
||||||
import Handler.Utils.Form
|
import Handler.Utils.Form
|
||||||
import Utils
|
import Utils
|
||||||
import Utils.Lens.TH
|
import Utils.Lens.TH
|
||||||
@ -349,6 +350,7 @@ data DBStyle = DBStyle
|
|||||||
-> Widget
|
-> Widget
|
||||||
-> Widget
|
-> Widget
|
||||||
-- ^ Filter UI, Filter Encoding, Filter action, table
|
-- ^ Filter UI, Filter Encoding, Filter action, table
|
||||||
|
, dbsCellTemplate :: String -- TODO: wip
|
||||||
}
|
}
|
||||||
|
|
||||||
instance Default DBStyle where
|
instance Default DBStyle where
|
||||||
@ -362,6 +364,7 @@ instance Default DBStyle where
|
|||||||
<!-- No Filter UI -->
|
<!-- No Filter UI -->
|
||||||
^{scrolltable}
|
^{scrolltable}
|
||||||
|]
|
|]
|
||||||
|
, dbsCellTemplate = "table/cell/body"
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultDBSFilterLayout :: Widget -- ^ Filter UI
|
defaultDBSFilterLayout :: Widget -- ^ Filter UI
|
||||||
@ -765,9 +768,11 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db
|
|||||||
wHeaders <- maybe (return Nothing) (fmap Just . genHeaders) pSortable
|
wHeaders <- maybe (return Nothing) (fmap Just . genHeaders) pSortable
|
||||||
|
|
||||||
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> cell') -> do
|
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> cell') -> do
|
||||||
widget <- cell' ^. cellContents
|
-- TODO: remove
|
||||||
let attrs = cell' ^. cellAttrs
|
-- widget <- cell' ^. cellContents
|
||||||
return $(widgetFile "table/cell/body")
|
-- let attrs = cell' ^. cellAttrs
|
||||||
|
-- return $(widgetFile "table/cell/body")
|
||||||
|
getTableWidget dbsCellTemplate cell' cellContents cellAttrs
|
||||||
|
|
||||||
return $(widgetFile "table/colonnade")
|
return $(widgetFile "table/colonnade")
|
||||||
|
|
||||||
|
|||||||
29
src/Handler/Utils/Table/Pagination/Utils.hs
Normal file
29
src/Handler/Utils/Table/Pagination/Utils.hs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
module Handler.Utils.Table.Pagination.Utils
|
||||||
|
( getTableWidget
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Import
|
||||||
|
|
||||||
|
import Control.Lens (Getting, (^.))
|
||||||
|
|
||||||
|
import Control.Monad.Writer ()
|
||||||
|
|
||||||
|
-- getTableWidget :: forall (m :: * -> *) x a s. HandlerSite m ~ UniWorX => String -> s -> Getting (WriterT x m a) s (WriterT x m a) -> Getting [(Text, Text)] s [(Text, Text)] -> WriterT x m Widget
|
||||||
|
getTableWidget :: (ToWidget site a, MonadIO m2, MonadThrow m2, MonadBaseControl IO m2, Monad m1, site ~ UniWorX) => String -> s -> Getting (m1 a) s (m1 a) -> Getting [(Text, Text)] s [(Text, Text)] -> m1 (WidgetT site m2 ())
|
||||||
|
getTableWidget widgetName cell' cellContents cellAttrs = case widgetName of
|
||||||
|
"table/cell/course-teaser" -> do
|
||||||
|
-- TODO: get course and deconstruct here
|
||||||
|
let courseId = "courseId" :: Text
|
||||||
|
courseTitle = "Some courseTitle" :: Text
|
||||||
|
courseShorthand = "cTShort" :: Text
|
||||||
|
courseLecturer = "Some courseLecturer" :: Text
|
||||||
|
courseSchoolName = "Some courseSchoolname" :: Text
|
||||||
|
isRegistered = False
|
||||||
|
courseDescription = "Some courseDescription" :: Text
|
||||||
|
courseRegisterTo = "Some courseRegisterTo" :: Text
|
||||||
|
return $(widgetFile "table/cell/course-teaser")
|
||||||
|
_ -> do -- defaults to "table/cell/body"
|
||||||
|
-- TODO: wip
|
||||||
|
widget <- cell' ^. cellContents
|
||||||
|
let attrs = cell' ^. cellAttrs
|
||||||
|
return $(widgetFile "table/cell/body")
|
||||||
25
templates/table/cell/course-teaser.julius
Normal file
25
templates/table/cell/course-teaser.julius
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
var COURSE_TEASER_EXPANDED_CLASS = 'course--expanded';
|
||||||
|
var COURSE_TEASER_CHEVRON_CLASS = 'course-chevron';
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
var courseTeaserId = #{String courseId};
|
||||||
|
var courseTeaser = document.querySelector('#course-' + courseTeaserId);
|
||||||
|
|
||||||
|
courseTeaser.addEventListener('click', function(event) {
|
||||||
|
var isLink = event.target.tagName.toLowerCase() === 'a';
|
||||||
|
var isChevron = event.target.classList.contains(COURSE_TEASER_CHEVRON_CLASS);
|
||||||
|
var isExpanded = courseTeaser.classList.contains(COURSE_TEASER_EXPANDED_CLASS);
|
||||||
|
|
||||||
|
if ((!isExpanded && !isLink) || isChevron) {
|
||||||
|
courseTeaser.classList.toggle(COURSE_TEASER_EXPANDED_CLASS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
courseTeaser.addEventListener('keydown', function(event) {
|
||||||
|
var eventKey = event.key;
|
||||||
|
if (eventKey === ' ' || eventKey === 'Enter') {
|
||||||
|
event.preventDefault();
|
||||||
|
courseTeaser.classList.toggle(COURSE_TEASER_EXPANDED_CLASS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -17,5 +17,4 @@ $newline never
|
|||||||
$forall row <- wRows
|
$forall row <- wRows
|
||||||
<tr .table__row>
|
<tr .table__row>
|
||||||
$forall widget <- row
|
$forall widget <- row
|
||||||
$# cell/body.hamlet
|
|
||||||
^{widget}
|
^{widget}
|
||||||
|
|||||||
21
templates/table/course-table.hamlet
Normal file
21
templates/table/course-table.hamlet
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
$newline never
|
||||||
|
<div .scrolltable>
|
||||||
|
<table *{dbsAttrs'}>
|
||||||
|
$maybe wHeaders' <- wHeaders
|
||||||
|
<thead>
|
||||||
|
<tr .table__row.table__row--head>
|
||||||
|
$forall widget <- wHeaders'
|
||||||
|
$# cell/header.hamlet
|
||||||
|
^{widget}
|
||||||
|
$nothing
|
||||||
|
<tbody>
|
||||||
|
$if null wRows && (dbsEmptyStyle == DBESHeading)
|
||||||
|
<td .table__row>
|
||||||
|
<td .table__td colspan=#{show columnCount}>
|
||||||
|
_{dbsEmptyMessage}
|
||||||
|
$else
|
||||||
|
$forall row <- wRows
|
||||||
|
<tr .table__row>
|
||||||
|
$forall widget <- row
|
||||||
|
$# cell/course-teaser.hamlet
|
||||||
|
^{widget}
|
||||||
Reference in New Issue
Block a user