diff --git a/src/calibre/srv/code.py b/src/calibre/srv/code.py index 0cef6bde2f..89b72d49df 100644 --- a/src/calibre/srv/code.py +++ b/src/calibre/srv/code.py @@ -64,6 +64,7 @@ def get_basic_query_data(ctx, rd): sorts, orders = ['timestamp'], ['desc'] return library_id, db, sorts, orders + _cached_translations = None @@ -82,17 +83,11 @@ def get_translations(): _cached_translations = load_json_file(zf.open(lang, 'r')) return _cached_translations + DEFAULT_NUMBER_OF_BOOKS = 50 -@endpoint('/interface-data/init', postprocess=json) -def interface_data(ctx, rd): - ''' - Return the data needed to create the server main UI - - Optional: ?num=50&sort=timestamp.desc&library_id= - &search=''&extra_books='' - ''' +def basic_interface_data(ctx, rd): ans = { 'username':rd.username, 'output_format':prefs['output_format'].upper(), @@ -103,8 +98,30 @@ def interface_data(ctx, rd): 'use_roman_numerals_for_series_number': get_use_roman(), 'translations': get_translations(), '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= + &search=''&extra_books='' + ''' + ans = basic_interface_data(ctx, rd) ud = {} if rd.username: # 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()), key=lambda (field, name):sort_key(name)) ans['field_metadata'] = db.field_metadata.all_metadata() - ans['icon_map'] = icon_map() - ans['icon_path'] = ctx.url_for('/icon', which='') mdata = ans['metadata'] = {} try: extra_books = set(int(x) for x in rd.query.get('extra_books', '').split(',')) diff --git a/src/pyj/book_list/home.pyj b/src/pyj/book_list/home.pyj index 114f09af1a..429cf67ed9 100644 --- a/src/pyj/book_list/home.pyj +++ b/src/pyj/book_list/home.pyj @@ -2,11 +2,30 @@ # License: GPL v3 Copyright: 2017, Kovid Goyal 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.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): 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) diff --git a/src/pyj/book_list/main.pyj b/src/pyj/book_list/main.pyj index 26c49c94f8..c36b0dcf6b 100644 --- a/src/pyj/book_list/main.pyj +++ b/src/pyj/book_list/main.pyj @@ -102,11 +102,20 @@ def load_interface_data(): 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(): - 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() else: - interface_data = get_interface_data() sd = UserSessionData(interface_data.username, interface_data.user_session_data) set_session_data(sd) + on_update_interface_data() init_ui() diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index 18fdfac65c..191c23a9d8 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -142,6 +142,8 @@ default_interface_data = { 'gui_last_modified_display_format': 'dd MMM yyyy', 'use_roman_numerals_for_series_number': True, 'allow_console_print':False, + 'default_library_id': None, + 'library_map': None, } def get_interface_data():