Skip to content

Commit 0ae0243

Browse files
Merge pull request #20028 from MauricioFauth/sql-bookmark-template
Refactor the sql/bookmark.twig template
2 parents 4c8d19d + 81104b0 commit 0ae0243

5 files changed

Lines changed: 42 additions & 38 deletions

File tree

resources/js/sql.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import $ from 'jquery';
22
import * as bootstrap from 'bootstrap';
33
import { AJAX } from './modules/ajax.ts';
4-
import { checkFormElementInRange, checkSqlQuery, prepareForAjaxRequest } from './modules/functions.ts';
4+
import { checkFormElementInRange, checkSqlQuery, emptyCheckTheField, prepareForAjaxRequest } from './modules/functions.ts';
55
import { Navigation } from './modules/navigation.ts';
66
import { CommonParams } from './modules/common.ts';
77
import createProfilingChart from './modules/functions/createProfilingChart.ts';
@@ -547,6 +547,13 @@ AJAX.registerOnload('sql.js', function () {
547547
// Ajaxification for 'Bookmark this SQL query'
548548
$(document).on('submit', '.bookmarkQueryForm', function (e) {
549549
e.preventDefault();
550+
551+
if (emptyCheckTheField(this, 'bkm_fields[bkm_label]')) {
552+
ajaxShowMessage(window.Messages.strFormEmpty, false, 'error');
553+
554+
return false;
555+
}
556+
550557
ajaxShowMessage();
551558
var argsep = CommonParams.get('arg_separator');
552559
$.post($(this).attr('action'), 'ajax_request=1' + argsep + $(this).serialize(), function (data) {
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
<form action="{{ url('/sql') }}" method="post" class="card bookmarkQueryForm d-print-none"
2-
onsubmit="return ! window.pmaEmptyCheckTheField(this, 'bkm_fields[bkm_label]');">
1+
<form action="{{ url('/sql') }}" method="post" class="card bookmarkQueryForm d-print-none disableAjax">
32
{{ get_hidden_inputs() }}
4-
<input type="hidden" name="db" value="{{ db }}">
5-
<input type="hidden" name="goto" value="{{ goto }}">
6-
<input type="hidden" name="bkm_fields[bkm_database]" value="{{ db }}">
7-
<input type="hidden" name="bkm_fields[bkm_user]" value="{{ user }}">
8-
<input type="hidden" name="bkm_fields[bkm_sql_query]" value="{{ sql_query }}">
3+
<input type="hidden" name="db" value="{{ db|e('html_attr') }}">
4+
<input type="hidden" name="goto" value="{{ url('/sql', {'db': db, 'table': table, 'sql_query': sql_query, 'id_bookmark': 1})|e('html_attr') }}">
5+
<input type="hidden" name="bkm_fields[bkm_database]" value="{{ db|e('html_attr') }}">
6+
<input type="hidden" name="bkm_fields[bkm_user]" value="{{ user|e('html_attr') }}">
7+
<input type="hidden" name="bkm_fields[bkm_sql_query]" value="{{ complete_sql_query|e('html_attr') }}">
98
<input type="hidden" name="store_bkm" value="1">
109

1110
<div class="card-header">{{ get_icon('b_bookmark', t('Bookmark this SQL query'), true) }}</div>
@@ -15,7 +14,7 @@
1514
<input class="form-control" id="bookmarkLabelField" type="text" name="bkm_fields[bkm_label]" value="">
1615
</div>
1716

18-
{% if allow_shared_bookmarks is defined and allow_shared_bookmarks %}
17+
{% if is_shared_bookmarks_allowed %}
1918
<div class="form-check form-switch">
2019
<input class="form-check-input" type="checkbox" role="switch" id="bookmarkAllUsersCheckbox" name="bkm_all_users" value="true">
2120
<label class="form-check-label" for="bookmarkAllUsersCheckbox">{{ t('Let every user access this bookmark') }}</label>

resources/templates/sql/no_results_returned.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
</div>
2121
{% endif %}
2222

23-
{{ bookmark|raw }}
23+
{% if bookmark is not empty %}
24+
{{ include('sql/_bookmark.twig', bookmark, with_context: false) }}
25+
{% endif %}
2426

2527
{{ include('modals/create_view.twig') }}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<div class="sqlqueryresults ajax">
2-
{{ previous_update_query|raw }}
3-
{{ profiling_chart|raw }}
4-
{{ missing_unique_column_message|raw }}
5-
{{ bookmark_created_message|raw }}
6-
{{ table|raw }}
7-
{{ bookmark_support|raw }}
2+
{{ previous_update_query|raw }}
3+
{{ profiling_chart|raw }}
4+
{{ missing_unique_column_message|raw }}
5+
{{ bookmark_created_message|raw }}
6+
{{ table|raw }}
7+
8+
{% if bookmark is not empty %}
9+
{{ include('sql/_bookmark.twig', bookmark, with_context: false) }}
10+
{% endif %}
811
</div>

src/Sql.php

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,25 +1019,21 @@ private function getQueryResponseForNoResultsReturned(
10191019

10201020
$profilingChart = $this->getProfilingChart($profilingResults);
10211021

1022-
$bookmark = '';
1022+
$bookmark = [];
10231023
$bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
10241024
if (
10251025
$bookmarkFeature !== null
10261026
&& (int) $request->getQueryParam('id_bookmark') <= 0
10271027
&& $sqlQuery
10281028
) {
1029-
$bookmark = $this->template->render('sql/bookmark', [
1029+
$bookmark = [
10301030
'db' => $db,
1031-
'goto' => Url::getFromRoute('/sql', [
1032-
'db' => $db,
1033-
'table' => $table,
1034-
'sql_query' => $sqlQuery,
1035-
'id_bookmark' => 1,
1036-
]),
1031+
'table' => $table,
10371032
'user' => $this->config->selectedServer['user'],
1038-
'sql_query' => $completeQuery,
1039-
'allow_shared_bookmarks' => $this->config->config->AllowSharedBookmarks,
1040-
]);
1033+
'sql_query' => $sqlQuery,
1034+
'complete_sql_query' => $completeQuery,
1035+
'is_shared_bookmarks_allowed' => $this->config->config->AllowSharedBookmarks,
1036+
];
10411037
}
10421038

10431039
return $this->template->render('sql/no_results_returned', [
@@ -1404,25 +1400,22 @@ private function getQueryResponseForResultsReturned(
14041400
$statementInfo,
14051401
);
14061402

1407-
$bookmarkSupportHtml = '';
1403+
$bookmark = [];
14081404
$bookmarkFeature = $this->relation->getRelationParameters()->bookmarkFeature;
14091405
if (
14101406
$bookmarkFeature !== null
14111407
&& $displayParts->hasBookmarkForm
14121408
&& (int) $request->getQueryParam('id_bookmark') <= 0
14131409
&& $sqlQuery
14141410
) {
1415-
$bookmarkSupportHtml = $this->template->render('sql/bookmark', [
1411+
$bookmark = [
14161412
'db' => $db,
1417-
'goto' => Url::getFromRoute('/sql', [
1418-
'db' => $db,
1419-
'table' => $table,
1420-
'sql_query' => $sqlQuery,
1421-
'id_bookmark' => 1,
1422-
]),
1413+
'table' => $table,
14231414
'user' => $this->config->selectedServer['user'],
1424-
'sql_query' => $completeQuery,
1425-
]);
1415+
'sql_query' => $sqlQuery,
1416+
'complete_sql_query' => $completeQuery,
1417+
'is_shared_bookmarks_allowed' => $this->config->config->AllowSharedBookmarks,
1418+
];
14261419
}
14271420

14281421
return $this->template->render('sql/sql_query_results', [
@@ -1431,7 +1424,7 @@ private function getQueryResponseForResultsReturned(
14311424
'missing_unique_column_message' => $missingUniqueColumnMessage,
14321425
'bookmark_created_message' => $bookmarkCreatedMessage,
14331426
'table' => $tableHtml,
1434-
'bookmark_support' => $bookmarkSupportHtml,
1427+
'bookmark' => $bookmark,
14351428
]);
14361429
}
14371430

0 commit comments

Comments
 (0)