Fix javascript issues, 'directions' in sortable-header, sorted attrs

This commit is contained in:
Gregor Kleen 2018-04-11 14:28:33 +02:00
parent f99c8b3b86
commit 08607a5e7c
3 changed files with 18 additions and 6 deletions

View File

@ -153,10 +153,16 @@ dbTable PSValidator{..} DBTable{ dbtIdent = (toPathPiece -> dbtIdent), .. } = do
let table = $(widgetFile "table/colonnade") let table = $(widgetFile "table/colonnade")
pageCount = max 1 . ceiling $ rowCount % psLimit pageCount = max 1 . ceiling $ rowCount % psLimit
tblLink f = decodeUtf8 . Builder.toLazyByteString . renderQueryText True $ f getParams tblLink f = decodeUtf8 . Builder.toLazyByteString . renderQueryText True $ f getParams
withSortLinks Sortable{ sortableContent = Cell{..}, .. } = Cell withSortLinks Sortable{ sortableContent = Cell{..}, .. } = Cell
{ cellContents = $(widgetFile "table/sortable-header") { cellContents = $(widgetFile "table/sortable-header")
, .. , cellAttrs = maybe mempty (const sortableAttr) sortableKey <> cellAttrs
} }
where
directions = [dir | (k, dir) <- psSorting, Just k == sortableKey ]
sortableAttr = foldMap toAttr directions
toAttr SortAsc = Html5.class_ "sorted-asc"
toAttr SortDesc = Html5.class_ "sorted-desc"
$(widgetFile "table/layout") $(widgetFile "table/layout")
where where
tblLayout :: Widget -> Handler Html tblLayout :: Widget -> Handler Html

View File

@ -23,8 +23,7 @@
event.preventDefault(); event.preventDefault();
var url = new URL(window.location.origin + window.location.pathname + this.getAttribute('href')); var url = new URL(window.location.origin + window.location.pathname + this.getAttribute('href'));
var order = this.parentNode.dataset.order || ASC; var order = this.parentNode.dataset.order || ASC;
// TODO: make use of dbtIdent instead of -terms- url.searchParams.set(#{String $ wIdent "table-only"}, 'yes');
url.searchParams.set('terms-table-only', 'true');
updateTableFrom(url); updateTableFrom(url);
markSorted(this.parentNode, order); markSorted(this.parentNode, order);
} }

View File

@ -1,7 +1,14 @@
^{cellContents} ^{cellContents}
$maybe flag <- sortableKey $maybe flag <- sortableKey
<br> <br>
<a href=#{tblLink $ setParam (wIdent "sorting") (Just $ flag <> "-asc")}>asc $case directions
/ $of [SortAsc]
<a href=#{tblLink $ setParam (wIdent "sorting") (Just $ flag <> "-desc")}>desc <a href=#{tblLink $ setParam (wIdent "sorting") (Just $ flag <> "-desc")}>desc
$of [SortDesc]
<a href=#{tblLink $ setParam (wIdent "sorting") (Just $ flag <> "-asc")}>asc
$of []
<a href=#{tblLink $ setParam (wIdent "sorting") (Just $ flag <> "-desc")}>desc
/
<a href=#{tblLink $ setParam (wIdent "sorting") (Just $ flag <> "-asc")}>asc
$of _
$nothing $nothing