diff --git a/web/pgadmin/static/js/sqleditor/filter_dialog.js b/web/pgadmin/static/js/sqleditor/filter_dialog.js index 56f49bd..7f86a25 100644 --- a/web/pgadmin/static/js/sqleditor/filter_dialog.js +++ b/web/pgadmin/static/js/sqleditor/filter_dialog.js @@ -215,18 +215,28 @@ let FilterDialog = { 'trans_id': handler.transId, }), filterCollectionModel - ).then(function () { + ).then(function (result) { // Hide Progress ... $( self.showFilterProgress[0] ).addClass('hidden'); - setTimeout( - function() { - self.close(); // Close the dialog now - Alertify.success(gettext('Filter updated successfully')); - queryToolActions.executeQuery(handler); - }, 10 - ); + + let response = result.data.data; + + if (response.status) { + setTimeout( + function() { + self.close(); // Close the dialog now + Alertify.success(gettext('Filter updated successfully')); + queryToolActions.executeQuery(handler); + }, 10 + ); + } else { + Alertify.alert( + gettext('Validation Error'), + response.result + ); + } }).catch(function (error) { // Hide Progress ... diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js index 6b386fd..e08b498 100644 --- a/web/pgadmin/tools/datagrid/static/js/datagrid.js +++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js @@ -302,6 +302,8 @@ define('pgadmin.datagrid', [ ); this.setContent($content.get(0)); + // Disable OK button + that.__internal.buttons[0].element.disabled = true; // Apply CodeMirror to filter text area. this.filter_obj = CodeMirror.fromTextArea($sql_filter.get(0), { @@ -324,6 +326,14 @@ define('pgadmin.datagrid', [ that.filter_obj.refresh(); that.filter_obj.focus(); }, 500); + + that.filter_obj.on('change', function() { + if (that.filter_obj.getValue() !== '') { + that.__internal.buttons[0].element.disabled = false; + } else { + that.__internal.buttons[0].element.disabled = true; + } + }); }, callback: function(closeEvent) { @@ -331,6 +341,7 @@ define('pgadmin.datagrid', [ if (closeEvent.button.text == gettext('OK')) { var sql = this.filter_obj.getValue(); var that = this; + closeEvent.cancel = true; // Do not close dialog // Make ajax call to include the filter by selection $.ajax({ @@ -344,6 +355,7 @@ define('pgadmin.datagrid', [ if (res.data.status) { // Initialize the data grid. self.create_transaction(that.baseUrl, null, 'false', parentData.server.server_type, '', grid_title, sql, false); + that.close(); // Close the dialog } else { alertify.alert( diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index 6659e3d..b748de3 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -276,21 +276,20 @@ class SQLFilter(object): status = True result = None - if row_filter is None or row_filter == '': - return False, gettext('Filter string is empty.') - - manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(self.sid) - conn = manager.connection(did=self.did) - - if conn.connected(): - sql = render_template( - "/".join([self.sql_path, 'validate.sql']), - nsp_name=self.nsp_name, object_name=self.object_name, - row_filter=row_filter) - - status, result = conn.execute_scalar(sql) - if not status: - result = result.partition("\n")[0] + if row_filter is not None and row_filter != '': + manager = \ + get_driver(PG_DEFAULT_DRIVER).connection_manager(self.sid) + conn = manager.connection(did=self.did) + + if conn.connected(): + sql = render_template( + "/".join([self.sql_path, 'validate.sql']), + nsp_name=self.nsp_name, object_name=self.object_name, + row_filter=row_filter) + + status, result = conn.execute_scalar(sql) + if not status: + result = result.partition("\n")[0] return status, result diff --git a/web/pgadmin/tools/sqleditor/utils/filter_dialog.py b/web/pgadmin/tools/sqleditor/utils/filter_dialog.py index 1bfa2e7..a78def4 100644 --- a/web/pgadmin/tools/sqleditor/utils/filter_dialog.py +++ b/web/pgadmin/tools/sqleditor/utils/filter_dialog.py @@ -87,12 +87,13 @@ class FilterDialog(object): if status and conn is not None and \ trans_obj is not None and session_obj is not None: trans_obj.set_data_sorting(data) - trans_obj.set_filter(data.get('sql')) - # As we changed the transaction object we need to - # restore it and update the session variable. - session_obj['command_obj'] = pickle.dumps(trans_obj, -1) - update_session_grid_transaction(trans_id, session_obj) - res = gettext('Data sorting object updated successfully') + status, res = trans_obj.set_filter(data.get('sql')) + if status: + # As we changed the transaction object we need to + # restore it and update the session variable. + session_obj['command_obj'] = pickle.dumps(trans_obj, -1) + update_session_grid_transaction(trans_id, session_obj) + res = gettext('Data sorting object updated successfully') else: return internal_server_error( errormsg=gettext('Failed to update the data on server.')