mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Track virtual library state as well
Also ensure that library and virtual library state is always present in the book list URLs
This commit is contained in:
parent
2246053e3a
commit
508c8578fd
@ -545,7 +545,8 @@ def search_result(ctx, rd, db, query, num, offset, sort, sort_order, vl=''):
|
||||
'base_url':ctx.url_for(search, library_id=db.server_library_id),
|
||||
'query': query,
|
||||
'library_id': db.server_library_id,
|
||||
'book_ids':ids
|
||||
'book_ids':ids,
|
||||
'vl': vl,
|
||||
}
|
||||
|
||||
|
||||
|
@ -304,15 +304,16 @@ def book_metadata(ctx, rd, book_id):
|
||||
'''
|
||||
Get metadata for the specified book. If no book_id is specified, return metadata for a random book.
|
||||
|
||||
Optional: ?library_id=<default library>
|
||||
Optional: ?library_id=<default library>&vl=<virtual library>
|
||||
'''
|
||||
library_id, db = get_basic_query_data(ctx, rd)[:2]
|
||||
library_id, db, sorts, orders, vl = get_basic_query_data(ctx, rd)
|
||||
|
||||
def notfound():
|
||||
raise HTTPNotFound(_('No book with id: {} in library: {}').format(book_id, library_id))
|
||||
|
||||
if not book_id:
|
||||
book_id = random.choice(tuple(db.all_book_ids()))
|
||||
all_ids = db.books_in_virtual_library(vl) if vl else db.all_book_ids()
|
||||
book_id = random.choice(tuple(all_ids))
|
||||
elif not db.has_id(book_id):
|
||||
notfound()
|
||||
data = book_as_json(db, book_id)
|
||||
|
@ -15,7 +15,7 @@ from session import get_interface_data
|
||||
from utils import fmt_sidx, parse_url_params, conditional_timeout
|
||||
|
||||
from book_list.router import back, open_book
|
||||
from book_list.library_data import book_metadata, cover_url, set_book_metadata, current_library_id, library_data, download_url, load_status
|
||||
from book_list.library_data import book_metadata, cover_url, set_book_metadata, current_library_id, library_data, download_url, load_status, current_virtual_library
|
||||
from book_list.top_bar import create_top_bar, set_title, add_button
|
||||
from book_list.ui import set_panel_handler
|
||||
from book_list.views import search
|
||||
@ -401,7 +401,7 @@ def fetch_metadata(container_id, book_id):
|
||||
if current_fetch:
|
||||
current_fetch.abort()
|
||||
current_fetch = ajax('interface-data/book-metadata/' + book_id, metadata_fetched.bind(None, container_id, book_id),
|
||||
query={'library_id':current_library_id().library_id})
|
||||
query={'library_id':current_library_id(), 'vl':current_virtual_library()})
|
||||
current_fetch.send()
|
||||
container = container.lastChild
|
||||
clear(container)
|
||||
|
@ -18,6 +18,11 @@ def current_library_id():
|
||||
return q.library_id or get_interface_data().default_library_id
|
||||
|
||||
|
||||
def current_virtual_library():
|
||||
q = parse_url_params()
|
||||
return q.vl or ''
|
||||
|
||||
|
||||
def url_books_query(sd):
|
||||
q = parse_url_params()
|
||||
sd = sd or get_session_data()
|
||||
@ -26,6 +31,7 @@ def url_books_query(sd):
|
||||
'library_id': lid,
|
||||
'sort': q.sort or sd.get_library_option(lid, 'sort'),
|
||||
'search': q.search,
|
||||
'vl': current_virtual_library(),
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +43,8 @@ def loaded_books_query():
|
||||
return {
|
||||
'library_id': sr.library_id if sr else None,
|
||||
'sort': sort,
|
||||
'search': sr?.query
|
||||
'search': sr?.query,
|
||||
'vl':sr?.vl
|
||||
}
|
||||
|
||||
|
||||
@ -111,8 +118,14 @@ def ensure_current_library_data():
|
||||
q = url_books_query()
|
||||
loaded = loaded_books_query()
|
||||
matches = True
|
||||
|
||||
def is_same(a, b):
|
||||
if not a and not b:
|
||||
return True
|
||||
return a is b
|
||||
|
||||
for key in q:
|
||||
if q[key] is not loaded[key]:
|
||||
if not is_same(q[key], loaded[key]):
|
||||
matches = False
|
||||
break
|
||||
if not matches:
|
||||
|
@ -12,7 +12,7 @@ from modals import show_modal
|
||||
from utils import rating_to_stars
|
||||
from session import get_interface_data
|
||||
|
||||
from book_list.library_data import library_data, current_library_id
|
||||
from book_list.library_data import library_data, current_library_id, current_virtual_library
|
||||
from book_list.ui import show_panel
|
||||
from book_list.router import back
|
||||
from book_list.top_bar import create_top_bar, add_button
|
||||
@ -357,7 +357,7 @@ def refresh():
|
||||
state.currently_loading.abort()
|
||||
state.currently_loading = None
|
||||
sd = get_session_data()
|
||||
query = {'library_id': current_library_id()}
|
||||
query = {'library_id': current_library_id(), 'vl':current_virtual_library()}
|
||||
for k in 'sort_tags_by partition_method collapse_at dont_collapse hide_empty_categories'.split(' '):
|
||||
query[k] = sd.get(k) + ''
|
||||
xhr = ajax('interface-data/tag-browser', on_data_fetched, query=query, bypass_cache=False)
|
||||
|
@ -8,7 +8,7 @@ from elementmaker import E
|
||||
from book_list.constants import book_list_container_id
|
||||
from book_list.globals import get_current_query
|
||||
from book_list.router import push_state
|
||||
from book_list.library_data import current_library_id
|
||||
from book_list.library_data import current_library_id, current_virtual_library
|
||||
|
||||
|
||||
panel_handlers = {}
|
||||
@ -45,6 +45,15 @@ def currently_showing_panel():
|
||||
return c.dataset.panel
|
||||
|
||||
|
||||
def add_library_info(query):
|
||||
if not query.library_id:
|
||||
query.library_id = current_library_id()
|
||||
if not query.vl:
|
||||
vlid = current_virtual_library()
|
||||
if vlid:
|
||||
query.vl = vlid
|
||||
|
||||
|
||||
def show_panel(panel, query=None, replace=False):
|
||||
if query is None:
|
||||
query = {}
|
||||
@ -52,6 +61,7 @@ def show_panel(panel, query=None, replace=False):
|
||||
query = {k:query[k] for k in query if k is not 'panel'}
|
||||
if panel is not 'home':
|
||||
query.panel = panel
|
||||
add_library_info(query)
|
||||
push_state(query, replace=replace)
|
||||
|
||||
|
||||
@ -75,7 +85,5 @@ apply_url_state.back_from_current = def back_from_current(current_query):
|
||||
q = {}
|
||||
else:
|
||||
q = {'panel':'book_list'}
|
||||
lid = current_library_id()
|
||||
if lid:
|
||||
q.library_id = lid
|
||||
add_library_info(q)
|
||||
return q
|
||||
|
@ -14,7 +14,7 @@ from book_list.cover_grid import (
|
||||
from book_list.globals import get_session_data
|
||||
from book_list.item_list import create_item, create_item_list
|
||||
from book_list.library_data import (
|
||||
book_metadata, current_library_id, current_sorted_field,
|
||||
book_metadata, current_sorted_field,
|
||||
ensure_current_library_data, library_data, load_status, loaded_books_query,
|
||||
thumbnail_cache, url_books_query
|
||||
)
|
||||
@ -61,7 +61,7 @@ def clear_grid():
|
||||
|
||||
|
||||
def show_book_details(book_id):
|
||||
show_panel('book_details', {'book_id':book_id, 'library_id':current_library_id()})
|
||||
show_panel('book_details', {'book_id':book_id})
|
||||
|
||||
|
||||
def create_image(book_id, max_width, max_height, on_load):
|
||||
@ -296,7 +296,7 @@ def create_more_actions_panel(container_id):
|
||||
items = [
|
||||
create_item(_('Book list mode'), subtitle=_('Change how the list of books is displayed')),
|
||||
create_item(_('A random book'), subtitle=_('Choose a random book from the library'), action=def():
|
||||
query = {'library_id': current_library_id(), 'book_id':'0'}
|
||||
query = {'book_id':'0'}
|
||||
show_panel('book_details', query=query, replace=True)
|
||||
),
|
||||
]
|
||||
|
@ -13,7 +13,7 @@ from utils import human_readable, debounce
|
||||
from book_list.constants import read_book_container_id
|
||||
from read_book.db import get_db
|
||||
from book_list.router import update_window_title
|
||||
from book_list.library_data import library_data, current_library_id
|
||||
from book_list.library_data import library_data, current_library_id, current_virtual_library
|
||||
from read_book.view import View
|
||||
|
||||
RENDER_VERSION = __RENDER_VERSION__
|
||||
@ -75,6 +75,7 @@ class ReadUI:
|
||||
if self.current_book_id:
|
||||
a.setAttribute('href', encode_query({
|
||||
'library_id':current_library_id(),
|
||||
'vl': current_virtual_library(),
|
||||
'book-id': (self.current_book_id + ''),
|
||||
'panel':'book-details'
|
||||
}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user