diff --git a/recopytex/dashboard/create_exam/app.py b/recopytex/dashboard/create_exam/app.py index 9da0690..179a89c 100644 --- a/recopytex/dashboard/create_exam/app.py +++ b/recopytex/dashboard/create_exam/app.py @@ -4,10 +4,13 @@ import dash import dash_html_components as html import dash_core_components as dcc +import dash_table from datetime import date import uuid +import pandas as pd -from ...scripts.getconfig import config, CONFIGPATH +from ...scripts.getconfig import config +from ...config import NO_ST_COLUMNS from ..app import app @@ -112,13 +115,15 @@ layout = html.Div( dash.dependencies.Input("add-exercise", "n_clicks"), dash.dependencies.State("exercises", "children"), ) -def display_dropdowns(n_clicks, children): - new_element = html.Div( +def add_exercise(n_clicks, children): + element_table = pd.DataFrame(columns=NO_ST_COLUMNS) + element_table = element_table.append(pd.Series(name=0)) + new_exercise = html.Div( children=[ html.Div( children=[ dcc.Input( - id={"type": "exercice", "index": str("n_clicks")}, + id={"type": "exercice", "index": str(n_clicks)}, type="text", placeholder="Nom de l'exercice", className="exercise-name", @@ -131,22 +136,66 @@ def display_dropdowns(n_clicks, children): ], className="exercise-head", ), - html.Div( + dash_table.DataTable( id={"type": "elements", "index": str(n_clicks)}, - children=[], + columns=[ + {"id": "Question", "name": "Question"}, + { + "id": "Competence", + "name": "Competence", + "presentation": "dropdown", + }, + {"id": "Domaine", "name": "Domaine"}, + {"id": "Commentaire", "name": "Commentaire"}, + {"id": "Bareme", "name": "Bareme"}, + {"id": "Est_nivele", "name": "Est_nivele"}, + ], + data=element_table.to_dict("records"), + editable=True, + dropdown={ + "Competence": {"options": [ + {'label': i, 'value': i} for i in config["competences"] + ]}, + }, + style_cell={ + "whiteSpace": "normal", + "height": "auto", + }, ), html.Button( "Ajouter un élément de notation", - id=f"add-element-{n_clicks}", + id={"type": "add-element", "index": str(n_clicks)}, className="add-element", ), ], className="exercise", ) - children.append(new_element) + children.append(new_exercise) return children +@app.callback( + dash.dependencies.Output( + {"type": "elements", "index": dash.dependencies.MATCH}, "data" + ), + dash.dependencies.Input( + {"type": "add-element", "index": dash.dependencies.MATCH}, "n_clicks" + ), + [ + dash.dependencies.State( + {"type": "elements", "index": dash.dependencies.MATCH}, "data" + ), + ], +) +def add_element(n_clicks, elements): + if n_clicks is None or n_clicks < len(elements): + return elements + + df = pd.DataFrame.from_records(elements) + df = df.append(pd.Series(name=n_clicks)) + return df.to_dict("records") + + @app.callback( dash.dependencies.Output("output", "children"), dash.dependencies.Input( @@ -155,10 +204,3 @@ def display_dropdowns(n_clicks, children): ) def display_output(exercices): return html.Div([html.P(f"{value}") for (i, value) in enumerate(exercices)]) - - -# @app.callback( -# dash.dependencies.Output("exam_store", "data"), -# ) -# def update_exam_store(): -# pass diff --git a/recopytex/dashboard/index.py b/recopytex/dashboard/index.py index c299937..79673ba 100644 --- a/recopytex/dashboard/index.py +++ b/recopytex/dashboard/index.py @@ -4,6 +4,7 @@ from dash.dependencies import Input, Output from .app import app from .exam_analysis import app as exam_analysis +from .create_exam import app as create_exam app.layout = html.Div( @@ -15,6 +16,8 @@ app.layout = html.Div( def display_page(pathname): if pathname == "/": return exam_analysis.layout + elif pathname == "/create-exam": + return create_exam.layout else: return "404"