public inbox for [email protected]
help / color / mirror / Atom feedFrom: Akshay Joshi <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: RM #1807 Query Tool Does Not Recognize When File Changes Have Been Saved
Date: Fri, 16 Dec 2016 14:17:05 +0530
Message-ID: <CANxoLDeuyz5d1+kKmpXiSdDMmtRGnKV+6dNmvtHeBTPjw6XV3w@mail.gmail.com> (raw)
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-hackers>
Hi All
Please find the attached patch to fix the RM #1807 Query Tool Does Not
Recognize When File Changes Have Been Saved.
--
*Akshay Joshi*
*Principal Software Engineer *
*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[application/octet-stream] RM_1807.patch (5.1K, 3-RM_1807.patch)
download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index 30a7932..3e0e938 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -305,7 +305,7 @@ define(
msg = '{{ _('The data has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
notify = true;
}
- } else if(self.handler.is_query_tool) {
+ } else if(self.handler.is_query_tool && self.handler.is_query_changed) {
// We will check for modified sql content
var sql = self.handler.gridView.query_tool_obj.getValue();
sql = sql.replace(/\s+/g, '');
@@ -1334,17 +1334,24 @@ define(
// If there is nothing to save, clear it.
if (!sql.length) { self.query_tool_obj.setValue(''); return; }
- alertify.confirm(
- '{{ _('Unsaved changes') }}',
- '{{ _('Are you sure you wish to discard the current changes?') }}',
- function() {
- // Do nothing as user do not want to save, just continue
- self.query_tool_obj.setValue('');
- },
- function() {
- return true;
- }
- ).set('labels', {ok:'Yes', cancel:'No'});
+ /* If is_query_changed flag is set to false then no need to
+ * confirm with the user for unsaved changes.
+ */
+ if (self.handler.is_query_changed) {
+ alertify.confirm(
+ '{{ _('Unsaved changes') }}',
+ '{{ _('Are you sure you wish to discard the current changes?') }}',
+ function() {
+ // Do nothing as user do not want to save, just continue
+ self.query_tool_obj.setValue('');
+ },
+ function() {
+ return true;
+ }
+ ).set('labels', {ok:'Yes', cancel:'No'});
+ } else {
+ self.query_tool_obj.setValue('');
+ }
},
// Callback function for the clear history button click.
@@ -2244,7 +2251,6 @@ define(
// Open save file dialog if query tool
if (self.is_query_tool) {
-
var current_file = self.gridView.current_file;
if (!_.isUndefined(current_file) && !save_as) {
self._save_file_handler(current_file);
@@ -2432,16 +2438,24 @@ define(
// If there is nothing to save, open file manager.
if (!sql.length) { self._open_select_file_manager(); return; }
- alertify.confirm('{{ _('Unsaved changes') }}',
- '{{ _('Are you sure you wish to discard the current changes?') }}',
- function() {
- // User do not want to save, just continue
- self._open_select_file_manager();
- },
- function() {
- return true;
- }
- ).set('labels', {ok:'Yes', cancel:'No'});
+ /* If is_query_changed flag is set to false then no need to
+ * confirm with the user for unsaved changes.
+ */
+ if (self.is_query_changed) {
+ alertify.confirm('{{ _('Unsaved changes') }}',
+ '{{ _('Are you sure you wish to discard the current changes?') }}',
+ function() {
+ // User do not want to save, just continue
+ self._open_select_file_manager();
+ },
+ function() {
+ return true;
+ }
+ ).set('labels', {ok:'Yes', cancel:'No'});
+ } else {
+ self._open_select_file_manager();
+ }
+
},
// Open FileManager
@@ -2484,6 +2498,13 @@ define(
self.trigger('pgadmin-sqleditor:loading-icon:hide');
// hide cursor
$busy_icon_div.removeClass('show_progress');
+
+ // disable save button on file save
+ $("#btn-save").prop('disabled', true);
+ $("#btn-file-menu-save").css('display', 'none');
+
+ // Update the flag as new content is just loaded.
+ self.is_query_changed = false;
},
error: function(e) {
var errmsg = $.parseJSON(e.responseText).errormsg;
@@ -2521,6 +2542,9 @@ define(
// disable save button on file save
$("#btn-save").prop('disabled', true);
$("#btn-file-menu-save").css('display', 'none');
+
+ // Update the flag as query is already saved.
+ self.is_query_changed = false;
}
self.trigger('pgadmin-sqleditor:loading-icon:hide');
},
@@ -2540,6 +2564,10 @@ define(
// codemirror text change event
_on_query_change: function(query_tool_obj) {
var self = this;
+
+ // Update the flag as query is changed.
+ self.is_query_changed = true;
+
if(query_tool_obj.getValue().length == 0) {
$("#btn-save").prop('disabled', true);
$("#btn-file-menu-save").css('display', 'none');
view thread (8+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin4][Patch]: RM #1807 Query Tool Does Not Recognize When File Changes Have Been Saved
In-Reply-To: <CANxoLDeuyz5d1+kKmpXiSdDMmtRGnKV+6dNmvtHeBTPjw6XV3w@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox