From a64243fc2ca46c08285039758fd8553b6e78c2c8 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Thu, 14 Oct 2021 22:05:01 +0200 Subject: [PATCH] add link button to config and log --- web/assets/images/settings.svg | 1 + web/view/config_views.py | 28 +++++++++++++++++----------- web/view/views.py | 12 +++++++++--- 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 web/assets/images/settings.svg diff --git a/web/assets/images/settings.svg b/web/assets/images/settings.svg new file mode 100644 index 0000000..3fcff7d --- /dev/null +++ b/web/assets/images/settings.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/web/view/config_views.py b/web/view/config_views.py index 21b3071..c42ab6c 100644 --- a/web/view/config_views.py +++ b/web/view/config_views.py @@ -13,7 +13,7 @@ import dash_core_components as dcc import dash_html_components as html config = Config() -config_layout = dbc.Row(dbc.Col(className="col-md-12 col-lg-2 ml-2", children=[ +login_config_layout = dbc.Row(dbc.Col(md=12, lg=2, children=[ html.H2('Config'), dbc.Form([ dbc.FormGroup([ @@ -116,15 +116,22 @@ config_otp_layout = dbc.Row(dbc.Col(className="col-md-12 col-lg-2 ml-2", childre def log_layout(): with open(LOG_FILE, "r") as f: log_text = f.read() - return html.H3(children=["Log:", dbc.Textarea( - valid=True, - bs_size="sm", - className="mt-3", - style={"height": "80vh"}, - placeholder="Log", - contentEditable=False, - value=log_text - )]) + return html.H3(children=["Log:", dbc.Container( + fluid=True, + style={"height": "80vh", + "overflow": "auto", + "display": "flex", + "flex-direction": "column-reverse", + "white-space": "pre-line"}, + children=log_text, + className="m-3 bg-light h5"), + html.Div(id="empty-div")]) + + +config_layout = dbc.Tabs([ + dbc.Tab([log_layout()], label="Log"), + dbc.Tab([login_config_layout], label="User config"), + dbc.Tab([config_otp_layout], label="OTP config")]) @dash_app.callback( @@ -146,7 +153,6 @@ def connectPSA(n_clicks, app_name, email, password, countrycode): # pylint: dis return dbc.Alert(res, color="danger") else: return "" - raise PreventUpdate() @dash_app.callback( diff --git a/web/view/views.py b/web/view/views.py index 097380e..5c56cc5 100644 --- a/web/view/views.py +++ b/web/view/views.py @@ -20,7 +20,7 @@ from web import figures from web.app import app, dash_app from web.db import Database -from web.view.config_views import config_layout, config_otp_layout, log_layout +from web.view.config_views import login_config_layout, config_otp_layout, log_layout, config_layout from web.utils import diff_dashtable, dash_date_to_datetime # pylint: disable=invalid-name @@ -39,7 +39,11 @@ CONFIG = Config() def add_header(el): - return html.H1('My car info'), el + return dbc.Row([dbc.Col(dcc.Link(html.H1('My car info'), href="/", style={"text-decoration": "none"})), + dbc.Col(dcc.Link(html.Img(src="assets/images/settings.svg", width="30veh"), + href="/config", + className="float-right"))], + className="justify-content-between"), el @dash_app.callback(Output('page-content', 'children'), @@ -51,10 +55,12 @@ def display_page(pathname, search): no_header = query_params.get("header", None) == ["false"] if pathname == "/config": page = config_layout + elif pathname == "/config_login": + page = login_config_layout elif pathname == "/log": page = log_layout() elif not CONFIG.is_good: - page = dcc.Location(pathname=dash_app.requests_pathname_external_prefix + "config", id="config_redirect") + page = dcc.Location(pathname=dash_app.requests_pathname_external_prefix + "config_login", id="config_redirect") elif pathname == "/config_otp": page = config_otp_layout elif pathname == "/control":