Content server: Allow editing notes from tag browser

This commit is contained in:
Kovid Goyal 2023-10-23 09:23:34 +05:30
parent c379616be0
commit a5abcf15ce
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 34 additions and 18 deletions

View File

@ -368,7 +368,9 @@ def resource_hash_to_url(ctx, scheme, digest, library_id):
def _get_note(ctx, rd, db, field, item_id, library_id):
note_data = db.notes_data_for(field, item_id)
if not note_data:
raise HTTPNotFound(f'Note for {field!r}:{item_id!r} not found')
if db.get_item_name(field, item_id):
return ''
raise HTTPNotFound(f'Item {field!r}:{item_id!r} not found')
note_data.pop('searchable_text', None)
resources = note_data.pop('resource_hashes', None)
if resources:

View File

@ -193,7 +193,7 @@ def render_metadata(mi, table, book_id, iframe_css): # {{{
link_maps = mi.link_maps or v'{}'
def show_note_action(field, item_id, item_val):
show_note(book_id, field, item_id, item_val)
show_note(field, item_id, item_val)
def add_note_link(field, name, val, parent):
if mi.items_with_notes[field] and mi.items_with_notes[field][val]:

View File

@ -87,9 +87,9 @@ def open_book_url(book_id, fmt, extra_query):
return ans + encode_query(q, '#')
def show_note(book_id, field, item_id, item_value, replace=False, library_id=None, close_action='back', panel='show_note'):
def show_note(field, item_id, item_value, replace=False, library_id=None, close_action='back', panel='show_note'):
lid = library_id or current_library_id()
q = {'book_id':book_id + '', 'field': field, 'item':item_value + '', 'item_id': (item_id or '')+ '', 'panel': panel}
q = {'field': field, 'item':item_value + '', 'item_id': (item_id or '')+ '', 'panel': panel}
if panel is 'show_note':
q.close_action = close_action
if lid:

View File

@ -14,7 +14,7 @@ from session import get_interface_data
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.router import back, show_note
from book_list.top_bar import create_top_bar, add_button
from book_list.globals import get_session_data
from book_list.theme import get_color, get_font_size
@ -222,20 +222,21 @@ def menu_clicked(i):
node = node_for_path().children[i]
data = node.data
name = data.original_name or data.name or data.sort
items = []
if data.count is not undefined:
items.append(_('Count: ') + data.count)
if data.avg_rating is not undefined:
items.append(_('Rating: {:.1f}').format(data.avg_rating))
suffix = ''
if items.length:
suffix = ' [' + items.join(' ') + ']'
title = E.h2(
style='display:flex; align-items: center; border-bottom: solid 1px currentColor; font-weight:bold; font-size:' + get_font_size('title'),
E.img(src=icon_for_node(node), style='height:2ex; margin-right: 0.5rem'),
E.span(name + suffix)
E.span(name)
)
def edit_note(field, item_name):
hide_modal()
show_note(field, 0, item_name, panel='edit_note')
if data.category and data.name and library_data.fields_that_support_notes.indexOf(data.category):
title.appendChild(E.a(svgicon('pencil'),
class_='blue-link', style='margin-left: 0.5em', href='javascript:void(0)',
onclick=edit_note.bind(None, data.category, data.name),
title=_('Edit or add notes for {}').format(data.name),
))
container.appendChild(title)
container.appendChild(E.div(
style='margin-top:1ex; margin-bottom: 1ex',
@ -280,6 +281,19 @@ def menu_clicked(i):
f.firstChild.nextSibling.addEventListener('change', def(ev):
get_session_data().set('and_search_terms', not ev.target.checked)
)
about_items = v'[]'
if data.count is not undefined:
about_items.push(_('Number of books: {}').format(data.count))
if data.avg_rating is not undefined:
about_items.push(_('Average rating of books: {:.1f}').format(data.avg_rating))
footer = E.div(
style='text-align:left; border-top: solid 1px currentColor; padding-top:1ex; margin-top:0.5ex;',
)
if about_items.length:
footer.appendChild(E.div(style='font-size: smaller', ' '.join(about_items)))
if footer.firstChild:
container.appendChild(footer)
show_modal(create_details)

View File

@ -69,7 +69,7 @@ def on_item_val_based_notes_fetched(load_type, xhr, ev):
q.html = data.html
q.item_id = str(data.item_id)
current_note_markup = q
show_note(q.book_id, q.field, q.item_id, q.item, replace=True, library_id=q.library_id or None, close_action=q.close_action, panel=q.panel)
show_note(q.field, q.item_id, q.item, replace=True, library_id=q.library_id or None, close_action=q.close_action, panel=q.panel)
return
old = container.querySelector('div.loading')
p = old.parentNode
@ -106,7 +106,7 @@ def on_notes_fetched(load_type, xhr, ev):
def edit_note():
q = parse_url_params()
show_note(q.book_id, q.field, q.item_id, q.item, library_id=q.library_id, panel='edit_note')
show_note(q.field, q.item_id, q.item, library_id=q.library_id, panel='edit_note')
def onkeydown(container_id, close_action, ev):
@ -215,7 +215,7 @@ def init_edit(container_id):
container = document.getElementById(container_id)
q = parse_url_params()
close_action, close_icon = get_close_action()
create_top_bar(container, title=_('Edit notes for:') + ' ' + q.item, action=close_action, icon=close_icon, tooltip=_('Discard any changes'))
create_top_bar(container, title=_('Edit {}').format(q.item), action=close_action, icon=close_icon, tooltip=_('Discard any changes'))
setup_container(container, close_action)
if q.item_id is '0' or q.item_id is 0 or not q.item_id:
return reroute_with_item_id(container, q)