public inbox for [email protected]  
help / color / mirror / Atom feed
From: Rahul Shirsat <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin][Patch] #4059 Query Tool button in Query Tool to open a new Query Window
Date: Thu, 27 Aug 2020 20:15:29 +0530
Message-ID: <CAKtn9dM5woCVYAc5dKAZ=eSuoDCw1HnJFNcX_=mduQ25Q16Bjg@mail.gmail.com> (raw)
In-Reply-To: <CAKtn9dPt5BB_vGqxYfbrPx7R=RWgXQsCPr0aCEtVDnN3W5C3-A@mail.gmail.com>
References: <CAKtn9dPt5BB_vGqxYfbrPx7R=RWgXQsCPr0aCEtVDnN3W5C3-A@mail.gmail.com>

Please find the update patch attached here.

On Thu, Aug 27, 2020 at 8:10 PM Rahul Shirsat <
[email protected]> wrote:

> Hi Hackers,
>
> Please find the attached patch below which adds the functionality of the
> query tool button in the query tool sqleditor.
>
> *Acceptance criteria:*
> - For sqleditor on same window & on new tab:
>
>    - When a query tool connection is initiated, as expected it will open
>    the connection based on the selected database in the treeview. Now, when
>    the user clicks the query tool connection button on the query tool window,
>    irrespective of the selected database in treeview, it should open a
>    connection based on the query tool connected database.
>    - Similarly, for a new tab, clicking on the query tool connection
>    button, it should open a connection based on the query tool connected
>    database, instead of selected treeview node.
>
> [image: query tool button.png]
>
> Additionally, an error is handled in the form of message dialog prompting
> the user to initiate the connection, when sqleditor is opened in the new
> tab with the main application window kept closed. This can be reviewed by
> refreshing the window as well as clicking on the query tool connection
> button.
>
> A prompt dialog message box is seen as:
>
> [image: Screen Shot 2020-08-27 at 8.04.33 PM.png]
>
> --
> *Rahul Shirsat*
> Software Engineer | EnterpriseDB Corporation.
>


-- 
*Rahul Shirsat*
Software Engineer | EnterpriseDB Corporation.


