From 08607a5e7c99bd1abbcef845de96b0ad49dc0741 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 11 Apr 2018 14:28:33 +0200 Subject: [PATCH] Fix javascript issues, 'directions' in sortable-header, sorted attrs --- src/Handler/Utils/Table/Pagination.hs | 8 +++++++- templates/table/colonnade.julius | 3 +-- templates/table/sortable-header.hamlet | 13 ++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index ef3ab45ec..776fd3498 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -153,10 +153,16 @@ dbTable PSValidator{..} DBTable{ dbtIdent = (toPathPiece -> dbtIdent), .. } = do let table = $(widgetFile "table/colonnade") pageCount = max 1 . ceiling $ rowCount % psLimit tblLink f = decodeUtf8 . Builder.toLazyByteString . renderQueryText True $ f getParams + withSortLinks Sortable{ sortableContent = Cell{..}, .. } = Cell { 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") where tblLayout :: Widget -> Handler Html diff --git a/templates/table/colonnade.julius b/templates/table/colonnade.julius index fcea7dea9..212ecf4ff 100644 --- a/templates/table/colonnade.julius +++ b/templates/table/colonnade.julius @@ -23,8 +23,7 @@ event.preventDefault(); var url = new URL(window.location.origin + window.location.pathname + this.getAttribute('href')); var order = this.parentNode.dataset.order || ASC; - // TODO: make use of dbtIdent instead of -terms- - url.searchParams.set('terms-table-only', 'true'); + url.searchParams.set(#{String $ wIdent "table-only"}, 'yes'); updateTableFrom(url); markSorted(this.parentNode, order); } diff --git a/templates/table/sortable-header.hamlet b/templates/table/sortable-header.hamlet index 1054b1ce0..b5e006b6a 100644 --- a/templates/table/sortable-header.hamlet +++ b/templates/table/sortable-header.hamlet @@ -1,7 +1,14 @@ ^{cellContents} $maybe flag <- sortableKey
- "-asc")}>asc - / - "-desc")}>desc + $case directions + $of [SortAsc] + "-desc")}>desc + $of [SortDesc] + "-asc")}>asc + $of [] + "-desc")}>desc + / + "-asc")}>asc + $of _ $nothing