diff --git a/web/pgadmin/browser/templates/browser/js/collection.js b/web/pgadmin/browser/templates/browser/js/collection.js index 68dc946..b35fe8f 100644 --- a/web/pgadmin/browser/templates/browser/js/collection.js +++ b/web/pgadmin/browser/templates/browser/js/collection.js @@ -36,6 +36,18 @@ function($, _, S, pgAdmin, Backbone, Alertify, Backform) { priority: 2, label: '{{ _("Refresh...") }}', icon: 'fa fa-refresh' }]); + + // show query tool in context & object menu of supported nodes. + if (pgAdmin.DataGrid && pgAdmin.unsupported_nodes) { + if (_.indexOf(pgAdmin.unsupported_nodes, this.type) == -1) { + pgAdmin.Browser.add_menus([{ + name: 'show_query_tool', node: this.type, module: this, + applies: ['object', 'context'], callback: 'show_query_tool', + priority: 3, label: '{{ _("Query tool") }}', + icon: 'fa fa-bolt' + }]); + } + } }, hasId: false, // A collection will always have a collection of statistics, when the node diff --git a/web/pgadmin/browser/templates/browser/js/node.js b/web/pgadmin/browser/templates/browser/js/node.js index 94da24e..514e2de 100644 --- a/web/pgadmin/browser/templates/browser/js/node.js +++ b/web/pgadmin/browser/templates/browser/js/node.js @@ -106,6 +106,19 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { }]); } } + + // show query tool in context & object menu of supported nodes. + if (pgAdmin.DataGrid && pgAdmin.unsupported_nodes) { + if (_.indexOf(pgAdmin.unsupported_nodes, self.type) == -1) { + pgAdmin.Browser.add_menus([{ + name: 'show_query_tool', node: self.type, module: self, + applies: ['object', 'context'], callback: 'show_query_tool', + priority: 3, label: '{{ _("Query tool") }}', + icon: 'fa fa-bolt' + }]); + } + } + // This will add options of scripts eg:'CREATE Script' if (self.hasScriptTypes && _.isArray(self.hasScriptTypes) && self.hasScriptTypes.length > 0) { @@ -604,6 +617,22 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { this, [obj.generate_url(i, sql_url, d, true), i] ); }, + + // Callback to render query editor + show_query_tool: function(args, item) { + var obj = this, + t = pgBrowser.tree, + i = item || t.selected(), + d = i && i.length == 1 ? t.itemData(i) : undefined; + + if (!d) + return; + + // Here call data grid method to render query tool + pgAdmin.DataGrid.show_query_tool.apply( + this, [undefined, i] + ); + }, // Callback called - when a node is selected in browser tree. selected: function(item, data, browser) { // Show the information about the selected node in the below panels, diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js b/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js index 316e886..be0ccb7 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js +++ b/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js @@ -37,7 +37,7 @@ define( }; // Define list of nodes on which Query tool option doesn't appears - var unsupported_nodes = [ + var unsupported_nodes = pgAdmin.unsupported_nodes = [ 'server-group', 'server', 'coll-tablespace', 'tablespace', 'coll-role', 'role', 'coll-resource_group', 'resource_group', 'coll-database'