Merge pull request #19308 from kamil-tekiela/formatSingleLine

Implement Format in a single line

Closes #17480
This commit is contained in:
Maurício Meneghini Fauth 2024-10-08 20:39:49 -03:00 committed by GitHub
commit 5d699d99ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View File

@ -263,7 +263,7 @@ const insertQuery = function (queryType) {
setQuery('');
return;
} else if (queryType === 'format') {
} else if (queryType === 'format' || queryType === 'formatSingleLine') {
if (window.codeMirrorEditor) {
$('#querymessage').html(window.Messages.strFormatting +
'&nbsp;<img class="ajaxIcon" src="' +
@ -272,7 +272,8 @@ const insertQuery = function (queryType) {
var params = {
'ajax_request': true,
'sql': window.codeMirrorEditor.getValue(),
'server': CommonParams.get('server')
'server': CommonParams.get('server'),
'formatSingleLine': queryType === 'formatSingleLine'
};
$.ajax({
type: 'POST',

View File

@ -38,6 +38,7 @@
<input type="button" value="{{ t('Clear') }}" id="clear" class="btn btn-secondary button sqlbutton">
{% if codemirror_enable %}
<input type="button" value="{{ t('Format') }}" id="format" class="btn btn-secondary button sqlbutton">
<input type="button" value="{{ t('Format as a single line') }}" id="formatSingleLine" class="btn btn-secondary button sqlbutton">
{% endif %}
</div>

View File

@ -23,7 +23,11 @@ final class SqlFormatController implements InvocableController
{
/** @var string $query */
$query = $request->getParsedBodyParam('sql', '');
$this->response->addJSON(['sql' => Formatter::format($query)]);
if ($request->getParsedBodyParam('formatSingleLine') === 'true') {
$this->response->addJSON(['sql' => Formatter::format($query, ['line_ending' => ' ', 'indentation' => ''])]);
} else {
$this->response->addJSON(['sql' => Formatter::format($query)]);
}
return $this->response->response();
}