Allow configuration of CSV and clipboard formatting of query results. Fixes #2781

This commit is contained in:
Khushboo Vashi
2017-11-20 13:50:47 +00:00
committed by Dave Page
parent 2579458091
commit 0c566f132e
19 changed files with 247 additions and 72 deletions

View File

@@ -235,6 +235,83 @@ class SqlEditorModule(PgAdminModule):
)
)
self.csv_quoting = self.preference.register(
'CSV_output', 'csv_quoting',
gettext("CSV quoting"), 'options', 'strings',
category_label=gettext('CSV Output'),
options=[{'label': 'None', 'value': 'none'},
{'label': 'All', 'value': 'all'},
{'label': 'Strings', 'value': 'strings'}],
select2={
'allowClear': False,
'tags': False
}
)
self.csv_quote_char = self.preference.register(
'CSV_output', 'csv_quote_char',
gettext("CSV quote character"), 'options', '"',
category_label=gettext('CSV Output'),
options=[{'label': '"', 'value': '"'},
{'label': '\'', 'value': '\''}],
select2={
'allowClear': False,
'tags': True
}
)
self.csv_field_separator = self.preference.register(
'CSV_output', 'csv_field_separator',
gettext("CSV field separator"), 'options', ',',
category_label=gettext('CSV output'),
options=[{'label': ';', 'value': ';'},
{'label': ',', 'value': ','},
{'label': '|', 'value': '|'},
{'label': 'Tab', 'value': '\t'}],
select2={
'allowClear': False,
'tags': True
}
)
self.results_grid_quoting = self.preference.register(
'Results_grid', 'results_grid_quoting',
gettext("Result copy quoting"), 'options', 'strings',
category_label=gettext('Results grid'),
options=[{'label': 'None', 'value': 'none'},
{'label': 'All', 'value': 'all'},
{'label': 'Strings', 'value': 'strings'}],
select2={
'allowClear': False,
'tags': False
}
)
self.results_grid_quote_char = self.preference.register(
'Results_grid', 'results_grid_quote_char',
gettext("Result copy quote character"), 'options', '"',
category_label=gettext('Results grid'),
options=[{'label': '"', 'value': '"'},
{'label': '\'', 'value': '\''}],
select2={
'allowClear': False,
'tags': True
}
)
self.results_grid_field_separator = self.preference.register(
'Results_grid', 'results_grid_field_separator',
gettext("Result copy field separator"), 'options', '\t',
category_label=gettext('Results grid'),
options=[{'label': ';', 'value': ';'},
{'label': ',', 'value': ','},
{'label': '|', 'value': '|'},
{'label': 'Tab', 'value': '\t'}],
select2={
'allowClear': False,
'tags': True
}
)
blueprint = SqlEditorModule(MODULE_NAME, __name__, static_url_path='/static')
@@ -1634,7 +1711,9 @@ def start_query_download_tool(trans_id):
r.call_on_close(cleanup)
return r
r = Response(gen(), mimetype='text/csv')
r = Response(gen(quote=blueprint.csv_quoting.get(),
quote_char=blueprint.csv_quote_char.get(),
field_separator=blueprint.csv_field_separator.get()), mimetype='text/csv')
if 'filename' in data and data['filename'] != "":
filename = data['filename']

View File

@@ -792,6 +792,20 @@ define('tools.querytool', [
handleQueryOutputKeyboardEvent(event, args);
});
} else {
var pref_cache = undefined;
args.grid.CSVOptions = {};
if (self.handler.is_new_browser_tab) {
pref_cache = window.opener.pgAdmin.Browser.preferences_cache;
} else {
pref_cache = window.top.pgAdmin.Browser.preferences_cache;
}
// Get CSV options from preferences cache
args.grid.CSVOptions.quoting = _.findWhere(pref_cache, {'module': 'sqleditor', 'name': 'results_grid_quoting'}).value;
args.grid.CSVOptions.quote_char = _.findWhere(pref_cache, {'module': 'sqleditor', 'name': 'results_grid_quote_char'}).value;
args.grid.CSVOptions.field_separator = _.findWhere(pref_cache, {'module': 'sqleditor', 'name': 'results_grid_field_separator'}).value;
handleQueryOutputKeyboardEvent(event, args);
}
});
@@ -1236,7 +1250,20 @@ define('tools.querytool', [
// Callback function for copy button click.
on_copy_row: function () {
var self = this;
var self = this,
pref_cache = undefined;
self.grid.CSVOptions = {};
if (self.handler.is_new_browser_tab) {
pref_cache = window.opener.pgAdmin.Browser.preferences_cache;
} else {
pref_cache = window.top.pgAdmin.Browser.preferences_cache;
}
// Get CSV options from preferences cache
self.grid.CSVOptions.quoting = _.findWhere(pref_cache, {'module': 'sqleditor', 'name': 'results_grid_quoting'}).value;
self.grid.CSVOptions.quote_char = _.findWhere(pref_cache, {'module': 'sqleditor', 'name': 'results_grid_quote_char'}).value;
self.grid.CSVOptions.field_separator = _.findWhere(pref_cache, {'module': 'sqleditor', 'name': 'results_grid_field_separator'}).value;
// Trigger the copy signal to the SqlEditorController class
self.handler.trigger(
@@ -1244,6 +1271,7 @@ define('tools.querytool', [
self,
self.handler
);
},
// Callback function for paste button click.
@@ -1496,7 +1524,7 @@ define('tools.querytool', [
keyAction: function (event) {
keyboardShortcuts.processEvent(this.handler, queryToolActions, event);
},
}
});
/* Defining controller class for data grid, which actually
@@ -3649,7 +3677,6 @@ define('tools.querytool', [
explain_timing = res.data.explain_timing;
auto_commit = res.data.auto_commit;
auto_rollback = res.data.auto_rollback;
updateUI();
}
},