From 3e35fab553990cab7a373dd87fec7af7921d706e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 16 May 2017 10:31:45 +0530 Subject: [PATCH] Adda button on the home page to show the currently logged in user --- imgsrc/srv/user.svg | 1 + src/pyj/book_list/constants.pyj | 1 + src/pyj/book_list/home.pyj | 27 ++++++++++++++++++++++++--- src/pyj/book_list/main.pyj | 8 +++----- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 imgsrc/srv/user.svg diff --git a/imgsrc/srv/user.svg b/imgsrc/srv/user.svg new file mode 100644 index 0000000000..5d34471482 --- /dev/null +++ b/imgsrc/srv/user.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/pyj/book_list/constants.pyj b/src/pyj/book_list/constants.pyj index a6c5041084..ad40262112 100644 --- a/src/pyj/book_list/constants.pyj +++ b/src/pyj/book_list/constants.pyj @@ -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' diff --git a/src/pyj/book_list/home.pyj b/src/pyj/book_list/home.pyj index 1c4b8667d4..808693c365 100644 --- a/src/pyj/book_list/home.pyj +++ b/src/pyj/book_list/home.pyj @@ -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 {}. 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') diff --git a/src/pyj/book_list/main.pyj b/src/pyj/book_list/main.pyj index 04d659c33c..33b44d7361 100644 --- a/src/pyj/book_list/main.pyj +++ b/src/pyj/book_list/main.pyj @@ -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():