mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Add a menu option to reset the layout. Fixes #1248
This commit is contained in:
committed by
Dave Page
parent
6b84dc832a
commit
d9804ae2a2
@@ -12,7 +12,8 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) {
|
|||||||
|
|
||||||
// Some scripts do export their object in the window only.
|
// Some scripts do export their object in the window only.
|
||||||
// Generally the one, which do no have AMD support.
|
// Generally the one, which do no have AMD support.
|
||||||
var wcDocker = window.wcDocker;
|
var wcDocker = window.wcDocker,
|
||||||
|
onbeforeunload_flag = true;
|
||||||
$ = $ || window.jQuery || window.$;
|
$ = $ || window.jQuery || window.$;
|
||||||
Bootstrap = Bootstrap || window.Bootstrap;
|
Bootstrap = Bootstrap || window.Bootstrap;
|
||||||
|
|
||||||
@@ -255,10 +256,19 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) {
|
|||||||
}], false);
|
}], false);
|
||||||
$obj_mnu.append(create_submenu.$el);
|
$obj_mnu.append(create_submenu.$el);
|
||||||
}
|
}
|
||||||
|
// Drop down menu for reset layout
|
||||||
|
var $file_mnu = navbar.find('li#mnu_file > ul.dropdown-menu').first();
|
||||||
|
if($file_mnu) {
|
||||||
|
$file_mnu.append('<li class="menu-item"><a href="#" onclick="pgAdmin.Browser.reset_current_layout()">' +
|
||||||
|
'<i class="fa fa-retweet"></i>' +
|
||||||
|
'<span>{{ _('Reset Layout') }}</span>' +
|
||||||
|
'</a></li>'
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
init: function() {
|
init: function() {
|
||||||
var obj=this;
|
var obj=this;
|
||||||
|
obj.save_layout = true;
|
||||||
if (obj.initialized) {
|
if (obj.initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -266,11 +276,16 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) {
|
|||||||
|
|
||||||
// Store the main browser layout
|
// Store the main browser layout
|
||||||
$(window).bind('unload', function() {
|
$(window).bind('unload', function() {
|
||||||
if(obj.docker) {
|
if(obj.docker && obj.save_layout) {
|
||||||
state = obj.docker.save();
|
state = obj.docker.save();
|
||||||
settings = { setting: "Browser/Layout", value: state };
|
settings = { setting: "Browser/Layout", value: state };
|
||||||
$.post("{{ url_for('settings.store') }}", settings);
|
$.ajax({
|
||||||
}
|
type: 'POST',
|
||||||
|
url: "{{ url_for('settings.store') }}",
|
||||||
|
data: settings,
|
||||||
|
async:false
|
||||||
|
});
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -634,21 +649,55 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) {
|
|||||||
|
|
||||||
navbar.children('#mnu_obj').removeClass('hide');
|
navbar.children('#mnu_obj').removeClass('hide');
|
||||||
obj.enable_disable_menus();
|
obj.enable_disable_menus();
|
||||||
|
},
|
||||||
|
// We will force unload method to not to save current layout
|
||||||
|
// and reload the window
|
||||||
|
reset_current_layout: function() {
|
||||||
|
var obj = this;
|
||||||
|
alertify.confirm('{{ _('Reset layout') }}',
|
||||||
|
'{{ _('Are you sure you want to reset the current layout? This will cause the application to reload and any un-saved data will be lost.') }}',
|
||||||
|
function() {
|
||||||
|
// User clicked OK button...
|
||||||
|
var current_url = document.URL;
|
||||||
|
|
||||||
|
// Delete the record from database as well, then only reload page
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ url_for('settings.reset_layout') }}',
|
||||||
|
type: 'DELETE',
|
||||||
|
async: false,
|
||||||
|
error: function() {
|
||||||
|
console.log('Something went wrong on server while resetting layout');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Toggle flag which will prevents save again
|
||||||
|
obj.save_layout = false;
|
||||||
|
// Flag will prevent onbeforeunload function to be called
|
||||||
|
onbeforeunload_flag = false;
|
||||||
|
// Now reload page
|
||||||
|
location.reload(true);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
// Do nothing as user cancel the operation
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
window.onbeforeunload = function(ev) {
|
window.onbeforeunload = function(ev) {
|
||||||
var e = ev || window.event;
|
var e = ev || window.event;
|
||||||
|
if(onbeforeunload_flag) {
|
||||||
|
var msg = '{{ _('Do you really want to leave the page?') }}';
|
||||||
|
|
||||||
var msg = '{{ _('Do you really want to leave the page?') }}';
|
// For IE and Firefox prior to version 4
|
||||||
|
if (e) {
|
||||||
|
e.returnValue = msg;
|
||||||
|
}
|
||||||
|
|
||||||
// For IE and Firefox prior to version 4
|
// For Safari
|
||||||
if (e) {
|
return msg;
|
||||||
e.returnValue = msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Safari
|
|
||||||
return msg;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return pgAdmin.Browser;
|
return pgAdmin.Browser;
|
||||||
|
|||||||
@@ -110,3 +110,23 @@ def get(setting=None, default=None):
|
|||||||
errormsg=errormsg,
|
errormsg=errormsg,
|
||||||
info=info,
|
info=info,
|
||||||
result=request.form)
|
result=request.form)
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.route("/reset_layout", methods=['DELETE'])
|
||||||
|
@login_required
|
||||||
|
def reset_layout():
|
||||||
|
"""Reset configuration setting"""
|
||||||
|
if request.method == 'DELETE':
|
||||||
|
# There can be only one record at most
|
||||||
|
data = Setting.query.filter_by(user_id=current_user.id).first()
|
||||||
|
try:
|
||||||
|
if data is not None:
|
||||||
|
db.session.delete(data)
|
||||||
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
return make_json_response(
|
||||||
|
status=410, success=0, errormsg=str(e)
|
||||||
|
)
|
||||||
|
|
||||||
|
return make_json_response(result=request.form)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user