From 1f90047621f449334db23aba53e0da8405fef6d3 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Thu, 26 Oct 2023 19:52:57 -0400 Subject: [PATCH] diagnostics: Add shortcut to re-run setup for app - When running diagnostics for an app, if there are any failures or warnings, then show a button to re-run setup. - When showing all diagnostics results, if there are any failures or warnings for an app, then show a button to re-run setup for that app. Signed-off-by: James Valleroy [sunil: Use Result class instead of strings for comparison] [sunil: Use flex box's justify-content-between to improve button styling] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/diagnostics/__init__.py | 6 ++++++ .../templates/diagnostics_app.html | 13 +++++++++++- .../templates/diagnostics_full.html | 21 ++++++++++++++----- plinth/modules/diagnostics/views.py | 10 +++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index 0009438b9..0285270a2 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -126,6 +126,7 @@ def _run_on_all_enabled_modules(): app_results = { 'diagnosis': None, 'exception': None, + 'show_rerun_setup': False, } try: @@ -135,6 +136,11 @@ def _run_on_all_enabled_modules(): exception) app_results['exception'] = str(exception) + for check in app_results['diagnosis']: + if check.result in [Result.FAILED, Result.WARNING]: + app_results['show_rerun_setup'] = True + break + with results_lock: current_results['results'][app_id].update(app_results) current_results['progress_percentage'] = \ diff --git a/plinth/modules/diagnostics/templates/diagnostics_app.html b/plinth/modules/diagnostics/templates/diagnostics_app.html index b1bd75dd4..ba2eb77e7 100644 --- a/plinth/modules/diagnostics/templates/diagnostics_app.html +++ b/plinth/modules/diagnostics/templates/diagnostics_app.html @@ -9,7 +9,18 @@

{% trans "Diagnostic Results" %}

-

{% blocktrans %}App: {{ app_name }}{% endblocktrans %}

+
+

{% blocktrans %}App: {{ app_name }}{% endblocktrans %}

+ + {% if show_rerun_setup %} +
+ {% csrf_token %} + +
+ {% endif %} +
{% if results %} {% include "diagnostics_results.html" with results=results %} diff --git a/plinth/modules/diagnostics/templates/diagnostics_full.html b/plinth/modules/diagnostics/templates/diagnostics_full.html index a6e59ebef..836abd505 100644 --- a/plinth/modules/diagnostics/templates/diagnostics_full.html +++ b/plinth/modules/diagnostics/templates/diagnostics_full.html @@ -33,11 +33,22 @@ {% if results %}

{% trans "Results" %}

{% for app_id, app_data in results.results.items %} -

- {% blocktrans with app_name=app_data.name %} - App: {{app_name}} - {% endblocktrans %} -

+
+

+ {% blocktrans with app_name=app_data.name %} + App: {{app_name}} + {% endblocktrans %} +

+ + {% if app_data.show_rerun_setup %} +
+ {% csrf_token %} + +
+ {% endif %} +
{% if app_data.diagnosis %} {% include "diagnostics_results.html" with results=app_data.diagnosis %} diff --git a/plinth/modules/diagnostics/views.py b/plinth/modules/diagnostics/views.py index 7b1c0830a..a7006b886 100644 --- a/plinth/modules/diagnostics/views.py +++ b/plinth/modules/diagnostics/views.py @@ -17,6 +17,8 @@ from plinth.app import App from plinth.modules import diagnostics from plinth.views import AppView +from .check import Result + logger = logging.getLogger(__name__) @@ -87,10 +89,18 @@ def diagnose_app(request, app_id): exception) diagnosis_exception = str(exception) + show_rerun_setup = False + for check in diagnosis: + if check.result in [Result.FAILED, Result.WARNING]: + show_rerun_setup = True + break + return TemplateResponse( request, 'diagnostics_app.html', { 'title': _('Diagnostic Test'), + 'app_id': app_id, 'app_name': app_name, 'results': diagnosis, 'exception': diagnosis_exception, + 'show_rerun_setup': show_rerun_setup, })