diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 6db0040..b2deb02 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -72,7 +72,8 @@ class SqlEditorModule(PgAdminModule): self.items_per_page = self.preference.register( 'display', 'items_per_page', gettext("Items per page in grid"), 'integer', 50, - category_label=gettext('Display') + category_label=gettext('Display'), + min_val=1 ) self.explain_verbose = self.preference.register( diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js index 14f6040..585545c 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js @@ -1106,6 +1106,8 @@ define( '{{ _('Initializing query execution.') }}' ); + $("#btn-flash").prop('disabled', true); + $.ajax({ url: "{{ url_for('sqleditor.index') }}" + "view_data/start/" + self.transId, method: 'GET', @@ -1141,6 +1143,10 @@ define( $('#btn-filter-dropdown').addClass('btn-default'); } + $("#btn-save").prop('disabled', true); + $("#btn-copy-row").prop('disabled', true); + $("#btn-paste-row").prop('disabled', true); + // Set the combo box value $(".limit").val(res.data.limit); @@ -1290,6 +1296,19 @@ define( $("#btn-filter-dropdown").prop('disabled', false); } + /* If user can edit the data then we should enabled + * add row, copy row and paste row buttons. + */ + if (self.can_edit) { + $("#btn-add-row").prop('disabled', false); + } + else { + $("#btn-save").prop('disabled', true); + $("#btn-add-row").prop('disabled', true); + $("#btn-copy-row").prop('disabled', true); + $("#btn-paste-row").prop('disabled', true); + } + // Fetch the columns metadata self.columns = self._fetch_column_metadata(data); @@ -1323,7 +1342,6 @@ define( self.collection.on('backgrid:editing', self.on_cell_editing, self); self.collection.on('backgrid:row:selected', self.on_row_selected, self); self.collection.on('backgrid:row:deselected', self.on_row_deselected, self); - self.listenTo(self.collection, "reset", self.collection_reset_callback); // Show message in message and history tab in case of query tool self.total_time = self.get_query_run_time(self.query_start_time, self.query_end_time); @@ -1354,29 +1372,7 @@ define( // Hide the loading icon self.trigger('pgadmin-sqleditor:loading-icon:hide'); - }, - - collection_reset_callback: function() { - var self = this - - /* If user can edit the data and current page is the - * last page of the paginator then we should enabled - * Copy Row, Paste Row and 'Add New Row' buttons. - */ - if (self.can_edit && - self.collection.state.currentPage != undefined && - self.collection.state.lastPage != undefined && - self.collection.state.currentPage == self.collection.state.lastPage) - { - $("#btn-add-row").prop('disabled', false); - $("#btn-copy-row").prop('disabled', false); - $("#btn-paste-row").prop('disabled', false); - } - else { - $("#btn-add-row").prop('disabled', true); - $("#btn-copy-row").prop('disabled', true); - $("#btn-paste-row").prop('disabled', true); - } + $("#btn-flash").prop('disabled', false); }, // This function creates the columns as required by the backgrid @@ -1558,6 +1554,8 @@ define( clear_grid = true; self.trigger('pgadmin-sqleditor:loading-icon:hide'); + $("#btn-flash").prop('disabled', false); + $('.sql-editor-message').text(msg); self.gridView.messages_panel.focus(); @@ -1703,6 +1701,10 @@ define( } self.selected_row = row; self.selected_model = row.model; + + if (self.can_edit) { + $("#btn-copy-row").prop('disabled', false); + } }, /* This is a callback function when backgrid row @@ -1726,7 +1728,23 @@ define( _add: function() { var self = this, empty_model = new (self.collection.model); - self.collection.add(empty_model); + + // If current page is not last page then confirm from the user + if (self.collection.state.currentPage != self.collection.state.lastPage) { + alertify.confirm('{{ _('Add New Row') }}', + '{{ _('The result set display will move to the last page. Do you wish to continue?') }}', + function() { + self.collection.getLastPage(); + self.collection.add(empty_model); + }, + function() { + // Do nothing as user canceled the operation. + } + ).set('labels', {ok:'Yes', cancel:'No'}); + } + else { + self.collection.add(empty_model); + } }, /* This function will fetch the list of changed models and make @@ -1818,6 +1836,7 @@ define( } else { self.trigger('pgadmin-sqleditor:loading-icon:hide'); + $("#btn-flash").prop('disabled', false); $('.sql-editor-message').text(res.data.result); self.gridView.messages_panel.focus(); } @@ -2156,6 +2175,7 @@ define( _copy_row: function() { var self = this; + $("#btn-paste-row").prop('disabled', false); // Save the selected model as copied model for future use if ('selected_model' in self) self.copied_model = self.selected_model; @@ -2166,7 +2186,6 @@ define( var self = this; new_model = null; if ('copied_model' in self && self.copied_model != null) { - $("#btn-save").prop('disabled', false); /* Find the model to be copied in the collection * if found then we need to clone the object, so @@ -2177,15 +2196,43 @@ define( else new_model = self.copied_model.clone(); - /* Add the model to the array of changedModels which - * will be used when save button is clicked. - */ - if (_.indexOf(self.changedModels, new_model.cid) == -1) { - self.changedModels.push(new_model.cid); + // If current page is not last page then confirm from the user + if (self.collection.state.currentPage != self.collection.state.lastPage) { + alertify.confirm('{{ _('Paste Row') }}', + '{{ _('The result set display will move to the last page. Do you wish to continue?') }}', + function() { + self.collection.getLastPage(); + + $("#btn-save").prop('disabled', false); + + /* Add the model to the array of changedModels which + * will be used when save button is clicked. + */ + if (_.indexOf(self.changedModels, new_model.cid) == -1) { + self.changedModels.push(new_model.cid); + } + + // Add the copied model to collection + self.collection.add(new_model); + }, + function() { + // Do nothing as user canceled the operation. + } + ).set('labels', {ok:'Yes', cancel:'No'}); } + else { + $("#btn-save").prop('disabled', false); - // Add the copied model to collection - self.collection.add(new_model); + /* Add the model to the array of changedModels which + * will be used when save button is clicked. + */ + if (_.indexOf(self.changedModels, new_model.cid) == -1) { + self.changedModels.push(new_model.cid); + } + + // Add the copied model to collection + self.collection.add(new_model); + } } }, @@ -2260,6 +2307,8 @@ define( '{{ _('Initializing the query execution!') }}' ); + $("#btn-flash").prop('disabled', true); + if (explain_prefix != undefined) sql = explain_prefix + ' ' + sql; diff --git a/web/pgadmin/utils/preferences.py b/web/pgadmin/utils/preferences.py index 862ccc8..00e4fd1 100644 --- a/web/pgadmin/utils/preferences.py +++ b/web/pgadmin/utils/preferences.py @@ -523,6 +523,10 @@ Did you forget to register it?""" ) try: + if pref.min_val is not None and int(value) < int(pref.min_val): + value = pref.min_val + if pref.max_val is not None and int(value) > int(pref.max_val): + value = pref.max_val pref.set(value) except Exception as e: current_app.logger.exeception(e)