Feat: dash setup and start home page

This commit is contained in:
Bertrand Benjamin 2021-04-13 06:26:45 +02:00
parent 94f8080acd
commit 598086ddb0
18 changed files with 148 additions and 0 deletions

View File

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
# encoding: utf-8
import dash
import flask
from .layout.layout import layout
server = flask.Flask(__name__)
app = dash.Dash(
__name__,
server=server,
suppress_callback_exceptions=True,
meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}],
)
app.layout = layout
server = app.server

View File

@ -0,0 +1,8 @@
#!/usr/bin/env python
# encoding: utf-8
from .app import app, server
from .routes import render_page_content
if __name__ == "__main__":
app.run_server(debug=True)

View File

@ -0,0 +1,9 @@
#!/usr/bin/env python
# encoding: utf-8
import dash_html_components as html
import dash_core_components as dcc
content = html.Div(id="page-content")
layout = html.Div([dcc.Location(id="url"), content])

View File

@ -0,0 +1,50 @@
#!/usr/bin/env python
# encoding: utf-8
import dash_html_components as html
from ....database.filesystem.loader import CSVLoader
from .models import get_tribes, get_exams, get_students
loader = CSVLoader("./test_config.yml")
def listing(elements, formating=lambda x: x):
return html.Ul(
children=[html.Li(children=formating(element)) for element in elements]
)
def format_tribe(tribe):
children = [html.H3(tribe["name"])]
exams = loader.get_exams([tribe["name"]])
if exams.empty:
children.append(html.P("Pas d'évaluation"))
else:
exams_html = listing([exam for id, exam in exams.iterrows()], format_exam)
children.append(exams_html)
return children
def format_exam(exam):
children = [html.P(exam["name"])]
return children
layout = html.Div(
children=[
html.H1("Recopytex"),
html.H2("Tribes"),
html.Div(
children=[listing(loader.get_tribes().values(), format_tribe)],
id="tribes",
),
html.H2("Config"),
html.Div(
children=[
html.P(str(loader.get_config())),
],
id="config",
),
]
)

View File

@ -0,0 +1,6 @@
#!/usr/bin/env python
# encoding: utf-8
from dash.dependencies import Input, Output
from ...app import app

View File

@ -0,0 +1,14 @@
#!/usr/bin/env python
# encoding: utf-8
def get_tribes(loader):
return loader.get_tribes()
def get_exams(loader, tribe):
return loader.get_exams([tribe])
def get_students(loader, tribe):
return loader.get_students([tribe])

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python
# encoding: utf-8
from dash.dependencies import Input, Output
from .app import app
from .pages.home import app as home
@app.callback(Output("page-content", "children"), [Input("url", "pathname")])
def render_page_content(pathname):
if pathname == "/":
return home.layout
# elif pathname == gdp_page_location:
# return gdp.layout
# elif pathname == iris_page_location:
# return iris.layout
# # If the user tries to reach a different page, return a 404 message
# return dbc.Jumbotron(
# [
# html.H1("404: Not found", className="text-danger"),
# html.Hr(),
# html.P(f"The pathname {pathname} was not recognised..."),
# ]
# )

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
# encoding: utf-8
import click
from ..dashboard.app import app as dash
@click.group()
def cli():
pass
@cli.command()
@click.option("--debug", default=0, help="Debug mode for dash")
def dashboard(debug):
dash.run_server(debug=bool(debug))