mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Properly detect when files have changed in the query tool and set the dirty flag accordingly. Fixes #1807
Note that (like pgAdmin 3) we don't make any attempt to detect if all changes have been undone and completely reverted as that could be very expensive with large scripts.
This commit is contained in:
parent
07e1c61eea
commit
ae809c4506
@ -307,15 +307,9 @@ define(
|
|||||||
msg = '{{ _('The data has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
msg = '{{ _('The data has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
||||||
notify = true;
|
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
|
msg = '{{ _('The query has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
||||||
var sql = self.handler.gridView.query_tool_obj.getValue();
|
notify = true;
|
||||||
sql = sql.replace(/\s+/g, '');
|
|
||||||
// If it is an empty query, do nothing.
|
|
||||||
if (sql.length > 0) {
|
|
||||||
msg = '{{ _('The query has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
|
||||||
notify = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(notify) {return self.user_confirmation(p, msg);}
|
if(notify) {return self.user_confirmation(p, msg);}
|
||||||
return true;
|
return true;
|
||||||
@ -1330,23 +1324,24 @@ define(
|
|||||||
this._stopEventPropogation(ev);
|
this._stopEventPropogation(ev);
|
||||||
this._closeDropDown(ev);
|
this._closeDropDown(ev);
|
||||||
|
|
||||||
// We will check for modified sql content
|
/* If is_query_changed flag is set to false then no need to
|
||||||
sql = self.query_tool_obj.getValue();
|
* confirm with the user for unsaved changes.
|
||||||
sql = sql.replace(/\s+/g, '');
|
*/
|
||||||
// If there is nothing to save, clear it.
|
if (self.handler.is_query_changed) {
|
||||||
if (!sql.length) { self.query_tool_obj.setValue(''); return; }
|
alertify.confirm(
|
||||||
|
'{{ _('Unsaved changes') }}',
|
||||||
alertify.confirm(
|
'{{ _('Are you sure you wish to discard the current changes?') }}',
|
||||||
'{{ _('Unsaved changes') }}',
|
function() {
|
||||||
'{{ _('Are you sure you wish to discard the current changes?') }}',
|
// Do nothing as user do not want to save, just continue
|
||||||
function() {
|
self.query_tool_obj.setValue('');
|
||||||
// Do nothing as user do not want to save, just continue
|
},
|
||||||
self.query_tool_obj.setValue('');
|
function() {
|
||||||
},
|
return true;
|
||||||
function() {
|
}
|
||||||
return true;
|
).set('labels', {ok:'Yes', cancel:'No'});
|
||||||
}
|
} else {
|
||||||
).set('labels', {ok:'Yes', cancel:'No'});
|
self.query_tool_obj.setValue('');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Callback function for the clear history button click.
|
// Callback function for the clear history button click.
|
||||||
@ -2246,7 +2241,6 @@ define(
|
|||||||
|
|
||||||
// Open save file dialog if query tool
|
// Open save file dialog if query tool
|
||||||
if (self.is_query_tool) {
|
if (self.is_query_tool) {
|
||||||
|
|
||||||
var current_file = self.gridView.current_file;
|
var current_file = self.gridView.current_file;
|
||||||
if (!_.isUndefined(current_file) && !save_as) {
|
if (!_.isUndefined(current_file) && !save_as) {
|
||||||
self._save_file_handler(current_file);
|
self._save_file_handler(current_file);
|
||||||
@ -2428,22 +2422,25 @@ define(
|
|||||||
// load select file dialog
|
// load select file dialog
|
||||||
_load_file: function() {
|
_load_file: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
// We will check for modified sql content
|
|
||||||
sql = self.gridView.query_tool_obj.getValue()
|
|
||||||
sql = sql.replace(/\s+/g, '');
|
|
||||||
// If there is nothing to save, open file manager.
|
|
||||||
if (!sql.length) { self._open_select_file_manager(); return; }
|
|
||||||
|
|
||||||
alertify.confirm('{{ _('Unsaved changes') }}',
|
/* If is_query_changed flag is set to false then no need to
|
||||||
'{{ _('Are you sure you wish to discard the current changes?') }}',
|
* confirm with the user for unsaved changes.
|
||||||
function() {
|
*/
|
||||||
// User do not want to save, just continue
|
if (self.is_query_changed) {
|
||||||
self._open_select_file_manager();
|
alertify.confirm('{{ _('Unsaved changes') }}',
|
||||||
},
|
'{{ _('Are you sure you wish to discard the current changes?') }}',
|
||||||
function() {
|
function() {
|
||||||
return true;
|
// User do not want to save, just continue
|
||||||
}
|
self._open_select_file_manager();
|
||||||
).set('labels', {ok:'Yes', cancel:'No'});
|
},
|
||||||
|
function() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
).set('labels', {ok:'Yes', cancel:'No'});
|
||||||
|
} else {
|
||||||
|
self._open_select_file_manager();
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Open FileManager
|
// Open FileManager
|
||||||
@ -2486,6 +2483,13 @@ define(
|
|||||||
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||||
// hide cursor
|
// hide cursor
|
||||||
$busy_icon_div.removeClass('show_progress');
|
$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) {
|
error: function(e) {
|
||||||
var errmsg = $.parseJSON(e.responseText).errormsg;
|
var errmsg = $.parseJSON(e.responseText).errormsg;
|
||||||
@ -2519,10 +2523,13 @@ define(
|
|||||||
if (res.data.status) {
|
if (res.data.status) {
|
||||||
alertify.success('{{ _('File saved successfully.') }}');
|
alertify.success('{{ _('File saved successfully.') }}');
|
||||||
self.gridView.current_file = e;
|
self.gridView.current_file = e;
|
||||||
self.setTitle(self.gridView.current_file.replace(/^\/|\/$/g, ''));
|
self.setTitle(self.gridView.current_file.replace(/^.*[\\\/]/g, ''));
|
||||||
// disable save button on file save
|
// disable save button on file save
|
||||||
$("#btn-save").prop('disabled', true);
|
$("#btn-save").prop('disabled', true);
|
||||||
$("#btn-file-menu-save").css('display', 'none');
|
$("#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');
|
self.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||||
},
|
},
|
||||||
@ -2542,15 +2549,28 @@ define(
|
|||||||
// codemirror text change event
|
// codemirror text change event
|
||||||
_on_query_change: function(query_tool_obj) {
|
_on_query_change: function(query_tool_obj) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if(query_tool_obj.getValue().length == 0) {
|
|
||||||
$("#btn-save").prop('disabled', true);
|
if (!self.is_query_changed) {
|
||||||
$("#btn-file-menu-save").css('display', 'none');
|
// Update the flag as query is going to changed.
|
||||||
$("#btn-file-menu-dropdown").prop('disabled', true);
|
self.is_query_changed = true;
|
||||||
} else {
|
|
||||||
if(self.gridView.current_file) {
|
if(self.gridView.current_file) {
|
||||||
var title = self.gridView.current_file.replace(/^\/|\/$/g, '') + ' *'
|
var title = self.gridView.current_file.replace(/^.*[\\\/]/g, '') + ' *'
|
||||||
|
self.setTitle(title);
|
||||||
|
} else {
|
||||||
|
var title = '';
|
||||||
|
|
||||||
|
// Find the title of the visible panel
|
||||||
|
_.each(window.top.pgAdmin.Browser.docker.findPanels('frm_datagrid'), function(p) {
|
||||||
|
if(p.isVisible()) {
|
||||||
|
self.gridView.panel_title = p._title;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
title = self.gridView.panel_title + ' *';
|
||||||
self.setTitle(title);
|
self.setTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#btn-save").prop('disabled', false);
|
$("#btn-save").prop('disabled', false);
|
||||||
$("#btn-file-menu-save").css('display', 'block');
|
$("#btn-file-menu-save").css('display', 'block');
|
||||||
$("#btn-file-menu-dropdown").prop('disabled', false);
|
$("#btn-file-menu-dropdown").prop('disabled', false);
|
||||||
|
Loading…
Reference in New Issue
Block a user