Skip to content

Commit bd44da2

Browse files
committed
feat: aggiunta formattazione query e funzione di copia-incolla
1 parent 28cc498 commit bd44da2

4 files changed

Lines changed: 114 additions & 29 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"devcode-it/ical-easy-reader": "dev-main",
3333
"devcode-it/sdd_ita": "dev-master",
3434
"digitick/sepa-xml": "^2.1",
35+
"doctrine/sql-formatter": "^1.5",
3536
"dragonmantank/cron-expression": "^1.0",
3637
"ezyang/htmlpurifier": "^4.8",
3738
"filp/whoops": "^2.15.0",

modules/viste/css/main.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Stili per la formattazione SQL */
2+
.sql-formatted {
3+
font-family: monospace;
4+
background-color: #f8f9fa;
5+
border-radius: 4px;
6+
padding: 15px;
7+
overflow: auto;
8+
max-height: 500px;
9+
}
10+
11+
.sql-formatted .keyword {
12+
color: #0033b3;
13+
font-weight: bold;
14+
}
15+
16+
.sql-formatted .string {
17+
color: #067d17;
18+
}
19+
20+
.sql-formatted .comment {
21+
color: #717171;
22+
font-style: italic;
23+
}
24+
25+
.sql-formatted .number {
26+
color: #1750eb;
27+
}
28+
29+
.sql-formatted .error {
30+
color: #ff0000;
31+
background-color: #fdd;
32+
}
33+
34+
/* Stile per il textarea nascosto usato per il copia-incolla */
35+
#query-to-copy {
36+
position: absolute;
37+
left: -9999px;
38+
}

modules/viste/edit.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Models\Clause;
2222
use Models\Module;
2323
use Models\View;
24+
use Doctrine\SqlFormatter\SqlFormatter;
2425

2526
include_once __DIR__.'/../../core.php';
2627

@@ -71,14 +72,23 @@
7172
if ($options != '' && $options != 'menu' && $options != 'custom') {
7273
$module_query = Util\Query::getQuery(Module::find($id_record));
7374

74-
$beautiful_query = nl2br(htmlentities((string) $module_query));
75-
$beautiful_query = str_replace(' ', '    ', $beautiful_query);
75+
// Utilizzo di SqlFormatter per formattare e colorare la query
76+
$sqlFormatter = new SqlFormatter();
77+
$beautiful_query = $sqlFormatter->highlight($module_query);
78+
79+
// Salva la query originale (senza formattazione HTML) per il copia-incolla
80+
$original_query = (string) $module_query;
7681

7782
echo '
7883
<div class="row">
7984
<div class="col-md-12">
80-
<p><strong>'.tr('Query risultante').':</strong></p>
81-
<div class="well">'.$beautiful_query.'</div>
85+
<p><strong>'.tr('Query risultante').':</strong>
86+
<button type="button" class="btn btn-sm btn-info" id="copy-query-btn" title="'.tr('Copia query').'">
87+
<i class="fa fa-copy"></i>
88+
</button>
89+
</p>
90+
<div class="sql-formatted well">'.$beautiful_query.'</div>
91+
<textarea id="query-to-copy" style="position: absolute; left: -9999px;">'.$original_query.'</textarea>
8292
8393
<div class="row">
8494
<div class="col-md-12 text-right">
@@ -129,29 +139,19 @@
129139
130140
</div>
131141
</div>';
132-
133-
echo '
134-
<script>
135-
function testQuery(){
136-
$("#main_loading").fadeIn();
137-
138-
$.ajax({
139-
url: "'.base_path().'/actions.php?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&op=test",
140-
cache: false,
141-
type: "post",
142-
processData: false,
143-
contentType: false,
144-
dataType : "html",
145-
success: function(data) {
146-
$("#main_loading").fadeOut();
147-
148-
if (data == "ok"){
149-
swal("'.tr('Query funzionante').'", "'.tr('La query attuale funziona correttamente!').'", "success");
150-
} else {
151-
swal("'.tr('Errore').'", data, "error");
152-
}
153-
}
154-
})
155-
}
156-
</script>';
157142
}
143+
144+
// Traduzioni per JavaScript
145+
echo '<script>
146+
if (typeof globals.translations === "undefined") {
147+
globals.translations = {};
148+
}
149+
globals.translations.copied = "'.tr('Copiato!').'";
150+
globals.translations.query_copied = "'.tr('La query è stata copiata negli appunti').'";
151+
globals.translations.working_query = "'.tr('Query funzionante').'";
152+
globals.translations.query_works_correctly = "'.tr('La query attuale funziona correttamente!').'";
153+
globals.translations.error = "'.tr('Errore').'";
154+
</script>
155+
<link rel="stylesheet" href="'.base_path().'/modules/viste/css/main.css">
156+
<script src="'.base_path().'/modules/viste/js/main.js"></script>
157+
';

modules/viste/js/main.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Funzione per copiare la query negli appunti
3+
*/
4+
function copyQueryToClipboard() {
5+
var copyText = document.getElementById("query-to-copy");
6+
copyText.select();
7+
document.execCommand("copy");
8+
9+
// Mostra un messaggio di conferma
10+
swal(globals.translations.copied, globals.translations.query_copied, "success");
11+
}
12+
13+
/**
14+
* Funzione per testare la query
15+
*/
16+
function testQuery() {
17+
$("#main_loading").fadeIn();
18+
19+
$.ajax({
20+
url: globals.rootdir + "/actions.php?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&op=test",
21+
cache: false,
22+
type: "post",
23+
processData: false,
24+
contentType: false,
25+
dataType: "html",
26+
success: function(data) {
27+
$("#main_loading").fadeOut();
28+
29+
if (data == "ok") {
30+
swal(globals.translations.working_query, globals.translations.query_works_correctly, "success");
31+
} else {
32+
swal(globals.translations.error, data, "error");
33+
}
34+
}
35+
});
36+
}
37+
38+
/**
39+
* Inizializzazione degli event listener quando il documento è pronto
40+
*/
41+
$(document).ready(function() {
42+
// Event listener per il pulsante di copia
43+
$("#copy-query-btn").click(function() {
44+
copyQueryToClipboard();
45+
});
46+
});

0 commit comments

Comments
 (0)