Ensure that the file format for the storage manager should be 'All files' and for other dialogs, it should remember the last selected format. Fixes #6325

pull/42/head
Pradip Parkale 2021-04-08 12:23:57 +05:30 committed by Akshay Joshi
parent 8aea86613e
commit 3a797b1efa
3 changed files with 105 additions and 11 deletions

View File

@ -22,6 +22,7 @@ Bug fixes
| `Issue #6076 <https://redmine.postgresql.org/issues/6076>`_ - Fixed an issue where correct error not thrown while importing servers and JSON file has incorrect/insufficient keys.
| `Issue #6220 <https://redmine.postgresql.org/issues/6220>`_ - Corrected the syntax for 'CREATE TRIGGER', use 'EXECUTE FUNCTION' instead of 'EXECUTE PROCEDURE' from v11 onwards.
| `Issue #6293 <https://redmine.postgresql.org/issues/6293>`_ - Fixed an issue where the procedure creation is failed when providing the Volatility option.
| `Issue #6325 <https://redmine.postgresql.org/issues/6325>`_ - Ensure that the file format for the storage manager should be 'All files' and for other dialogs, it should remember the last selected format.
| `Issue #6327 <https://redmine.postgresql.org/issues/6327>`_ - Ensure that while comparing domains check function dependencies should be considered in schema diff.
| `Issue #6333 <https://redmine.postgresql.org/issues/6333>`_ - Fixed sizing issue of help dialog for Query Tool and ERD Tool when open in the new browser tab.
| `Issue #6338 <https://redmine.postgresql.org/issues/6338>`_ - Added missing dependency 'xdg-utils' for the desktop packages in RPM and Debian.

View File

@ -52,6 +52,18 @@ define([
});
};
var getFileFormat = function(data) {
// Get last selected file format
return $.ajax({
async: false,
cache: false,
url: url_for('settings.get_file_format_setting'),
data : $.extend({}, data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
});
};
// Set enable/disable state of list and grid view
var setViewButtonsFor = function(viewMode) {
if (viewMode == 'grid') {
@ -1330,18 +1342,22 @@ define([
if (types_len > 0) {
var i = 0,
t,
selected = false,
have_all_types = false;
let fileFormats = '';
let response = getFileFormat(config.options.allowed_file_types);
let lastSelectedFormat = response.responseJSON.info;
while (i < types_len) {
t = allowed_types[i];
if (!selected && (types_len == 1 || t != '*')) {
fileFormats += '<option value=' + t + ' selected>' + t + '</option>';
selected = true;
if ((types_len == 1 || t != '*')) {
if(t === lastSelectedFormat)
fileFormats += '<option value=' + t + ' selected >' + t + '</option>';
else
fileFormats += '<option value=' + t + ' >' + t + '</option>';
have_all_types = (have_all_types || (t == '*'));
} else {
fileFormats += '<option value="' + t + '">' +
} else if ((lastSelectedFormat === '*')) {
fileFormats += '<option value="' + t + '" selected >' +
(t == '*' ? gettext('All Files') : t) + '</option>';
have_all_types = (have_all_types || (t == '*'));
}
@ -1370,6 +1386,13 @@ define([
curr_path = $('.currentpath').val(),
user_input_file = null,
input_path = $('.storage_dialog #uploader .input-path').val();
config.options.selectedFormat = selected_val;
$.ajax({
url: url_for('settings.save_file_format_setting'),
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(config.options),
});
if (curr_path.endsWith('/')) {
user_input_file = input_path.substring(curr_path.lastIndexOf('/')+1);
} else {
@ -1928,10 +1951,15 @@ define([
getDetailView: function(path) {
if (path.lastIndexOf('/') == path.length - 1 || path.lastIndexOf('\\') == path.length - 1) {
var allowed_types = this.config.options.allowed_file_types;
var set_type = allowed_types[0];
if (allowed_types[0] == '*') {
set_type = allowed_types[1];
}
let set_type;
let response = getFileFormat(this.config.options.allowed_file_types);
let lastSelectedFormat = response.responseJSON.info;
if (_.isUndefined(lastSelectedFormat))
set_type = allowed_types[0];
else
set_type = lastSelectedFormat;
getFolderInfo(path, set_type);
}
},

View File

@ -57,7 +57,9 @@ class SettingsModule(PgAdminModule):
return [
'settings.store', 'settings.store_bulk', 'settings.reset_layout',
'settings.save_tree_state', 'settings.get_tree_state',
'settings.reset_tree_state'
'settings.reset_tree_state',
'settings.save_file_format_setting',
'settings.get_file_format_setting'
]
@ -218,3 +220,66 @@ def get_browser_tree_state():
return Response(response=data,
status=200,
mimetype="application/json")
def _get_dialog_type(file_type):
"""
This function return dialog type
:param file_type:
:return: dialog type.
"""
if 'pgerd' in file_type:
return 'erd_file_type'
elif 'backup' in file_type:
return 'backup_file_type'
elif 'csv' in file_type and 'txt' in file_type:
return 'import_export_file_type'
elif 'csv' in file_type and 'txt' not in file_type:
return 'storage_manager_file_type'
else:
return 'sqleditor_file_format'
@blueprint.route("/save_file_format_setting/",
endpoint="save_file_format_setting",
methods=['POST'])
@login_required
def save_file_format_setting():
"""
This function save the selected file format.
:return: save file format response
"""
data = request.form if request.form else json.loads(
request.data.decode('utf-8'))
file_type = _get_dialog_type(data['allowed_file_types'])
store_setting(file_type, data['selectedFormat'])
return make_json_response(success=True,
info=data,
result=request.form)
@blueprint.route("/get_file_format_setting/",
endpoint="get_file_format_setting",
methods=['GET'])
@login_required
def get_file_format_setting():
"""
This function return the last selected file format
:return: last selected file format
"""
data = dict()
for k, v in request.args.items():
try:
data[k] = json.loads(v, encoding='utf-8')
except (ValueError, TypeError, KeyError):
data[k] = v
file_type = _get_dialog_type(list(data.values()))
data = Setting.query.filter_by(
user_id=current_user.id, setting=file_type).first()
if data is None:
return make_json_response(success=True, info='*')
else:
return make_json_response(success=True, info=data.value)