From d476343b99b8c121039ba9e7ebc532eac5b1f853 Mon Sep 17 00:00:00 2001 From: Khushboo Vashi Date: Tue, 3 Dec 2019 11:52:02 +0530 Subject: [PATCH] =?UTF-8?q?Enhance=20the=20logic=20to=20change=20the=20lab?= =?UTF-8?q?el=C2=A0from=20'Delete/Drop'=20to=20'Remove'=20for=20the=20serv?= =?UTF-8?q?er=20and=20server=20group=20node.=20Fixes=20#4923?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en_US/release_notes_4_16.rst | 1 + .../server_groups/servers/static/js/server.js | 2 + .../server_groups/static/js/server_group.js | 1 + web/pgadmin/browser/static/js/node.js | 72 ++++++------------- 4 files changed, 27 insertions(+), 49 deletions(-) diff --git a/docs/en_US/release_notes_4_16.rst b/docs/en_US/release_notes_4_16.rst index 8e8612075..b8e3fc46e 100644 --- a/docs/en_US/release_notes_4_16.rst +++ b/docs/en_US/release_notes_4_16.rst @@ -33,6 +33,7 @@ Bug fixes | `Issue #4818 `_ - Fix server connection drops out issue in query tool. | `Issue #4836 `_ - Updated the json file name from 'servers.json' to 'pgadmin4/servers.json' in the container deployment section of the documentation. | `Issue #4878 `_ - Ensure that the superuser should be able to create role, as the superuser overrides all the access restrictions. +| `Issue #4923 `_ - Enhance the logic to change the label from 'Delete/Drop' to 'Remove' for the server and server group node. | `Issue #4925 `_ - Shown some text on process watcher till the initial logs are loaded. | `Issue #4926 `_ - Fix VPN network disconnect issue where pgAdmin4 hangs on expanding the Servers node. | `Issue #4930 `_ - Fix main window tab navigation accessibility issue. diff --git a/web/pgadmin/browser/server_groups/servers/static/js/server.js b/web/pgadmin/browser/server_groups/servers/static/js/server.js index 843794d53..8d6361378 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/server.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/server.js @@ -58,6 +58,8 @@ define('pgadmin.node.server', [ dialogHelp: url_for('help.static', {'filename': 'server_dialog.html'}), label: gettext('Server'), canDrop: true, + dropAsRemove: true, + dropPriority: 5, hasStatistics: true, hasCollectiveStatistics: true, can_expand: function(d) { diff --git a/web/pgadmin/browser/server_groups/static/js/server_group.js b/web/pgadmin/browser/server_groups/static/js/server_group.js index 62daa3d5b..8457db658 100644 --- a/web/pgadmin/browser/server_groups/static/js/server_group.js +++ b/web/pgadmin/browser/server_groups/static/js/server_group.js @@ -70,6 +70,7 @@ define('pgadmin.node.server_group', [ }, }), canDrop: function(itemData) { return itemData.can_delete; }, + dropAsRemove: true, canDelete: function(i) { var s = pgAdmin.Browser.tree.siblings(i, true); diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index fbce346f0..e7e80c8d7 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -28,10 +28,6 @@ define('pgadmin.browser.node', [ F1: 112, }; - const REMOVE_SERVER_PRIORITY = 5; - const REMOVE_SERVER_LABEL = 'Remove Server'; - const SERVER = 'server'; - // It has already been defined. // Avoid running this script again. if (pgBrowser.Node) @@ -146,8 +142,8 @@ define('pgadmin.browser.node', [ module: self, applies: ['object', 'context'], callback: 'delete_obj', - priority: self.get_menu_item_priority(self.type, 2), - label: self.change_menu_label(self.type, gettext('Delete/Drop')), + priority: self.dropPriority, + label: (self.dropAsRemove) ? gettext('Remove %s', self.label) : gettext('Delete/Drop'), data: { 'url': 'drop', }, @@ -539,6 +535,14 @@ define('pgadmin.browser.node', [ * Override this, when a node is not deletable. */ canDropCascade: false, + /********************************************************************************* + dropAsRemove should be true in case, Drop object label needs to be replaced by Remove + */ + dropAsRemove: false, + /****************************************************************************** + dropPriority is set to 2 by default, override it when change is required + */ + dropPriority: 2, // List of common callbacks - that can be used for different // operations! callbacks: { @@ -748,7 +752,10 @@ define('pgadmin.browser.node', [ obj = pgBrowser.Nodes[d._type]; var objName = d.label; - var msg, title; + var msg, title, drop_label; + + if (obj.dropAsRemove) drop_label = 'Remove'; else drop_label = 'Drop'; + if (input.url == 'delete') { msg = gettext('Are you sure you want to drop %s "%s" and all the objects that depend on it?', @@ -764,31 +771,15 @@ define('pgadmin.browser.node', [ return; } } else { - var remove_drop_text; - if(obj.type === SERVER) { - remove_drop_text = 'Remove'; - } - else { - remove_drop_text = 'DROP'; - } - - msg = gettext('Are you sure you want to %s %s "%s"?', remove_drop_text.toLowerCase(), obj.label.toLowerCase(), d.label); - title = gettext('%s %s?', remove_drop_text, obj.label); + msg = gettext('Are you sure you want to %s %s "%s"?', drop_label.toLowerCase(), obj.label.toLowerCase(), d.label); + title = gettext('%s %s?', drop_label, obj.label); if (!(_.isFunction(obj.canDrop) ? obj.canDrop.apply(obj, [d, i]) : obj.canDrop)) { - if(obj.type === SERVER) { - Alertify.error( - gettext('The %s "%s" cannot be removed.', obj.label, d.label), - 10 - ); - } - else { - Alertify.error( - gettext('The %s "%s" cannot be dropped.', obj.label, d.label), - 10 - ); - } + Alertify.error( + gettext('The %s "%s" cannot be dropped/removed.', obj.label, d.label), + 10 + ); return; } } @@ -817,14 +808,9 @@ define('pgadmin.browser.node', [ console.warn(e.stack || e); } } - if(obj.type === SERVER) { - pgBrowser.report_error( - gettext('Error removing %s: "%s"', obj.label, objName), msg); - } - else { - pgBrowser.report_error( - gettext('Error dropping %s: "%s"', obj.label, objName), msg); - } + pgBrowser.report_error( + gettext('Error dropping/removing %s: "%s"', obj.label, objName), msg); + }); }, null).show(); @@ -1829,18 +1815,6 @@ define('pgadmin.browser.node', [ return this.parent_type; } }, - get_menu_item_priority: function(type, default_priority) { //downgrade Remove Server priority in menus only for Servers - if(type && type === SERVER) { - return REMOVE_SERVER_PRIORITY; - } - return default_priority; - }, - change_menu_label: function(type, default_label) { //change Delete/Drop menu option to Remove Server - if(type && type === SERVER) { - return gettext(REMOVE_SERVER_LABEL); - } - return default_label; - }, }); return pgAdmin.Browser.Node;