public inbox for [email protected]
help / color / mirror / Atom feedFrom: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM4228] Incorrect table listed in panel header
Date: Tue, 11 Jun 2019 13:05:01 +0530
Message-ID: <CAM9w-_ng=HU=SUp=Hih3_cfxxcWaUqwURQZx4TERAM+hHtzydg@mail.gmail.com> (raw)
Hi Hackers,
Attached is the patch to fix incorrect label on panels when using filtered
rows.
I've also moved redundant code for filter data in datagrid.js to
show_data.js, reusing the existing code of view/edit data.
Kindly review.
--
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"
Attachments:
[application/octet-stream] RM4228.patch (22.4K, 3-RM4228.patch)
download | inline diff:
diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js
index 3e2e1440..5910fc43 100644
--- a/web/pgadmin/tools/datagrid/static/js/datagrid.js
+++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js
@@ -12,18 +12,16 @@ define('pgadmin.datagrid', [
'pgadmin.alertifyjs', 'sources/pgadmin', 'bundled_codemirror',
'sources/sqleditor_utils', 'backbone',
'tools/datagrid/static/js/show_data',
- 'tools/datagrid/static/js/get_panel_title',
'tools/datagrid/static/js/show_query_tool', 'pgadmin.browser.toolbar',
'wcdocker',
], function(
gettext, url_for, $, _, alertify, pgAdmin, codemirror, sqlEditorUtils,
- Backbone, showData, panelTitle, showQueryTool, toolBar
+ Backbone, showData, showQueryTool, toolBar
) {
// Some scripts do export their object in the window only.
// Generally the one, which do no have AMD support.
var wcDocker = window.wcDocker,
- pgBrowser = pgAdmin.Browser,
- CodeMirror = codemirror.default;
+ pgBrowser = pgAdmin.Browser;
/* Return back, this has been called more than once */
if (pgAdmin.DataGrid)
@@ -202,188 +200,14 @@ define('pgadmin.datagrid', [
// This is a callback function to show filtered data when user click on menu item.
show_filtered_row: function(data, i) {
- var self = this,
- d = pgAdmin.Browser.tree.itemData(i);
- if (d === undefined) {
- alertify.alert(
- gettext('Data Grid Error'),
- gettext('No object selected.')
- );
- return;
- }
-
- // Get the parent data from the tree node hierarchy.
- var node = pgBrowser.Nodes[d._type],
- parentData = node.getTreeNodeHierarchy(i);
-
- // If server or database is undefined then return from the function.
- if (parentData.server === undefined || parentData.database === undefined) {
- return;
- }
-
- // If schema, view, catalog object all are undefined then return from the function.
- if (parentData.schema === undefined && parentData.view === undefined &&
- parentData.catalog === undefined) {
- return;
- }
-
- let nsp_name = showData.retrieveNameSpaceName(parentData);
-
- var url_params = {
- 'cmd_type': data.mnuid,
- 'obj_type': d._type,
- 'sgid': parentData.server_group._id,
- 'sid': parentData.server._id,
- 'did': parentData.database._id,
- 'obj_id': d._id,
- };
-
- var baseUrl = url_for('datagrid.initialize_datagrid', url_params);
-
- // Create url to validate the SQL filter
- var validateUrl = url_for('datagrid.filter_validate', {
- 'sid': url_params['sid'],
- 'did': url_params['did'],
- 'obj_id': url_params['obj_id'],
- });
-
- let grid_title = showData.generateDatagridTitle(parentData, nsp_name, d);
-
- // Create filter dialog using alertify
- if (!alertify.filterDialog) {
- alertify.dialog('filterDialog', function factory() {
- return {
- main: function(title, message, baseUrl, validateUrl) {
- this.set('title', title);
- this.message = message;
- this.baseUrl = baseUrl;
- this.validateUrl = validateUrl;
- },
-
- setup:function() {
- return {
- buttons:[{
- text: gettext('Cancel'),
- key: 27,
- className: 'btn btn-secondary fa fa-times pg-alertify-button',
- },{
- text: gettext('OK'),
- key: 13,
- className: 'btn btn-primary fa fa-check pg-alertify-button',
- }],
- options: {
- modal: 0,
- resizable: true,
- maximizable: false,
- pinnable: false,
- autoReset: false,
- },
- };
- },
- build: function() {
- alertify.pgDialogBuild.apply(this);
- },
- prepare:function() {
- var that = this,
- $content = $(this.message),
- $sql_filter = $content.find('#sql_filter');
-
- $(this.elements.header).attr('data-title', this.get('title'));
- $(this.elements.body.childNodes[0]).addClass(
- 'dataview_filter_dialog'
- );
-
- this.setContent($content.get(0));
- // Disable OK button
- that.__internal.buttons[1].element.disabled = true;
-
- // Apply CodeMirror to filter text area.
- this.filter_obj = CodeMirror.fromTextArea($sql_filter.get(0), {
- lineNumbers: true,
- mode: 'text/x-pgsql',
- extraKeys: pgBrowser.editor_shortcut_keys,
- indentWithTabs: !self.preferences.use_spaces,
- indentUnit: self.preferences.tab_size,
- tabSize: self.preferences.tab_size,
- lineWrapping: self.preferences.wrap_code,
- autoCloseBrackets: self.preferences.insert_pair_brackets,
- matchBrackets: self.preferences.brace_matching,
- });
-
- let sql_font_size = sqlEditorUtils.calcFontSize(self.preferences.sql_font_size);
- $(this.filter_obj.getWrapperElement()).css('font-size', sql_font_size);
-
- setTimeout(function() {
- // Set focus on editor
- that.filter_obj.refresh();
- that.filter_obj.focus();
- }, 500);
-
- that.filter_obj.on('change', function() {
- if (that.filter_obj.getValue() !== '') {
- that.__internal.buttons[1].element.disabled = false;
- } else {
- that.__internal.buttons[1].element.disabled = true;
- }
- });
- },
-
- callback: function(closeEvent) {
-
- if (closeEvent.button.text == gettext('OK')) {
- var sql = this.filter_obj.getValue();
- var that = this;
- closeEvent.cancel = true; // Do not close dialog
-
- // Make ajax call to include the filter by selection
- $.ajax({
- url: that.validateUrl,
- method: 'POST',
- async: false,
- contentType: 'application/json',
- data: JSON.stringify(sql),
- })
- .done(function(res) {
- if (res.data.status) {
- // Initialize the data grid.
- self.create_transaction(that.baseUrl, null, 'false', parentData.server.server_type, '', grid_title, sql, false);
- that.close(); // Close the dialog
- }
- else {
- alertify.alert(
- gettext('Validation Error'),
- res.data.result
- );
- }
- })
- .fail(function(e) {
- alertify.alert(
- gettext('Validation Error'),
- e
- );
- });
- }
- },
- };
- });
- }
-
- $.get(url_for('datagrid.filter'),
- function(data) {
- alertify.filterDialog('Data Filter', data, baseUrl, validateUrl)
- .resizeTo(pgBrowser.stdW.sm,pgBrowser.stdH.sm);
- }
- );
+ showData.showDataGrid(this, pgBrowser, alertify, data, i, true, this.preferences);
},
- get_panel_title: function() {
- return panelTitle.getPanelTitle(pgBrowser);
- },
// This is a callback function to show query tool when user click on menu item.
- show_query_tool: function(url, aciTreeIdentifier, panelTitle) {
- showQueryTool.showQueryTool(this, pgBrowser, alertify, url,
- aciTreeIdentifier, panelTitle);
+ show_query_tool: function(url, aciTreeIdentifier) {
+ showQueryTool.showQueryTool(this, pgBrowser, alertify, url, aciTreeIdentifier);
},
+
create_transaction: function(baseUrl, target, is_query_tool, server_type, sURL, panel_title, sql_filter, recreate) {
var self = this;
target = target || self;
@@ -439,28 +263,20 @@ define('pgadmin.datagrid', [
launch_grid: function(trans_obj) {
var self = this,
panel_title = trans_obj.panel_title,
- grid_title = self.get_panel_title(),
+ grid_title = trans_obj.panel_title,
panel_icon = '',
panel_tooltip = '';
if (trans_obj.is_query_tool == 'false') {
// Edit grid titles
- grid_title = panel_title + '/' + grid_title;
panel_tooltip = gettext('View/Edit Data - ') + grid_title;
panel_title = grid_title;
panel_icon = 'fa fa-table';
} else {
- if (panel_title) {
- // Script titles
- panel_tooltip = panel_title.toUpperCase() + ' ' + gettext('Script - ') + grid_title;
- panel_title = grid_title;
- panel_icon = 'fa fa-file-text-o';
- } else {
- // Query tool titles
- panel_tooltip = gettext('Query Tool - ') + grid_title;
- panel_title = grid_title;
- panel_icon = 'fa fa-bolt';
- }
+ // Query tool titles
+ panel_tooltip = gettext('Query Tool - ') + grid_title;
+ panel_title = grid_title;
+ panel_icon = 'fa fa-bolt';
}
// Open the panel if frame is initialized
diff --git a/web/pgadmin/tools/datagrid/static/js/get_panel_title.js b/web/pgadmin/tools/datagrid/static/js/get_panel_title.js
index 635e3d82..6aff905d 100644
--- a/web/pgadmin/tools/datagrid/static/js/get_panel_title.js
+++ b/web/pgadmin/tools/datagrid/static/js/get_panel_title.js
@@ -18,8 +18,10 @@ function isServerInformationAvailable(parentData) {
return parentData.server === undefined;
}
-export function getPanelTitle(pgBrowser) {
- const selected_item = pgBrowser.treeMenu.selected();
+export function getPanelTitle(pgBrowser, selected_item=null) {
+ if(selected_item == null) {
+ selected_item = pgBrowser.treeMenu.selected();
+ }
const parentData = getTreeNodeHierarchyFromIdentifier
.call(pgBrowser, selected_item);
diff --git a/web/pgadmin/tools/datagrid/static/js/show_data.js b/web/pgadmin/tools/datagrid/static/js/show_data.js
index eca27526..253f31d3 100644
--- a/web/pgadmin/tools/datagrid/static/js/show_data.js
+++ b/web/pgadmin/tools/datagrid/static/js/show_data.js
@@ -9,13 +9,19 @@
import gettext from '../../../../static/js/gettext';
import url_for from '../../../../static/js/url_for';
import {getTreeNodeHierarchyFromIdentifier} from '../../../../static/js/tree/pgadmin_tree_node';
+import {getPanelTitle} from './get_panel_title';
+import CodeMirror from 'bundled_codemirror';
+import * as SqlEditorUtils from 'sources/sqleditor_utils';
+import $ from 'jquery';
export function showDataGrid(
datagrid,
pgBrowser,
alertify,
connectionData,
- aciTreeIdentifier
+ aciTreeIdentifier,
+ filter=false,
+ preferences=null
) {
const node = pgBrowser.treeMenu.findNodeByDomElement(aciTreeIdentifier);
if (node === undefined || !node.getData()) {
@@ -36,19 +42,44 @@ export function showDataGrid(
return;
}
- let namespaceName = retrieveNameSpaceName(parentData);
const baseUrl = generateUrl(connectionData, node.getData(), parentData);
- const grid_title = generateDatagridTitle(parentData, namespaceName, node.getData());
-
- datagrid.create_transaction(
- baseUrl,
- null,
- 'false',
- parentData.server.server_type,
- '',
- grid_title,
- ''
- );
+ const grid_title = generateDatagridTitle(pgBrowser, aciTreeIdentifier);
+
+ if(filter) {
+ initFilterDialog(alertify, pgBrowser, preferences);
+
+ const validateUrl = generateFilterValidateUrl(node.getData(), parentData);
+
+ let okCallback = function(sql) {
+ datagrid.create_transaction(
+ baseUrl,
+ null,
+ 'false',
+ parentData.server.server_type,
+ '',
+ grid_title,
+ sql,
+ false
+ );
+ };
+
+ $.get(url_for('datagrid.filter'),
+ function(data) {
+ alertify.filterDialog(`Data Filter - ${grid_title}`, data, validateUrl, preferences, okCallback)
+ .resizeTo(pgBrowser.stdW.sm,pgBrowser.stdH.sm);
+ }
+ );
+ } else {
+ datagrid.create_transaction(
+ baseUrl,
+ null,
+ 'false',
+ parentData.server.server_type,
+ '',
+ grid_title,
+ ''
+ );
+ }
}
@@ -78,6 +109,138 @@ function generateUrl(connectionData, nodeData, parentData) {
return url_for('datagrid.initialize_datagrid', url_params);
}
+function generateFilterValidateUrl(nodeData, parentData) {
+ // Create url to validate the SQL filter
+ var url_params = {
+ 'sid': parentData.server._id,
+ 'did': parentData.database._id,
+ 'obj_id': nodeData._id,
+ };
+
+ return url_for('datagrid.filter_validate', url_params);
+}
+
+function initFilterDialog(alertify, pgBrowser) {
+ // Create filter dialog using alertify
+ if (!alertify.filterDialog) {
+ alertify.dialog('filterDialog', function factory() {
+ return {
+ main: function(title, message, validateUrl, preferences, okCallback) {
+ this.set('title', title);
+ this.message = message;
+ this.validateUrl = validateUrl;
+ this.okCallback = okCallback;
+ this.preferences = preferences;
+ },
+
+ setup:function() {
+ return {
+ buttons:[{
+ text: gettext('Cancel'),
+ key: 27,
+ className: 'btn btn-secondary fa fa-times pg-alertify-button',
+ },{
+ text: gettext('OK'),
+ key: 13,
+ className: 'btn btn-primary fa fa-check pg-alertify-button',
+ }],
+ options: {
+ modal: 0,
+ resizable: true,
+ maximizable: false,
+ pinnable: false,
+ autoReset: false,
+ },
+ };
+ },
+ build: function() {
+ alertify.pgDialogBuild.apply(this);
+ },
+ prepare:function() {
+ var that = this,
+ $content = $(this.message),
+ $sql_filter = $content.find('#sql_filter');
+
+ $(this.elements.header).attr('data-title', this.get('title'));
+ $(this.elements.body.childNodes[0]).addClass(
+ 'dataview_filter_dialog'
+ );
+
+ this.setContent($content.get(0));
+ // Disable OK button
+ that.__internal.buttons[1].element.disabled = true;
+
+ // Apply CodeMirror to filter text area.
+ this.filter_obj = CodeMirror.fromTextArea($sql_filter.get(0), {
+ lineNumbers: true,
+ mode: 'text/x-pgsql',
+ extraKeys: pgBrowser.editor_shortcut_keys,
+ indentWithTabs: !that.preferences.use_spaces,
+ indentUnit: that.preferences.tab_size,
+ tabSize: that.preferences.tab_size,
+ lineWrapping: that.preferences.wrap_code,
+ autoCloseBrackets: that.preferences.insert_pair_brackets,
+ matchBrackets: that.preferences.brace_matching,
+ });
+
+ let sql_font_size = SqlEditorUtils.calcFontSize(that.preferences.sql_font_size);
+ $(this.filter_obj.getWrapperElement()).css('font-size', sql_font_size);
+
+ setTimeout(function() {
+ // Set focus on editor
+ that.filter_obj.refresh();
+ that.filter_obj.focus();
+ }, 500);
+
+ that.filter_obj.on('change', function() {
+ if (that.filter_obj.getValue() !== '') {
+ that.__internal.buttons[1].element.disabled = false;
+ } else {
+ that.__internal.buttons[1].element.disabled = true;
+ }
+ });
+ },
+
+ callback: function(closeEvent) {
+
+ if (closeEvent.button.text == gettext('OK')) {
+ var sql = this.filter_obj.getValue();
+ var that = this;
+ closeEvent.cancel = true; // Do not close dialog
+
+ // Make ajax call to include the filter by selection
+ $.ajax({
+ url: that.validateUrl,
+ method: 'POST',
+ async: false,
+ contentType: 'application/json',
+ data: JSON.stringify(sql),
+ })
+ .done(function(res) {
+ if (res.data.status) {
+ that.okCallback(sql);
+ that.close(); // Close the dialog
+ }
+ else {
+ alertify.alert(
+ gettext('Validation Error'),
+ res.data.result
+ );
+ }
+ })
+ .fail(function(e) {
+ alertify.alert(
+ gettext('Validation Error'),
+ e
+ );
+ });
+ }
+ },
+ };
+ });
+ }
+}
+
function hasServerOrDatabaseConfiguration(parentData) {
return parentData.server === undefined || parentData.database === undefined;
}
@@ -87,6 +250,17 @@ function hasSchemaOrCatalogOrViewInformation(parentData) {
parentData.catalog !== undefined;
}
-export function generateDatagridTitle(parentData, namespaceName, nodeData) {
- return `${namespaceName}.${nodeData.label}`;
+export function generateDatagridTitle(pgBrowser, aciTreeIdentifier) {
+ const baseTitle = getPanelTitle(pgBrowser, aciTreeIdentifier);
+
+ const parentData = getTreeNodeHierarchyFromIdentifier.call(
+ pgBrowser,
+ aciTreeIdentifier
+ );
+
+ const namespaceName = retrieveNameSpaceName(parentData);
+
+ const node = pgBrowser.treeMenu.findNodeByDomElement(aciTreeIdentifier);
+
+ return `${namespaceName}.${node.getData().label}/${baseTitle}`;
}
diff --git a/web/pgadmin/tools/datagrid/static/js/show_query_tool.js b/web/pgadmin/tools/datagrid/static/js/show_query_tool.js
index b6ccd5c8..1fd9eee9 100644
--- a/web/pgadmin/tools/datagrid/static/js/show_query_tool.js
+++ b/web/pgadmin/tools/datagrid/static/js/show_query_tool.js
@@ -10,6 +10,7 @@
import gettext from '../../../../static/js/gettext';
import url_for from '../../../../static/js/url_for';
import {getTreeNodeHierarchyFromIdentifier} from '../../../../static/js/tree/pgadmin_tree_node';
+import {getPanelTitle} from './get_panel_title';
function hasDatabaseInformation(parentData) {
return parentData.database;
@@ -34,10 +35,14 @@ function hasServerInformations(parentData) {
return parentData.server === undefined;
}
-export function showQueryTool(datagrid, pgBrowser, alertify, url,
- aciTreeIdentifier, panelTitle) {
+function generateTitle(pgBrowser, aciTreeIdentifier) {
+ const baseTitle = getPanelTitle(pgBrowser, aciTreeIdentifier);
+ return baseTitle;
+}
+
+export function showQueryTool(datagrid, pgBrowser, alertify, url, aciTreeIdentifier) {
const sURL = url || '';
- const queryToolTitle = panelTitle || '';
+ const queryToolTitle = generateTitle(pgBrowser, aciTreeIdentifier);
const currentNode = pgBrowser.treeMenu.findNodeByDomElement(aciTreeIdentifier);
if (currentNode === undefined) {
diff --git a/web/regression/javascript/datagrid/show_data_spec.js b/web/regression/javascript/datagrid/show_data_spec.js
index c5c01256..3a97e5a2 100644
--- a/web/regression/javascript/datagrid/show_data_spec.js
+++ b/web/regression/javascript/datagrid/show_data_spec.js
@@ -63,6 +63,7 @@ describe('#show_data', () => {
label: 'server1',
server_type: 'pg',
_id: 2,
+ user: {name: 'someuser'},
}, ['parent', 'server_group1']);
pgBrowser.treeMenu.addChild(serverGroup1, server1);
@@ -133,7 +134,7 @@ describe('#show_data', () => {
'false',
'pg',
'',
- 'schema1.schema1',
+ 'schema1.schema1/database1/someuser@server1',
''
);
});
@@ -148,7 +149,7 @@ describe('#show_data', () => {
'false',
'pg',
'',
- 'view1.view1',
+ 'view1.view1/database1/someuser@server1',
''
);
});
@@ -163,7 +164,7 @@ describe('#show_data', () => {
'false',
'pg',
'',
- 'catalog1.catalog1',
+ 'catalog1.catalog1/database1/someuser@server1',
''
);
});
diff --git a/web/regression/javascript/datagrid/show_query_tool_spec.js b/web/regression/javascript/datagrid/show_query_tool_spec.js
index 3dbd4781..04cda926 100644
--- a/web/regression/javascript/datagrid/show_query_tool_spec.js
+++ b/web/regression/javascript/datagrid/show_query_tool_spec.js
@@ -51,6 +51,8 @@ describe('#showQueryTool', () => {
label: 'server1',
server_type: 'pg',
_id: 2,
+ user: {name: 'someuser'},
+ db: 'otherdblabel',
});
pgBrowser.treeMenu.addChild(serverGroup1, server1);
@@ -64,7 +66,7 @@ describe('#showQueryTool', () => {
context('cannot find the tree node', () => {
beforeEach(() => {
- showQueryTool(queryTool, pgBrowser, alertify, '', [{id: '10'}], 'title');
+ showQueryTool(queryTool, pgBrowser, alertify, '', [{id: '10'}]);
});
it('does not create a transaction', () => {
expect(queryTool.create_transaction).not.toHaveBeenCalled();
@@ -92,14 +94,14 @@ describe('#showQueryTool', () => {
context('current node is underneath a server', () => {
context('current node is not underneath a database', () => {
it('creates a transaction', () => {
- showQueryTool(queryTool, pgBrowser, alertify, 'http://someurl', [{id: 'server1'}], 'title');
+ showQueryTool(queryTool, pgBrowser, alertify, 'http://someurl', [{id: 'server1'}]);
expect(queryTool.create_transaction).toHaveBeenCalledWith(
'/initialize/query_tool/1/2',
null,
'true',
'pg',
'http://someurl',
- 'title',
+ 'otherdblabel/someuser@server1',
'',
false
);
@@ -115,7 +117,7 @@ describe('#showQueryTool', () => {
'true',
'pg',
'http://someurl',
- 'title',
+ 'database1/someuser@server1',
'',
false
);
view thread (4+ 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][RM4228] Incorrect table listed in panel header
In-Reply-To: <CAM9w-_ng=HU=SUp=Hih3_cfxxcWaUqwURQZx4TERAM+hHtzydg@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