Attachments:

  [image/png] query tool button.png (78.2K, 3-query%20tool%20button.png)
  download | view image

  [image/png] Screen Shot 2020-08-27 at 8.04.33 PM.png (47.9K, 4-Screen%20Shot%202020-08-27%20at%208.04.33%20PM.png)
  download | view image

  [application/octet-stream] RM4059_v2.patch (5.3K, 5-RM4059_v2.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html
index 9de7bf511..ae240cd5c 100644
--- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html
+++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html
@@ -14,6 +14,14 @@
 <div id="main-editor_panel">
     <div class="sql-editor">
         <div id="btn-toolbar" class="editor-toolbar" role="toolbar" aria-label="">
+            <div class="btn-group mr-1" role="group" aria-label="">
+                <button id="btn-show-query-tool" type="button" class="btn btn-sm btn-primary-icon btn-show-query-tool"
+                        title=""
+                        accesskey=""
+                        tabindex="0">
+                    <i class="pg-font-icon icon-query-tool" aria-hidden="true" role="img"></i>
+                </button>
+            </div>
             <div class="btn-group mr-1" role="group" aria-label="">
                 <button id="btn-load-file" type="button" class="btn btn-sm btn-primary-icon btn-load-file"
                         title=""
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index dae9edea4..a0724ff9e 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -90,6 +90,7 @@ define('tools.querytool', [
 
     // Bind all the events
     events: {
+      'click #btn-show-query-tool': 'on_show_query_tool',
       'click .btn-load-file': 'on_file_load',
       'click #btn-save-file': 'on_save_file',
       'click #btn-file-menu-save': 'on_save_file',
@@ -1959,6 +1960,20 @@ define('tools.querytool', [
       ev.stopPropagation();
     },
 
+    // callback function for show query tool click.
+    on_show_query_tool: function(ev) {
+      var self = this;
+
+      this._stopEventPropogation(ev);
+      this._closeDropDown(ev);
+
+      self.handler.trigger(
+        'pgadmin-sqleditor:button:show_query_tool',
+        self,
+        self.handler
+      );
+    },
+
     // callback function for load file button click.
     on_file_load: function(ev) {
       var self = this;
@@ -2017,6 +2032,48 @@ define('tools.querytool', [
     this.initialize.apply(this, arguments);
   };
 
+  /* This function is used to check whether user have closed
+   * the main window when query tool is opened on new tab
+   */
+  var is_main_window_alive = function() {
+
+    if((pgWindow.default && pgWindow.default.closed) ||
+        pgWindow.default.pgAdmin && pgWindow.default.pgAdmin.Browser
+            && pgWindow.default.pgAdmin.Browser.preference_version() <= 0) {
+
+      alertify.alert()
+        .setting({
+          'title': gettext('Connection lost'),
+          'label':gettext('Close'),
+          'message': gettext('The pgAdmin browser window has been closed and the connection to the server is lost. Please close this window and open a new pgAdmin session.'),
+          'onok': function(){
+            //Close the window after connection is lost
+            window.close();
+          },
+        }).show();
+    }
+  };
+
+  var set_tree_node = function() {
+
+    let browser = pgWindow.default.pgAdmin.Browser;
+    let tree = browser.tree;
+
+    var t = tree,
+      i = t.selected(),
+      d = i && i.length == 1 ? t.itemData(i) : undefined;
+
+    if(!d)
+      return;
+
+    var selected_tree_node = { t, i, d };
+
+    if(!pgWindow.default.pgAdmin.selected_tree_map)
+      pgWindow.default.pgAdmin.selected_tree_map = new Map();
+
+    pgWindow.default.pgAdmin.selected_tree_map.set(d._id.toString(), selected_tree_node);
+  };
+
   _.extend(
     SqlEditorController.prototype,
     Backbone.Events,
@@ -2026,6 +2083,11 @@ define('tools.querytool', [
         this.container = container;
         this.state = {};
         this.csrf_token = pgAdmin.csrf_token;
+
+        //call to check whether user have closed the parent window and trying to refresh, if yes return error.
+        is_main_window_alive();
+        set_tree_node();
+
         // Disable animation first
         modifyAnimation.modifyAlertifyAnimation();
 
@@ -2411,6 +2473,7 @@ define('tools.querytool', [
         self.on('pgadmin-sqleditor:button:explain-timing', self._explain_timing, self);
         self.on('pgadmin-sqleditor:button:explain-summary', self._explain_summary, self);
         self.on('pgadmin-sqleditor:button:explain-settings', self._explain_settings, self);
+        self.on('pgadmin-sqleditor:button:show_query_tool', self._show_query_tool, self);
         // Indentation related
         self.on('pgadmin-sqleditor:indent_selected_code', self._indent_selected_code, self);
         self.on('pgadmin-sqleditor:unindent_selected_code', self._unindent_selected_code, self);
@@ -4227,6 +4290,19 @@ define('tools.querytool', [
         this._toggle_explain_option('settings');
       },
 
+      _show_query_tool: function() {
+        var self = this;
+
+        setTimeout(() => {
+          var tree_node = pgWindow.default.pgAdmin.selected_tree_map.get(self.url_params.did);
+          if(self.preferences.new_browser_tab) {
+            is_main_window_alive();
+          }
+
+          pgWindow.default.pgAdmin.DataGrid.show_query_tool('', tree_node.i);
+        }, 200);
+      },
+
       /*
        * This function will indent selected code
        */


view thread (7+ 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]
  Subject: Re: [pgAdmin][Patch] #4059 Query Tool button in Query Tool to open a new Query Window
  In-Reply-To: <CAKtn9dM5woCVYAc5dKAZ=eSuoDCw1HnJFNcX_=mduQ25Q16Bjg@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