mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow updating interface data independently of init
This commit is contained in:
parent
2cf1d1fb7a
commit
8cb4545b96
@ -64,6 +64,7 @@ def get_basic_query_data(ctx, rd):
|
|||||||
sorts, orders = ['timestamp'], ['desc']
|
sorts, orders = ['timestamp'], ['desc']
|
||||||
return library_id, db, sorts, orders
|
return library_id, db, sorts, orders
|
||||||
|
|
||||||
|
|
||||||
_cached_translations = None
|
_cached_translations = None
|
||||||
|
|
||||||
|
|
||||||
@ -82,17 +83,11 @@ def get_translations():
|
|||||||
_cached_translations = load_json_file(zf.open(lang, 'r'))
|
_cached_translations = load_json_file(zf.open(lang, 'r'))
|
||||||
return _cached_translations
|
return _cached_translations
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_NUMBER_OF_BOOKS = 50
|
DEFAULT_NUMBER_OF_BOOKS = 50
|
||||||
|
|
||||||
|
|
||||||
@endpoint('/interface-data/init', postprocess=json)
|
def basic_interface_data(ctx, rd):
|
||||||
def interface_data(ctx, rd):
|
|
||||||
'''
|
|
||||||
Return the data needed to create the server main UI
|
|
||||||
|
|
||||||
Optional: ?num=50&sort=timestamp.desc&library_id=<default library>
|
|
||||||
&search=''&extra_books=''
|
|
||||||
'''
|
|
||||||
ans = {
|
ans = {
|
||||||
'username':rd.username,
|
'username':rd.username,
|
||||||
'output_format':prefs['output_format'].upper(),
|
'output_format':prefs['output_format'].upper(),
|
||||||
@ -103,8 +98,30 @@ def interface_data(ctx, rd):
|
|||||||
'use_roman_numerals_for_series_number': get_use_roman(),
|
'use_roman_numerals_for_series_number': get_use_roman(),
|
||||||
'translations': get_translations(),
|
'translations': get_translations(),
|
||||||
'allow_console_print':getattr(rd.opts, 'allow_console_print', False),
|
'allow_console_print':getattr(rd.opts, 'allow_console_print', False),
|
||||||
|
'icon_map': icon_map(),
|
||||||
|
'icon_path': ctx.url_for('/icon', which=''),
|
||||||
}
|
}
|
||||||
ans['library_map'], ans['default_library'] = ctx.library_info(rd)
|
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@endpoint('/interface-data/update', postprocess=json)
|
||||||
|
def update_interface_data(ctx, rd):
|
||||||
|
'''
|
||||||
|
Return the interface data needed for the server UI
|
||||||
|
'''
|
||||||
|
return basic_interface_data(ctx, rd)
|
||||||
|
|
||||||
|
|
||||||
|
@endpoint('/interface-data/init', postprocess=json)
|
||||||
|
def interface_data(ctx, rd):
|
||||||
|
'''
|
||||||
|
Return the data needed to create the server UI as well as a list of books.
|
||||||
|
|
||||||
|
Optional: ?num=50&sort=timestamp.desc&library_id=<default library>
|
||||||
|
&search=''&extra_books=''
|
||||||
|
'''
|
||||||
|
ans = basic_interface_data(ctx, rd)
|
||||||
ud = {}
|
ud = {}
|
||||||
if rd.username:
|
if rd.username:
|
||||||
# Override session data with stored values for the authenticated user,
|
# Override session data with stored values for the authenticated user,
|
||||||
@ -133,8 +150,6 @@ def interface_data(ctx, rd):
|
|||||||
sanitize_sort_field_name(db.field_metadata, k), v) for k, v in sf.iteritems()),
|
sanitize_sort_field_name(db.field_metadata, k), v) for k, v in sf.iteritems()),
|
||||||
key=lambda (field, name):sort_key(name))
|
key=lambda (field, name):sort_key(name))
|
||||||
ans['field_metadata'] = db.field_metadata.all_metadata()
|
ans['field_metadata'] = db.field_metadata.all_metadata()
|
||||||
ans['icon_map'] = icon_map()
|
|
||||||
ans['icon_path'] = ctx.url_for('/icon', which='')
|
|
||||||
mdata = ans['metadata'] = {}
|
mdata = ans['metadata'] = {}
|
||||||
try:
|
try:
|
||||||
extra_books = set(int(x) for x in rd.query.get('extra_books', '').split(','))
|
extra_books = set(int(x) for x in rd.query.get('extra_books', '').split(','))
|
||||||
|
@ -2,11 +2,30 @@
|
|||||||
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import hash_literals, bound_methods
|
from __python__ import hash_literals, bound_methods
|
||||||
|
|
||||||
|
from dom import ensure_id
|
||||||
|
from elementmaker import E
|
||||||
|
|
||||||
|
from book_list.globals import get_db
|
||||||
from book_list.top_bar import create_top_bar
|
from book_list.top_bar import create_top_bar
|
||||||
from book_list.ui import set_default_panel_handler
|
from book_list.ui import set_default_panel_handler
|
||||||
|
|
||||||
|
|
||||||
|
def show_recent():
|
||||||
|
db = get_db()
|
||||||
|
if not db.initialized:
|
||||||
|
window.setTimeout(show_recent.bind(this), 5)
|
||||||
|
return
|
||||||
|
container = document.getElementById(this)
|
||||||
|
if not container:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def init(container_id):
|
def init(container_id):
|
||||||
create_top_bar(container_id, run_animation=True)
|
create_top_bar(container_id, run_animation=True)
|
||||||
|
container = document.getElementById(container_id)
|
||||||
|
recent = E.div(style='display:none')
|
||||||
|
recent_container_id = ensure_id(recent)
|
||||||
|
container.appendChild(recent)
|
||||||
|
window.setTimeout(show_recent.bind(recent_container_id), 5)
|
||||||
|
|
||||||
set_default_panel_handler(init)
|
set_default_panel_handler(init)
|
||||||
|
@ -102,11 +102,20 @@ def load_interface_data():
|
|||||||
ajax('interface-data/init', on_data_loaded, on_data_load_progress, query=query).send()
|
ajax('interface-data/init', on_data_loaded, on_data_load_progress, query=query).send()
|
||||||
|
|
||||||
|
|
||||||
|
def on_update_interface_data():
|
||||||
|
ajax('interface-data/update', def (end_type, xhr, ev):
|
||||||
|
if end_type is 'load':
|
||||||
|
data = JSON.parse(xhr.responseText)
|
||||||
|
update_interface_data(data)
|
||||||
|
).send()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if get_interface_data().is_default:
|
interface_data = get_interface_data()
|
||||||
|
if interface_data.is_default or not interface_data.library_map:
|
||||||
load_interface_data()
|
load_interface_data()
|
||||||
else:
|
else:
|
||||||
interface_data = get_interface_data()
|
|
||||||
sd = UserSessionData(interface_data.username, interface_data.user_session_data)
|
sd = UserSessionData(interface_data.username, interface_data.user_session_data)
|
||||||
set_session_data(sd)
|
set_session_data(sd)
|
||||||
|
on_update_interface_data()
|
||||||
init_ui()
|
init_ui()
|
||||||
|
@ -142,6 +142,8 @@ default_interface_data = {
|
|||||||
'gui_last_modified_display_format': 'dd MMM yyyy',
|
'gui_last_modified_display_format': 'dd MMM yyyy',
|
||||||
'use_roman_numerals_for_series_number': True,
|
'use_roman_numerals_for_series_number': True,
|
||||||
'allow_console_print':False,
|
'allow_console_print':False,
|
||||||
|
'default_library_id': None,
|
||||||
|
'library_map': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_interface_data():
|
def get_interface_data():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user