Skip to content

Commit

Permalink
Add test and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 17, 2023
1 parent 4e2074d commit c4a8340
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def __getattribute__(self, attr):
curdoc and attr not in session_config[curdoc]):
new_obj = copy.copy(super().__getattribute__(attr))
setattr(self, attr, new_obj)
if attr in global_params or attr in ('global_loading_spinner', 'theme'):
if attr in global_params or attr == 'theme':
return super().__getattribute__(attr)
elif curdoc and curdoc in session_config and attr in session_config[curdoc]:
return session_config[curdoc][attr]
Expand Down
34 changes: 23 additions & 11 deletions panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
)
from bokeh.embed.util import RenderItem
from bokeh.io import curdoc
from bokeh.models import CustomJS
from bokeh.server.server import Server as BokehServer
from bokeh.server.urls import per_app_patterns
from bokeh.server.views.autoload_js_handler import (
Expand Down Expand Up @@ -121,6 +122,14 @@ def _eval_panel(
from ..pane import panel as as_panel
from ..template import BaseTemplate

if config.global_loading_spinner:
doc.js_on_event(
'document_ready', CustomJS(code=f"""
const body = document.getElementsByTagName('body')[0]
body.classList.remove({LOADING_INDICATOR_CSS_CLASS!r}, {config.loading_spinner!r})
""")
)

# Set up instrumentation for logging sessions
logger.info(LOG_SESSION_LAUNCHING, id(doc))
def _log_session_destroyed(session_context):
Expand Down Expand Up @@ -215,28 +224,31 @@ def server_html_page_for_session(
if template is FILE:
template = BASE_TEMPLATE

session.document._template_variables['theme_name'] = config.theme
session.document._template_variables['dist_url'] = dist_url
for root in session.document.roots:
doc = session.document
doc._template_variables['theme_name'] = config.theme
doc._template_variables['dist_url'] = dist_url
for root in doc.roots:
patch_model_css(root, dist_url=dist_url)

render_item = RenderItem(
token = token or session.token,
roots = session.document.roots,
roots = doc.roots,
use_for_title = False,
)

if template_variables is None:
template_variables = {}

bundle = bundle_resources(session.document.roots, resources)
html = html_page_for_render_items(bundle, {}, [render_item], title,
template=template, template_variables=template_variables)

if config.global_loading_spinner:
html = html.replace(
'<body>', f'<body class="{LOADING_INDICATOR_CSS_CLASS} {config.loading_spinner}">'
with set_curdoc(doc):
bundle = bundle_resources(doc.roots, resources)
html = html_page_for_render_items(
bundle, {}, [render_item], title, template=template,
template_variables=template_variables
)
if config.global_loading_spinner:
html = html.replace(
'<body>', f'<body class="{LOADING_INDICATOR_CSS_CLASS} {config.loading_spinner}">'
)
return html


Expand Down
27 changes: 27 additions & 0 deletions panel/tests/ui/io/test_loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time

import pytest

try:
from playwright.sync_api import expect
except ImportError:
pytestmark = pytest.mark.skip('playwright not available')

from panel.config import config
from panel.io.server import serve
from panel.pane import Markdown

pytestmark = pytest.mark.ui

def test_global_loading_indicator(page, port):
def app():
config.global_loading_spinner = True
return Markdown('Blah')

serve(app, port=port, threaded=True, show=False)

time.sleep(0.5)

page.goto(f"http://localhost:{port}")

expect(page.locator("body")).not_to_have_class('pn-loading')

0 comments on commit c4a8340

Please sign in to comment.