Merge pull request #19308 from kamil-tekiela/formatSingleLine
Implement Format in a single line Closes #17480
This commit is contained in:
commit
5d699d99ef
@ -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 +
|
||||
' <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',
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user