diff --git a/web/pgadmin/static/js/sqleditor_utils.js b/web/pgadmin/static/js/sqleditor_utils.js index 9d14ac46..51026f65 100644 --- a/web/pgadmin/static/js/sqleditor_utils.js +++ b/web/pgadmin/static/js/sqleditor_utils.js @@ -195,22 +195,6 @@ define(['jquery', 'sources/gettext', 'sources/url_for'], } return '1em'; }, - - removeSlashInTheString: (value) => { - let locationList = []; - let idx = 0; - while (value && value.indexOf('/') !== -1) { - locationList.push(value.indexOf('/') + idx); - value = value.replace('/', ''); - // No of slashes already removed, so we need to increment the - // index accordingly when adding into location list - idx++; - } - return { - 'slashLocations': locationList.join(','), - 'title': encodeURIComponent(value), - }; - }, }; return sqlEditorUtils; }); diff --git a/web/pgadmin/static/js/utils.js b/web/pgadmin/static/js/utils.js index 1c58a9eb..627e4bbb 100644 --- a/web/pgadmin/static/js/utils.js +++ b/web/pgadmin/static/js/utils.js @@ -83,3 +83,19 @@ export function getGCD(inp_arr) { export function getMod(no, divisor) { return ((no % divisor) + divisor) % divisor; } + +export function removeSlashInTheString(value) { + let locationList = []; + let idx = 0; + while (value && value.indexOf('/') !== -1) { + locationList.push(value.indexOf('/') + idx); + value = value.replace('/', ''); + // No of slashes already removed, so we need to increment the + // index accordingly when adding into location list + idx++; + } + return { + 'slashLocations': locationList.join(','), + 'title': encodeURIComponent(value), + }; +} diff --git a/web/pgadmin/static/scss/_webcabin.pgadmin.scss b/web/pgadmin/static/scss/_webcabin.pgadmin.scss index 543336d2..786f4a37 100644 --- a/web/pgadmin/static/scss/_webcabin.pgadmin.scss +++ b/web/pgadmin/static/scss/_webcabin.pgadmin.scss @@ -22,6 +22,12 @@ background-color: $color-bg-theme; } +.wcFrameTitle { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} + .wcFrameTitleBar { height: $title-height; background-color: $color-bg-theme; diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py index c0f61e9f..ece8325f 100644 --- a/web/pgadmin/tools/datagrid/__init__.py +++ b/web/pgadmin/tools/datagrid/__init__.py @@ -30,6 +30,7 @@ from pgadmin.utils.driver import get_driver from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost from pgadmin.utils.preferences import Preferences from pgadmin.settings import get_setting +from pgadmin.utils.paths import add_fslash_string query_tool_close_session_lock = Lock() @@ -234,13 +235,8 @@ def panel(trans_id, is_query_tool, editor_title): # If title has slash(es) in it then replace it if request.args and request.args['fslashes'] != '': - try: - fslashesList = request.args['fslashes'].split(',') - for idx in fslashesList: - idx = int(idx) - editor_title = editor_title[:idx] + '/' + editor_title[idx:] - except IndexError as e: - app.logger.exception(e) + editor_title = add_fslash_string( + editor_title, request.args['fslashes']) # We need client OS information to render correct Keyboard shortcuts user_agent = UserAgent(request.headers.get('User-Agent')) diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js index 5910fc43..6f352b87 100644 --- a/web/pgadmin/tools/datagrid/static/js/datagrid.js +++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js @@ -13,10 +13,10 @@ define('pgadmin.datagrid', [ 'sources/sqleditor_utils', 'backbone', 'tools/datagrid/static/js/show_data', 'tools/datagrid/static/js/show_query_tool', 'pgadmin.browser.toolbar', - 'wcdocker', + 'sources/utils', 'wcdocker', ], function( gettext, url_for, $, _, alertify, pgAdmin, codemirror, sqlEditorUtils, - Backbone, showData, showQueryTool, toolBar + Backbone, showData, showQueryTool, toolBar, pgadminUtils ) { // Some scripts do export their object in the window only. // Generally the one, which do no have AMD support. @@ -280,7 +280,7 @@ define('pgadmin.datagrid', [ } // Open the panel if frame is initialized - let titileForURLObj = sqlEditorUtils.removeSlashInTheString(grid_title); + let titileForURLObj = pgadminUtils.removeSlashInTheString(grid_title); var url_params = { 'trans_id': trans_obj.gridTransId, 'is_query_tool': trans_obj.is_query_tool, diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index babd1efa..805d9dc8 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -33,6 +33,8 @@ from pgadmin.settings import get_setting from config import PG_DEFAULT_DRIVER from pgadmin.model import db, DebuggerFunctionArguments from pgadmin.tools.debugger.utils.debugger_instance import DebuggerInstance +from pgadmin.utils.paths import add_fslash_string + # Constants ASYNC_OK = 1 @@ -528,9 +530,10 @@ def init_function(node_type, sid, did, scid, fid, trid=None): ) -@blueprint.route('/direct/', methods=['GET'], endpoint='direct') +@blueprint.route('/direct//', + methods=['GET'], endpoint='direct') @login_required -def direct_new(trans_id): +def direct_new(trans_id, panel_title): de_inst = DebuggerInstance(trans_id) # Return from the function if transaction id not found @@ -567,8 +570,12 @@ def direct_new(trans_id): # We need client OS information to render correct Keyboard shortcuts user_agent = UserAgent(request.headers.get('User-Agent')) + if request.args and request.args['fslashes'] != '': + panel_title = add_fslash_string( + panel_title, request.args['fslashes']) + function_arguments = '(' - if 'functionData' in session: + if de_inst.function_data is not None: if 'args_name' in de_inst.function_data and \ de_inst.function_data['args_name'] is not None and \ de_inst.function_data['args_name'] != '': @@ -589,7 +596,8 @@ def direct_new(trans_id): layout = get_setting('Debugger/Layout') function_name_with_arguments = \ - de_inst.debugger_data['function_name'] + function_arguments + de_inst.debugger_data['function_name'] + function_arguments \ + + '/' + panel_title return render_template( "debugger/direct.html", diff --git a/web/pgadmin/tools/debugger/static/js/debugger.js b/web/pgadmin/tools/debugger/static/js/debugger.js index a2149bf1..b05a0479 100644 --- a/web/pgadmin/tools/debugger/static/js/debugger.js +++ b/web/pgadmin/tools/debugger/static/js/debugger.js @@ -11,11 +11,11 @@ define([ 'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'underscore.string', 'alertify', 'sources/pgadmin', 'pgadmin.browser', 'backbone', 'pgadmin.backgrid', 'codemirror', 'pgadmin.backform', - 'pgadmin.tools.debugger.ui', 'pgadmin.tools.debugger.utils', - 'wcdocker', 'pgadmin.browser.frame', + 'pgadmin.tools.debugger.ui', 'pgadmin.tools.debugger.utils', 'tools/datagrid/static/js/get_panel_title', + 'sources/utils', 'wcdocker', 'pgadmin.browser.frame', ], function( gettext, url_for, $, _, S, Alertify, pgAdmin, pgBrowser, Backbone, Backgrid, - CodeMirror, Backform, get_function_arguments, debuggerUtils + CodeMirror, Backform, get_function_arguments, debuggerUtils, panelTitle, pgadminUtils ) { var pgTools = pgAdmin.Tools = pgAdmin.Tools || {}, wcDocker = window.wcDocker; @@ -340,6 +340,9 @@ define([ if (!d) return; + var panel_title = panelTitle.getPanelTitle(pgBrowser, item), + panel_title_for_url = pgadminUtils.removeSlashInTheString(panel_title); + var treeInfo = node.getTreeNodeHierarchy.apply(node, [i]), baseUrl; @@ -409,8 +412,11 @@ define([ .done(function(res) { var url = url_for('debugger.direct', { 'trans_id': res.data.debuggerTransId, + 'panel_title': panel_title_for_url.title, }); + url += '?fslashes=' + panel_title_for_url.slashLocations; + if (self.preferences.debugger_new_browser_tab) { window.open(url, '_blank'); } else { @@ -428,6 +434,7 @@ define([ 'frm_debugger', wcDocker.DOCK.STACKED, dashboardPanel[0] ); + panel.title(''+panel_title+''); panel.focus(); // Panel Closed event @@ -466,6 +473,10 @@ define([ self = this, is_edb_proc = d._type == 'edbproc'; + + var panel_title = panelTitle.getPanelTitle(pgBrowser, item), + panel_title_for_url = pgadminUtils.removeSlashInTheString(panel_title); + if (!d) return; @@ -482,7 +493,7 @@ define([ trans_id = res.data.trans_id; // Open Alertify the dialog to take the input arguments from user if function having input arguments if (debug_info[0]['require_input']) { - get_function_arguments(debug_info[0], 0, is_edb_proc, trans_id); + get_function_arguments(debug_info[0], 0, is_edb_proc, trans_id, panel_title); } else { // Initialize the target and create asynchronous connection and unique transaction ID // If there is no arguments to the functions then we should not ask for for function arguments and @@ -530,8 +541,11 @@ define([ var url = url_for('debugger.direct', { 'trans_id': trans_id, + 'panel_title': panel_title_for_url.title, }); + url += '?fslashes=' + panel_title_for_url.slashLocations; + if (self.preferences.debugger_new_browser_tab) { window.open(url, '_blank'); } else { @@ -549,6 +563,7 @@ define([ 'frm_debugger', wcDocker.DOCK.STACKED, dashboardPanel[0] ); + panel.title(''+panel_title+''); panel.focus(); // Register Panel Closed event diff --git a/web/pgadmin/tools/debugger/static/js/debugger_ui.js b/web/pgadmin/tools/debugger/static/js/debugger_ui.js index f05a22dc..371b787e 100644 --- a/web/pgadmin/tools/debugger/static/js/debugger_ui.js +++ b/web/pgadmin/tools/debugger/static/js/debugger_ui.js @@ -10,9 +10,9 @@ define([ 'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone', 'pgadmin.alertifyjs', 'sources/pgadmin', 'pgadmin.browser', - 'pgadmin.backgrid', 'wcdocker', + 'pgadmin.backgrid', 'sources/utils', 'wcdocker', ], function( - gettext, url_for, $, _, Backbone, Alertify, pgAdmin, pgBrowser, Backgrid + gettext, url_for, $, _, Backbone, Alertify, pgAdmin, pgBrowser, Backgrid, pgadminUtils ) { var wcDocker = window.wcDocker; @@ -163,11 +163,11 @@ define([ } }; - var res = function(debug_info, restart_debug, is_edb_proc, trans_id) { + var res = function(debug_info, restart_debug, is_edb_proc, trans_id, panel_title) { if (!Alertify.debuggerInputArgsDialog) { Alertify.dialog('debuggerInputArgsDialog', function factory() { return { - main: function(title, debug_info, restart_debug, is_edb_proc, trans_id) { + main: function(title, debug_info, restart_debug, is_edb_proc, trans_id, panel_title) { this.preferences = window.top.pgAdmin.Browser.get_preferences_for_module('debugger'); this.set('title', title); @@ -176,6 +176,7 @@ define([ this.set('debug_info', debug_info); this.set('restart_debug', restart_debug); this.set('trans_id', trans_id); + this.set('panel_title', panel_title); // Variables to store the data sent from sqlite database var func_args_data = this.func_args_data = []; @@ -581,6 +582,7 @@ define([ debug_info: undefined, restart_debug: undefined, trans_id: undefined, + panel_title: undefined, }, setup: function() { return { @@ -752,12 +754,16 @@ define([ }) .done(function(res) { + var panel_title_for_url = pgadminUtils.removeSlashInTheString(panel_title); var url = url_for( 'debugger.direct', { 'trans_id': res.data.debuggerTransId, + 'panel_title': panel_title_for_url.title, } ); + url += '?fslashes=' + panel_title_for_url.slashLocations; + if (self.preferences.debugger_new_browser_tab) { window.open(url, '_blank'); } else { @@ -773,6 +779,7 @@ define([ 'frm_debugger', wcDocker.DOCK.STACKED, dashboardPanel[0] ); + panel.title(''+self.setting('panel_title')+''); panel.focus(); // Panel Closed event @@ -970,7 +977,7 @@ define([ } Alertify.debuggerInputArgsDialog( - gettext('Debugger'), debug_info, restart_debug, is_edb_proc, trans_id + gettext('Debugger'), debug_info, restart_debug, is_edb_proc, trans_id, panel_title ).resizeTo(pgBrowser.stdW.md,pgBrowser.stdH.md); }; diff --git a/web/pgadmin/utils/paths.py b/web/pgadmin/utils/paths.py index 8f188474..84c08cc5 100644 --- a/web/pgadmin/utils/paths.py +++ b/web/pgadmin/utils/paths.py @@ -102,3 +102,13 @@ def get_cookie_path(): '/browser/', '' ) return cookie_root_path + + +def add_fslash_string(_text=None, _fslashes=''): + try: + for idx in map(int, _fslashes.split(',')): + _text = _text[:idx] + '/' + _text[idx:] + except IndexError as e: + current_app.logger.exception(e) + + return _text diff --git a/web/regression/javascript/pgadmin_utils_spec.js b/web/regression/javascript/pgadmin_utils_spec.js index 02bd5478..e7181069 100644 --- a/web/regression/javascript/pgadmin_utils_spec.js +++ b/web/regression/javascript/pgadmin_utils_spec.js @@ -7,7 +7,7 @@ // ////////////////////////////////////////////////////////////// -import { getEpoch, getGCD, getMod } from 'sources/utils'; +import { getEpoch, getGCD, getMod, removeSlashInTheString} from 'sources/utils'; describe('getEpoch', function () { it('should return non zero', function () { @@ -51,3 +51,59 @@ describe('getMod', function () { expect(getMod(-7,5)).toEqual(3); }); }); + +describe('Remove the slashes', function () { + it('it will remove the slashes', function () { + expect( + removeSlashInTheString('/') + ).toEqual({ + 'slashLocations': '0', + 'title': '', + }); + }); + + it('it will remove if slashes are present', function () { + expect( + removeSlashInTheString('my/test') + ).toEqual({ + 'slashLocations': '2', + 'title': 'mytest', + }); + }); + + it('it will remove all the slashes are present', function () { + expect( + removeSlashInTheString('my/test/value') + ).toEqual({ + 'slashLocations': '2,7', + 'title': 'mytestvalue', + }); + }); + + it('it will remove all the slashes are present', function () { + expect( + removeSlashInTheString('a/bb/ccc/dddd/eeeee') + ).toEqual({ + 'slashLocations': '1,4,8,13', + 'title': 'abbcccddddeeeee', + }); + }); + + it('it will not remove if slash is not present', function () { + expect( + removeSlashInTheString('mytest') + ).toEqual({ + 'slashLocations': '', + 'title': 'mytest', + }); + }); + + it('it will not remove if value is not present', function () { + expect( + removeSlashInTheString('') + ).toEqual({ + 'slashLocations': '', + 'title': '', + }); + }); +}); diff --git a/web/regression/javascript/sqleditor_utils_spec.js b/web/regression/javascript/sqleditor_utils_spec.js index 789f370c..614caeb5 100644 --- a/web/regression/javascript/sqleditor_utils_spec.js +++ b/web/regression/javascript/sqleditor_utils_spec.js @@ -36,61 +36,5 @@ define(['sources/sqleditor_utils'], expect(SqlEditorUtils.calcFontSize(2)).toEqual('2em'); }); }); - - describe('Remove the slashes', function () { - it('it will remove the slashes', function () { - expect( - SqlEditorUtils.removeSlashInTheString('/') - ).toEqual({ - 'slashLocations': '0', - 'title': '', - }); - }); - - it('it will remove if slashes are present', function () { - expect( - SqlEditorUtils.removeSlashInTheString('my/test') - ).toEqual({ - 'slashLocations': '2', - 'title': 'mytest', - }); - }); - - it('it will remove all the slashes are present', function () { - expect( - SqlEditorUtils.removeSlashInTheString('my/test/value') - ).toEqual({ - 'slashLocations': '2,7', - 'title': 'mytestvalue', - }); - }); - - it('it will remove all the slashes are present', function () { - expect( - SqlEditorUtils.removeSlashInTheString('a/bb/ccc/dddd/eeeee') - ).toEqual({ - 'slashLocations': '1,4,8,13', - 'title': 'abbcccddddeeeee', - }); - }); - - it('it will not remove if slash is not present', function () { - expect( - SqlEditorUtils.removeSlashInTheString('mytest') - ).toEqual({ - 'slashLocations': '', - 'title': 'mytest', - }); - }); - - it('it will not remove if value is not present', function () { - expect( - SqlEditorUtils.removeSlashInTheString('') - ).toEqual({ - 'slashLocations': '', - 'title': '', - }); - }); - }); }); });