From c548eac5efaf94a652ee75656e3438930e69bbfe Mon Sep 17 00:00:00 2001 From: Dave Page Date: Thu, 14 Mar 2019 15:48:21 +0000 Subject: [PATCH] Append the file suffix to filenames when needed in the File Create dialogue. Fixes #4069 --- docs/en_US/release_notes_4_4.rst | 1 + .../file_manager/static/js/create_dialogue.js | 22 ++++++++++++++++++- .../misc/file_manager/static/js/utility.js | 12 +++++----- .../file_manager/js/file_manager_config.json | 1 - 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/en_US/release_notes_4_4.rst b/docs/en_US/release_notes_4_4.rst index ed678a954..d355744bd 100644 --- a/docs/en_US/release_notes_4_4.rst +++ b/docs/en_US/release_notes_4_4.rst @@ -24,5 +24,6 @@ Bug fixes | `Bug #4053 `_ - Enable the online help button on the index dialogue. | `Bug #4054 `_ - Handle resultsets with zero columns correctly in the Query Tool. | `Bug #4060 `_ - Fix the latexpdf doc build. +| `Bug #4069 `_ - Append the file suffix to filenames when needed in the File Create dialogue. | `Bug #4071 `_ - Ensure that Firefox prompts for a filename/location when downloading query results as a CSV file. | `Bug #4073 `_ - Change the CodeMirror active line background colour to $color-danger-lighter so it doesn't conflict with the selection colour. \ No newline at end of file diff --git a/web/pgadmin/misc/file_manager/static/js/create_dialogue.js b/web/pgadmin/misc/file_manager/static/js/create_dialogue.js index 4a77906ee..5f9a43e93 100644 --- a/web/pgadmin/misc/file_manager/static/js/create_dialogue.js +++ b/web/pgadmin/misc/file_manager/static/js/create_dialogue.js @@ -146,7 +146,27 @@ module.exports = Alertify.dialog('createModeDlg', function() { file_data = { 'path': $('.currentpath').val(), }, - innerbody; + innerbody, + sep = '/', + ext = $('.allowed_file_types select').val(); + + /* + Add the file extension if necessary, and if the file type selector + isn't set to "All Files". If there's no . at all in the path, or + there is a . already but it's not following the last /, AND the + extension isn't *, then we add the extension. + */ + + if (navigator.platform.toUpperCase().indexOf('WIN')!==-1) { + sep = '\\'; + } + + if ((!newFile.includes('.') || + newFile.split('.').pop().includes(sep)) && + ext != '*') { + newFile = newFile + '.' + ext; + $('.storage_dialog #uploader .input-path').val(newFile); + } if (!this.check_permission(newFile)) { closeEvent.cancel = true; diff --git a/web/pgadmin/misc/file_manager/static/js/utility.js b/web/pgadmin/misc/file_manager/static/js/utility.js index 2730eef62..57417231c 100644 --- a/web/pgadmin/misc/file_manager/static/js/utility.js +++ b/web/pgadmin/misc/file_manager/static/js/utility.js @@ -1358,7 +1358,7 @@ define([ $('.file_manager button.delete, .file_manager button.download, .file_manager button.rename').removeAttr( 'disabled' ); - // set selected folder name in breadcrums + // set selected folder name in breadcrumbs $('.file_manager #uploader .show_selected_file').remove(); } @@ -1388,7 +1388,7 @@ define([ path = '/'; } - if (config.options.platform_type === 'win32') { + if (navigator.platform.toUpperCase().indexOf('WIN')!==-1) { path = path.replace(/\//g, '\\'); } else { path = path.replace(/\\/g, '/'); @@ -1533,20 +1533,20 @@ define([ $('.storage_dialog #uploader').find('a').remove(); $('.storage_dialog #uploader').find('b').remove(); - if (config.options.platform_type === 'win32') { + if (navigator.platform.toUpperCase().indexOf('WIN')!==-1) { path = path.replace(/\//g, '\\'); } else { path = path.replace(/\\/g, '/'); } path = decodeURI(path); - if (config.options.platform_type === 'win32') { + if (navigator.platform.toUpperCase().indexOf('WIN')!==-1) { if (config.options.show_volumes && path == '\\') { $('.storage_dialog #uploader .input-path').val(''); } else { $('.storage_dialog #uploader .input-path').val(path); } - } else if (!config.options.platform_type === 'win32' && + } else if (!(navigator.platform.toUpperCase().indexOf('WIN')!==-1) && (path == '' || !S.startsWith(path, '/'))) { path = '/' + path; $('.storage_dialog #uploader .input-path').val(path); @@ -1706,7 +1706,7 @@ define([ // helpful in show/hide toolbar button for Windows hideButtons: function() { return ( - this.config.options.platform_type == 'win32' && + navigator.platform.toUpperCase().indexOf('WIN')!==-1 && $('.currentpath').val() === '' ); }, diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager_config.json b/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager_config.json index b29fcfb5f..06502675b 100644 --- a/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager_config.json +++ b/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager_config.json @@ -10,7 +10,6 @@ "fileRoot": "{{data.fileroot}}", "capabilities": [{% for i in data.capabilities %}{% if loop.index != 1 %}, {% endif %}"{{i}}"{% endfor %}], "allowed_file_types": [{% for i in data.supported_types %}{% if loop.index != 1 %}, {% endif %}"{{i}}"{% endfor %}], - "platform_type": "{{ data.platform_type }}", "show_volumes": {% if data.show_volumes %}true{% else %}false{% endif %} }, "security": {