mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Sync annots from browser to server when using the sync button
This commit is contained in:
parent
f2e7f3e924
commit
c290f4e1cb
@ -106,6 +106,15 @@ class AnnotationsManager: # {{{
|
|||||||
self.set_highlights()
|
self.set_highlights()
|
||||||
self.set_bookmarks()
|
self.set_bookmarks()
|
||||||
|
|
||||||
|
def sync_annots_to_server(self, which):
|
||||||
|
if ui_operations.annots_changed:
|
||||||
|
amap = {}
|
||||||
|
if not which or which is 'bookmarks':
|
||||||
|
amap.bookmark = self.bookmarks.as_array()
|
||||||
|
if not which or which is 'highlights':
|
||||||
|
amap.highlight = Object.values(self.highlights)
|
||||||
|
ui_operations.annots_changed(amap)
|
||||||
|
|
||||||
def set_bookmarks(self, bookmarks):
|
def set_bookmarks(self, bookmarks):
|
||||||
bookmarks = bookmarks or v'[]'
|
bookmarks = bookmarks or v'[]'
|
||||||
self.bookmarks = list(bookmarks)
|
self.bookmarks = list(bookmarks)
|
||||||
@ -125,8 +134,7 @@ class AnnotationsManager: # {{{
|
|||||||
'title': title,
|
'title': title,
|
||||||
})
|
})
|
||||||
sort_annot_list(self.bookmarks, bookmark_get_cfi)
|
sort_annot_list(self.bookmarks, bookmark_get_cfi)
|
||||||
if ui_operations.bookmarks_changed:
|
self.sync_annots_to_server('bookmarks')
|
||||||
ui_operations.bookmarks_changed(self.bookmarks.as_array())
|
|
||||||
|
|
||||||
def remove_bookmark(self, title):
|
def remove_bookmark(self, title):
|
||||||
changed = False
|
changed = False
|
||||||
@ -135,8 +143,8 @@ class AnnotationsManager: # {{{
|
|||||||
b.removed = True
|
b.removed = True
|
||||||
b.timestamp = Date().toISOString()
|
b.timestamp = Date().toISOString()
|
||||||
changed = True
|
changed = True
|
||||||
if changed and ui_operations.bookmarks_changed:
|
if changed:
|
||||||
ui_operations.bookmarks_changed(self.bookmarks.as_array())
|
self.sync_annots_to_server('bookmarks')
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
def default_bookmark_title(self):
|
def default_bookmark_title(self):
|
||||||
@ -180,8 +188,7 @@ class AnnotationsManager: # {{{
|
|||||||
|
|
||||||
def delete_highlight(self, uuid):
|
def delete_highlight(self, uuid):
|
||||||
if self.remove_highlight(uuid):
|
if self.remove_highlight(uuid):
|
||||||
if ui_operations.highlights_changed:
|
self.sync_annots_to_server('highlights')
|
||||||
ui_operations.highlights_changed(Object.values(self.highlights))
|
|
||||||
|
|
||||||
def notes_for_highlight(self, uuid):
|
def notes_for_highlight(self, uuid):
|
||||||
h = self.highlights[uuid] if uuid else None
|
h = self.highlights[uuid] if uuid else None
|
||||||
@ -195,8 +202,7 @@ class AnnotationsManager: # {{{
|
|||||||
h.notes = notes
|
h.notes = notes
|
||||||
else:
|
else:
|
||||||
v'delete h.notes'
|
v'delete h.notes'
|
||||||
if ui_operations.highlights_changed:
|
self.sync_annots_to_server('highlights')
|
||||||
ui_operations.highlights_changed(Object.values(self.highlights))
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -244,8 +250,7 @@ class AnnotationsManager: # {{{
|
|||||||
}
|
}
|
||||||
if notes:
|
if notes:
|
||||||
annot.notes = notes
|
annot.notes = notes
|
||||||
if ui_operations.highlights_changed:
|
self.sync_annots_to_server('highlights')
|
||||||
ui_operations.highlights_changed(Object.values(self.highlights))
|
|
||||||
|
|
||||||
def highlights_for_currently_showing(self):
|
def highlights_for_currently_showing(self):
|
||||||
name = self.view.currently_showing.name
|
name = self.view.currently_showing.name
|
||||||
|
@ -135,6 +135,7 @@ class SyncBook: # {{{
|
|||||||
set_css(container, background_color=get_color('window-background'))
|
set_css(container, background_color=get_color('window-background'))
|
||||||
book = self.overlay.view.book
|
book = self.overlay.view.book
|
||||||
to_sync = v'[[book.key, new Date(0)]]'
|
to_sync = v'[[book.key, new Date(0)]]'
|
||||||
|
self.overlay.view.annotations_manager.sync_annots_to_server()
|
||||||
sync_library_books(book.key[0], to_sync, self.sync_data_received)
|
sync_library_books(book.key[0], to_sync, self.sync_data_received)
|
||||||
container.appendChild(E.div(
|
container.appendChild(E.div(
|
||||||
style='display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%',
|
style='display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%',
|
||||||
|
@ -75,8 +75,7 @@ class ReadUI:
|
|||||||
ui_operations.focus_iframe = self.focus_iframe.bind(self)
|
ui_operations.focus_iframe = self.focus_iframe.bind(self)
|
||||||
ui_operations.toggle_toc = self.toggle_toc.bind(self)
|
ui_operations.toggle_toc = self.toggle_toc.bind(self)
|
||||||
ui_operations.toggle_full_screen = self.toggle_full_screen.bind(self)
|
ui_operations.toggle_full_screen = self.toggle_full_screen.bind(self)
|
||||||
ui_operations.highlights_changed = self.highlights_changed.bind(self)
|
ui_operations.annots_changed = self.annots_changed.bind(self)
|
||||||
ui_operations.bookmarks_changed = self.bookmarks_changed.bind(self)
|
|
||||||
ui_operations.annotations_synced = self.annotations_synced.bind(self)
|
ui_operations.annotations_synced = self.annotations_synced.bind(self)
|
||||||
ui_operations.wait_for_messages_from = self.wait_for_messages_from.bind(self)
|
ui_operations.wait_for_messages_from = self.wait_for_messages_from.bind(self)
|
||||||
ui_operations.stop_waiting_for_messages_from = self.stop_waiting_for_messages_from.bind(self)
|
ui_operations.stop_waiting_for_messages_from = self.stop_waiting_for_messages_from.bind(self)
|
||||||
@ -217,12 +216,6 @@ class ReadUI:
|
|||||||
self.db.update_annotations_data_from_key(library_id, book_id, fmt, {'annotations_map': amap})
|
self.db.update_annotations_data_from_key(library_id, book_id, fmt, {'annotations_map': amap})
|
||||||
ajax_send(f'book-update-annotations/{library_id}/{book_id}/{fmt}', amap, def (): pass;)
|
ajax_send(f'book-update-annotations/{library_id}/{book_id}/{fmt}', amap, def (): pass;)
|
||||||
|
|
||||||
def highlights_changed(self, highlights):
|
|
||||||
self.annots_changed({'highlight': highlights})
|
|
||||||
|
|
||||||
def bookmarks_changed(self, bookmarks):
|
|
||||||
self.annots_changed({'bookmark': bookmarks})
|
|
||||||
|
|
||||||
def annotations_synced(self, amap):
|
def annotations_synced(self, amap):
|
||||||
library_id = self.base_url_data.library_id
|
library_id = self.base_url_data.library_id
|
||||||
book_id = self.base_url_data.book_id
|
book_id = self.base_url_data.book_id
|
||||||
|
@ -394,8 +394,9 @@ if window is window.top:
|
|||||||
to_python.scrollbar_context_menu(x, y, frac)
|
to_python.scrollbar_context_menu(x, y, frac)
|
||||||
ui_operations.close_prep_finished = def(cfi):
|
ui_operations.close_prep_finished = def(cfi):
|
||||||
to_python.close_prep_finished(cfi)
|
to_python.close_prep_finished(cfi)
|
||||||
ui_operations.highlights_changed = def(highlights):
|
ui_operations.annots_changed = def(amap):
|
||||||
to_python.highlights_changed(highlights)
|
if amap.highlight:
|
||||||
|
to_python.highlights_changed(amap.highlight)
|
||||||
|
|
||||||
document.body.appendChild(E.div(id='view'))
|
document.body.appendChild(E.div(id='view'))
|
||||||
window.onerror = onerror
|
window.onerror = onerror
|
||||||
|
Loading…
x
Reference in New Issue
Block a user