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 <jvalleroy@mailbox.org>
[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 <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2023-10-26 19:52:57 -04:00 committed by Sunil Mohan Adapa
parent 2a8b9b94ba
commit 1f90047621
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 44 additions and 6 deletions

View File

@ -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'] = \

View File

@ -9,7 +9,18 @@
<h2>{% trans "Diagnostic Results" %}</h2>
<h3>{% blocktrans %}App: {{ app_name }}{% endblocktrans %}</h3>
<div class="row align-items-center justify-content-between">
<h3>{% blocktrans %}App: {{ app_name }}{% endblocktrans %}</h3>
{% if show_rerun_setup %}
<form class="form form-diagnostics-rerun-setup-button" method="post"
action="{% url 'rerun-setup' app_id=app_id %}">
{% csrf_token %}
<input type="submit" class="btn btn-default"
name="rerun-setup" value="{% trans "Re-run setup" %}"/>
</form>
{% endif %}
</div>
{% if results %}
{% include "diagnostics_results.html" with results=results %}

View File

@ -33,11 +33,22 @@
{% if results %}
<h3>{% trans "Results" %}</h3>
{% for app_id, app_data in results.results.items %}
<h4>
{% blocktrans with app_name=app_data.name %}
App: {{app_name}}
{% endblocktrans %}
</h4>
<div class="row align-items-center justify-content-between">
<h4>
{% blocktrans with app_name=app_data.name %}
App: {{app_name}}
{% endblocktrans %}
</h4>
{% if app_data.show_rerun_setup %}
<form class="form form-diagnostics-rerun-setup-button" method="post"
action="{% url 'rerun-setup' app_id=app_id %}">
{% csrf_token %}
<input type="submit" class="btn btn-default"
name="rerun-setup" value="{% trans "Re-run setup" %}"/>
</form>
{% endif %}
</div>
{% if app_data.diagnosis %}
{% include "diagnostics_results.html" with results=app_data.diagnosis %}

View File

@ -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,
})