diff --git a/docs/en_US/release_notes_4_4.rst b/docs/en_US/release_notes_4_4.rst index 5a99c6a78..61b240501 100644 --- a/docs/en_US/release_notes_4_4.rst +++ b/docs/en_US/release_notes_4_4.rst @@ -54,3 +54,4 @@ Bug fixes | `Bug #4073 `_ - Change the CodeMirror active line background colour to $color-danger-lighter so it doesn't conflict with the selection colour. | `Bug #4081 `_ - Fix the RE-SQL syntax for roles with a VALID UNTIL clause. | `Bug #4090 `_ - Improve the German translation for Backup Server. +| `Bug #4099 `_ - Fix SQL help for EPAS 10+, and refactor the URL generation code into a testable function. \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js b/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js index c8cc8a5a9..cb74f6506 100644 --- a/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js +++ b/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js @@ -189,7 +189,7 @@ define('pgadmin.node.pga_jobstep', [ }, helpMessage: S( gettext('Please specify the connection string for the remote database server. Each parameter setting is in the form keyword = value. Spaces around the equal sign are optional. To write an empty value, or a value containing spaces, surround it with single quotes, e.g., keyword = \'a value\'. Single quotes and backslashes within the value must be escaped with a backslash, i.e., \' and \\.
For more information, please see the documentation on %s') ).sprintf( - 'libpq connection strings' + 'libpq connection strings' ).value(), mode: ['create', 'edit'], },{ id: 'jstonerror', label: gettext('On error'), cell: 'select2', diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index 9e7dee071..34c90cf47 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -11,9 +11,9 @@ define('pgadmin.browser', [ 'sources/tree/tree', 'sources/gettext', 'sources/url_for', 'require', 'jquery', 'underscore', 'underscore.string', 'bootstrap', 'sources/pgadmin', 'pgadmin.alertifyjs', 'bundled_codemirror', - 'sources/check_node_visibility', './toolbar', 'pgadmin.browser.utils', 'wcdocker', - 'jquery.contextmenu', 'jquery.aciplugin', 'jquery.acitree', 'pgadmin.browser.preferences', - 'pgadmin.browser.messages', + 'sources/check_node_visibility', './toolbar', 'pgadmin.help', 'pgadmin.browser.utils', + 'wcdocker', 'jquery.contextmenu', 'jquery.aciplugin', 'jquery.acitree', + 'pgadmin.browser.preferences', 'pgadmin.browser.messages', 'pgadmin.browser.menu', 'pgadmin.browser.panel', 'pgadmin.browser.error', 'pgadmin.browser.frame', 'pgadmin.browser.node', 'pgadmin.browser.collection', @@ -21,8 +21,9 @@ define('pgadmin.browser', [ 'pgadmin.browser.keyboard', 'sources/tree/pgadmin_tree_save_state', ], function( tree, - gettext, url_for, require, $, _, S, Bootstrap, pgAdmin, Alertify, - codemirror, checkNodeVisibility, toolBar + gettext, url_for, require, $, _, S, + Bootstrap, pgAdmin, Alertify, codemirror, + checkNodeVisibility, toolBar, help ) { window.jQuery = window.$ = $; // Some scripts do export their object in the window only. @@ -653,14 +654,7 @@ define('pgadmin.browser', [ baseUrl = pgBrowser.utils.edbas_help_path; } - var major = Math.floor(server.version / 10000), - minor = Math.floor(server.version / 100) - (major * 100); - - baseUrl = baseUrl.replace('$VERSION$', major + '.' + minor); - if (!S(baseUrl).endsWith('/')) { - baseUrl = baseUrl + '/'; - } - var fullUrl = baseUrl + url; + var fullUrl = help.getHelpUrl(baseUrl, url, server.version); window.open(fullUrl, 'postgres_help'); } else if(type == 'dialog_help') { diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index 319f39c2c..ae70cd641 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -11,11 +11,14 @@ define('pgadmin.browser.node', [ 'sources/tree/pgadmin_tree_node', 'sources/url_for', 'sources/gettext', 'jquery', 'underscore', 'underscore.string', 'sources/pgadmin', 'pgadmin.browser.menu', 'backbone', 'pgadmin.alertifyjs', 'pgadmin.browser.datamodel', - 'backform', 'sources/browser/generate_url', 'sources/utils', 'pgadmin.browser.utils', - 'pgadmin.backform', + 'backform', 'sources/browser/generate_url', 'pgadmin.help', 'sources/utils', + 'pgadmin.browser.utils', 'pgadmin.backform', ], function( pgadminTreeNode, url_for, - gettext, $, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform, generateUrl, commonUtils + gettext, $, _, S, pgAdmin, + Menu, Backbone, Alertify, pgBrowser, + Backform, generateUrl, help, + commonUtils ) { var wcDocker = window.wcDocker, @@ -1218,26 +1221,20 @@ define('pgadmin.browser.node', [ url = pgBrowser.utils.edbas_help_path; } - var major = Math.floor(server.version / 10000), - minor = Math.floor(server.version / 100) - (major * 100); - - url = url.replace('$VERSION$', major + '.' + minor); - if (!S(url).endsWith('/')) { - url = url + '/'; - } + var fullUrl = ''; if (that.sqlCreateHelp == '' && that.sqlAlterHelp != '') { - url = url + that.sqlAlterHelp; + fullUrl = help.getHelpUrl(url, that.sqlAlterHelp, server.version); } else if (that.sqlCreateHelp != '' && that.sqlAlterHelp == '') { - url = url + that.sqlCreateHelp; + fullUrl = help.getHelpUrl(url, that.sqlCreateHelp, server.version); } else { if (view.model.isNew()) { - url = url + that.sqlCreateHelp; + fullUrl = help.getHelpUrl(url, that.sqlCreateHelp, server.version); } else { - url = url + that.sqlAlterHelp; + fullUrl = help.getHelpUrl(url, that.sqlAlterHelp, server.version); } } - window.open(url, 'postgres_help'); + window.open(fullUrl, 'postgres_help'); }.bind(panel), onDialogHelp = function() { diff --git a/web/pgadmin/help/__init__.py b/web/pgadmin/help/__init__.py index 016bbc6d0..1312d5d32 100644 --- a/web/pgadmin/help/__init__.py +++ b/web/pgadmin/help/__init__.py @@ -55,7 +55,7 @@ class HelpModule(PgAdminModule): self.pg_help_path = self.help_preference.register( 'help', 'pg_help_path', gettext("PostgreSQL Help Path"), 'text', - 'https://www.postgresql.org/docs/$VERSION$/static/', + 'https://www.postgresql.org/docs/$VERSION$/', category_label=gettext('Help'), help_str=gettext( 'Path to the PostgreSQL documentation. $VERSION$ will be ' diff --git a/web/pgadmin/help/static/js/help.js b/web/pgadmin/help/static/js/help.js new file mode 100644 index 000000000..3e8f35de0 --- /dev/null +++ b/web/pgadmin/help/static/js/help.js @@ -0,0 +1,27 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin 4 - PostgreSQL Tools +// +// Copyright (C) 2013 - 2019, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +////////////////////////////////////////////////////////////////////////// + +export function getHelpUrl(base_path, file, version) { + var major = Math.floor(version / 10000), + minor = Math.floor(version / 100) - (major * 100), + url = ''; + + // Handle the version number format change in PG 10+ + if (major >= 10) { + url = base_path.replace('$VERSION$', major); + } else { + url = base_path.replace('$VERSION$', major + '.' + minor); + } + + if (url.substr(-1) != '/') { + url = url + '/'; + } + + return url + file; +}; diff --git a/web/regression/javascript/help/help_spec.js b/web/regression/javascript/help/help_spec.js new file mode 100644 index 000000000..3baa626b2 --- /dev/null +++ b/web/regression/javascript/help/help_spec.js @@ -0,0 +1,56 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin 4 - PostgreSQL Tools +// +// Copyright (C) 2013 - 2019, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +////////////////////////////////////////////////////////////////////////// + +import { getHelpUrl } from '../../../pgadmin/help/static/js/help'; + +describe('Test help functions', function() { + describe('when getHelpUrl is called', function(){ + + // PG 9.6 docs + it('it should be able to return a correct URL for PG 9.6 docs with a trailing slash', function() { + expect(getHelpUrl('https://www.postgresql.org/docs/$VERSION$/', 'index.html', 90600)).toEqual('https://www.postgresql.org/docs/9.6/index.html'); + }); + + // PG 10 docs + it('it should be able to return a correct URL for PG 10 docs with a trailing slash', function() { + expect(getHelpUrl('https://www.postgresql.org/docs/$VERSION$/', 'index.html', 100000)).toEqual('https://www.postgresql.org/docs/10/index.html'); + }); + + // PG 9.6 docs + it('it should be able to return a correct URL for PG 9.6 docs without a trailing slash', function() { + expect(getHelpUrl('https://www.postgresql.org/docs/$VERSION$', 'index.html', 90600)).toEqual('https://www.postgresql.org/docs/9.6/index.html'); + }); + + // PG 10 docs + it('it should be able to return a correct URL for PG 10 docs without a trailing slash', function() { + expect(getHelpUrl('https://www.postgresql.org/docs/$VERSION$', 'index.html', 100000)).toEqual('https://www.postgresql.org/docs/10/index.html'); + }); + + // EPAS 9.6 docs + it('it should be able to return a correct URL for EPAS 9.6 docs with a trailing slash', function() { + expect(getHelpUrl('https://www.enterprisedb.com/docs/en/$VERSION$/pg/', 'index.html', 90600)).toEqual('https://www.enterprisedb.com/docs/en/9.6/pg/index.html'); + }); + + // EPAS 10 docs + it('it should be able to return a correct URL for EPAS 10 docs with a trailing slash', function() { + expect(getHelpUrl('https://www.enterprisedb.com/docs/en/$VERSION$/pg/', 'index.html', 100000)).toEqual('https://www.enterprisedb.com/docs/en/10/pg/index.html'); + }); + + // EPAS 9.6 docs + it('it should be able to return a correct URL for EPAS 9.6 docs without a trailing slash', function() { + expect(getHelpUrl('https://www.enterprisedb.com/docs/en/$VERSION$/pg', 'index.html', 90600)).toEqual('https://www.enterprisedb.com/docs/en/9.6/pg/index.html'); + }); + + // EPAS 10 docs + it('it should be able to return a correct URL for EPAS 10 docs without a trailing slash', function() { + expect(getHelpUrl('https://www.enterprisedb.com/docs/en/$VERSION$/pg', 'index.html', 100000)).toEqual('https://www.enterprisedb.com/docs/en/10/pg/index.html'); + }); + + }); +}); diff --git a/web/webpack.shim.js b/web/webpack.shim.js index 3f547b26c..53c00ba3e 100644 --- a/web/webpack.shim.js +++ b/web/webpack.shim.js @@ -210,6 +210,7 @@ var webpackShimConfig = { 'pgadmin.datagrid': path.join(__dirname, './pgadmin/tools/datagrid/static/js/datagrid'), 'pgadmin.file_manager': path.join(__dirname, './pgadmin/misc/file_manager/static/js/file_manager'), 'pgadmin.file_utility': path.join(__dirname, './pgadmin/misc/file_manager/static/js/utility'), + 'pgadmin.help': path.join(__dirname, './pgadmin/help/static/js/help'), 'pgadmin.misc.explain': path.join(__dirname, './pgadmin/misc/static/explain/js/explain'), 'pgadmin.node.cast': path.join(__dirname, './pgadmin/browser/server_groups/servers/databases/casts/static/js/cast'), 'pgadmin.node.catalog': path.join(__dirname, './pgadmin/browser/server_groups/servers/databases/schemas/static/js/catalog'),