public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pradip Parkale <[email protected]>
To: Akshay Joshi <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin][RM6325]:Tools > Storage Manager should have file type as "All files" by default
Date: Wed, 7 Apr 2021 19:18:49 +0530
Message-ID: <CAJ9T6St1+zSv4BwRmZb4vgtn=FszW_GYd2x6n-jVXuyJ9tBr+w@mail.gmail.com> (raw)
In-Reply-To: <CANxoLDfz6jXS4Lu60P-CKaLw-hZmTCb9q1wYdeCP_T-shMqLRw@mail.gmail.com>
References: <CAJ9T6Sv=jR0BwkdW=gygzQuAioEVRj6-B07Tgzqm+fbW=ugL_w@mail.gmail.com>
	<CANxoLDe+B5Zk+1Qjm5vtHDYRUQSE32MdaazNYbm3f0qii-O_ZQ@mail.gmail.com>
	<CAJ9T6SuRC+L3cNvenQ1Y0pLEndp0Et+N4rSfUtR8fQE6FXsj9A@mail.gmail.com>
	<CANxoLDfz6jXS4Lu60P-CKaLw-hZmTCb9q1wYdeCP_T-shMqLRw@mail.gmail.com>

Hi Akshay,

Please find the attached patch. I have added the check to handle the
exception for Python 3.9.


On Wed, Apr 7, 2021 at 5:43 PM Akshay Joshi <[email protected]>
wrote:

> Hi Pradip
>
> I am getting the error with Python 3.9. It is working fine with Python
> 3.8. Please fix the issue on Python 3.9 and resend the patch again
>
> On Wed, Apr 7, 2021 at 4:44 PM Pradip Parkale <
> [email protected]> wrote:
>
>> Hi Akshay,
>>
>> Please find an updated patch. I missed few lines in my previous patch.
>>
>> On Wed, Apr 7, 2021 at 3:45 PM Akshay Joshi <
>> [email protected]> wrote:
>>
>>> Hi Pradip
>>>
>>> The issue is not fixed as per the expectation. Please fix and resend the
>>> patch.
>>>
>>> On Wed, Apr 7, 2021 at 1:17 PM Pradip Parkale <
>>> [email protected]> wrote:
>>>
>>>> Hi Hackers,
>>>>
>>>> Please find the attached patch for #6325 - Tools > Storage Manager
>>>> should have file type as "All files" by default.
>>>>
>>>>
>>>> --
>>>> Thanks & Regards,
>>>> Pradip Parkale
>>>> Software Engineer | EnterpriseDB Corporation
>>>>
>>>
>>>
>>> --
>>> *Thanks & Regards*
>>> *Akshay Joshi*
>>> *pgAdmin Hacker | Principal Software Architect*
>>> *EDB Postgres <http://edbpostgres.com>*
>>>
>>> *Mobile: +91 976-788-8246*
>>>
>>
>>
>> --
>> Thanks & Regards,
>> Pradip Parkale
>> Software Engineer | EnterpriseDB Corporation
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM6325_v3.patch (6.1K, 3-RM6325_v3.patch)
  download | inline diff:
diff --git a/web/pgadmin/misc/file_manager/static/js/utility.js b/web/pgadmin/misc/file_manager/static/js/utility.js
index 67c4be047..2766ee957 100644
--- a/web/pgadmin/misc/file_manager/static/js/utility.js
+++ b/web/pgadmin/misc/file_manager/static/js/utility.js
@@ -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);
       }
     },
diff --git a/web/pgadmin/settings/__init__.py b/web/pgadmin/settings/__init__.py
index c49feea41..91ff3204f 100644
--- a/web/pgadmin/settings/__init__.py
+++ b/web/pgadmin/settings/__init__.py
@@ -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'
+
+
[email protected]("/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)
+
+
[email protected]("/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)


view thread (6+ 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], [email protected]
  Subject: Re: [pgAdmin][RM6325]:Tools > Storage Manager should have file type as "All files" by default
  In-Reply-To: <CAJ9T6St1+zSv4BwRmZb4vgtn=FszW_GYd2x6n-jVXuyJ9tBr+w@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