From 11d608bf47ea45992002b95f1d0c8c13f09d23b9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 2 Jun 2020 11:44:03 +0530 Subject: [PATCH] Content server: In the book list hovering over the library name now shows the total number of books in the library. Fixes #1881384 [[Enhancement - Content server] Show number of books in a library](https://bugs.launchpad.net/calibre/+bug/1881384) --- src/calibre/db/cache.py | 6 ++++++ src/calibre/srv/ajax.py | 2 ++ src/pyj/book_list/top_bar.pyj | 7 +++++++ src/pyj/book_list/views.pyj | 4 +++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index f0fe96a04d..8352a9d0dd 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1027,6 +1027,12 @@ class Cache(object): return frozenset(self._search('', vl)) return frozenset(self._search('', search_restriction)) + @read_api + def number_of_books_in_virtual_library(self, vl=None, search_restriction=None): + if not vl and not search_restriction: + return len(self.fields['uuid'].table.book_col_map) + return len(self.books_in_virtual_library(vl, search_restriction)) + @api def get_categories(self, sort='name', book_ids=None, already_fixed=None, first_letter_sort=False): diff --git a/src/calibre/srv/ajax.py b/src/calibre/srv/ajax.py index 246a565ba6..6b5d6292b5 100644 --- a/src/calibre/srv/ajax.py +++ b/src/calibre/srv/ajax.py @@ -539,8 +539,10 @@ def search_result(ctx, rd, db, query, num, offset, sort, sort_order, vl=''): ids = db.multisort(fields=multisort, ids_to_sort=ids) total_num = len(ids) ids = ids[offset:offset+num] + num_books = db.number_of_books_in_virtual_library(vl) if query else total_num ans = { 'total_num': total_num, 'sort_order':sort_order, + 'num_books_without_search': num_books, 'offset':offset, 'num':len(ids), 'sort':sort, 'base_url':ctx.url_for(search, library_id=db.server_library_id), 'query': query, diff --git a/src/pyj/book_list/top_bar.pyj b/src/pyj/book_list/top_bar.pyj index 07fe5dd8bb..1270865df0 100644 --- a/src/pyj/book_list/top_bar.pyj +++ b/src/pyj/book_list/top_bar.pyj @@ -82,6 +82,13 @@ def set_title(container, text): for bar in bars: bar.firstChild.firstChild.nextSibling.textContent = text + +def set_title_tooltip(container, text): + bars = get_bars(container) + for bar in bars: + bar.firstChild.firstChild.nextSibling.title = text + + def create_top_bar(container, **kw): create_markup(container) set_left_data(container, **kw) diff --git a/src/pyj/book_list/views.pyj b/src/pyj/book_list/views.pyj index 3bb5e5b046..7a98709199 100644 --- a/src/pyj/book_list/views.pyj +++ b/src/pyj/book_list/views.pyj @@ -34,7 +34,7 @@ from book_list.router import back, home, push_state, update_window_title from book_list.search import ( init as init_search_panel, set_apply_search, tb_config_panel_handler ) -from book_list.top_bar import add_button, create_top_bar +from book_list.top_bar import add_button, create_top_bar, set_title_tooltip from book_list.ui import query_as_href, set_panel_handler, show_panel from dom import add_extra_css, build_rule, clear, ensure_id, set_css from modals import error_dialog @@ -319,6 +319,8 @@ def check_for_books_loaded(): ) return create_books_list(container) + if library_data.search_result and jstype(library_data.search_result.num_books_without_search) is 'number': + set_title_tooltip(this, _('Total number of books: {}').format(library_data.search_result.num_books_without_search)) def init(container_id):