From c92115faf3674c18d36cd1d4d9fd492170dca1f2 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Wed, 21 Aug 2024 18:53:07 +0200 Subject: [PATCH] Update save shelf sort algorithm --- cps/shelf.py | 57 ++++++++++++++++++++++------------------ cps/static/js/main.js | 11 +++++++- cps/templates/shelf.html | 23 ++++++++-------- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/cps/shelf.py b/cps/shelf.py index 41d5ce1d..e4f93909 100644 --- a/cps/shelf.py +++ b/cps/shelf.py @@ -250,7 +250,7 @@ def show_simpleshelf(shelf_id): return render_show_shelf(2, shelf_id, 1, None) -@shelf.route("/shelf/", defaults={"sort_param": "order", 'page': 1}) +@shelf.route("/shelf/", defaults={"sort_param": "stored", 'page': 1}) @shelf.route("/shelf//", defaults={'page': 1}) @shelf.route("/shelf///") @login_required_if_no_ano @@ -418,32 +418,37 @@ def change_shelf_order(shelf_id, order): 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() - + status = current_user.get_view_property("shelf", 'man') # check user is allowed to access shelf if shelf and check_shelf_view_permissions(shelf): if shelf_type == 1: - 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 == 'shelfnew': - change_shelf_order(shelf_id, [ub.BookShelf.date_added.desc()]) - if sort_param == 'shelfold': - change_shelf_order(shelf_id, [ub.BookShelf.date_added]) - 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(), db.Series.name, db.Books.series_index]) - if sort_param == 'authza': - change_shelf_order(shelf_id, [db.Books.author_sort.desc(), - db.Series.name.desc(), - db.Books.series_index.desc()]) + if status != 'on': + if sort_param == 'stored': + sort_param = current_user.get_view_property("shelf", 'stored') + else: + current_user.set_view_property("shelf", 'stored', sort_param) + 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 == 'shelfnew': + change_shelf_order(shelf_id, [ub.BookShelf.date_added.desc()]) + if sort_param == 'shelfold': + change_shelf_order(shelf_id, [ub.BookShelf.date_added]) + 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(), db.Series.name, db.Books.series_index]) + if sort_param == 'authza': + change_shelf_order(shelf_id, [db.Books.author_sort.desc(), + db.Series.name.desc(), + db.Books.series_index.desc()]) page = "shelf.html" pagesize = 0 else: @@ -475,7 +480,9 @@ def render_show_shelf(shelf_type, shelf_id, page_no, sort_param): pagination=pagination, title=_("Shelf: '%(name)s'", name=shelf.name), shelf=shelf, - page="shelf") + page="shelf", + status=status, + order=sort_param) else: flash(_("Error opening shelf. Shelf does not exist or is not accessible"), category="error") return redirect(url_for("web.index")) diff --git a/cps/static/js/main.js b/cps/static/js/main.js index d04a0459..a29382e2 100644 --- a/cps/static/js/main.js +++ b/cps/static/js/main.js @@ -166,7 +166,6 @@ $("#form-upload-format").uploadprogress({ modalTitleFailed: $("#form-upload-format").data("failed") }); - $(document).ready(function() { var inp = $('#query').first() if (inp.length) { @@ -623,6 +622,7 @@ $(function() { }); $("#toggle_order_shelf").click(function() { + $("#toggle_order_shelf").toggleClass("dummy"); $("#new").toggleClass("disabled"); $("#old").toggleClass("disabled"); $("#asc").toggleClass("disabled"); @@ -634,8 +634,17 @@ $(function() { $("#shelf_new").toggleClass("disabled"); $("#shelf_old").toggleClass("disabled"); var alternative_text = $("#toggle_order_shelf").data('alt-text'); + var status = $("#toggle_order_shelf").hasClass("dummy") ? "on" : "off"; $("#toggle_order_shelf").data('alt-text', $("#toggle_order_shelf").html()); $("#toggle_order_shelf").html(alternative_text); + + $.ajax({ + method:"post", + contentType: "application/json; charset=utf-8", + dataType: "json", + url: getPath() + "/ajax/view", + data: "{\"shelf\": {\"man\": \"" + status + "\"}}", + }); }); $("#btndeluser").click(function() { diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index d0fdb399..d9c4ec27 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -15,18 +15,19 @@ {% if entries.__len__() %} {{ _('Arrange books manually') }} - + {% endif %} {% endif %}