Browse Source

Bug 32613: Add database tables to autocomplete

This patch adds a database call to get the table and column names in the
database and parse them into the autocomplete engine.

Test Plan:
As previous commit but also check for column/table names in the
autocomplete popup

Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
23.05.x
Jacob O'Mara 1 year ago
committed by Tomas Cohen Arazi
parent
commit
8925a0b7b6
Signed by: tomascohen GPG Key ID: 0A272EA1B2F3C15F
  1. 135
      koha-tmpl/intranet-tmpl/lib/codemirror/sql.js
  2. 3
      koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt
  3. 33
      reports/guided_reports.pl

135
koha-tmpl/intranet-tmpl/lib/codemirror/sql.js

File diff suppressed because one or more lines are too long

3
koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt

@ -1563,6 +1563,9 @@
}, },
extraKeys: {"Tab": "autocomplete"}, //enable tab to accept auto-complete extraKeys: {"Tab": "autocomplete"}, //enable tab to accept auto-complete
hint: CodeMirror.hint.sql, hint: CodeMirror.hint.sql,
hintOptions: {
tables: [% To.json(tables) | $raw %]
}
}); });
var ExcludedTriggerKeys = { //key-code combinations of keys that will not fire the auto-complete script var ExcludedTriggerKeys = { //key-code combinations of keys that will not fire the auto-complete script
"8": "backspace", "8": "backspace",

33
reports/guided_reports.pl

@ -163,16 +163,16 @@ elsif ( $phase eq 'Delete Multiple') {
} }
elsif ( $phase eq 'Delete Saved') { elsif ( $phase eq 'Delete Saved') {
# delete a report from the saved reports list # delete a report from the saved reports list
my $ids = $input->param('reports'); my $ids = $input->param('reports');
delete_report($ids); delete_report($ids);
print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved"); print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved");
exit; exit;
} }
elsif ( $phase eq 'Show SQL'){ elsif ( $phase eq 'Show SQL'){
my $id = $input->param('reports'); my $id = $input->param('reports');
my $report = Koha::Reports->find($id); my $report = Koha::Reports->find($id);
$template->param( $template->param(
@ -192,6 +192,7 @@ elsif ( $phase eq 'Edit SQL'){
my $report = Koha::Reports->find($id); my $report = Koha::Reports->find($id);
my $group = $report->report_group; my $group = $report->report_group;
my $subgroup = $report->report_subgroup; my $subgroup = $report->report_subgroup;
my $tables = get_tables();
$template->param( $template->param(
'sql' => $report->savedsql, 'sql' => $report->savedsql,
'reportname' => $report->report_name, 'reportname' => $report->report_name,
@ -203,7 +204,8 @@ elsif ( $phase eq 'Edit SQL'){
'usecache' => $usecache, 'usecache' => $usecache,
'editsql' => 1, 'editsql' => 1,
'mana_id' => $report->{mana_id}, 'mana_id' => $report->{mana_id},
'mana_comments' => $report->{comments} 'mana_comments' => $report->{comments},
'tables' => $tables
); );
} }
@ -219,6 +221,7 @@ elsif ( $phase eq 'Update SQL'){
my $public = $input->param('public'); my $public = $input->param('public');
my $save_anyway = $input->param('save_anyway'); my $save_anyway = $input->param('save_anyway');
my @errors; my @errors;
my $tables = get_tables();
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
if( $cache_expiry_units ){ if( $cache_expiry_units ){
@ -263,7 +266,7 @@ elsif ( $phase eq 'Update SQL'){
'public' => $public, 'public' => $public,
'problematic_authvals' => $problematic_authvals, 'problematic_authvals' => $problematic_authvals,
'warn_authval_problem' => 1, 'warn_authval_problem' => 1,
'phase_update' => 1 'phase_update' => 1,
); );
} else { } else {
@ -288,6 +291,7 @@ elsif ( $phase eq 'Update SQL'){
'cache_expiry' => $cache_expiry, 'cache_expiry' => $cache_expiry,
'public' => $public, 'public' => $public,
'usecache' => $usecache, 'usecache' => $usecache,
'tables' => $tables
); );
logaction( "REPORTS", "MODIFY", $id, "$reportname | $sql" ) if C4::Context->preference("ReportsLog"); logaction( "REPORTS", "MODIFY", $id, "$reportname | $sql" ) if C4::Context->preference("ReportsLog");
} }
@ -556,6 +560,7 @@ elsif ( $phase eq 'Save Report' ) {
my $cache_expiry_units = $input->param('cache_expiry_units'); my $cache_expiry_units = $input->param('cache_expiry_units');
my $public = $input->param('public'); my $public = $input->param('public');
my $save_anyway = $input->param('save_anyway'); my $save_anyway = $input->param('save_anyway');
my $tables = get_tables();
# if we have the units, then we came from creating a report from SQL and thus need to handle converting units # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
@ -640,6 +645,7 @@ elsif ( $phase eq 'Save Report' ) {
'cache_expiry' => $cache_expiry, 'cache_expiry' => $cache_expiry,
'public' => $public, 'public' => $public,
'usecache' => $usecache, 'usecache' => $usecache,
'tables' => $tables
); );
} }
} }
@ -998,6 +1004,8 @@ elsif ( $phase eq 'Create report from SQL' || $phase eq 'Create report from exis
$notes = $report->notes // ''; $notes = $report->notes // '';
} }
my $tables = get_tables();
$template->param( $template->param(
sql => $sql, sql => $sql,
reportname => $reportname, reportname => $reportname,
@ -1007,6 +1015,7 @@ elsif ( $phase eq 'Create report from SQL' || $phase eq 'Create report from exis
'public' => '0', 'public' => '0',
'cache_expiry' => 300, 'cache_expiry' => 300,
'usecache' => $usecache, 'usecache' => $usecache,
'tables' => $tables,
); );
} }
@ -1024,6 +1033,20 @@ sub header_cell_loop {
return \@headers; return \@headers;
} }
#get a list of available tables for auto-complete
sub get_tables {
my $result = {};
my $tables = C4::Reports::Guided->get_all_tables();
for my $table (@{$tables}) {
my $sql = "SHOW COLUMNS FROM $table";
my $rows = C4::Context->dbh->selectall_arrayref($sql, { Slice => {} });
for my $row (@{$rows}) {
push @{$result->{$table}}, $row->{Field};
}
}
return $result;
}
foreach (1..6) { foreach (1..6) {
$template->{VARS}->{'build' . $_} and last; $template->{VARS}->{'build' . $_} and last;
} }

Loading…
Cancel
Save