From cc0d4679270dbc6bffb137d31ffa8162d27262ce Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Thu, 8 Dec 2022 19:17:12 +0530 Subject: [PATCH] Fixed blank screen issue while opening query tools in new tab from native menu. #5503 --- runtime/src/js/pgadmin.js | 7 ++++ web/pgadmin/static/js/utils.js | 37 +++++++++++++++++++ web/pgadmin/tools/__init__.py | 22 ++++++++++- web/pgadmin/tools/erd/static/js/ERDModule.js | 10 +---- .../tools/psql/static/js/psql_module.js | 6 +-- .../sqleditor/static/js/SQLEditorModule.js | 14 +------ 6 files changed, 71 insertions(+), 25 deletions(-) diff --git a/runtime/src/js/pgadmin.js b/runtime/src/js/pgadmin.js index faebfb47d..434a1cfd6 100644 --- a/runtime/src/js/pgadmin.js +++ b/runtime/src/js/pgadmin.js @@ -248,9 +248,16 @@ function launchPgAdminWindow() { docsURLSubStrings.forEach(function (key) { if (url.indexOf(key) >= 0) { isDocURL = true; + + if(key.indexOf('help') >= 0) { + url = url.slice(url.indexOf('/help')) + url = startPageUrl.slice(0, startPageUrl.indexOf('?') -1 ) + url; + } } + }); + if (openDocsInBrowser && isDocURL) { // Do not open the window policy.ignore(); diff --git a/web/pgadmin/static/js/utils.js b/web/pgadmin/static/js/utils.js index 34f697f27..e241446c6 100644 --- a/web/pgadmin/static/js/utils.js +++ b/web/pgadmin/static/js/utils.js @@ -9,11 +9,13 @@ import _ from 'lodash'; import $ from 'jquery'; +import url_for from './url_for'; import gettext from 'sources/gettext'; import 'wcdocker'; import Notify from './helpers/Notifier'; import { hasTrojanSource } from 'anti-trojan-source'; import convert from 'convert-units'; +import getApiInstance from './api_instance'; let wcDocker = window.wcDocker; @@ -665,3 +667,38 @@ export function fullHexColor(shortHex) { } return shortHex; } + +export function openNewWindow(toolForm, title) { + let {name: browser} = getBrowser(); + if(browser == 'Nwjs') { + let api = getApiInstance(); + api({ + url: url_for('tools.initialize', null), + method: 'GET', + }) + .then(function () { + openWindow(toolForm, title); + }) + .catch(function (error) { + Notify.error(gettext(`Error in Tool initialize ${error.response.data}`)); + }); + } + else { + openWindow(toolForm, title); + } +} + +function openWindow(toolForm, title) { + let newWin = window.open('', '_blank'); + if (newWin) { + newWin.document.write(toolForm); + newWin.document.title = title; + let pgBrowser = window.pgAdmin.Browser; + // Send the signal to runtime, so that proper zoom level will be set. + setTimeout(function() { + pgBrowser.send_signal_to_runtime('Runtime new window opened'); + }, 500); + } else { + return false; + } +} \ No newline at end of file diff --git a/web/pgadmin/tools/__init__.py b/web/pgadmin/tools/__init__.py index e73f994f5..29fcc5381 100644 --- a/web/pgadmin/tools/__init__.py +++ b/web/pgadmin/tools/__init__.py @@ -14,7 +14,7 @@ from flask import url_for from flask_babel import Domain, gettext from pgadmin.utils import PgAdminModule -from pgadmin.utils.ajax import bad_request +from pgadmin.utils.ajax import bad_request, make_json_response from pgadmin.utils.constants import MIMETYPE_APP_JS MODULE_NAME = 'tools' @@ -67,6 +67,15 @@ class ToolsModule(PgAdminModule): from .user_management import blueprint as module app.register_blueprint(module) + def get_exposed_url_endpoints(self): + """ + Returns: + list: URL endpoints for tools module + """ + return [ + 'tools.initialize', + ] + # Initialise the module blueprint = ToolsModule(MODULE_NAME, __name__) @@ -94,3 +103,14 @@ def translations(): status=200, mimetype=MIMETYPE_APP_JS ) + + +@blueprint.route( + '/initialize/', + methods=["GET"], + endpoint='initialize' +) +def initialize(): + return make_json_response( + data={} + ) diff --git a/web/pgadmin/tools/erd/static/js/ERDModule.js b/web/pgadmin/tools/erd/static/js/ERDModule.js index a2d10c6e4..29d5cc86e 100644 --- a/web/pgadmin/tools/erd/static/js/ERDModule.js +++ b/web/pgadmin/tools/erd/static/js/ERDModule.js @@ -17,6 +17,7 @@ import ReactDOM from 'react-dom'; import ERDTool from './erd_tool/components/ERDTool'; import ModalProvider from '../../../../static/js/helpers/ModalProvider'; import Theme from '../../../../static/js/Theme'; +import { openNewWindow } from '../../../../static/js/utils'; import $ from 'jquery'; const wcDocker = window.wcDocker; @@ -131,13 +132,7 @@ export default class ERDModule { let open_new_tab = this.pgBrowser.get_preferences_for_module('browser').new_browser_tab_open; if (open_new_tab && open_new_tab.includes('erd_tool')) { - let newWin = window.open('', '_blank'); - newWin.document.write(erdToolForm); - newWin.document.title = panelTitle; - // Send the signal to runtime, so that proper zoom level will be set. - setTimeout(function() { - this.pgBrowser.send_signal_to_runtime('Runtime new window opened'); - }, 500); + openNewWindow(erdToolForm, panelTitle); } else { /* On successfully initialization find the dashboard panel, * create new panel and add it to the dashboard panel. @@ -181,7 +176,6 @@ export default class ERDModule { openErdToolURL(erdToolPanel); } } - getPanelUrl(transId, parentData, gen) { let openUrl = url_for('erd.panel', { trans_id: transId, diff --git a/web/pgadmin/tools/psql/static/js/psql_module.js b/web/pgadmin/tools/psql/static/js/psql_module.js index 8dbc67c7a..803f6f1fc 100644 --- a/web/pgadmin/tools/psql/static/js/psql_module.js +++ b/web/pgadmin/tools/psql/static/js/psql_module.js @@ -18,7 +18,7 @@ import {retrieveAncestorOfTypeServer} from 'sources/tree/tree_utils'; import pgWindow from 'sources/window'; import Notify from '../../../../static/js/helpers/Notifier'; import { copyToClipboard } from '../../../../static/js/clipboard'; - +import { openNewWindow } from '../../../../static/js/utils'; import {generateTitle, refresh_db_node} from 'tools/sqleditor/static/js/sqleditor_title'; @@ -167,9 +167,7 @@ export function initialize(gettext, url_for, $, _, pgAdmin, csrfToken, Browser) `; let open_new_tab = pgBrowser.get_preferences_for_module('browser').new_browser_tab_open; if (open_new_tab && open_new_tab.includes('psql_tool')) { - let newWin = window.open('', '_blank'); - newWin.document.write(psqlToolForm); - newWin.document.title = panelTitle; + openNewWindow(psqlToolForm, panelTitle); } else { /* On successfully initialization find the properties panel, * create new panel and add it to the dashboard panel. diff --git a/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js b/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js index 94f140276..23cec7390 100644 --- a/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js +++ b/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js @@ -26,6 +26,7 @@ import QueryToolComponent from './components/QueryToolComponent'; import ModalProvider from '../../../../static/js/helpers/ModalProvider'; import Theme from '../../../../static/js/Theme'; import { showRenamePanel } from '../../../../static/js/Dialogs'; +import { openNewWindow } from '../../../../static/js/utils'; const wcDocker = window.wcDocker; @@ -340,17 +341,7 @@ export default class SQLEditor { let browser_preferences = pgBrowser.get_preferences_for_module('browser'); let open_new_tab = browser_preferences.new_browser_tab_open; if (open_new_tab && open_new_tab.includes('qt')) { - let newWin = window.open('', '_blank'); - if(newWin) { - newWin.document.write(queryToolForm); - newWin.document.title = panel_title; - // Send the signal to runtime, so that proper zoom level will be set. - setTimeout(function() { - pgBrowser.send_signal_to_runtime('Runtime new window opened'); - }, 500); - } else { - return false; - } + openNewWindow(queryToolForm, panel_title); } else { /* On successfully initialization find the dashboard panel, * create new panel and add it to the dashboard panel. @@ -359,7 +350,6 @@ export default class SQLEditor { } return true; } - setupPreferencesWorker() { if (window.location == window.parent?.location) { /* Sync the local preferences with the main window if in new tab */