mikespub-org / seblucas-cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
65 stars 7 forks source link

Bootstrap5 sort toggle #45

Closed dunxd closed 1 year ago

dunxd commented 1 year ago

I've added a function to bootstrap5's scripts/cops.js that enables toggling the sort order, and added some doT.js logic that runs the function when clicking on the sort buttons.

It doesn't change the icon to reflect the current order, or update the url, so refresh will always revert to the default sort order.

This won't work server side, since it only works on the currentData.entries object.

mikespub commented 1 year ago

Hmmm - there was a similar "feature" in the default template to filter by tag, but all it really does is filter within the currently listed entries. Not very helpful if you have 5.000+ books and only show 48 or 100 at a time...

Wouldn't this be the same problem here, if you simply reverse the currentData?

mikespub commented 1 year ago

BTW I fixed the different sort options in code with https://github.com/mikespub-org/seblucas-cops/commit/a27953d5e42f79a7908d907c7e0c45909ce52b58 including authors and rating, so you should be able to add actual +asc or +desc to the sort param in your templates as needed...

dunxd commented 1 year ago

I saw that, and I could use it for server side toggling. Is the direction available to doT? I only see desc present as part of the it.sorted string.

To be honest, the logic in the templates gets really convoluted and hard to read...

dunxd commented 1 year ago

Hmmm - there was a similar "feature" in the default template to filter by tag, but all it really does is filter within the currently listed entries. Not very helpful if you have 5.000+ books and only show 48 or 100 at a time...

Wouldn't this be the same problem here, if you simply reverse the currentData?

That is a good point. I hadn't considered pagination. This will work on the Recent Additions page, and on any book listing page where the number of possible entries is lower than the items limit, but I think coding that logic into the templates is a step too far. Maybe we don't need this, or should do server side via the query string.

It was a useful exercise to learn how to rewrite part of the page using jQuery.

dunxd commented 1 year ago

I saw that, and I could use it for server side toggling. Is the direction available to doT? I only see desc present as part of the it.sorted string.

Here I am thinking if we had e.g. it.sorteddir, it would be easy to add the appropriate url query and current sort direction icon via template logic that should work with both client and server side rendering. For example:

<a href="&sort=timestamp{{? it.sorteddir == "desc" }}+desc{{??}}+asc{{?}}">Added</a>
<i class="bi-{{? it.sorteddir == "desc" }}sort-numberic-down{{??}}sort-numeric-up-alt{{?}}"></i>
mikespub commented 1 year ago

Indeed, the lack of template inheritance, with blocks, macros etc. was one of the reasons why I added the Twig template engine as capability for the future. Note: in theory those exist in doT.js as well, but not quite in doT.php...

See Templates and Inheritance for twigged template - although it isn't really taking full advantage of it yet...

Anyway, regarding the asc or desc, there's a default direction in which it will sort if nothing is specified - mostly ascending, except the timestamp for recently added books. The it.sorted will contain $page->sorted, and that contains the order by which the underlying booklist (or baselist = non-booklist) was sorted for the current page.

You'll notice in bootstrap2 header.html that I didn't really check or care how it was currently sorted though - I just gave the option to click on it - something to improve if you want to change the order :-)

dunxd commented 1 year ago

If the direction is only available as part of the string in it.sorted then how can the template use it in logic both server side and client side? Client side I could use a javascript function to search the string, but PHP isn't going to like that.

mikespub commented 1 year ago

If the direction is only available as part of the string in it.sorted then how can the template use it in logic both server side and client side? Client side I could use a javascript function to search the string, but PHP isn't going to like that.

Yes indeed, adding it.sortorder in JSON renderer will probably be easier...

At some point we'll want to clean up all those 100s of variables though, because we keep adding to them

dunxd commented 1 year ago

Ok - let's forget this one. I made another for server side sort ordering.