diff --git a/cps/db.py b/cps/db.py index 2e428f72..f30fb609 100644 --- a/cps/db.py +++ b/cps/db.py @@ -445,6 +445,8 @@ class CalibreDB(): cls.config = config cls.dispose() + # toDo: if db changed -> delete shelfs, delete download books, delete read boks, kobo sync?? + if not config.config_calibre_dir: config.invalidate() return False diff --git a/cps/shelf.py b/cps/shelf.py index be102ea9..6dae333c 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -381,27 +381,53 @@ def order_shelf(shelf_id): title=_(u"Change order of Shelf: '%(name)s'", name=shelf.name), shelf=shelf, page="shelforder") +def change_shelf_order(shelf_id, order): + result = calibre_db.session.query(db.Books).join(ub.BookShelf,ub.BookShelf.book_id == db.Books.id)\ + .filter(ub.BookShelf.shelf == shelf_id).order_by(*order).all() + for index, entry in enumerate(result): + book = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id) \ + .filter(ub.BookShelf.book_id == entry.id).first() + book.order = index + try: + ub.session.commit() + except OperationalError: + ub.session.rollback() def render_show_shelf(shelf_type, shelf_id, page_no, sort_param): shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() # check user is allowed to access shelf if shelf and check_shelf_view_permissions(shelf): + if shelf_type == 1: + # order = [ub.BookShelf.order.asc()] + if sort_param == 'pubnew': + change_shelf_order(shelf_id, [db.Books.pubdate.desc()]) + if sort_param == 'pubold': + change_shelf_order(shelf_id, [db.Books.pubdate]) + if sort_param == 'abc': + change_shelf_order(shelf_id, [db.Books.sort]) + if sort_param == 'zyx': + change_shelf_order(shelf_id, [db.Books.sort.desc()]) + if sort_param == 'new': + change_shelf_order(shelf_id, [db.Books.timestamp.desc()]) + if sort_param == 'old': + change_shelf_order(shelf_id, [db.Books.timestamp]) + if sort_param == 'authaz': + change_shelf_order(shelf_id, [db.Books.author_sort.asc()]) + if sort_param == 'authza': + change_shelf_order(shelf_id, [db.Books.author_sort.desc()]) page = "shelf.html" pagesize = 0 - order = [ub.BookShelf.order.asc()] else: pagesize = sys.maxsize page = 'shelfdown.html' - order = [ub.BookShelf.order.asc()] result, __, pagination = calibre_db.fill_indexpage(page_no, pagesize, db.Books, ub.BookShelf.shelf == shelf_id, - order, + [ub.BookShelf.order.asc()], ub.BookShelf,ub.BookShelf.book_id == db.Books.id) - # delete chelf entries where book is not existent anymore, can happen if book is deleted outside calibre-web wrong_entries = calibre_db.session.query(ub.BookShelf)\ .join(db.Books, ub.BookShelf.book_id == db.Books.id, isouter=True)\ diff --git a/cps/static/js/main.js b/cps/static/js/main.js index d02d3b58..d891d30e 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -497,6 +497,19 @@ $(function() { ); }); + $("#toggle_order_shelf").click(function() { + $("#new").toggleClass("disabled"); + $("#old").toggleClass("disabled"); + $("#asc").toggleClass("disabled"); + $("#desc").toggleClass("disabled"); + $("#auth_az").toggleClass("disabled"); + $("#auth_za").toggleClass("disabled"); + $("#pub_new").toggleClass("disabled"); + $("#pub_old").toggleClass("disabled"); + var alternative_text = $("#toggle_order_shelf").data('alt-text'); + $("#toggle_order_shelf")[0].attributes['data-alt-text'].value = $("#toggle_order_shelf").html(); + $("#toggle_order_shelf").html(alternative_text); + }); $("#btndeluser").click(function() { ConfirmDialog( diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index 32e3da4f..2110d905 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -8,8 +8,10 @@ {% if g.user.is_authenticated %} {% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}