From b737612adb0fbf41cd3057eddae52b72b514f8d8 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 22 Jan 2021 05:39:14 +0100 Subject: [PATCH] Feat: Start display summary --- recopytex/dashboard/create_exam/app.py | 44 ++++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/recopytex/dashboard/create_exam/app.py b/recopytex/dashboard/create_exam/app.py index 179a89c..bc42366 100644 --- a/recopytex/dashboard/create_exam/app.py +++ b/recopytex/dashboard/create_exam/app.py @@ -60,7 +60,7 @@ layout = html.Div( children=[ "Nom de l'évaluation", dcc.Input( - id="name", + id="exam_name", type="text", placeholder="Nom de l'évaluation", ), @@ -70,7 +70,7 @@ layout = html.Div( children=[ "Date", dcc.DatePickerSingle( - id="my-date-picker-single", + id="date", date=date.today(), **get_current_year_limit(), ), @@ -101,7 +101,7 @@ layout = html.Div( className="add-exercise", ), html.Div( - id="output", + id="summary", ), ] ), @@ -116,6 +116,8 @@ layout = html.Div( dash.dependencies.State("exercises", "children"), ) def add_exercise(n_clicks, children): + if n_clicks is None: + return children element_table = pd.DataFrame(columns=NO_ST_COLUMNS) element_table = element_table.append(pd.Series(name=0)) new_exercise = html.Div( @@ -130,7 +132,7 @@ def add_exercise(n_clicks, children): ), html.Button( "X", - id=f"delete-exercise-{n_clicks}", + id={"type": "exercice", "index": str(n_clicks)}, className="delete-exercise", ), ], @@ -152,10 +154,13 @@ def add_exercise(n_clicks, children): ], data=element_table.to_dict("records"), editable=True, + row_deletable=True, dropdown={ - "Competence": {"options": [ - {'label': i, 'value': i} for i in config["competences"] - ]}, + "Competence": { + "options": [ + {"label": i, "value": i} for i in config["competences"] + ] + }, }, style_cell={ "whiteSpace": "normal", @@ -169,6 +174,7 @@ def add_exercise(n_clicks, children): ), ], className="exercise", + id=f"exercise-{n_clicks}", ) children.append(new_exercise) return children @@ -197,10 +203,22 @@ def add_element(n_clicks, elements): @app.callback( - dash.dependencies.Output("output", "children"), - dash.dependencies.Input( - {"type": "exercice", "index": dash.dependencies.ALL}, "value" - ), + dash.dependencies.Output("summary", "children"), + [ + dash.dependencies.Input("tribe", "value"), + dash.dependencies.Input("exam_name", "value"), + dash.dependencies.Input("date", "date"), + dash.dependencies.Input("term", "value"), + dash.dependencies.Input( + {"type": "exercice", "index": dash.dependencies.ALL}, "value" + ), + ], ) -def display_output(exercices): - return html.Div([html.P(f"{value}") for (i, value) in enumerate(exercices)]) +def display_summary(tribe, exam_name, date, term, exercices): + return html.Section( + children=[ + html.H1(f"{exam_name} pour les {tribe}"), + html.P(f"Fait le {date} (Trimestre {term})"), + ] + + [html.P(f"{value}") for (i, value) in enumerate(exercices)] + )