mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix an issue in the Query Tool which causes it to hang in some installations of Chrome 53.0.2785.116 on Mac.
This commit also modifies the Query Tool to load SlickGrid using require.js.
This commit is contained in:
@@ -73,6 +73,10 @@
|
||||
name: 'codemirror',
|
||||
location: '{{ url_for('static', filename='js/codemirror')}}',
|
||||
main: 'lib/codemirror'
|
||||
},{
|
||||
name: 'slickgrid',
|
||||
location: '{{ url_for('static', filename='js/slickgrid')}}',
|
||||
main: 'slick.core'
|
||||
}],
|
||||
shim: {
|
||||
"backbone": {
|
||||
@@ -119,17 +123,22 @@
|
||||
"pgadmin.backform": {
|
||||
"deps": ['backform', "pgadmin.backgrid", "select2"],
|
||||
},
|
||||
"jquery.event.drag": {
|
||||
"deps": ['jquery'], "exports": 'jQuery.fn.drag'
|
||||
},
|
||||
"jquery.ui": {"deps": ['jquery']},
|
||||
"slickgrid": {
|
||||
"deps": ['jquery', "jquery.ui", "jquery.event.drag", "slick.core",
|
||||
"slick.cellrangedecorator", "slick.cellrangeselector",
|
||||
"slick.cellselectionmodel", "slick.formatters",
|
||||
"slick.pgadmin.formatters", "slick.editors",
|
||||
"slick.pgadmin.editors", "slick.tooltip",
|
||||
"slick.checkboxselectcolumn", "slick.cellcopymanager",
|
||||
"slick.rowselectionmodel"
|
||||
"deps": [
|
||||
'jquery', "jquery.ui", "jquery.event.drag"
|
||||
],
|
||||
"exports": 'Slick'
|
||||
},
|
||||
"slickgrid/slick.grid": {
|
||||
"deps": [
|
||||
'jquery', "jquery.ui", "jquery.event.drag", "slickgrid"
|
||||
],
|
||||
"exports": 'Slick.Grid'
|
||||
},
|
||||
"flotr2": {
|
||||
deps: ['bean'],
|
||||
exports: function(bean) {
|
||||
@@ -166,20 +175,7 @@
|
||||
"pgadmin.backgrid": "{{ url_for('static', filename='js/backgrid/backgrid.pgadmin') }}",
|
||||
'pgadmin.backform': "{{ url_for('static', filename='js/backform.pgadmin') }}",
|
||||
"jquery.event.drag": "{{ url_for('static', filename='js/jquery-ui/jquery.event.drag-2.2') }}",
|
||||
"slickgrid": "{{ url_for('static', filename='js/slickgrid/slick.grid') }}",
|
||||
"slick.core": "{{ url_for('static', filename='js/slickgrid/slick.core') }}",
|
||||
"slick.formatters": "{{ url_for('static', filename='js/slickgrid/slick.formatters') }}",
|
||||
"slick.pgadmin.formatters": "{{ url_for('static', filename='js/slickgrid/slick.pgadmin.formatters') }}",
|
||||
"slick.editors": "{{ url_for('static', filename='js/slickgrid/slick.editors') }}",
|
||||
"slick.pgadmin.editors": "{{ url_for('static', filename='js/slickgrid/slick.pgadmin.editors') }}",
|
||||
"jquery.ui": "{{ url_for('static', filename='js/jquery-ui/jquery-ui-1.11.3' if config.DEBUG else 'js/jquery-ui/jquery-ui-1.11.3.min') }}",
|
||||
"slick.cellrangedecorator": "{{ url_for('static', filename='js/slickgrid/plugins/slick.cellrangedecorator') }}",
|
||||
"slick.cellrangeselector": "{{ url_for('static', filename='js/slickgrid/plugins/slick.cellrangeselector') }}",
|
||||
"slick.cellselectionmodel": "{{ url_for('static', filename='js/slickgrid/plugins/slick.cellselectionmodel') }}",
|
||||
"slick.tooltip": "{{ url_for('static', filename='js/slickgrid/plugins/slick.autotooltips') }}",
|
||||
"slick.checkboxselectcolumn": "{{ url_for('static', filename='js/slickgrid/plugins/slick.checkboxselectcolumn') }}",
|
||||
"slick.cellcopymanager": "{{ url_for('static', filename='js/slickgrid/plugins/slick.cellcopymanager') }}",
|
||||
"slick.rowselectionmodel": "{{ url_for('static', filename='js/slickgrid/plugins/slick.rowselectionmodel') }}",
|
||||
bean :"{{ url_for('static', filename='js/flotr2/' + ('bean' if config.DEBUG else 'bean-min')) }}",
|
||||
flotr2 :"{{ url_for('static', filename='js/flotr2/flotr2.amd') }}"{% for script in current_app.javascripts %},
|
||||
'{{ script.name }}': "{{ script.path }}"{% endfor %}
|
||||
|
||||
@@ -2,26 +2,37 @@ define(
|
||||
[
|
||||
'jquery', 'underscore', 'underscore.string', 'alertify', 'pgadmin',
|
||||
'backbone', 'backgrid', 'codemirror', 'pgadmin.misc.explain', 'slickgrid',
|
||||
'bootstrap', 'pgadmin.browser',
|
||||
'bootstrap', 'pgadmin.browser', 'wcdocker',
|
||||
'codemirror/mode/sql/sql', 'codemirror/addon/selection/mark-selection',
|
||||
'codemirror/addon/selection/active-line',
|
||||
'codemirror/addon/fold/foldgutter', 'codemirror/addon/fold/foldcode',
|
||||
'codemirror/addon/hint/show-hint', 'codemirror/addon/hint/sql-hint',
|
||||
'codemirror/addon/fold/pgadmin-sqlfoldcode','codemirror/addon/scroll/simplescrollbars',
|
||||
'backgrid.sizeable.columns', 'wcdocker', 'pgadmin.file_manager'
|
||||
'codemirror/addon/selection/active-line', 'codemirror/addon/fold/foldcode',
|
||||
'codemirror/addon/fold/foldgutter', 'codemirror/addon/hint/show-hint',
|
||||
'codemirror/addon/hint/sql-hint', 'pgadmin.file_manager',
|
||||
'codemirror/addon/fold/pgadmin-sqlfoldcode',
|
||||
'codemirror/addon/scroll/simplescrollbars',
|
||||
'backgrid.sizeable.columns', 'slickgrid/slick.formatters',
|
||||
'slickgrid/slick.pgadmin.formatters', 'slickgrid/slick.editors',
|
||||
'slickgrid/slick.pgadmin.editors', 'slickgrid/plugins/slick.autotooltips',
|
||||
'slickgrid/plugins/slick.cellrangedecorator',
|
||||
'slickgrid/plugins/slick.cellrangeselector',
|
||||
'slickgrid/plugins/slick.cellselectionmodel',
|
||||
'slickgrid/plugins/slick.checkboxselectcolumn',
|
||||
'slickgrid/plugins/slick.cellcopymanager',
|
||||
'slickgrid/plugins/slick.rowselectionmodel',
|
||||
'slickgrid/slick.grid'
|
||||
],
|
||||
function(
|
||||
$, _, S, alertify, pgAdmin, Backbone, Backgrid, CodeMirror, pgExplain, Slick
|
||||
$, _, S, alertify, pgAdmin, Backbone, Backgrid, CodeMirror, pgExplain
|
||||
) {
|
||||
// Some scripts do export their object in the window only.
|
||||
// Generally the one, which do no have AMD support.
|
||||
var wcDocker = window.wcDocker,
|
||||
pgBrowser = pgAdmin.Browser;
|
||||
|
||||
/* Return back, this has been called more than once */
|
||||
if (pgAdmin.SqlEditor)
|
||||
return pgAdmin.SqlEditor;
|
||||
|
||||
// Some scripts do export their object in the window only.
|
||||
// Generally the one, which do no have AMD support.
|
||||
var wcDocker = window.wcDocker,
|
||||
pgBrowser = pgAdmin.Browser,
|
||||
Slick = window.Slick;
|
||||
|
||||
/* Get the function definition from
|
||||
* http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript/35302975#35302975
|
||||
*/
|
||||
@@ -316,16 +327,24 @@ define(
|
||||
*/
|
||||
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
|
||||
var data = [],
|
||||
result = [];
|
||||
var doc = editor.getDoc();
|
||||
var cur = doc.getCursor();
|
||||
var current_line = cur.line; // gets the line number in the cursor position
|
||||
var current_cur = cur.ch; // get the current cursor position
|
||||
|
||||
/* Render function for hint to add our own class
|
||||
doc = editor.getDoc(),
|
||||
cur = doc.getCursor(),
|
||||
// Get the current cursor position
|
||||
current_cur = cur.ch,
|
||||
// function context
|
||||
ctx = {
|
||||
editor: editor,
|
||||
// URL for auto-complete
|
||||
url: "{{ url_for('sqleditor.index') }}" + "autocomplete/" +
|
||||
self.transId,
|
||||
data: data,
|
||||
// Get the line number in the cursor position
|
||||
current_line: cur.line,
|
||||
/*
|
||||
* Render function for hint to add our own class
|
||||
* and icon as per the object type.
|
||||
*/
|
||||
var hint_render = function(elt, data, cur) {
|
||||
hint_render: function(elt, data, cur) {
|
||||
var el = document.createElement('span');
|
||||
|
||||
switch(cur.type) {
|
||||
@@ -347,47 +366,52 @@ define(
|
||||
|
||||
el.appendChild(document.createTextNode(cur.text));
|
||||
elt.appendChild(el);
|
||||
}
|
||||
};
|
||||
|
||||
var full_text = doc.getValue();
|
||||
data.push(doc.getValue());
|
||||
// Get the text from start to the current cursor position.
|
||||
var text_before_cursor = doc.getRange({ line: 0, ch: 0 },
|
||||
{ line: current_line, ch: current_cur });
|
||||
|
||||
data.push(full_text);
|
||||
data.push(text_before_cursor);
|
||||
data.push(
|
||||
doc.getRange(
|
||||
{ line: 0, ch: 0 },
|
||||
{ line: ctx.current_line, ch: current_cur }
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
then: function(cb) {
|
||||
var self = this;
|
||||
// Make ajax call to find the autocomplete data
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "autocomplete/" + self.transId,
|
||||
url: self.url,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
data: JSON.stringify(self.data),
|
||||
success: function(res) {
|
||||
var result = [];
|
||||
|
||||
_.each(res.data.result, function(obj, key) {
|
||||
result.push({
|
||||
text: key, type: obj.object_type,
|
||||
render: hint_render
|
||||
render: self.hint_render
|
||||
});
|
||||
});
|
||||
|
||||
// Sort function to sort the suggestion's alphabetically.
|
||||
result.sort(function(a, b){
|
||||
var textA = a.text.toLowerCase(), textB = b.text.toLowerCase()
|
||||
var textA = a.text.toLowerCase(), textB = b.text.toLowerCase();
|
||||
if (textA < textB) //sort string ascending
|
||||
return -1
|
||||
return -1;
|
||||
if (textA > textB)
|
||||
return 1
|
||||
return 0 //default return value (no sorting)
|
||||
})
|
||||
}
|
||||
return 1;
|
||||
return 0; //default return value (no sorting)
|
||||
});
|
||||
|
||||
/* Below logic find the start and end point
|
||||
/*
|
||||
* Below logic find the start and end point
|
||||
* to replace the selected auto complete suggestion.
|
||||
*/
|
||||
var token = editor.getTokenAt(cur), start, end, search;
|
||||
var token = self.editor.getTokenAt(cur), start, end, search;
|
||||
if (token.end > cur.ch) {
|
||||
token.end = cur.ch;
|
||||
token.string = token.string.slice(0, cur.ch - token.start);
|
||||
@@ -402,14 +426,23 @@ define(
|
||||
search = "";
|
||||
}
|
||||
|
||||
/* Added 1 in the start position if search string
|
||||
/*
|
||||
* Added 1 in the start position if search string
|
||||
* started with "." or "`" else auto complete of code mirror
|
||||
* will remove the "." when user select any suggestion.
|
||||
*/
|
||||
if (search.charAt(0) == "." || search.charAt(0) == "``")
|
||||
start += 1;
|
||||
|
||||
return {list: result, from: {line: current_line, ch: start }, to: { line: current_line, ch: end }};
|
||||
cb({
|
||||
list: result,
|
||||
from: {line: self.current_line, ch: start },
|
||||
to: { line: self.current_line, ch: end }
|
||||
});
|
||||
}
|
||||
});
|
||||
}.bind(ctx)
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
@@ -778,12 +811,18 @@ define(
|
||||
|
||||
// Resize SlickGrid when window resize
|
||||
$( window ).resize( function() {
|
||||
// Resize grid only when 'Data Output' panel is visible.
|
||||
if(self.data_output_panel.isVisible()) {
|
||||
self.grid_resize(grid);
|
||||
}
|
||||
});
|
||||
|
||||
// Resize SlickGrid when output Panel resize
|
||||
self.data_output_panel.on(wcDocker.EVENT.RESIZE_ENDED, function() {
|
||||
// Resize grid only when 'Data Output' panel is visible.
|
||||
if(self.data_output_panel.isVisible()) {
|
||||
self.grid_resize(grid);
|
||||
}
|
||||
});
|
||||
|
||||
// Resize SlickGrid when output Panel gets focus
|
||||
@@ -1722,7 +1761,9 @@ define(
|
||||
}
|
||||
|
||||
// Fetch the columns metadata
|
||||
self.columns = self._fetch_column_metadata(data);
|
||||
self._fetch_column_metadata.call(
|
||||
self, data, function() {
|
||||
var self = this;
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:message',
|
||||
@@ -1748,27 +1789,54 @@ define(
|
||||
* and add json formatted data to collection and render.
|
||||
*/
|
||||
var explain_data_array = [];
|
||||
if(data.result &&
|
||||
data.result[0] && data.result[0].hasOwnProperty('QUERY PLAN') &&
|
||||
_.isObject(data.result[0]['QUERY PLAN'])) {
|
||||
if(
|
||||
data.result && data.result.length > 1 &&
|
||||
data.result[0] && data.result[0].hasOwnProperty(
|
||||
'QUERY PLAN'
|
||||
) && _.isObject(data.result[0]['QUERY PLAN'])
|
||||
) {
|
||||
var explain_data = {'QUERY PLAN' : JSON.stringify(data.result[0]['QUERY PLAN'], null, 2)};
|
||||
explain_data_array.push(explain_data);
|
||||
self.gridView.explain_panel.focus();
|
||||
pgExplain.DrawJSONPlan($('.sql-editor-explain'), data.result[0]['QUERY PLAN']);
|
||||
self.gridView.render_grid(explain_data_array, self.columns, self.can_edit);
|
||||
}
|
||||
else {
|
||||
self.gridView.render_grid(data.result, self.columns, self.can_edit);
|
||||
// Make sure - the 'Data Output' panel is visible, before - we
|
||||
// start rendering the grid.
|
||||
self.gridView.data_output_panel.focus();
|
||||
setTimeout(
|
||||
function() {
|
||||
self.gridView.render_grid(
|
||||
explain_data_array, self.columns, self.can_edit
|
||||
);
|
||||
// Make sure - the 'Explain' panel is visible, before - we
|
||||
// start rendering the grid.
|
||||
self.gridView.explain_panel.focus();
|
||||
pgExplain.DrawJSONPlan(
|
||||
$('.sql-editor-explain'), data.result[0]['QUERY PLAN']
|
||||
);
|
||||
}, 10
|
||||
);
|
||||
} else {
|
||||
// Make sure - the 'Data Output' panel is visible, before - we
|
||||
// start rendering the grid.
|
||||
self.gridView.data_output_panel.focus();
|
||||
setTimeout(
|
||||
function() {
|
||||
self.gridView.render_grid(data.result, self.columns, self.can_edit);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
|
||||
// Hide the loading icon
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
$("#btn-flash").prop('disabled', false);
|
||||
}.bind(self),
|
||||
function() {
|
||||
this.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
$("#btn-flash").prop('disabled', false);
|
||||
}.bind(self)
|
||||
);
|
||||
},
|
||||
|
||||
// This function creates the columns as required by the backgrid
|
||||
_fetch_column_metadata: function(data) {
|
||||
_fetch_column_metadata: function(data, cb, _fail) {
|
||||
var colinfo = data.colinfo,
|
||||
primary_keys = data.primary_keys,
|
||||
result = data.result,
|
||||
@@ -1784,7 +1852,6 @@ define(
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "fetch/types/" + self.transId,
|
||||
method: 'GET',
|
||||
async: false,
|
||||
success: function(res) {
|
||||
if (res.data.status) {
|
||||
// Store pg_types in an array
|
||||
@@ -1868,10 +1935,13 @@ define(
|
||||
else {
|
||||
alertify.alert('Fetching Type Error', res.data.result);
|
||||
}
|
||||
self.columns = columns;
|
||||
if (cb && typeof(cb) == 'function') {
|
||||
cb();
|
||||
}
|
||||
},
|
||||
fail: _fail
|
||||
});
|
||||
|
||||
return columns;
|
||||
},
|
||||
|
||||
// This function is used to raise appropriate message.
|
||||
@@ -2060,16 +2130,21 @@ define(
|
||||
}
|
||||
|
||||
if (save_data) {
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Saving the updated data...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to save the data
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "save/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(self.data_store),
|
||||
success: function(res) {
|
||||
var grid = self.slickgrid,
|
||||
data = grid.getData();;
|
||||
data = grid.getData();
|
||||
if (res.data.status) {
|
||||
// Remove deleted rows from client as well
|
||||
if(is_deleted) {
|
||||
@@ -2100,7 +2175,6 @@ define(
|
||||
$('.sql-editor-message').html('');
|
||||
} else {
|
||||
// Something went wrong while saving data on the db server
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
$("#btn-flash").prop('disabled', false);
|
||||
$('.sql-editor-message').text(res.data.result);
|
||||
var err_msg = S('{{ _('%s.') }}').sprintf(res.data.result).value();
|
||||
@@ -2126,11 +2200,13 @@ define(
|
||||
'query': r.sql, 'row_affected': r.rows_affected,
|
||||
'total_time': self.total_time, 'message': r.result
|
||||
});
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
});
|
||||
|
||||
grid.invalidate();
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
if (e.readyState == 0) {
|
||||
self.update_msg_history(false,
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
@@ -2228,17 +2304,20 @@ define(
|
||||
|
||||
// read file data and return as response
|
||||
_select_file_handler: function(e) {
|
||||
var self = this;
|
||||
|
||||
var self = this,
|
||||
data = {
|
||||
'file_name': e
|
||||
}
|
||||
};
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Loading the file...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to load the data from file
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "load_file/",
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(res) {
|
||||
@@ -2247,10 +2326,12 @@ define(
|
||||
self.gridView.current_file = e;
|
||||
self.setTitle(self.gridView.current_file.replace(/^\/|\/$/g, ''));
|
||||
}
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
},
|
||||
error: function(e) {
|
||||
var errmsg = $.parseJSON(e.responseText).errormsg;
|
||||
alertify.error(errmsg);
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2262,12 +2343,15 @@ define(
|
||||
'file_name': e,
|
||||
'file_content': self.gridView.query_tool_obj.getValue()
|
||||
}
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Saving the queries in the file...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to save the data to file
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "save_file/",
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(res) {
|
||||
@@ -2279,11 +2363,18 @@ define(
|
||||
$("#btn-save").prop('disabled', true);
|
||||
$("#btn-file-menu-save").css('display', 'none');
|
||||
}
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
|
||||
var errmsg = $.parseJSON(e.responseText).errormsg;
|
||||
setTimeout(
|
||||
function() {
|
||||
alertify.error(errmsg);
|
||||
}
|
||||
}, 10
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -2323,6 +2414,10 @@ define(
|
||||
_show_filter: function() {
|
||||
var self = this;
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Loading the existing filter options...') }}'
|
||||
);
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "filter/get/" + self.transId,
|
||||
method: 'GET',
|
||||
@@ -2338,23 +2433,32 @@ define(
|
||||
self.gridView.filter_obj.setValue(res.data.result);
|
||||
}
|
||||
else {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
alertify.alert('Get Filter Error', res.data.result);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
if (e.readyState == 0) {
|
||||
alertify.alert('Get Filter Error',
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
);
|
||||
return;
|
||||
}
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
|
||||
var msg = e.responseText;
|
||||
var msg;
|
||||
if (e.readyState == 0) {
|
||||
msg =
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
} else {
|
||||
msg = e.responseText;
|
||||
if (e.responseJSON != undefined &&
|
||||
e.responseJSON.errormsg != undefined)
|
||||
msg = e.responseJSON.errormsg;
|
||||
|
||||
}
|
||||
setTimeout(
|
||||
function() {
|
||||
alertify.alert('Get Filter Error', msg);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2381,14 +2485,21 @@ define(
|
||||
// Add column name and it's' value to data
|
||||
data[column_info.field] = _values[column_info.field] || '';
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Applying the new filter...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to include the filter by selection
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "filter/inclusive/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(res) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (res.data.status) {
|
||||
// Refresh the sql grid
|
||||
self._refresh();
|
||||
@@ -2396,8 +2507,13 @@ define(
|
||||
else {
|
||||
alertify.alert('Filter By Selection Error', res.data.result);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (e.readyState == 0) {
|
||||
alertify.alert('Filter By Selection Error',
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
@@ -2411,6 +2527,8 @@ define(
|
||||
msg = e.responseJSON.errormsg;
|
||||
|
||||
alertify.alert('Filter By Selection Error', msg);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2437,14 +2555,21 @@ define(
|
||||
// Add column name and it's' value to data
|
||||
data[column_info.field] = _values[column_info.field] || '';
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Applying the new filter...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to exclude the filter by selection.
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "filter/exclusive/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(res) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (res.data.status) {
|
||||
// Refresh the sql grid
|
||||
self._refresh();
|
||||
@@ -2452,8 +2577,14 @@ define(
|
||||
else {
|
||||
alertify.alert('Filter Exclude Selection Error', res.data.result);
|
||||
}
|
||||
}, 10
|
||||
);
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
if (e.readyState == 0) {
|
||||
alertify.alert('Filter Exclude Selection Error',
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
@@ -2467,6 +2598,8 @@ define(
|
||||
msg = e.responseJSON.errormsg;
|
||||
|
||||
alertify.alert('Filter Exclude Selection Error', msg);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2475,12 +2608,19 @@ define(
|
||||
_remove_filter: function () {
|
||||
var self = this;
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Removing the filter...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to exclude the filter by selection.
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "filter/remove/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
success: function(res) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (res.data.status) {
|
||||
// Refresh the sql grid
|
||||
self._refresh();
|
||||
@@ -2488,8 +2628,13 @@ define(
|
||||
else {
|
||||
alertify.alert('Remove Filter Error', res.data.result);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (e.readyState == 0) {
|
||||
alertify.alert('Remove Filter Error',
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
@@ -2504,6 +2649,8 @@ define(
|
||||
|
||||
alertify.alert('Remove Filter Error', msg);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -2512,14 +2659,21 @@ define(
|
||||
var self = this;
|
||||
sql = self.gridView.filter_obj.getValue();
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Applying the filter...') }}'
|
||||
);
|
||||
|
||||
// Make ajax call to include the filter by selection
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "filter/apply/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(sql),
|
||||
success: function(res) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (res.data.status) {
|
||||
$('#filter').addClass('hidden');
|
||||
$('#editor-panel').removeClass('sql-editor-busy-fetching');
|
||||
@@ -2529,8 +2683,13 @@ define(
|
||||
else {
|
||||
alertify.alert('Apply Filter Error',res.data.result);
|
||||
}
|
||||
}, 10
|
||||
);
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (e.readyState == 0) {
|
||||
alertify.alert('Apply Filter Error',
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
@@ -2544,6 +2703,8 @@ define(
|
||||
msg = e.responseJSON.errormsg;
|
||||
|
||||
alertify.alert('Apply Filter Error', msg);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2703,22 +2864,33 @@ define(
|
||||
var self = this;
|
||||
limit = parseInt($(".limit").val());
|
||||
|
||||
self.trigger(
|
||||
'pgadmin-sqleditor:loading-icon:show',
|
||||
'{{ _('Setting the limit on the result...') }}'
|
||||
);
|
||||
// Make ajax call to change the limit
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "limit/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(limit),
|
||||
success: function(res) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (res.data.status) {
|
||||
// Refresh the sql grid
|
||||
self._refresh();
|
||||
}
|
||||
else
|
||||
alertify.alert('Change limit Error', res.data.result);
|
||||
}, 10
|
||||
);
|
||||
},
|
||||
error: function(e) {
|
||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
setTimeout(
|
||||
function() {
|
||||
if (e.readyState == 0) {
|
||||
alertify.alert('Change limit Error',
|
||||
'{{ _('Not connected to the server or the connection to the server has been closed.') }}'
|
||||
@@ -2732,6 +2904,8 @@ define(
|
||||
msg = e.responseJSON.errormsg;
|
||||
|
||||
alertify.alert('Change limit Error', msg);
|
||||
}, 10
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2784,7 +2958,6 @@ define(
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "query_tool/start/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(sql),
|
||||
success: function(res) {
|
||||
@@ -2911,7 +3084,6 @@ define(
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "cancel/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
success: function(res) {
|
||||
if (res.data.status) {
|
||||
@@ -2985,13 +3157,11 @@ define(
|
||||
alertify.alert('Get Object Name Error', msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var cur_time = new Date();
|
||||
var filename = 'data-' + cur_time.getTime() + '.csv';
|
||||
self._trigger_csv_download(sql, filename);
|
||||
}
|
||||
|
||||
},
|
||||
// Trigger query result download to csv.
|
||||
_trigger_csv_download: function(query, filename) {
|
||||
@@ -3018,7 +3188,6 @@ define(
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "auto_rollback/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(auto_rollback),
|
||||
success: function(res) {
|
||||
@@ -3058,7 +3227,6 @@ define(
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "auto_commit/" + self.transId,
|
||||
method: 'POST',
|
||||
async: false,
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(auto_commit),
|
||||
success: function(res) {
|
||||
@@ -3267,29 +3435,8 @@ define(
|
||||
explain_buffers = false,
|
||||
explain_timing = false,
|
||||
auto_commit = true,
|
||||
auto_rollback = false;
|
||||
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "query_tool/preferences/" + self.transId ,
|
||||
method: 'GET',
|
||||
async: false,
|
||||
success: function(res) {
|
||||
if (res.data) {
|
||||
explain_verbose = res.data.explain_verbose;
|
||||
explain_costs = res.data.explain_costs;
|
||||
explain_buffers = res.data.explain_buffers;
|
||||
explain_timing = res.data.explain_timing;
|
||||
auto_commit = res.data.auto_commit;
|
||||
auto_rollback = res.data.auto_rollback;
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
alertify.alert('Get Preferences error',
|
||||
'{{ _('Error occurred while getting query tool options ') }}'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
auto_rollback = false,
|
||||
updateUI = function() {
|
||||
// Set Auto-commit and auto-rollback on query editor
|
||||
if (auto_commit &&
|
||||
$('.auto-commit').hasClass('visibility-hidden') === true)
|
||||
@@ -3329,6 +3476,30 @@ define(
|
||||
else {
|
||||
$('.explain-timing').addClass('visibility-hidden');
|
||||
}
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: "{{ url_for('sqleditor.index') }}" + "query_tool/preferences/" + self.transId ,
|
||||
method: 'GET',
|
||||
success: function(res) {
|
||||
if (res.data) {
|
||||
explain_verbose = res.data.explain_verbose;
|
||||
explain_costs = res.data.explain_costs;
|
||||
explain_buffers = res.data.explain_buffers;
|
||||
explain_timing = res.data.explain_timing;
|
||||
auto_commit = res.data.auto_commit;
|
||||
auto_rollback = res.data.auto_rollback;
|
||||
|
||||
updateUI();
|
||||
}
|
||||
},
|
||||
error: function(e) {
|
||||
updateUI();
|
||||
alertify.alert('Get Preferences error',
|
||||
'{{ _('Error occurred while getting query tool options ') }}'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user