Wire up the search panel

This commit is contained in:
Kovid Goyal 2017-02-15 15:03:22 +05:30
parent 9f83584025
commit ee3f47fdd2
3 changed files with 18 additions and 12 deletions

View File

@ -25,6 +25,7 @@ def url_books_query(sd):
return { return {
'library_id': lid, 'library_id': lid,
'sort': q.sort or sd.get_library_option(lid, 'sort'), 'sort': q.sort or sd.get_library_option(lid, 'sort'),
'search': q.search,
} }
@ -36,6 +37,7 @@ def loaded_books_query():
return { return {
'library_id': sr.library_id if sr else None, 'library_id': sr.library_id if sr else None,
'sort': sort, 'sort': sort,
'search': sr?.query
} }

View File

@ -70,9 +70,10 @@ def node_for_path(path):
def execute_search(text): def execute_search(text):
container = document.getElementById(state.container_id) if not text:
search_control = container.querySelector('input[name="search-books"]') container = document.getElementById(state.container_id)
text = text or search_control.value or '' search_control = container.querySelector('input[name="search-books"]')
text = search_control.value or ''
apply_search(text) apply_search(text)
@ -122,8 +123,7 @@ def search_expression_for_item(node, node_state):
rnum = '{}.5'.format(rnum - 1) rnum = '{}.5'.format(rnum - 1)
expr = '{}:{}'.format(category, rnum) expr = '{}:{}'.format(category, rnum)
else: else:
interface_data = get_interface_data() fm = library_data.field_metadata[item.category]
fm = interface_data.field_metadata[item.category]
suffix = ':' if fm and fm.is_csp else '' suffix = ':' if fm and fm.is_csp else ''
name = item.original_name or item.name or item.sort name = item.original_name or item.name or item.sort
if not name: 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') 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.firstChild.addEventListener('click', node_clicked.bind(None, i))
div.lastChild.addEventListener('click', menu_clicked.bind(i)) div.lastChild.addEventListener('click', menu_clicked.bind(None, i))
container.appendChild(div) container.appendChild(div)
def render_breadcrumbs(): def render_breadcrumbs():
@ -333,12 +333,12 @@ def on_data_fetched(end_type, xhr, ev):
container.appendChild(ediv) container.appendChild(ediv)
ediv.innerHTML = '<h3>' + _('Failed to load tag browser data') + '</h3>' + error_html ediv.innerHTML = '<h3>' + _('Failed to load tag browser data') + '</h3>' + error_html
def process_node(node): def process_node(node, item_map):
state.node_id_map[node.id] = node state.node_id_map[node.id] = node
node.data = item_map[node.id] node.data = item_map[node.id]
for child in node.children: for child in node.children:
child.parent = node child.parent = node
process_node(child) process_node(child, item_map)
if end_type is 'load': if end_type is 'load':
try: try:
@ -346,11 +346,10 @@ def on_data_fetched(end_type, xhr, ev):
except Exception as err: except Exception as err:
show_error(err + '') show_error(err + '')
return return
item_map = tag_browser_data.item_map
state.tag_browser_data = tag_browser_data.root state.tag_browser_data = tag_browser_data.root
state.node_id_map = {} state.node_id_map = {}
state.active_nodes = {} state.active_nodes = {}
process_node(state.tag_browser_data) process_node(state.tag_browser_data, tag_browser_data.item_map)
render_tag_browser() render_tag_browser()
else: else:
show_error(xhr.error_html) show_error(xhr.error_html)

View File

@ -241,7 +241,12 @@ def create_sort_panel(container_id):
# Searching {{{ # Searching {{{
def search(query, replace=False): 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);) set_apply_search(def(query): search(query, True);)