Adda button on the home page to show the currently logged in user

This commit is contained in:
Kovid Goyal 2017-05-16 10:31:45 +05:30
parent efc68144f0
commit 3e35fab553
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 29 additions and 8 deletions

1
imgsrc/srv/user.svg Normal file
View File

@ -0,0 +1 @@
<svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1600 1405q0 120-73 189.5t-194 69.5h-874q-121 0-194-69.5t-73-189.5q0-53 3.5-103.5t14-109 26.5-108.5 43-97.5 62-81 85.5-53.5 111.5-20q9 0 42 21.5t74.5 48 108 48 133.5 21.5 133.5-21.5 108-48 74.5-48 42-21.5q61 0 111.5 20t85.5 53.5 62 81 43 97.5 26.5 108.5 14 109 3.5 103.5zm-320-893q0 159-112.5 271.5t-271.5 112.5-271.5-112.5-112.5-271.5 112.5-271.5 271.5-112.5 271.5 112.5 112.5 271.5z"/></svg>

After

Width:  |  Height:  |  Size: 493 B

View File

@ -5,3 +5,4 @@ from __python__ import hash_literals, bound_methods
book_list_container_id = 'book-list-container'
read_book_container_id = 'read-book-container'
INIT_ENDPOINT = 'interface-data/init'

View File

@ -7,13 +7,14 @@ from gettext import gettext as _
from book_list.cover_grid import BORDER_RADIUS
from book_list.globals import get_db
from book_list.library_data import sync_library_books, last_virtual_library_for
from book_list.library_data import last_virtual_library_for, sync_library_books
from book_list.router import open_book, update_window_title
from book_list.top_bar import create_top_bar
from book_list.top_bar import add_button, create_top_bar
from book_list.ui import set_default_panel_handler, show_panel
from dom import add_extra_css, build_rule, ensure_id
from modals import create_custom_dialog
from session import get_device_uuid, get_interface_data
from utils import conditional_timeout, username_key
from utils import conditional_timeout, username_key, safe_set_inner_html
from widgets import create_button
CLASS_NAME = 'home-page'
@ -135,12 +136,32 @@ def show_recent():
db.get_recently_read_books(show_recent_stage2.bind(container.id))
def show_user_details():
interface_data = get_interface_data()
create_custom_dialog(_('Logged in as {}').format(interface_data.username), def(parent, close_modal):
msg = E.div()
safe_set_inner_html(msg, _(
'You are logged in as the user <b>{}</b>. To log in '
'as a different user, you will have to restart the browser.').format(interface_data.username))
parent.appendChild(msg)
parent.appendChild(
E.div(class_='button-box',
create_button(_('Close'), None, close_modal),
)
)
)
def init(container_id):
update_window_title()
container = document.getElementById(container_id)
container.classList.add(CLASS_NAME)
create_top_bar(container, run_animation=True)
interface_data = get_interface_data()
if interface_data.username:
add_button(container, 'user', show_user_details, _('Logged in as {}').format(interface_data.username))
# Recent books
recent = E.div(style='display:none', class_='recently-read')

View File

@ -12,7 +12,7 @@ from gettext import gettext as _, install
from popups import install_event_filters
from utils import safe_set_inner_html
from book_list.constants import book_list_container_id, read_book_container_id
from book_list.constants import book_list_container_id, read_book_container_id, INIT_ENDPOINT
from book_list.library_data import fetch_init_data, update_library_data, url_books_query
from book_list.theme import get_color
from book_list.router import update_window_title, set_default_mode_handler, apply_url, set_mode_handler, on_pop_state
@ -21,7 +21,7 @@ from book_list.ui import apply_url_state as book_list_mode_handler
from read_book.ui import ReadUI
# Register the various panels
from book_list.home import change_user
import book_list.home # noqa: unused-import
import book_list.views # noqa: unused-import
import book_list.local_books # noqa: unused-import
import book_list.book_details # noqa: unused-import
@ -84,8 +84,6 @@ def install_data_and_init_ui(raw_data):
get_translations(data.translations)
init_ui()
change_user.install_data_and_init_ui = install_data_and_init_ui
change_user.endpoint = 'interface-data/init'
def on_data_loaded(end_type, xhr, ev):
remove_initial_progress_bar()
@ -114,7 +112,7 @@ def load_interface_data():
if not idata.is_default:
temp = UserSessionData(None, {}) # So that settings for anonymous users are preserved
query = url_books_query(temp)
ajax(change_user.endpoint, on_data_loaded, on_data_load_progress, query=query).send()
ajax(INIT_ENDPOINT, on_data_loaded, on_data_load_progress, query=query).send()
def do_update_interface_data():