Merge #16736 - Inject the error report modal on each request to error reports

Pull-request: #16736

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-03-16 11:03:12 +01:00
commit 19b6b79565
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
7 changed files with 41 additions and 20 deletions

View File

@ -98,12 +98,18 @@ var ErrorReport = {
};
$.post('index.php?route=/error-report', reportData).done(function (data) {
// Delete the modal to refresh it in case the user changed SendErrorReports value
if (document.getElementById('errorReportModal') !== null) {
$('#errorReportModal').remove();
}
$('body').append($(data.report_modal));
const $errorReportModal = $('#errorReportModal');
$errorReportModal.on('show.bs.modal', function () {
// Prevents multiple onClick events
$('#errorReportModalConfirm').off('click', sendErrorReport);
$('#errorReportModalConfirm').on('click', sendErrorReport);
this.querySelector('.modal-body').innerHTML = data.message;
$('#errorReportModal .modal-body').html(data.message);
});
$errorReportModal.modal('show');
});

View File

@ -162,6 +162,7 @@ class ErrorReportController extends AbstractController
} elseif (! empty($_POST['get_settings'])) {
$this->response->addJSON('report_setting', $cfg['SendErrorReports']);
} elseif ($_POST['exception_type'] === 'js') {
$this->response->addJSON('report_modal', $this->errorReport->getEmptyModal());
$this->response->addHTML($this->errorReport->getForm());
} else {
// clear previous errors & save new ones.

View File

@ -287,6 +287,7 @@ class ErrorReport
'report_data' => $reportData,
'hidden_inputs' => Url::getHiddenInputs(),
'hidden_fields' => null,
'allowed_to_send_error_reports' => $this->config->get('SendErrorReports') !== 'never',
];
if (! empty($reportData)) {
@ -295,4 +296,11 @@ class ErrorReport
return $this->template->render('error/report_form', $datas);
}
public function getEmptyModal(): string
{
return $this->template->render('error/report_modal', [
'allowed_to_send_error_reports' => $this->config->get('SendErrorReports') !== 'never',
]);
}
}

View File

@ -363,7 +363,6 @@ class Footer
'is_demo' => $GLOBALS['cfg']['DBG']['demo'],
'demo_message' => $demoMessage ?? '',
'footer' => $footer ?? '',
'has_error_report_modal' => $GLOBALS['cfg']['SendErrorReports'] !== 'never',
]);
}

View File

@ -1,3 +1,4 @@
{% if allowed_to_send_error_reports %}
<p>
{% trans %}
This report automatically includes data about the error and information about relevant configuration settings. It will be sent to the phpMyAdmin team for debugging the error.
@ -28,3 +29,8 @@
{{ hidden_inputs|raw }}
{{ hidden_fields|raw }}
</form>
{% else %}
<div class="mb-3">
<pre class="pre-scrollable">{{ report_data|json_encode(constant('JSON_PRETTY_PRINT') b-or constant('JSON_UNESCAPED_SLASHES')) }}</pre>
</div>
{% endif %}

View File

@ -0,0 +1,19 @@
<div class="modal fade" id="errorReportModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="errorReportModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="errorReportModalLabel">{% trans 'Submit error report' %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans 'Cancel' %}"></button>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
{% if allowed_to_send_error_reports %}
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'Cancel' %}</button>
<button type="button" class="btn btn-primary" id="errorReportModalConfirm">{% trans 'Send error report' %}</button>
{% else %}
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">{% trans 'Close' %}</button>
{% endif %}
</div>
</div>
</div>
</div>

View File

@ -16,24 +16,6 @@
</div>
{% endif %}
{% if has_error_report_modal %}
<div class="modal fade" id="errorReportModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="errorReportModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="errorReportModalLabel">{% trans 'Submit error report' %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans 'Cancel' %}"></button>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'Cancel' %}</button>
<button type="button" class="btn btn-primary" id="errorReportModalConfirm">{% trans 'Send error report' %}</button>
</div>
</div>
</div>
</div>
{% endif %}
{{ footer|raw }}
{% endif %}
{% if not is_ajax %}