From ee3f47fdd25e4dae995cae57de639e055eccfa4b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Feb 2017 15:03:22 +0530 Subject: [PATCH] Wire up the search panel --- src/pyj/book_list/library_data.pyj | 2 ++ src/pyj/book_list/search.pyj | 21 ++++++++++----------- src/pyj/book_list/views.pyj | 7 ++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/pyj/book_list/library_data.pyj b/src/pyj/book_list/library_data.pyj index 9dc419d7d1..3f20f4f22f 100644 --- a/src/pyj/book_list/library_data.pyj +++ b/src/pyj/book_list/library_data.pyj @@ -25,6 +25,7 @@ def url_books_query(sd): return { 'library_id': lid, 'sort': q.sort or sd.get_library_option(lid, 'sort'), + 'search': q.search, } @@ -36,6 +37,7 @@ def loaded_books_query(): return { 'library_id': sr.library_id if sr else None, 'sort': sort, + 'search': sr?.query } diff --git a/src/pyj/book_list/search.pyj b/src/pyj/book_list/search.pyj index c0621f3077..3ab69efd57 100644 --- a/src/pyj/book_list/search.pyj +++ b/src/pyj/book_list/search.pyj @@ -70,9 +70,10 @@ def node_for_path(path): def execute_search(text): - container = document.getElementById(state.container_id) - search_control = container.querySelector('input[name="search-books"]') - text = text or search_control.value or '' + if not text: + container = document.getElementById(state.container_id) + search_control = container.querySelector('input[name="search-books"]') + text = search_control.value or '' apply_search(text) @@ -122,8 +123,7 @@ def search_expression_for_item(node, node_state): rnum = '{}.5'.format(rnum - 1) expr = '{}:{}'.format(category, rnum) else: - interface_data = get_interface_data() - fm = interface_data.field_metadata[item.category] + fm = library_data.field_metadata[item.category] suffix = ':' if fm and fm.is_csp else '' name = item.original_name or item.name or item.sort if not name: @@ -274,8 +274,8 @@ def render_children(container, children): ) ) set_css(div, max_width='45vw', border='solid 1px currentColor', border_radius='20px', margin='0.5rem', cursor='pointer', overflow='hidden', user_select='none') - div.firstChild.addEventListener('click', node_clicked.bind(i)) - div.lastChild.addEventListener('click', menu_clicked.bind(i)) + div.firstChild.addEventListener('click', node_clicked.bind(None, i)) + div.lastChild.addEventListener('click', menu_clicked.bind(None, i)) container.appendChild(div) def render_breadcrumbs(): @@ -333,12 +333,12 @@ def on_data_fetched(end_type, xhr, ev): container.appendChild(ediv) ediv.innerHTML = '

' + _('Failed to load tag browser data') + '

' + error_html - def process_node(node): + def process_node(node, item_map): state.node_id_map[node.id] = node node.data = item_map[node.id] for child in node.children: child.parent = node - process_node(child) + process_node(child, item_map) if end_type is 'load': try: @@ -346,11 +346,10 @@ def on_data_fetched(end_type, xhr, ev): except Exception as err: show_error(err + '') return - item_map = tag_browser_data.item_map state.tag_browser_data = tag_browser_data.root state.node_id_map = {} state.active_nodes = {} - process_node(state.tag_browser_data) + process_node(state.tag_browser_data, tag_browser_data.item_map) render_tag_browser() else: show_error(xhr.error_html) diff --git a/src/pyj/book_list/views.pyj b/src/pyj/book_list/views.pyj index 722dd9c923..7c9f6231e6 100644 --- a/src/pyj/book_list/views.pyj +++ b/src/pyj/book_list/views.pyj @@ -241,7 +241,12 @@ def create_sort_panel(container_id): # Searching {{{ def search(query, replace=False): - pass + q = loaded_books_query() + if query: + q.search = query + else: + v'delete q.search' + show_panel('book_list', query=q, replace=replace) set_apply_search(def(query): search(query, True);)