diff --git a/web/package.json b/web/package.json index f43473b08..f5c03bc3a 100644 --- a/web/package.json +++ b/web/package.json @@ -58,7 +58,6 @@ "karma-webpack": "^5.0.0", "loader-utils": "^3.2.1", "mini-css-extract-plugin": "^1.3.5", - "popper.js": "^1.16.1", "postcss-loader": "^5.0.0", "process": "^0.11.10", "prop-types": "^15.7.2", @@ -103,8 +102,6 @@ "babelify": "~10.0.0", "bignumber.js": "^9.0.1", "bootstrap": "^4.3.1", - "bootstrap-datepicker": "^1.8.0", - "bootstrap4-toggle": "^3.6.1", "brace": "^0.11.1", "browserfs": "^1.4.3", "chart.js": "^3.0.0", @@ -122,6 +119,7 @@ "insert-if": "^1.1.0", "ip-address": "^7.1.0", "jquery": "^3.6.0", + "jquery-contextmenu": "^2.9.2", "json-bignumber": "^1.0.1", "jsoneditor": "^9.5.4", "jsoneditor-react": "^3.1.1", @@ -137,6 +135,7 @@ "path-fx": "^2.0.0", "pathfinding": "^0.4.18", "paths-js": "^0.4.9", + "popper.js": "^1.16.1", "postcss": "^8.2.15", "raf": "^3.4.1", "rc-dock": "^3.2.9", @@ -158,17 +157,15 @@ "react-timer-hook": "^3.0.5", "react-virtualized-auto-sizer": "^1.0.6", "react-window": "^1.8.5", - "select2": "^4.0.13", "snapsvg-cjs": "^0.0.6", "socket.io-client": "^4.5.0", "split.js": "^1.5.10", "styled-components": "^5.2.1", - "tempusdominus-bootstrap-4": "^5.1.2", "tempusdominus-core": "^5.19.3", "uplot": "^1.6.24", "uplot-react": "^1.1.4", "valid-filename": "^2.0.1", - "webcabin-docker": "git+https://github.com/pgadmin-org/wcdocker/#3df8aac825ee2892f4d824de273b779cc6dbcad8", + "webcabin-docker": "git+https://github.com/pgadmin-org/wcdocker/#460fc6d90ba170bb177faaa8277f5fbb8279522a", "wkx": "^0.5.0", "xterm": "^4.11.0", "xterm-addon-fit": "^0.5.0", diff --git a/web/pgadmin/about/static/js/AboutComponent.jsx b/web/pgadmin/about/static/js/AboutComponent.jsx index 68e1e9339..cd34002e1 100644 --- a/web/pgadmin/about/static/js/AboutComponent.jsx +++ b/web/pgadmin/about/static/js/AboutComponent.jsx @@ -58,7 +58,7 @@ export default function AboutComponent() { return ( - + {gettext('Version')} @@ -66,7 +66,7 @@ export default function AboutComponent() { {aboutData.version} - + {gettext('Application Mode')} @@ -74,7 +74,7 @@ export default function AboutComponent() { {aboutData.app_mode} - + {gettext('Current User')} @@ -83,7 +83,7 @@ export default function AboutComponent() { { aboutData.nwjs && - + {gettext('NW.js Version')} @@ -92,7 +92,7 @@ export default function AboutComponent() { } - + {gettext('Browser')} @@ -100,7 +100,7 @@ export default function AboutComponent() { {aboutData.browser_details} - + {gettext('Operating System')} @@ -108,7 +108,7 @@ export default function AboutComponent() { {aboutData.os_details} - + {gettext('pgAdmin Database File')} @@ -116,7 +116,7 @@ export default function AboutComponent() { {aboutData.config_db} - + {gettext('Log File')} @@ -148,4 +148,4 @@ export default function AboutComponent() { AboutComponent.propTypes = { closeModal: PropTypes.func -}; \ No newline at end of file +}; diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index d4434217e..1c29fe3f7 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -66,7 +66,6 @@ except ImportError as e: MODULE_NAME = 'browser' BROWSER_STATIC = 'browser.static' -JQUERY_ACIPLUGIN = 'jquery.aciplugin' BROWSER_INDEX = 'browser.index' PGADMIN_BROWSER = 'pgAdmin.Browser' PASS_ERROR_MSG = gettext('Your password has not been changed.') diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js index 186e1d724..2fb4d8059 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/static/js/schema.js @@ -12,9 +12,9 @@ import { getNodePrivilegeRoleSchema } from '../../../../static/js/privilege.ui'; import { getNodeListByName } from '../../../../../../static/js/node_ajax'; define('pgadmin.node.schema', [ - 'sources/gettext', 'sources/url_for', 'jquery', + 'sources/gettext', 'sources/url_for', 'pgadmin.browser', 'pgadmin.browser.collection', -], function(gettext, url_for, $, pgBrowser) { +], function(gettext, url_for, pgBrowser) { // Extend the browser's collection class for schema collection if (!pgBrowser.Nodes['coll-schema']) { diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/compound_triggers/static/js/compound_trigger.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/compound_triggers/static/js/compound_trigger.js index 567009397..42ff2db93 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/compound_triggers/static/js/compound_trigger.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/compound_triggers/static/js/compound_trigger.js @@ -10,14 +10,15 @@ import { getNodeListByName } from '../../../../../../../../static/js/node_ajax'; import CompoundTriggerSchema from './compound_trigger.ui'; import Notify from '../../../../../../../../../static/js/helpers/Notifier'; +import getApiInstance from '../../../../../../../../../static/js/api_instance'; define('pgadmin.node.compound_trigger', [ - 'sources/gettext', 'sources/url_for', 'jquery', + 'sources/gettext', 'sources/url_for', 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.node.schema.dir/schema_child_tree_node', 'pgadmin.browser.collection', ], function( - gettext, url_for, $, pgAdmin, pgBrowser, SchemaChildTreeNode + gettext, url_for, pgAdmin, pgBrowser, SchemaChildTreeNode ) { if (!pgBrowser.Nodes['coll-compound_trigger']) { @@ -112,31 +113,27 @@ define('pgadmin.node.compound_trigger', [ return false; let data = d; - $.ajax({ - url: obj.generate_url(i, 'enable' , d, true), - type:'PUT', - data: {'is_enable_trigger' : 'O'}, - dataType: 'json', - }) - .done(function(res) { - if (res.success == 1) { - Notify.success(res.info); - t.removeIcon(i); - data.icon = 'icon-compound_trigger'; - t.addIcon(i, {icon: data.icon}); - t.unload(i); - t.setInode(false); - t.deselect(i); - // Fetch updated data from server - setTimeout(function() { - t.select(i); - }, 10); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + getApiInstance().put( + obj.generate_url(i, 'enable' , d, true), + {'is_enable_trigger' : 'O'} + ).then(({data: res})=> { + if(res.success == 1) { + Notify.success(res.info); + t.removeIcon(i); + data.icon = 'icon-compound_trigger'; + t.addIcon(i, {icon: data.icon}); t.unload(i); - }); + t.setInode(false); + t.deselect(i); + // Fetch updated data from server + setTimeout(function() { + t.select(i); + }, 10); + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }, /* Disable compound trigger */ disable_compound_trigger: function(args) { @@ -150,31 +147,27 @@ define('pgadmin.node.compound_trigger', [ return false; let data = d; - $.ajax({ - url: obj.generate_url(i, 'enable' , d, true), - type:'PUT', - data: {'is_enable_trigger' : 'D'}, - dataType: 'json', - }) - .done(function(res) { - if (res.success == 1) { - Notify.success(res.info); - t.removeIcon(i); - data.icon = 'icon-compound_trigger-bad'; - t.addIcon(i, {icon: data.icon}); - t.unload(i); - t.setInode(false); - t.deselect(i); - // Fetch updated data from server - setTimeout(function() { - t.select(i); - }, 10); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error, gettext('Disable compound trigger failed')); + getApiInstance().put( + obj.generate_url(i, 'enable' , d, true), + {'is_enable_trigger' : 'D'} + ).then(({data: res})=> { + if(res.success == 1) { + Notify.success(res.info); + t.removeIcon(i); + data.icon = 'icon-compound_trigger-bad'; + t.addIcon(i, {icon: data.icon}); t.unload(i); - }); + t.setInode(false); + t.deselect(i); + // Fetch updated data from server + setTimeout(function() { + t.select(i); + }, 10); + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }, }, canDrop: SchemaChildTreeNode.isTreeItemOfChildOfSchema, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js index 57459dedd..a945f5128 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.js @@ -10,13 +10,14 @@ import CheckConstraintSchema from './check_constraint.ui'; import Notify from '../../../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../../../static/js/api_instance'; // Check Constraint Module: Node define('pgadmin.node.check_constraint', [ - 'sources/gettext', 'sources/url_for', 'jquery', + 'sources/gettext', 'sources/url_for', 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.node.schema.dir/schema_child_tree_node', 'pgadmin.browser.collection', -], function(gettext, url_for, $, pgAdmin, pgBrowser, schemaChildTreeNode) { +], function(gettext, url_for, pgAdmin, pgBrowser, schemaChildTreeNode) { // Check Constraint Node if (!pgBrowser.Nodes['check_constraint']) { @@ -69,11 +70,8 @@ define('pgadmin.node.check_constraint', [ if (d) { let data = d; - $.ajax({ - url: obj.generate_url(i, 'validate', d, true), - type:'GET', - }) - .done(function(res) { + getApiInstance().get(obj.generate_url(i, 'validate', d, true)) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.removeIcon(i); @@ -84,8 +82,8 @@ define('pgadmin.node.check_constraint', [ setTimeout(function() {t.select(i);}, 100); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js index f27732ff7..5a482e2c6 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.js @@ -10,12 +10,13 @@ import { getNodeForeignKeySchema } from './foreign_key.ui'; import Notify from '../../../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../../../static/js/api_instance'; define('pgadmin.node.foreign_key', [ - 'sources/gettext', 'sources/url_for', 'jquery', + 'sources/gettext', 'sources/url_for', 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.browser.collection', ], function( - gettext, url_for, $, pgAdmin, pgBrowser + gettext, url_for, pgAdmin, pgBrowser ) { // Extend the browser's node class for foreign key node if (!pgBrowser.Nodes['foreign_key']) { @@ -65,11 +66,8 @@ define('pgadmin.node.foreign_key', [ if (d) { let data = d; - $.ajax({ - url: obj.generate_url(i, 'validate', d, true), - type:'GET', - }) - .done(function(res) { + getApiInstance().get(obj.generate_url(i, 'validate', d, true)) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.removeIcon(i); @@ -80,8 +78,8 @@ define('pgadmin.node.foreign_key', [ setTimeout(function() {t.select(i);}, 100); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js index f20f5f89b..69f2242df 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js @@ -10,6 +10,7 @@ import { getNodePartitionTableSchema } from './partition.ui'; import Notify from '../../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../../static/js/api_instance'; define([ 'sources/gettext', 'sources/url_for', 'jquery', @@ -166,13 +167,8 @@ function( if (!d) return false; - $.ajax({ - url: obj.generate_url(i, 'set_trigger' , d, true), - type:'PUT', - data: params, - dataType: 'json', - }) - .done(function(res) { + getApiInstance().put(obj.generate_url(i, 'set_trigger' , d, true), params) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.unload(i); @@ -183,8 +179,8 @@ function( }, 10); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, @@ -213,17 +209,12 @@ function( gettext('Are you sure you want to truncate table %s?', d.label), function () { let data = d; - $.ajax({ - url: obj.generate_url(i, 'truncate' , d, true), - type:'PUT', - data: params, - dataType: 'json', - }) - .done(function(res) { + getApiInstance().put(obj.generate_url(i, 'truncate' , d, true), params) + .then(({data: res})=>{ obj.on_done(res, data, t, i); }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, @@ -244,15 +235,12 @@ function( gettext('Are you sure you want to reset the statistics for table "%s"?', d._label), function () { let data = d; - $.ajax({ - url: obj.generate_url(i, 'reset' , d, true), - type:'DELETE', - }) - .done(function(res) { + getApiInstance().delete(obj.generate_url(i, 'reset' , d, true)) + .then(({data: res})=>{ obj.on_done(res, data, t, i); }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, @@ -273,11 +261,8 @@ function( gettext('Detach Partition'), gettext('Are you sure you want to detach the partition %s?', d._label), function () { - $.ajax({ - url: obj.generate_url(i, 'detach' , d, true), - type:'PUT', - }) - .done(function(res) { + getApiInstance().put(obj.generate_url(i, 'detach' , d, true)) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); let n = t.next(i); @@ -293,8 +278,8 @@ function( } } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); }); }, function() {/*This is intentional (SonarQube)*/} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/static/js/rule.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/static/js/rule.js index 454dd8232..437f3a9b7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/static/js/rule.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/rules/static/js/rule.js @@ -9,6 +9,7 @@ import RuleSchema from './rule.ui'; import Notify from '../../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../../static/js/api_instance'; define('pgadmin.node.rule', [ 'sources/gettext', 'sources/url_for', 'jquery', @@ -134,13 +135,8 @@ define('pgadmin.node.rule', [ return false; let data = d; - $.ajax({ - url: obj.generate_url(i, 'obj' , d, true), - type:'PUT', - data: {'is_enable_rule' : 'O'}, - dataType: 'json', - }) - .done(function() { + getApiInstance().put(obj.generate_url(i, 'obj' , d, true), {'is_enable_rule' : 'O'}) + .then(()=>{ Notify.success('Rule updated.'); t.removeIcon(i); data.icon = 'icon-rule'; @@ -153,9 +149,8 @@ define('pgadmin.node.rule', [ t.select(i); }, 10); }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - t.unload(i); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); }); }, /* Disable rule */ @@ -170,13 +165,8 @@ define('pgadmin.node.rule', [ return false; let data = d; - $.ajax({ - url: obj.generate_url(i, 'obj' , d, true), - type:'PUT', - data: {'is_enable_rule' : 'D'}, - dataType: 'json', - }) - .done(function() { + getApiInstance().put(obj.generate_url(i, 'obj' , d, true), {'is_enable_rule' : 'D'}) + .then(()=>{ Notify.success('Rule updated'); t.removeIcon(i); data.icon = 'icon-rule-bad'; @@ -189,9 +179,8 @@ define('pgadmin.node.rule', [ t.select(i); }, 10); }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error, gettext('Disable rule failed')); - t.unload(i); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); }); }, }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js index 8fc99e6bc..188a03bdc 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.js @@ -9,6 +9,7 @@ import { getNodeTableSchema } from './table.ui'; import Notify from '../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../static/js/api_instance'; define('pgadmin.node.table', [ 'pgadmin.tables.js/enable_disable_triggers', @@ -187,13 +188,8 @@ define('pgadmin.node.table', [ gettext('Are you sure you want to truncate table %s?', d.label), function () { let data = d; - $.ajax({ - url: obj.generate_url(i, 'truncate' , d, true), - type:'PUT', - data: params, - dataType: 'json', - }) - .done(function(res) { + getApiInstance().put(obj.generate_url(i, 'truncate' , d, true), params) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.removeIcon(i); @@ -211,8 +207,8 @@ define('pgadmin.node.table', [ Notify.error(res.info); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, function() {/*This is intentional (SonarQube)*/} @@ -233,11 +229,8 @@ define('pgadmin.node.table', [ gettext('Are you sure you want to reset the statistics for table "%s"?', d._label), function () { let data = d; - $.ajax({ - url: obj.generate_url(i, 'reset' , d, true), - type:'DELETE', - }) - .done(function(res) { + getApiInstance().delete(obj.generate_url(i, 'reset' , d, true)) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.removeIcon(i); @@ -252,8 +245,8 @@ define('pgadmin.node.table', [ }, 10); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, @@ -274,11 +267,8 @@ define('pgadmin.node.table', [ ...d, _type: this.type, }; // Fetch the total rows of a table - $.ajax({ - url: obj.generate_url(i, 'count_rows' , newD, true), - type:'GET', - }) - .done(function(res) { + getApiInstance().get(obj.generate_url(i, 'count_rows' , newD, true)) + .then(({data: res})=>{ Notify.success(res.info, null); d.rows_cnt = res.data.total_rows; t.unload(i); @@ -288,8 +278,8 @@ define('pgadmin.node.table', [ t.select(i); }, 10); }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js index 3afbb5b05..944020683 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js @@ -10,6 +10,7 @@ import { getNodeListByName, getNodeAjaxOptions } from '../../../../../../../../s import TriggerSchema from './trigger.ui'; import Notify from '../../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../../static/js/api_instance'; define('pgadmin.node.trigger', [ 'sources/gettext', 'sources/url_for', 'jquery', @@ -108,13 +109,8 @@ define('pgadmin.node.trigger', [ return false; let data = d; - $.ajax({ - url: obj.generate_url(i, 'enable' , d, true), - type:'PUT', - data: {'is_enable_trigger' : 'O'}, - dataType: 'json', - }) - .done(function(res) { + getApiInstance().put(obj.generate_url(i, 'enable' , d, true), {'is_enable_trigger' : 'O'}) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.removeIcon(i); @@ -130,8 +126,8 @@ define('pgadmin.node.trigger', [ }, 10); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, @@ -147,13 +143,8 @@ define('pgadmin.node.trigger', [ return false; let data = d; - $.ajax({ - url: obj.generate_url(i, 'enable' , d, true), - type:'PUT', - data: {'is_enable_trigger' : 'D'}, - dataType: 'json', - }) - .done(function(res) { + getApiInstance().put(obj.generate_url(i, 'enable' , d, true), {'is_enable_trigger' : 'D'}) + .then(({data: res})=>{ if (res.success == 1) { Notify.success(res.info); t.removeIcon(i); @@ -169,8 +160,8 @@ define('pgadmin.node.trigger', [ }, 10); } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error, gettext('Disable trigger failed')); + .catch((error)=>{ + Notify.pgRespErrorNotify(error); t.unload(i); }); }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py index e9e9c585f..b7784b2ef 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py @@ -1965,8 +1965,8 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings): request.data, encoding='utf-8' ) # Convert str 'true' to boolean type - is_cascade = json.loads(data.get('cascade') or 'false') - is_identity = json.loads(data.get('identity') or 'false') + is_cascade = data.get('cascade') or False + is_identity = data.get('identity') or False data = res['rows'][0] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py index 465f0ffc6..12b1ef566 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/__init__.py @@ -2161,8 +2161,8 @@ class MViewNode(ViewNode, VacuumSettings): request.data, encoding='utf-8' ) - is_concurrent = json.loads(data['concurrent']) - with_data = json.loads(data['with_data']) + is_concurrent = data['concurrent'] + with_data = data['with_data'] data = dict() data['is_concurrent'] = is_concurrent data['is_with_data'] = with_data diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js index 0b75d3ee0..1129e24c9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/mview.js @@ -13,6 +13,7 @@ import { getNodePrivilegeRoleSchema } from '../../../../../static/js/privilege.u import { getNodeVacuumSettingsSchema } from '../../../../../static/js/vacuum.ui'; import Notify from '../../../../../../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../../../../../../static/js/api_instance'; define('pgadmin.node.mview', [ 'sources/gettext', 'sources/url_for', 'jquery', @@ -86,39 +87,39 @@ define('pgadmin.node.mview', [ pgBrowser.add_menus([{ name: 'create_mview_on_coll', node: 'coll-mview', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', - category: 'create', priority: 1, + category: 'create', priority: 1, data: {action: 'create', check: true}, enable: 'canCreate', label: gettext('Materialized View...'), },{ name: 'create_mview', node: 'mview', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', - category: 'create', priority: 1, + category: 'create', priority: 1, data: {action: 'create', check: true}, enable: 'canCreate', label: gettext('Materialized View...'), },{ name: 'create_mview', node: 'schema', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', - category: 'create', priority: 18, + category: 'create', priority: 18, data: {action: 'create', check: false}, enable: 'canCreate', label: gettext('Materialized View...'), },{ name: 'refresh_mview_data', node: 'mview', module: this, priority: 1, callback: 'refresh_mview', category: 'refresh_mview', applies: ['object', 'context'], label: gettext('With data'), - data: {concurrent: false, with_data: true}, + data: {concurrent: false, with_data: true}, },{ name: 'refresh_mview_nodata', node: 'mview', callback: 'refresh_mview', priority: 2, module: this, category: 'refresh_mview', applies: ['object', 'context'], label: gettext('With no data'), data: { concurrent: false, with_data: false, - }, + }, },{ name: 'refresh_mview_concurrent', node: 'mview', module: this, category: 'refresh_mview', enable: 'is_version_supported', data: {concurrent: true, with_data: true}, priority: 3, applies: ['object', 'context'], callback: 'refresh_mview', - label: gettext('With data (concurrently)'), + label: gettext('With data (concurrently)'), },{ name: 'refresh_mview_concurrent_nodata', node: 'mview', module: this, category: 'refresh_mview', enable: 'is_version_supported', @@ -181,47 +182,41 @@ define('pgadmin.node.mview', [ return; } - $.ajax({ - url: obj.generate_url(i, 'check_utility_exists' , d, true), - type: 'GET', - dataType: 'json', - }).done(function(res) { - if (!res.success) { + const api = getApiInstance(); + api.get(obj.generate_url(i, 'check_utility_exists' , d, true)) + .then(({data: res})=>{ + if (!res.success) { + Notify.alert( + gettext('Utility not found'), + res.errormsg + ); + return; + } + + api.put(obj.generate_url(i, 'refresh_data' , d, true), {'concurrent': args.concurrent, 'with_data': args.with_data}) + .then(({data: refreshed_res})=>{ + if (refreshed_res.data && refreshed_res.data.status) { + //Do nothing as we are creating the job and exiting from the main dialog + pgBrowser.BgProcessManager.startProcess(refreshed_res.data.job_id, refreshed_res.data.desc); + } else { + Notify.alert( + gettext('Failed to create materialized view refresh job.'), + refreshed_res.errormsg + ); + } + }) + .catch((error)=>{ + Notify.pgRespErrorNotify( + error, gettext('Failed to create materialized view refresh job.') + ); + }); + }) + .catch(()=>{ Notify.alert( gettext('Utility not found'), - res.errormsg + gettext('Failed to fetch Utility information') ); - return; - } - // Make ajax call to refresh mview data - $.ajax({ - url: obj.generate_url(i, 'refresh_data' , d, true), - type: 'PUT', - data: {'concurrent': args.concurrent, 'with_data': args.with_data}, - dataType: 'json', - }) - .done(function(refreshed_res) { - if (refreshed_res.data && refreshed_res.data.status) { - //Do nothing as we are creating the job and exiting from the main dialog - pgBrowser.BgProcessManager.startProcess(refreshed_res.data.job_id, refreshed_res.data.desc); - } else { - Notify.alert( - gettext('Failed to create materialized view refresh job.'), - refreshed_res.errormsg - ); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify( - xhr, error, gettext('Failed to create materialized view refresh job.') - ); - }); - }).fail(function() { - Notify.alert( - gettext('Utility not found'), - gettext('Failed to fetch Utility information') - ); - }); + }); }, is_version_supported: function(data, item) { diff --git a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js index b42f069a4..ec9d82ff0 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js +++ b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js @@ -14,6 +14,7 @@ import DatabaseSchema from './database.ui'; import Notify from '../../../../../../static/js/helpers/Notifier'; import { showServerPassword } from '../../../../../../static/js/Dialogs/index'; import _ from 'lodash'; +import getApiInstance, { parseApiError } from '../../../../../../static/js/api_instance'; define('pgadmin.node.database', [ 'sources/gettext', 'sources/url_for', 'jquery', @@ -228,41 +229,38 @@ define('pgadmin.node.database', [ gettext('Are you sure you want to disconnect from database - %s?', d.label), function() { let data = d; - $.ajax({ - url: obj.generate_url(i, 'connect', d, true), - type:'DELETE', - }) - .done(function(res) { - if (res.success == 1) { - let prv_i = t.parent(i); - if(res.data.info_prefix) { - res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`; - } - Notify.success(res.info); - t.removeIcon(i); - data.connected = false; - data.icon = data.isTemplate ? 'icon-database-template-not-connected':'icon-database-not-connected'; - - t.addIcon(i, {icon: data.icon}); - t.unload(i); - pgBrowser.Events.trigger('pgadmin:browser:tree:update-tree-state', i); - setTimeout(function() { - t.select(prv_i); - }, 10); - - } else { - try { - Notify.error(res.errormsg); - } catch (e) { - console.warn(e.stack || e); - } - t.unload(i); + getApiInstance().delete( + obj.generate_url(i, 'connect', d, true), + ).then(({data: res})=> { + if (res.success == 1) { + let prv_i = t.parent(i); + if(res.data.info_prefix) { + res.info = `${_.escape(res.data.info_prefix)} - ${res.info}`; } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + Notify.success(res.info); + t.removeIcon(i); + data.connected = false; + data.icon = data.isTemplate ? 'icon-database-template-not-connected':'icon-database-not-connected'; + + t.addIcon(i, {icon: data.icon}); t.unload(i); - }); + pgBrowser.Events.trigger('pgadmin:browser:tree:update-tree-state', i); + setTimeout(function() { + t.select(prv_i); + }, 10); + + } else { + try { + Notify.error(res.errormsg); + } catch (e) { + console.warn(e.stack || e); + } + t.unload(i); + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }, function() { return true; } ); @@ -372,16 +370,17 @@ define('pgadmin.node.database', [ }, }; + let api = getApiInstance(); let connect_to_database = function(obj, data, tree, item, _wasConnected) { connect(obj, data, tree, item, _wasConnected); }, connect = function (obj, data, tree, item, _wasConnected) { let wasConnected = _wasConnected || data.connected, onFailure = function( - xhr, status, error, _model, _data, _tree, _item, _status + error, _model, _data, _tree, _item, _status ) { data.is_connecting = false; - if (xhr.status != 200 && xhr.responseText.search('Ticket expired') !== -1) { + if (error.response?.status != 200 && error.response?.request?.responseText?.search('Ticket expired') !== -1) { tree.addIcon(_item, {icon: 'icon-server-connecting'}); let fetchTicket = Kerberos.fetch_ticket(); fetchTicket.then( @@ -392,7 +391,7 @@ define('pgadmin.node.database', [ tree.setInode(_item); let dbIcon = data.isTemplate ? 'icon-database-template-not-connected':'icon-database-not-connected'; tree.addIcon(_item, {icon: dbIcon}); - Notify.pgNotifier(fun_error, xhr, gettext('Connect to database.')); + Notify.pgNotifier(fun_error, error, gettext('Connect to database.')); } ); } else { @@ -402,7 +401,7 @@ define('pgadmin.node.database', [ tree.addIcon(_item, {icon: dbIcon}); } - Notify.pgNotifier('error', xhr, error, function(msg) { + Notify.pgNotifier('error', error, 'Error', function(msg) { setTimeout(function() { if (msg == 'CRYPTKEY_SET') { connect_to_database(_model, _data, _tree, _item, _wasConnected); @@ -473,21 +472,21 @@ define('pgadmin.node.database', [ _tree.select(server); }; - $.post( - obj.generate_url(item, 'connect', data, true) - ).done(function(res) { - if (res.success == 1) { - return onSuccess(res, obj, data, tree, item, wasConnected); - } - }).fail(function(xhr, status, error) { - if (xhr.status === 410) { - error = gettext('Error: Object not found - %s.', error); - } + api.post(obj.generate_url(item, 'connect', data, true)) + .then(({data: res})=>{ + if (res.success == 1) { + return onSuccess(res, obj, data, tree, item, wasConnected); + } + }) + .catch((error)=>{ + if (error.response?.status === 410) { + error = gettext('Error: Object not found - %s.', parseApiError(error)); + } - return onFailure( - xhr, status, error, obj, data, tree, item, wasConnected - ); - }); + return onFailure( + error, obj, data, tree, item, wasConnected + ); + }); }; } diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js b/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js index a71b23ed7..5003d5466 100644 --- a/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js +++ b/web/pgadmin/browser/server_groups/servers/pgagent/static/js/pga_job.js @@ -11,6 +11,7 @@ import { getNodeAjaxOptions } from '../../../../../static/js/node_ajax'; import PgaJobSchema from './pga_job.ui'; import { getNodePgaJobStepSchema } from '../../steps/static/js/pga_jobstep.ui'; import Notify from '../../../../../../static/js/helpers/Notifier'; +import getApiInstance from '../../../../../../static/js/api_instance'; define('pgadmin.node.pga_job', [ 'sources/gettext', 'sources/url_for', 'jquery', 'pgadmin.browser', @@ -91,17 +92,15 @@ define('pgadmin.node.pga_job', [ d = i ? t.itemData(i) : undefined; if (d) { - $.ajax({ - url: obj.generate_url(i, 'run_now', d, true), - method:'PUT', - }) - // 'pgagent.pga_job' table updated with current time to run the job - // now. - .done(function() { t.unload(i); }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); + getApiInstance().put( + obj.generate_url(i, 'run_now', d, true), + ).then(({data: res})=> { + Notify.success(res.info); + t.unload(i); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); } return false; diff --git a/web/pgadmin/browser/server_groups/servers/static/js/binary_path.ui.js b/web/pgadmin/browser/server_groups/servers/static/js/binary_path.ui.js index 2ae5bb99a..ae2dadb22 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/binary_path.ui.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/binary_path.ui.js @@ -68,7 +68,7 @@ export default class BinaryPathSchema extends BaseUISchema { Notify.alert(gettext('Validate binary path'), gettext(res.data.data)); }) .catch(function (error) { - Notify.pgNotifier(error, gettext('Failed to validate binary path.')); + Notify.pgNotifier('error', error, gettext('Failed to validate binary path.')); }); } return true; 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 486ec147e..a63728285 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/server.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/server.js @@ -12,6 +12,7 @@ import ServerSchema from './server.ui'; import Notify from '../../../../../static/js/helpers/Notifier'; import { showServerPassword, showChangeServerPassword, showNamedRestorePoint } from '../../../../../static/js/Dialogs/index'; import _ from 'lodash'; +import getApiInstance, { parseApiError } from '../../../../../static/js/api_instance'; define('pgadmin.node.server', [ 'sources/gettext', 'sources/url_for', 'jquery', @@ -196,45 +197,40 @@ define('pgadmin.node.server', [ notify = notify || _.isUndefined(notify) || _.isNull(notify); let disconnect = function() { - $.ajax({ - url: obj.generate_url(i, 'connect', d, true), - type:'DELETE', - }) - .done(function(res) { - if (res.success == 1) { - Notify.success(res.info); - d = t.itemData(i); - t.removeIcon(i); - d.connected = false; - if (d.shared && pgAdmin.server_mode == 'True'){ - d.icon = 'icon-shared-server-not-connected'; - }else{ - d.icon = 'icon-server-not-connected'; + getApiInstance().delete( + obj.generate_url(i, 'connect', d, true), + ).then(({data: res})=> { + if (res.success == 1) { + Notify.success(res.info); + d = t.itemData(i); + t.removeIcon(i); + d.connected = false; + if (d.shared && pgAdmin.server_mode == 'True'){ + d.icon = 'icon-shared-server-not-connected'; + }else{ + d.icon = 'icon-server-not-connected'; + } + t.addIcon(i, {icon: d.icon}); + obj.callbacks.refresh.apply(obj, [null, i]); + setTimeout(() => { + t.close(i); + }, 10); + if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) { + delete pgBrowser.serverInfo[d._id]; + } + else { + try { + Notify.error(res.errormsg); + } catch (e) { + console.warn(e.stack || e); } - t.addIcon(i, {icon: d.icon}); - obj.callbacks.refresh.apply(obj, [null, i]); - setTimeout(() => { - t.close(i); - }, 10); - if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) { - delete pgBrowser.serverInfo[d._id]; - } - else { - try { - Notify.error(res.errormsg); - } catch (e) { - console.warn(e.stack || e); - } - t.unload(i); - } - pgBrowser.Events.trigger( - 'pgadmin:server:disconnect', {item: i, data: d}, false - ); - }}) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); + t.unload(i); + } + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }; if (notify) { @@ -295,22 +291,19 @@ define('pgadmin.node.server', [ gettext('Reload server configuration'), gettext('Are you sure you want to reload the server configuration on %s?', d.label), function() { - $.ajax({ - url: obj.generate_url(i, 'reload', d, true), - method:'GET', - }) - .done(function(res) { - if (res.data.status) { - Notify.success(res.data.result); - } - else { - Notify.error(res.data.result); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); + getApiInstance().get( + obj.generate_url(i, 'reload', d, true), + ).then(({data: res})=> { + if (res.data.status) { + Notify.success(res.data.result); + } + else { + Notify.error(res.data.result); + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }, function() { return true; }, ); @@ -344,19 +337,16 @@ define('pgadmin.node.server', [ if (d) { // Call to check if server is using pgpass file or not - $.ajax({ - url: check_pgpass_url, - method:'GET', - }) - .done(function(res) { - if (res.success && res.data.is_pgpass) { - is_pgpass_file_used = true; - } - showChangeServerPassword(gettext('Change Password'), d, obj, i, is_pgpass_file_used); - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - }); + getApiInstance().get( + check_pgpass_url + ).then(({data: res})=> { + if (res.success && res.data.is_pgpass) { + is_pgpass_file_used = true; + } + showChangeServerPassword(gettext('Change Password'), d, obj, i, is_pgpass_file_used); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + }); } return false; @@ -387,18 +377,14 @@ define('pgadmin.node.server', [ if (!d) return false; - $.ajax({ - url: obj.generate_url(i, 'wal_replay' , d, true), - type:'DELETE', - dataType: 'json', - }) - .done(function(res) { - obj.on_done(res, t, i); - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); + getApiInstance().delete( + obj.generate_url(i, 'wal_replay' , d, true) + ).then(({data: res})=> { + obj.on_done(res, t, i); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }, /* Resume WAL Replay */ @@ -412,18 +398,14 @@ define('pgadmin.node.server', [ if (!d) return false; - $.ajax({ - url: obj.generate_url(i, 'wal_replay' , d, true), - type:'PUT', - dataType: 'json', - }) - .done(function(res) { - obj.on_done(res, t, i); - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - t.unload(i); - }); + getApiInstance().put( + obj.generate_url(i, 'wal_replay' , d, true) + ).then(({data: res})=> { + obj.on_done(res, t, i); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + t.unload(i); + }); }, /* Cleat saved database server password */ @@ -439,22 +421,19 @@ define('pgadmin.node.server', [ gettext('Clear saved password'), gettext('Are you sure you want to clear the saved password for server %s?', d.label), function() { - $.ajax({ - url: obj.generate_url(i, 'clear_saved_password', d, true), - method:'PUT', - }) - .done(function(res) { - if (res.success == 1) { - Notify.success(res.info); - t.itemData(i).is_password_saved=res.data.is_password_saved; - } - else { - Notify.error(res.info); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - }); + getApiInstance().put( + obj.generate_url(i, 'clear_saved_password' , d, true) + ).then(({data: res})=> { + if (res.success == 1) { + Notify.success(res.info); + t.itemData(i).is_password_saved=res.data.is_password_saved; + } + else { + Notify.error(res.info); + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + }); }, function() { return true; } ); @@ -476,22 +455,19 @@ define('pgadmin.node.server', [ gettext('Clear SSH Tunnel password'), gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?', d.label), function() { - $.ajax({ - url: obj.generate_url(i, 'clear_sshtunnel_password', d, true), - method:'PUT', - }) - .done(function(res) { - if (res.success == 1) { - Notify.success(res.info); - t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved; - } - else { - Notify.error(res.info); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - }); + getApiInstance().put( + obj.generate_url(i, 'clear_sshtunnel_password' , d, true) + ).then(({data: res})=> { + if (res.success == 1) { + Notify.success(res.info); + t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved; + } + else { + Notify.error(res.info); + } + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + }); }, function() { return true; } ); @@ -595,8 +571,8 @@ define('pgadmin.node.server', [ // Open properties dialog in edit mode let server_url = obj.generate_url(item, 'obj', data, true); // Fetch the updated data - $.get(server_url) - .done(function(res) { + getApiInstance().get(server_url) + .then(({data: res})=>{ if (res.shared && _.isNull(res.username) && data.user_id != current_user.id) { if (!res.service) { pgAdmin.Browser.Node.callbacks.show_obj_properties.call( @@ -617,13 +593,14 @@ define('pgadmin.node.server', [ else if (res.cloud_status == -1) { pgAdmin.Browser.BgProcessManager.recheckCloudServer(data._id); } - }).always(function(){ + }) + .then(()=>{ data.is_connecting = false; }); let wasConnected = reconnect || data.connected, onFailure = function( - xhr, status, error, _node, _data, _tree, _item, _wasConnected + xhr, error, _node, _data, _tree, _item, _wasConnected ) { data.connected = false; @@ -647,7 +624,7 @@ define('pgadmin.node.server', [ }, function() { tree.addIcon(_item, {icon: 'icon-server-not-connected'}); - Notify.pgNotifier('Connection error', xhr, gettext('Connect to server.')); + Notify.pgNotifier('error', 'Connection error', xhr, gettext('Connect to server.')); } ); } else { @@ -750,20 +727,20 @@ define('pgadmin.node.server', [ tree.removeIcon(item); tree.addIcon(item, {icon: 'icon-server-connecting'}); let url = obj.generate_url(item, 'connect', data, true); - $.post(url) - .done(function(res) { + getApiInstance().post(url) + .then(({data: res})=>{ if (res.success == 1) { return onSuccess( res, obj, data, tree, item, wasConnected ); } }) - .fail(function(xhr, status, error) { + .catch((xhr)=>{ return onFailure( - xhr, status, error, obj, data, tree, item, wasConnected + xhr.response?.request, parseApiError(xhr), obj, data, tree, item, wasConnected ); }) - .always(function(){ + .then(()=>{ data.is_connecting = false; }); }; @@ -773,8 +750,9 @@ define('pgadmin.node.server', [ tree.setLeaf(item); tree.removeIcon(item); tree.addIcon(item, {icon: 'icon-server-connecting'}); - $.get(url) - .done(function(res) { + + getApiInstance().get(url) + .then(({data: res})=>{ tree.setInode(item); if (res && res.data) { if (typeof res.data.icon == 'string') { @@ -796,14 +774,14 @@ define('pgadmin.node.server', [ ); } }) - .fail(function(xhr, status, error) { + .catch((error)=>{ tree.setInode(item); if (data.shared && pgAdmin.server_mode == 'True'){ tree.addIcon(item, {icon: 'icon-shared-server-not-connected'}); }else{ tree.addIcon(item, {icon: 'icon-server-not-connected'}); } - Notify.pgRespErrorNotify(xhr, error); + Notify.pgRespErrorNotify(error); }); }; } diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index 2745566a0..632c6cc0c 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -16,23 +16,26 @@ import { checkMasterPassword } from '../../../static/js/Dialogs/index'; import { pgHandleItemError } from '../../../static/js/utils'; import { Search } from './quick_search/trigger_search'; import { send_heartbeat, stop_heartbeat } from './heartbeat'; +import getApiInstance from '../../../static/js/api_instance'; define('pgadmin.browser', [ - 'sources/gettext', 'sources/url_for', 'require', 'jquery', - 'bootstrap', 'sources/pgadmin', 'bundled_codemirror', + 'sources/gettext', 'sources/url_for', 'jquery', + 'sources/pgadmin', 'bundled_codemirror', 'sources/check_node_visibility', './toolbar', 'pgadmin.help', 'sources/csrf', 'sources/utils', 'sources/window', 'pgadmin.authenticate.kerberos', 'sources/tree/tree_init', - 'pgadmin.browser.utils', 'wcdocker', 'jquery.contextmenu', + 'pgadmin.browser.utils', 'pgadmin.browser.preferences', 'pgadmin.browser.messages', 'pgadmin.browser.panel', 'pgadmin.browser.layout', - 'pgadmin.browser.error', 'pgadmin.browser.frame', + 'pgadmin.browser.frame', 'pgadmin.browser.node', 'pgadmin.browser.collection', 'pgadmin.browser.activity', 'sources/codemirror/addon/fold/pgadmin-sqlfoldcode', - 'pgadmin.browser.keyboard', 'sources/tree/pgadmin_tree_save_state' + 'pgadmin.browser.keyboard', 'sources/tree/pgadmin_tree_save_state', + /* wcDocker dependencies */ + 'bootstrap', 'jquery-contextmenu', 'wcdocker', ], function( - gettext, url_for, require, $, - Bootstrap, pgAdmin, codemirror, + gettext, url_for, $, + pgAdmin, codemirror, checkNodeVisibility, toolBar, help, csrfToken, pgadminUtils, pgWindow, Kerberos, InitTree, ) { @@ -201,9 +204,9 @@ define('pgadmin.browser', [ icon: '', limit: 1, content: '
', - onCreate: function(panel, $container) { + onCreate: function(panel, container) { toolBar.initializeToolbar(panel, wcDocker); - $container.addClass('pg-no-overflow'); + container.classList.add('pg-no-overflow'); }, }), // Properties of the object node @@ -216,10 +219,10 @@ define('pgadmin.browser', [ isPrivate: true, elContainer: true, limit: 1, - content: '
' + select_object_msg + '
', + content: '
' + select_object_msg + '
', events: panelEvents, - onCreate: function(myPanel, $container) { - $container.addClass('pg-no-overflow'); + onCreate: function(myPanel, container) { + container.classList.add('pg-no-overflow'); }, }), // Statistics of the object @@ -232,7 +235,7 @@ define('pgadmin.browser', [ isPrivate: false, limit : 1, canHide: true, - content: '
' + select_object_msg + '
', + content: '
', events: panelEvents, }), // Reversed engineered SQL for the object @@ -244,7 +247,7 @@ define('pgadmin.browser', [ isCloseable: false, isPrivate: true, limit: 1, - content: '
', + content: '
', }), // Dependencies of the object 'dependencies': new pgAdmin.Browser.Panel({ @@ -256,7 +259,7 @@ define('pgadmin.browser', [ isPrivate: false, canHide: true, limit: 1, - content: '
' + select_object_msg + '
', + content: '
', events: panelEvents, }), // Dependents of the object @@ -269,7 +272,7 @@ define('pgadmin.browser', [ isPrivate: false, limit: 1, canHide: true, - content: '
' + select_object_msg + '
', + content: '
', events: panelEvents, }), // Background processes @@ -282,7 +285,7 @@ define('pgadmin.browser', [ isPrivate: false, limit: 1, canHide: true, - content: '
', + content: '
', events: panelEvents, }), }, @@ -526,17 +529,6 @@ define('pgadmin.browser', [ initializeModalProvider(); initializeNotifier(); - // Syntax highlight the SQL Pane - if(document.getElementById('sql-textarea')){ - obj.editor = CodeMirror.fromTextArea( - document.getElementById('sql-textarea'), { - lineNumbers: true, - mode: 'text/x-pgsql', - readOnly: true, - extraKeys: pgAdmin.Browser.editor_shortcut_keys, - screenReaderLabel: gettext('SQL'), - }); - } /* Cache may take time to load for the first time * Reflect the changes once cache is available */ @@ -568,18 +560,15 @@ define('pgadmin.browser', [ // Register scripts and add menus pgBrowser.utils.registerScripts(this); - let headers = {}; - headers[pgAdmin.csrf_token_header] = pgAdmin.csrf_token; - // Ping the server every 5 minutes setInterval(function() { - $.ajax({ - url: url_for('misc.cleanup'), - type:'POST', - headers: headers, - }) - .done(function() {/*This is intentional (SonarQube)*/}) - .fail(function() {/*This is intentional (SonarQube)*/}); + getApiInstance().post( + url_for('misc.cleanup') + ).then(()=> { + /*This is intentional (SonarQube)*/ + }).catch(function() { + /*This is intentional (SonarQube)*/ + }); }, 300000); obj.Events.on( @@ -608,12 +597,9 @@ define('pgadmin.browser', [ if (this.tree) this.tree.resizeTree(); }, check_corrupted_db_file: function() { - $.ajax({ - url: url_for('browser.check_corrupted_db_file'), - type: 'GET', - dataType: 'json', - contentType: 'application/json', - }).done((res)=> { + getApiInstance().get( + url_for('browser.check_corrupted_db_file') + ).then(({data: res})=> { if(res.data.length > 0) { Notify.alert( @@ -626,16 +612,14 @@ define('pgadmin.browser', [ res.data.substring(0, res.data.length - 14), ); } - }).fail(function(xhr, status, error) { + }).catch(function(error) { Notify.alert(error); }); }, check_master_password: function(on_resp_callback) { - $.ajax({ - url: url_for('browser.check_master_password'), - type: 'GET', - contentType: 'application/json', - }).done((res)=> { + getApiInstance().get( + url_for('browser.check_master_password') + ).then(({data: res})=> { if(on_resp_callback) { if(res.data) { on_resp_callback(true); @@ -643,23 +627,21 @@ define('pgadmin.browser', [ on_resp_callback(false); } } - }).fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); }); }, reset_master_password: function() { let self = this; - $.ajax({ - url: url_for('browser.set_master_password'), - type: 'DELETE', - contentType: 'application/json', - }).done((res)=> { + getApiInstance().delete( + url_for('browser.set_master_password') + ).then(({data: res})=> { if(!res.data) { self.set_master_password(''); } - }).fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); }); }, @@ -1687,59 +1669,51 @@ define('pgadmin.browser', [ }); return; } + + let api = getApiInstance(); let fetchNodeInfo = function(__i, __d, __n) { let info = __n.getTreeNodeHierarchy(__i), url = __n.generate_url(__i, 'nodes', __d, true); - $.ajax({ - url: url, - type: 'GET', - cache: false, - dataType: 'json', - }) - .done(function(res) { + api.get( + url + ).then(({data: res})=> { // Node information can come as result/data - let newData = res.result || res.data; + let newData = res.result || res.data; - newData._label = newData.label; - newData.label = _.escape(newData.label); + newData._label = newData.label; + newData.label = _.escape(newData.label); - ctx.t.setLabel(ctx.i, {label: newData.label}); - ctx.t.addIcon(ctx.i, {icon: newData.icon}); - ctx.t.setId(ctx.i, {id: newData.id}); - if (newData.inode) - ctx.t.setInode(ctx.i, {inode: true}); + ctx.t.setLabel(ctx.i, {label: newData.label}); + ctx.t.addIcon(ctx.i, {icon: newData.icon}); + ctx.t.setId(ctx.i, {id: newData.id}); + if (newData.inode) + ctx.t.setInode(ctx.i, {inode: true}); - // This will update the tree item data. - let itemData = ctx.t.itemData(ctx.i); - _.extend(itemData, newData); + // This will update the tree item data. + let itemData = ctx.t.itemData(ctx.i); + _.extend(itemData, newData); - if ( - __n.can_expand && typeof(__n.can_expand) == 'function' - ) { - if (!__n.can_expand(itemData)) { - ctx.t.unload(ctx.i); - return; - } + if ( + __n.can_expand && typeof(__n.can_expand) == 'function' + ) { + if (!__n.can_expand(itemData)) { + ctx.t.unload(ctx.i); + return; } - ctx.b._refreshNode(ctx, ctx.branch); - let success = (ctx.o && ctx.o.success) || ctx.success; - if (success && typeof(success) == 'function') { - success(); - } - }) - .fail(function(xhr, error) { - if (!pgHandleItemError( - xhr, {item: __i, info: info} - )) { - let contentType = xhr.getResponseHeader('Content-Type'), - jsonResp = ( - contentType && - contentType.indexOf('application/json') == 0 && - JSON.parse(xhr.responseText) - ) || {}; - - if (xhr.status == 410 && jsonResp.success == 0) { + } + ctx.b._refreshNode(ctx, ctx.branch); + let success = (ctx.o && ctx.o.success) || ctx.success; + if (success && typeof(success) == 'function') { + success(); + } + }).catch(function(error) { + if (!pgHandleItemError( + error, {item: __i, info: info} + )) { + if(error.response.headers['content-type'] == 'application/json') { + let jsonResp = error.response.data ?? {}; + if(error.response.status == 410 && jsonResp.success == 0) { let parent = ctx.t.parent(ctx.i); ctx.t.remove(ctx.i, { @@ -1755,16 +1729,17 @@ define('pgadmin.browser', [ }, }); } - - Notify.pgNotifier(error, xhr, gettext('Error retrieving details for the node.'), function (msg) { - if (msg == 'CRYPTKEY_SET') { - fetchNodeInfo(__i, __d, __n); - } else { - console.warn(arguments); - } - }); } - }); + + Notify.pgNotifier('error', error, gettext('Error retrieving details for the node.'), function (msg) { + if (msg == 'CRYPTKEY_SET') { + fetchNodeInfo(__i, __d, __n); + } else { + console.warn(arguments); + } + }); + } + }); }.bind(this); if (n && n.collection_node) { @@ -1935,6 +1910,7 @@ define('pgadmin.browser', [ }, addChildTreeNodes: function(_treeHierarchy, _node, _type, _arrayIds, _callback) { + let api = getApiInstance(); let module = _type in pgBrowser.Nodes && pgBrowser.Nodes[_type], childTreeInfo = _arrayIds.length && _.extend( {}, _.mapValues(_treeHierarchy, function(_val) { @@ -1961,20 +1937,17 @@ define('pgadmin.browser', [ _node = _node || arguments[1]; - $.ajax({ - url: childNodeUrl, - dataType: 'json', - }) - .done(function(res) { - if (res.success) { - arrayChildNodeData.push(res.data); - } - fetchNodeInfo(_callback); - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - fetchNodeInfo(_callback); - }); + api.get( + childNodeUrl + ).then(({data: res})=> { + if (res.success) { + arrayChildNodeData.push(res.data); + } + fetchNodeInfo(_callback); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); + fetchNodeInfo(_callback); + }); }; diff --git a/web/pgadmin/browser/static/js/error.js b/web/pgadmin/browser/static/js/error.js deleted file mode 100644 index 231a0cff0..000000000 --- a/web/pgadmin/browser/static/js/error.js +++ /dev/null @@ -1,63 +0,0 @@ -///////////////////////////////////////////////////////////// -// -// pgAdmin 4 - PostgreSQL Tools -// -// Copyright (C) 2013 - 2023, The pgAdmin Development Team -// This software is released under the PostgreSQL Licence -// -////////////////////////////////////////////////////////////// - -import Notify from '../../../static/js/helpers/Notifier'; -import _ from 'lodash'; - -define( - ['sources/gettext', 'sources/pgadmin'], - function(gettext, pgAdmin) { - pgAdmin.Browser = pgAdmin.Browser || {}; - - _.extend(pgAdmin.Browser, { - report_error: function(title, message, info, callback) { - title = _.escape(title); - message = _.escape(message); - info = _.escape(info); - let text ='
' - + '
' - + '' - + '
' - + '
' + message + '
' - + '
' - + '
'; - - if (info != null && info != '') { - text += '
' - + '' - + '
' - + '
' + info + '
' - + '
' - + '
' - + '
'; - } - - text += ''; - Notify.alert( - _.unescape(title), - text, - function() { - if(callback) { - callback(); - } - } - ); - }, - }); - - return pgAdmin.Browser.report_error; - }); diff --git a/web/pgadmin/browser/static/js/frame.js b/web/pgadmin/browser/static/js/frame.js index 9538c3775..adfd7451d 100644 --- a/web/pgadmin/browser/static/js/frame.js +++ b/web/pgadmin/browser/static/js/frame.js @@ -46,7 +46,6 @@ define([ isPrivate: that.isPrivate, isLayoutMember: that.isLayoutMember, onCreate: function(myPanel) { - $(myPanel).data('pgAdminName', that.name); myPanel.initSize(that.width, that.height); if (!(myPanel.showTitle??true)) @@ -61,13 +60,17 @@ define([ myPanel.layout().addItem($frameArea); that.panel = myPanel; let frame = new wcIFrame($frameArea, myPanel); - $(myPanel).data('frameInitialized', false); - $(myPanel).data('embeddedFrame', frame); + + myPanel.frameData = { + pgAdminName: that.name, + frameInitialized: false, + embeddedFrame: frame, + }; if (that.url != '' && that.url != 'about:blank') { setTimeout(function() { frame.openURL(that.url); - $(myPanel).data('frameInitialized', true); + myPanel.frameData.frameInitialized = true; pgBrowser.Events.trigger( 'pgadmin-browser:frame:urlloaded:' + that.name, frame, that.url, self @@ -75,7 +78,7 @@ define([ }, 50); } else { frame.openURL('about:blank'); - $(myPanel).data('frameInitialized', true); + myPanel.frameData.frameInitialized = true; pgBrowser.Events.trigger( 'pgadmin-browser:frame:urlloaded:' + that.name, frame, that.url, self @@ -112,7 +115,7 @@ define([ } }, eventFunc: function(eventName) { - let name = $(this).data('pgAdminName'); + let name = this.frameData.pgAdminName; try { pgBrowser.Events.trigger('pgadmin-browser:frame', eventName, this, arguments); diff --git a/web/pgadmin/browser/static/js/keyboard.js b/web/pgadmin/browser/static/js/keyboard.js index 4d2f9eda9..97c44f55b 100644 --- a/web/pgadmin/browser/static/js/keyboard.js +++ b/web/pgadmin/browser/static/js/keyboard.js @@ -9,13 +9,10 @@ import _ from 'lodash'; import pgAdmin from '../../../static/js/pgadmin'; -import $ from 'jquery'; import Mousetrap from 'mousetrap'; import * as commonUtils from '../../../static/js/utils'; -import dialogTabNavigator from '../../../static/js/dialog_tab_navigator'; -import * as keyboardFunc from 'sources/keyboard_shortcuts'; -import pgWindow from 'sources/window'; import gettext from 'sources/gettext'; +import pgWindow from 'sources/window'; const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; @@ -78,33 +75,6 @@ _.extend(pgBrowser.keyboardNavigation, { _.each(self.shortcutMethods, (keyCombo, callback) => { self._bindWithMousetrap(keyCombo.shortcuts, self[callback], keyCombo.bindElem); }); - - - /* Dropdown submenu was not working properly for up/down arrow keys. - * So up/down/right/left events for dropdown were removed from Mousetrap and were - * handled manually. - */ - const LEFT_KEY = 37, - UP_KEY = 38, - RIGHT_KEY = 39, - DOWN_KEY = 40; - - $('.pg-navbar').on('keydown', (event)=> { - switch(event.keyCode) { - case LEFT_KEY: - self.bindMainMenuLeft(event); - break; - case UP_KEY: - self.bindMainMenuUpDown(event, 'up'); - break; - case RIGHT_KEY: - self.bindMainMenuRight(event); - break; - case DOWN_KEY: - self.bindMainMenuUpDown(event, 'down'); - break; - } - }); }, _bindWithMousetrap: function(shortcuts, callback, bindElem) { const self = this; @@ -179,89 +149,10 @@ _.extend(pgBrowser.keyboardNavigation, { } }, 1000); }, - bindMainMenuLeft: function(event) { - if ($(event.target).hasClass('nav-link')) { // Menu items - let currNavMenu = $(event.target).closest('.nav-item'); - keyboardFunc._stopEventPropagation(event); - - currNavMenu = currNavMenu.prev('.nav-item'); - // Skip hidden menus - while(currNavMenu.hasClass('d-none')) { - currNavMenu = currNavMenu.prev('.nav-item'); - } - - currNavMenu.find('.dropdown-toggle').first().dropdown('toggle'); - - } else if($(event.target).closest('.dropdown-menu').length > 0) { - let currLi = $(event.target).closest('li'); - keyboardFunc._stopEventPropagation(event); - /*close submenu*/ - let currMenu = currLi.closest('.dropdown-menu'); - if(currMenu.closest('.dropdown-submenu').length > 0) { - currMenu.removeClass('show'); - currMenu.closest('.dropdown-submenu').removeClass('dropdown-submenu-visible'); - currLi = currMenu.closest('.dropdown-submenu'); - currLi.find('.dropdown-item').trigger('focus'); - } - } - }, - bindMainMenuRight: function(event) { - if ($(event.target).hasClass('nav-link')) { // Menu items - let currNavMenu = $(event.target).closest('.nav-item'); - keyboardFunc._stopEventPropagation(event); - - currNavMenu = currNavMenu.next('.nav-item'); - // Skip hidden menus - while(currNavMenu.hasClass('d-none')) { - currNavMenu = currNavMenu.next('.nav-item'); - } - - currNavMenu.find('.dropdown-toggle').first().dropdown('toggle'); - } else if($(event.target).closest('.dropdown-menu').length > 0) { - let currLi = $(event.target).closest('li'); - keyboardFunc._stopEventPropagation(event); - - /*open submenu if any*/ - if(currLi.hasClass('dropdown-submenu')){ - currLi.addClass('dropdown-submenu-visible'); - currLi.find('.dropdown-menu').addClass('show'); - currLi.find('.dropdown-menu .dropdown-item').first().trigger('focus'); - } - } - }, - bindMainMenuUpDown: function(event, combo) { - // Handle Sub-menus - if($(event.target).closest('.dropdown-menu').length > 0) { - keyboardFunc._stopEventPropagation(event); - let currLi = $(event.target).closest('li'); - /*close all the submenus on movement*/ - let dropMenu = $(event.target).closest('.dropdown-menu'); - dropMenu.find('.show').removeClass('show'); - dropMenu.find('.dropdown-submenu').removeClass('dropdown-submenu-visible'); - if(combo === 'up') { - currLi = currLi.prev(); - } - else if(combo === 'down'){ - currLi = currLi.next(); - } - - /*do not focus on divider and disabled */ - while(currLi.hasClass('dropdown-divider') - || currLi.find('.dropdown-item').first().hasClass('disabled')) { - if(combo === 'up') { - currLi = currLi.prev(); - } - else if(combo === 'down'){ - currLi = currLi.next(); - } - } - currLi.find('.dropdown-item').trigger('focus'); - } - }, bindLeftTree: function() { const tree = this.getTreeDetails(); - $('#tree').trigger('focus'); + document.querySelector('[id="tree"]').focus(); tree.t.select(tree.i); }, bindSubMenuQueryTool: function() { @@ -336,17 +227,6 @@ _.extend(pgBrowser.keyboardNavigation, { // Call refresh object callback pgAdmin.Browser.Node.callbacks.refresh.call(pgAdmin.Browser.Nodes[tree.t.itemData(tree.i)._type]); }, - bindContextMenu: function(event) { - const tree = this.getTreeDetails(); - let _srcElement = event.srcElement || event.target; - const left = $(_srcElement).find('.aciTreeEntry').position().left + 70; - const top = $(_srcElement).find('.aciTreeEntry').position().top + 70; - - tree.t.blur(tree.i); - $('#tree').trigger('blur'); - // Call context menu and set position - tree.i.children().contextMenu({x: left, y: top}); - }, bindDirectDebugging: function() { const tree = this.getTreeDetails(); const type = tree.t.itemData(tree.i)._type; @@ -359,24 +239,6 @@ _.extend(pgBrowser.keyboardNavigation, { pgAdmin.Tools.Debugger.get_function_information(pgAdmin.Browser.Nodes[type]); } }, - bindDropMultipleObjects: function() { - let isPropertyPanelVisible = this.isPropertyPanelVisible(); - if (isPropertyPanelVisible === true && $('button.delete_multiple').length > 0) { - $('button.delete_multiple').click(); - } - }, - bindDropCascadeMultipleObjects: function() { - let isPropertyPanelVisible = this.isPropertyPanelVisible(); - if (isPropertyPanelVisible === true && $('button.delete_multiple_cascade').length > 0) { - $('button.delete_multiple_cascade').click(); - } - }, - bindAddGridRow: function() { - let subNode = $(document.activeElement).closest('.object.subnode'); - if ($(subNode).length) { - $(subNode).find('.add').click(); - } - }, isPropertyPanelVisible: function() { let isPanelVisible = false; _.each(pgAdmin.Browser.docker.findPanels(), (panel) => { @@ -396,12 +258,6 @@ _.extend(pgBrowser.keyboardNavigation, { d: selectedTreeNodeData, }; }, - getDialogTabNavigator: function(dialogContainer) { - const backward_shortcut = pgWindow.pgAdmin.Browser.get_preference('browser', 'dialog_tab_backward').value; - const forward_shortcut = pgWindow.pgAdmin.Browser.get_preference('browser', 'dialog_tab_forward').value; - - return new dialogTabNavigator.dialogTabNavigator(dialogContainer, backward_shortcut, forward_shortcut); - }, bindOpenQuickSearch: function() { pgWindow.pgAdmin.Browser.all_menus_cache.help.mnu_quick_search_help.callback(); }, diff --git a/web/pgadmin/browser/static/js/layout.js b/web/pgadmin/browser/static/js/layout.js index a715b4d0f..cf813946e 100644 --- a/web/pgadmin/browser/static/js/layout.js +++ b/web/pgadmin/browser/static/js/layout.js @@ -9,11 +9,11 @@ import pgAdmin from 'sources/pgadmin'; import url_for from 'sources/url_for'; -import $ from 'jquery'; import gettext from 'sources/gettext'; import 'wcdocker'; import pgWindow from 'sources/window'; import Notify from '../../../static/js/helpers/Notifier'; +import getApiInstance from '../../../static/js/api_instance'; const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; @@ -50,11 +50,8 @@ _.extend(pgBrowser, { if(docker) { let layout = docker.save(), settings = { setting: layout_id, value: layout }; - $.ajax({ - type: 'POST', - url: url_for('settings.store_bulk'), - data: settings, - }); + + getApiInstance().post(url_for('settings.store_bulk'), settings); } }, @@ -143,17 +140,15 @@ _.extend(pgBrowser, { save_lock_layout: function(op) { let browser = pgWindow.pgAdmin.Browser; - $.ajax({ - url: url_for('browser.lock_layout'), - method: 'PUT', - contentType: 'application/json', - data: JSON.stringify({ + getApiInstance().put( + url_for('browser.lock_layout'), + JSON.stringify({ 'value': op, - }), - }).done(function() { + }) + ).then(()=> { browser.cache_preferences('browser'); - }).fail(function(xhr, error) { - Notify.pgNotifier(error, xhr, gettext('Failed to save the lock layout setting.')); + }).catch(function(error) { + Notify.pgNotifier('error', error, gettext('Failed to save the lock layout setting.')); }); }, diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index 156e8dd9f..c1537e558 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -10,13 +10,14 @@ import {getNodeView, removeNodeView} from './node_view'; import Notify from '../../../static/js/helpers/Notifier'; import _ from 'lodash'; +import getApiInstance from '../../../static/js/api_instance'; define('pgadmin.browser.node', [ - 'sources/gettext', 'jquery', 'sources/pgadmin', + 'sources/gettext', 'sources/pgadmin', 'sources/browser/generate_url', 'sources/utils', 'pgadmin.browser.utils', 'pgadmin.browser.events', ], function( - gettext, $, pgAdmin, generateUrl, commonUtils + gettext, pgAdmin, generateUrl, commonUtils ) { let wcDocker = window.wcDocker; @@ -354,9 +355,9 @@ define('pgadmin.browser.node', [ isLayoutMember: false, canMaximise: true, elContainer: true, - content: '
' + gettext('Please wait while we fetch information ...') + '
', - onCreate: function(myPanel, $container) { - $container.addClass('pg-no-overflow'); + content: '
', + onCreate: function(myPanel, container) { + container.classList.add('pg-no-overflow'); }, events: events, }); @@ -379,9 +380,9 @@ define('pgadmin.browser.node', [ isLayoutMember: false, canMaximise: true, elContainer: true, - content: '
' + gettext('Please wait while we fetch information about the node from the server...') + '
', - onCreate: function(myPanel, $container) { - $container.addClass('pg-no-overflow'); + content: '
', + onCreate: function(myPanel, container) { + container.classList.add('pg-no-overflow'); }, events: events, }); @@ -688,45 +689,41 @@ define('pgadmin.browser.node', [ } Notify.confirm(title, msg, function() { - $.ajax({ - url: obj.generate_url(i, input.url, d, true), - type: 'DELETE', - }) - .done(function(res) { - if(res.success == 2){ - Notify.error(res.info, null); - return; + getApiInstance().delete( + obj.generate_url(i, input.url, d, true), + ).then(({data: res})=> { + if(res.success == 2){ + Notify.error(res.info, null); + return; + } + if (res.success == 0) { + Notify.alert(res.errormsg, res.info); + } else { + // Remove the node from tree and set collection node as selected. + let selectNextNode = true; + if(obj.selectParentNodeOnDelete) { + let prv_i = t.parent(i); + setTimeout(function() { + t.select(prv_i); + }, 10); + selectNextNode = false; } - if (res.success == 0) { - pgBrowser.report_error(res.errormsg, res.info); - } else { - // Remove the node from tree and set collection node as selected. - let selectNextNode = true; - if(obj.selectParentNodeOnDelete) { - let prv_i = t.parent(i); - setTimeout(function() { - t.select(prv_i); - }, 10); - selectNextNode = false; - } - pgBrowser.removeTreeNode(i, selectNextNode); + pgBrowser.removeTreeNode(i, selectNextNode); + } + return true; + }).catch(function(xhr) { + let errmsg = xhr.responseText; + /* Error from the server */ + if (xhr.status == 417 || xhr.status == 410 || xhr.status == 500) { + try { + let data = JSON.parse(xhr.responseText); + errmsg = data.info || data.errormsg; + } catch (e) { + console.warn(e.stack || e); } - return true; - }) - .fail(function(jqx) { - let errmsg = jqx.responseText; - /* Error from the server */ - if (jqx.status == 417 || jqx.status == 410 || jqx.status == 500) { - try { - let data = JSON.parse(jqx.responseText); - errmsg = data.info || data.errormsg; - } catch (e) { - console.warn(e.stack || e); - } - } - pgBrowser.report_error( - gettext('Error dropping/removing %s: "%s"', obj.label, objName), errmsg); - }); + } + Notify.alert(gettext('Error dropping/removing %s: "%s"', obj.label, objName), errmsg); + }); } ); }, @@ -822,23 +819,27 @@ define('pgadmin.browser.node', [ fgcolor = serverData.icon.split(' ')[2] || ''; if (bgcolor) { - let dynamic_class = 'pga_server_' + serverData._id + '_bgcolor', - style_tag; - + let dynamic_class = 'pga_server_' + serverData._id + '_bgcolor'; // Prepare dynamic style tag - style_tag = ''; + const styleTag = document.createElement('style'); + styleTag.setAttribute('id', dynamic_class); + styleTag.setAttribute('type', 'text/css'); + styleTag.innerText = ` + .${dynamic_class} .file-label { + border-radius: 3px; + margin-bottom: 2px; + background: ${bgcolor} !important; + } + ${fgcolor ? ` + .${dynamic_class} span.file-name { + color: ${fgcolor} !important; + } + `:''} + `; // Prepare dynamic style tag using template - $('#' + dynamic_class).remove(); - $(style_tag).appendTo('head'); + document.querySelector(`style[id="${dynamic_class}"]`).remove(); + document.head.appendChild(styleTag); // Add dynamic class to the tree node. pgBrowser.tree.addCssClass(item, dynamic_class); } @@ -895,7 +896,6 @@ define('pgadmin.browser.node', [ t = pgBrowser.tree, data = _item && t.itemData(_item); - $(pgBrowser.panels['properties'].panel).removeData('node-prop'); pgBrowser.Events.trigger( 'pgadmin:browser:tree:refresh', _item || pgBrowser.tree.selected(), { success: function() { diff --git a/web/pgadmin/browser/static/js/node_view.jsx b/web/pgadmin/browser/static/js/node_view.jsx index e530484ec..993966601 100644 --- a/web/pgadmin/browser/static/js/node_view.jsx +++ b/web/pgadmin/browser/static/js/node_view.jsx @@ -63,25 +63,8 @@ export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, fo } else if(err.message){ console.error('error msg', err.message); } - - if (err?.response?.data?.info == 'CRYPTKEY_MISSING') { - Notify.pgNotifier('error', err.request, 'The master password is not set', function(msg) { - setTimeout(function() { - if (msg == 'CRYPTKEY_SET') { - resolve(initData()); - } else if (msg == 'CRYPTKEY_NOT_SET') { - reject(err); - } - }, 100); - }); - } else if (err?.response?.data?.errormsg) { - Notify.alert( - gettext('Error'), - gettext(err.response.data.errormsg) - ); - - reject(err); - } + reject(err); + Notify.pgRespErrorNotify(err); }); } }); diff --git a/web/pgadmin/browser/static/js/panel.js b/web/pgadmin/browser/static/js/panel.js index 69f8ec4eb..fdbce815f 100644 --- a/web/pgadmin/browser/static/js/panel.js +++ b/web/pgadmin/browser/static/js/panel.js @@ -11,8 +11,8 @@ import { getPanelView } from './panel_view'; import _ from 'lodash'; define( - ['sources/pgadmin', 'jquery', 'wcdocker'], - function(pgAdmin, $) { + ['sources/pgadmin', 'wcdocker'], + function(pgAdmin) { let pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}, wcDocker = window.wcDocker; @@ -52,7 +52,9 @@ define( limit: that.limit, isLayoutMember: that.isLayoutMember, onCreate: function(myPanel) { - $(myPanel).data('pgAdminName', that.name); + myPanel.panelData = { + pgAdminName: that.name, + }; myPanel.initSize(that.width, that.height); if (!that.showTitle) @@ -64,18 +66,18 @@ define( myPanel.icon(that.icon); } - let $container = $('
', { - 'class': 'pg-panel-content', - }).append($(that.content)); + let container = document.createElement('div'); + container.setAttribute('class', 'pg-panel-content'); + container.innerHTML = that.content; // Add extra classes if (!_.isNull('extraClasses')) { - $container.addClass(that.extraClasses); + container.classList.add(that.extraClasses); } myPanel.maximisable(!!that.canMaximise); myPanel.closeable(!!that.isCloseable); - myPanel.layout().addItem($container); + myPanel.layout().addItem(container); that.panel = myPanel; if (that.events && _.isObject(that.events)) { _.each(that.events, function(v, k) { @@ -99,21 +101,20 @@ define( }); if (that.onCreate && _.isFunction(that.onCreate)) { - that.onCreate.apply(that, [myPanel, $container]); + that.onCreate.apply(that, [myPanel, container]); } // Prevent browser from opening the drag file. // Using addEventListener to avoid conflict with jquery.drag ['dragover', 'drop'].forEach((eventName)=>{ - $container[0].addEventListener(eventName, function(event) { + container.addEventListener(eventName, function(event) { event.stopPropagation(); event.preventDefault(); }); }); if (that.elContainer) { - myPanel.pgElContainer = $container; - $container.addClass('pg-el-container'); + myPanel.pgElContainer = container; _.each([ wcDocker.EVENT.RESIZED, wcDocker.EVENT.ATTACHED, wcDocker.EVENT.DETACHED, wcDocker.EVENT.VISIBILITY_CHANGED, @@ -126,7 +127,7 @@ define( if (myPanel._type == 'dashboard' || myPanel._type == 'processes') { getPanelView( pgBrowser.tree, - $container[0], + container, pgBrowser, myPanel._type ); @@ -136,7 +137,7 @@ define( pgBrowser.onPreferencesChange('dashboards', function() { getPanelView( pgBrowser.tree, - $container[0], + container, pgBrowser, myPanel._type ); @@ -146,7 +147,7 @@ define( pgBrowser.onPreferencesChange('graphs', function() { getPanelView( pgBrowser.tree, - $container[0], + container, pgBrowser, myPanel._type ); @@ -162,7 +163,7 @@ define( if(myPanel.isVisible() && myPanel._type !== 'properties') { getPanelView( pgBrowser.tree, - $container[0], + container, pgBrowser, myPanel._type ); @@ -174,7 +175,7 @@ define( if(myPanel.isVisible() && myPanel._type !== 'properties') { getPanelView( pgBrowser.tree, - $container[0], + container, pgBrowser, myPanel._type ); @@ -186,7 +187,7 @@ define( if(myPanel.isVisible() && myPanel._type !== 'properties') { getPanelView( pgBrowser.tree, - $container[0], + container, pgBrowser, myPanel._type ); @@ -197,7 +198,7 @@ define( } }, eventFunc: function(eventName) { - let name = $(this).data('pgAdminName'); + let name = this.panelData.pgAdminName; try { pgBrowser.Events.trigger( 'pgadmin-browser:panel', eventName, this, arguments @@ -248,18 +249,16 @@ define( elAttr = 'xl'; } - p.pgElContainer.attr('el', elAttr); + p.pgElContainer.setAttribute('el', elAttr); }, 100 ); } }, handleVisibility: function(eventName) { - if (_.isNull(pgBrowser.tree)) return; - let selectedPanel = pgBrowser.docker.findPanels(this._type)[0]; let isPanelVisible = selectedPanel.isVisible(); - let $container = selectedPanel + let container = selectedPanel .layout() .scene() .find('.pg-panel-content'); @@ -268,7 +267,7 @@ define( if (eventName == 'panelVisibilityChanged') { getPanelView( pgBrowser.tree, - $container[0], + container[0], pgBrowser, this._type ); @@ -277,7 +276,7 @@ define( if (eventName == 'panelClosed' && selectedPanel._type == 'dashboard') { getPanelView( pgBrowser.tree, - $container[0], + container[0], pgBrowser, this._type, false diff --git a/web/pgadmin/browser/static/js/preferences.js b/web/pgadmin/browser/static/js/preferences.js index 365fd98de..06423ee45 100644 --- a/web/pgadmin/browser/static/js/preferences.js +++ b/web/pgadmin/browser/static/js/preferences.js @@ -9,12 +9,10 @@ import pgAdmin from 'sources/pgadmin'; import url_for from 'sources/url_for'; -import $ from 'jquery'; -import pgWindow from 'sources/window'; import Notify from '../../../static/js/helpers/Notifier'; -import { calcFontSize } from '../../../static/js/utils'; import { shortcutToString } from '../../../static/js/components/ShortcutTitle'; import gettext from 'sources/gettext'; +import getApiInstance from '../../../static/js/api_instance'; const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {}; @@ -78,16 +76,11 @@ _.extend(pgBrowser, { // Get and cache the preferences cache_preferences: function (modulesChanged) { - let self = this, - headers = {}; - headers[pgAdmin.csrf_token_header] = pgAdmin.csrf_token; + let self = this; setTimeout(function() { - $.ajax({ - url: url_for('preferences.get_all'), - headers: headers, - }) - .done(function(res) { + getApiInstance().get(url_for('preferences.get_all')) + .then(({data: res})=>{ self.preferences_cache = res; self.preference_version(self.generate_preference_version()); @@ -97,43 +90,30 @@ _.extend(pgBrowser, { pgBrowser.browserTreeState.init(); /* Once the cache is loaded after changing the preferences, - * notify the modules of the change - */ + * notify the modules of the change + */ if(modulesChanged) { if(typeof modulesChanged === 'string'){ - $.event.trigger('prefchange:'+modulesChanged); + pgBrowser.Events.trigger('prefchange:'+modulesChanged); } else { _.each(modulesChanged, (val, key)=> { - $.event.trigger('prefchange:'+key); + pgBrowser.Events.trigger('prefchange:'+key); }); } } }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch(function(error) { + Notify.pgRespErrorNotify(error); }); }, 500); }, triggerPreferencesChange: function(moduleChanged) { - $.event.trigger('prefchange:'+moduleChanged); + pgBrowser.Events.trigger('prefchange:'+moduleChanged); }, reflectPreferences: function(module) { let obj = this; - - if(module === 'sqleditor' || module === null || typeof module === 'undefined') { - let sqlEditPreferences = obj.get_preferences_for_module('sqleditor'); - - $(obj?.editor?.getWrapperElement()).css( - 'font-size', calcFontSize(sqlEditPreferences.sql_font_size) - ); - obj?.editor?.setOption('tabSize', sqlEditPreferences.tab_size); - obj?.editor?.setOption('lineWrapping', sqlEditPreferences.wrap_code); - obj?.editor?.setOption('autoCloseBrackets', sqlEditPreferences.insert_pair_brackets); - obj?.editor?.setOption('matchBrackets', sqlEditPreferences.brace_matching); - obj?.editor?.refresh(); - } //browser preference if(module === 'browser') { let browserPreferences = obj.get_preferences_for_module('browser'); @@ -158,13 +138,7 @@ _.extend(pgBrowser, { }, onPreferencesChange: function(module, eventHandler) { - let eventWindow = pgWindow; - if (window.location === window.parent?.location ) { - // The page is in a new tab - eventWindow = window; - } - - $(eventWindow).on('prefchange:'+module, function(event) { + pgBrowser.Events.on('prefchange:'+module, function(event) { eventHandler(event); }); }, diff --git a/web/pgadmin/browser/static/scss/_browser.scss b/web/pgadmin/browser/static/scss/_browser.scss index ae72f0e69..2f972b0ee 100644 --- a/web/pgadmin/browser/static/scss/_browser.scss +++ b/web/pgadmin/browser/static/scss/_browser.scss @@ -52,6 +52,10 @@ samp, border-style: solid; border-width: 1px; font-size: 1.15em; + + color: $color-fg !important; + border-color: $border-color !important; + background-color: $color-secondary; } .pg-toolbar-psql { diff --git a/web/pgadmin/browser/templates/browser/js/utils.js b/web/pgadmin/browser/templates/browser/js/utils.js index 5c3e2713e..d6d270029 100644 --- a/web/pgadmin/browser/templates/browser/js/utils.js +++ b/web/pgadmin/browser/templates/browser/js/utils.js @@ -168,28 +168,6 @@ define('pgadmin.browser.utils', ], }, {% endif %} - - // load the module right now - load_module: function(name, path, c) { - let obj = this; - require([name],function(m) { - try { - // initialize the module (if 'init' function present). - if (m.init && typeof(m.init) == 'function') - m.init(); - } catch (e) { - // Log this exception on console to understand the issue properly. - console.log(e); - obj.report_error(gettext('Error loading script - ') + path); - } - if (c) - c.loaded += 1; - }, function() { - // Log the arguments on console to understand the issue properly. - console.log(arguments); - obj.report_error(gettext('Error loading script - ') + path); - }); - } }; return pgBrowser; }); diff --git a/web/pgadmin/dashboard/static/js/Dashboard.jsx b/web/pgadmin/dashboard/static/js/Dashboard.jsx index d2d7c8c4d..2c8f13d22 100644 --- a/web/pgadmin/dashboard/static/js/Dashboard.jsx +++ b/web/pgadmin/dashboard/static/js/Dashboard.jsx @@ -16,7 +16,7 @@ import { makeStyles } from '@material-ui/core/styles'; import url_for from 'sources/url_for'; import Graphs from './Graphs'; import Notify from '../../../static/js/helpers/Notifier'; -import { Box, Tab, Tabs } from '@material-ui/core'; +import { Box, Card, CardContent, CardHeader, Tab, Tabs } from '@material-ui/core'; import { PgIconButton } from '../../../static/js/components/Buttons'; import CancelIcon from '@material-ui/icons/Cancel'; import StopSharpIcon from '@material-ui/icons/StopSharp'; @@ -108,6 +108,28 @@ const useStyles = makeStyles((theme) => ({ height: '1.9rem', width: '2.2rem', ...theme.mixins.panelBorder, + }, + chartCard: { + border: '1px solid '+theme.otherVars.borderColor, + }, + chartCardContent: { + padding: '0.25rem 0.5rem', + height: '165px', + display: 'flex', + }, + chartLegend: { + marginLeft: 'auto', + '& > div': { + display: 'flex', + fontWeight: 'normal', + + '& .legend-value': { + marginLeft: '4px', + '& .legend-label': { + marginLeft: '4px', + } + } + } } })); @@ -901,33 +923,27 @@ Dashboard.propTypes = { }; export function ChartContainer(props) { + const classes = useStyles(); + return ( -
-
-
-
{props.title}
-
-
- {props.datasets?.map((datum, i)=>( -
-      - {datum.label} -
- ))} -
+ + +
{props.title}
+
+
+ {props.datasets?.map((datum, i)=>( +
+      + {datum.label} +
+ ))}
-
-
- {!props.errorMsg && !props.isTest && props.children} - -
-
+ } /> + + {!props.errorMsg ? props.children : } + + ); } @@ -939,35 +955,3 @@ ChartContainer.propTypes = { errorMsg: PropTypes.string, isTest: PropTypes.bool }; - -export function ChartError(props) { - if (props.message === null) { - return <>; - } - return ( -
- {props.message} -
- ); -} - -ChartError.propTypes = { - message: PropTypes.string, -}; - -export function DashboardRow({ children }) { - return
{children}
; -} -DashboardRow.propTypes = { - children: PropTypes.node.isRequired, -}; - -export function DashboardRowCol({ breakpoint, parts, children }) { - return
{children}
; -} - -DashboardRowCol.propTypes = { - breakpoint: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']).isRequired, - parts: PropTypes.number.isRequired, - children: PropTypes.node.isRequired, -}; diff --git a/web/pgadmin/dashboard/static/js/Graphs.jsx b/web/pgadmin/dashboard/static/js/Graphs.jsx index 5195811c0..58346e353 100644 --- a/web/pgadmin/dashboard/static/js/Graphs.jsx +++ b/web/pgadmin/dashboard/static/js/Graphs.jsx @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////// import React, { useEffect, useRef, useState, useReducer, useMemo } from 'react'; import { DATA_POINT_SIZE } from 'sources/chartjs'; -import {ChartContainer, DashboardRowCol, DashboardRow} from './Dashboard'; +import {ChartContainer} from './Dashboard'; import url_for from 'sources/url_for'; import axios from 'axios'; import gettext from 'sources/gettext'; @@ -16,6 +16,7 @@ import {getGCD, getEpoch} from 'sources/utils'; import {useInterval, usePrevious} from 'sources/custom_hooks'; import PropTypes from 'prop-types'; import StreamingChart from '../../../static/js/components/PgChart/StreamingChart'; +import { Grid } from '@material-ui/core'; export const X_AXIS_LENGTH = 75; @@ -208,7 +209,7 @@ export default function Graphs({preferences, sid, did, pageVisible, enablePoll=t return ( <> -
{pollDelay}
+
{pollDelay}
{chartDrawnOnce && - - + + - - + + - - - - + + + + - - + + - - + + - - + + ); } diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index 88dcc0d7e..be816c116 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -117,11 +117,6 @@ class FileManagerModule(PgAdminModule): LABEL = gettext("Storage") - def get_own_stylesheets(self): - return [ - url_for('static', filename='vendor/jquery.dropzone/dropzone.css') - ] - def get_own_menuitems(self): return { 'file_items': [] @@ -182,9 +177,9 @@ blueprint = FileManagerModule(MODULE_NAME, __name__) @blueprint.route("/", endpoint='index') @login_required def index(): - """Render the preferences dialog.""" - return render_template( - MODULE_NAME + "/index.html", _=gettext) + return bad_request( + errormsg=gettext("This URL cannot be called directly.") + ) @blueprint.route("/utility.js") diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/index.html b/web/pgadmin/misc/file_manager/templates/file_manager/index.html deleted file mode 100644 index f0869489a..000000000 --- a/web/pgadmin/misc/file_manager/templates/file_manager/index.html +++ /dev/null @@ -1,91 +0,0 @@ - - - - -
-
-
-
-
-
- - -
- -
-
-
-
- - - - - - - -
- - -
-
-
-
-
- - {{ _('Loading...') }} - -
-
-
-
- {{ _('Are you sure you want to delete this item?') }} - - - - -
-
- {{ _('Are you sure you want to replace this file?') }} - - - - -
-
-
- -
- - diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/js/languages/en.json b/web/pgadmin/misc/file_manager/templates/file_manager/js/languages/en.json deleted file mode 100644 index cc2b91b4d..000000000 --- a/web/pgadmin/misc/file_manager/templates/file_manager/js/languages/en.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "LANGUAGE_FILE_NOT_FOUND": "Language file not found.", - "upload_success": "File uploaded successfully.", - "upload_error": "Error uploading file", - "browse": "Browse...", - "bytes": " bytes", - "cancel": "Cancel", - "close": "Close", - "confirmation_delete": "Are you sure you wish to delete this file?", - "current_folder": "", - "del": "Delete", - "download": "Download", - "dz_dictDefaultMessage": "Drop files here to upload", - "dz_dictFallbackMessage": "Your browser does not support drag'n'drop file uploads.", - "dz_dictMaxFilesExceeded": "Only %s simultaneous uploads are allowed.", - "dz_dictInvalidFileType": "You can't upload files of this type.", - "edit": "Edit file", - "file_size_limit": "The file size limit (per file) is ", - "file_too_big": "The file is too big.", - "gb": "gb", - "grid_view": "Switch to grid view.", - "items": "items", - "kb": "kb", - "list_view": "Switch to list view.", - "mb": "mb", - "modified": "Modified", - "move": "Move to ...", - "name": "Name", - "new_folder": "New Folder", - "no": "No", - "no_foldername": "No folder name was provided.", - "rename": "Rename", - "save": "Save", - "select": "Select", - "size": "Size", - "successful_added_folder": "New folder added successfully.", - "successful_delete": "Delete successful.", - "successful_rename": "Rename successful.", - "upload": "Upload", - "yes": "Yes", - "could_not_retrieve_folder": "No files/folders found" -} diff --git a/web/pgadmin/misc/properties/CollectionNodeProperties.jsx b/web/pgadmin/misc/properties/CollectionNodeProperties.jsx index 572563622..a88c35e21 100644 --- a/web/pgadmin/misc/properties/CollectionNodeProperties.jsx +++ b/web/pgadmin/misc/properties/CollectionNodeProperties.jsx @@ -167,7 +167,7 @@ export function CollectionNodeView({ }) .then(function (res) { if (res.success == 0) { - pgBrowser.report_error(res.errormsg, res.info); + Notify.alert(res.errormsg, res.info); } pgAdmin.Browser.tree.refresh(selItem); setReload(!reload); diff --git a/web/pgadmin/settings/static/js/settings.js b/web/pgadmin/settings/static/js/settings.js index 60abc8069..f8aec3b26 100644 --- a/web/pgadmin/settings/static/js/settings.js +++ b/web/pgadmin/settings/static/js/settings.js @@ -7,13 +7,13 @@ // ////////////////////////////////////////////////////////////// +import getApiInstance from '../../../static/js/api_instance'; import Notify from '../../../static/js/helpers/Notifier'; import { getBrowser } from '../../../static/js/utils'; define('pgadmin.settings', [ - 'jquery', 'sources/pgadmin', - 'sources/gettext', 'sources/url_for', -], function($, pgAdmin, gettext, url_for) { + 'sources/pgadmin', 'sources/gettext', 'sources/url_for', +], function(pgAdmin, gettext, url_for) { // This defines the Preference/Options Dialog for pgAdmin IV. pgAdmin = pgAdmin || window.pgAdmin || {}; @@ -38,17 +38,13 @@ define('pgadmin.settings', [ Notify.confirm(gettext('Reset layout'), gettext('Are you sure you want to reset the current layout? This will cause the application to reload and any un-saved data will be lost.'), function() { - let reloadingIndicator = $('
'); - $('body').append(reloadingIndicator); + const reloadingIndicator = document.createElement('div'); + reloadingIndicator.setAttribute('id', 'reloading-indicator'); + document.body.appendChild(reloadingIndicator); + // Delete the record from database as well, then only reload page - $.ajax({ - url: url_for('settings.reset_layout'), - type: 'DELETE', - async: false, - }) - .done(function() { - // Prevent saving layout on server for next page reload. - $(window).off('unload'); + getApiInstance().delete(url_for('settings.reset_layout')) + .then(()=>{ window.onbeforeunload = null; // Now reload page location.reload(true); @@ -56,14 +52,12 @@ define('pgadmin.settings', [ if(browser == 'Nwjs') { pgAdmin.Browser.create_menus(); } - }) - .fail(function() { + .catch(()=>{ console.warn( 'Something went wrong on server while resetting layout.' ); }); - }, function() { // Do nothing as user canceled the operation. diff --git a/web/pgadmin/static/css/style.css b/web/pgadmin/static/css/style.css index d66ce13f1..7dbaf737c 100644 --- a/web/pgadmin/static/css/style.css +++ b/web/pgadmin/static/css/style.css @@ -1,10 +1,4 @@ @import 'node_modules/@fortawesome/fontawesome-free/css/all.css'; -@import 'node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css'; -@import 'node_modules/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.css'; -@import 'node_modules/bootstrap4-toggle/css/bootstrap4-toggle.min.css'; -@import 'node_modules/jquery-contextmenu/dist/jquery.contextMenu.css'; -@import 'node_modules/webcabin-docker/Build/wcDocker.css'; -@import 'node_modules/select2/dist/css/select2.min.css'; @import 'node_modules/leaflet/dist/leaflet.css'; @import 'node_modules/codemirror/lib/codemirror.css'; @@ -20,3 +14,6 @@ @import 'node_modules/uplot/dist/uPlot.min.css'; +/* wcDocker dependencies */ +@import 'node_modules/webcabin-docker/Build/wcDocker.css'; +@import 'node_modules/jquery-contextmenu/dist/jquery.contextMenu.css'; diff --git a/web/pgadmin/static/js/Dialogs/index.jsx b/web/pgadmin/static/js/Dialogs/index.jsx index f9c5bc9ae..aec4cf261 100644 --- a/web/pgadmin/static/js/Dialogs/index.jsx +++ b/web/pgadmin/static/js/Dialogs/index.jsx @@ -99,8 +99,7 @@ export function showServerPassword() { }) .catch((err)=>{ return onFailure( - err.response.request, status, err, nodeObj, nodeData, treeNodeInfo, - itemNodeData, status + err, nodeObj, nodeData, treeNodeInfo, itemNodeData, status ); }); }} @@ -141,7 +140,7 @@ export function showSchemaDiffServerPassword() { }) .catch((err)=>{ return onFailure( - err.response.request, status, err, serverID, successCallback + err, serverID, successCallback ); }); }} @@ -165,8 +164,8 @@ export function checkMasterPassword(data, masterpass_callback_queue, cancel_call } else { masterPassCallbacks(masterpass_callback_queue); } - }).catch(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + }).catch(function(error) { + Notify.pgRespErrorNotify(error); }); } @@ -288,8 +287,8 @@ export function showNamedRestorePoint() { onClose(); Notify.success(res.data.data.result); }) - .catch(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); + .catch(function(error) { + Notify.pgRespErrorNotify(error); }); }} /> diff --git a/web/pgadmin/static/js/SchemaView/index.jsx b/web/pgadmin/static/js/SchemaView/index.jsx index 558042025..06fc59220 100644 --- a/web/pgadmin/static/js/SchemaView/index.jsx +++ b/web/pgadmin/static/js/SchemaView/index.jsx @@ -20,6 +20,7 @@ import HelpIcon from '@material-ui/icons/HelpRounded'; import EditIcon from '@material-ui/icons/Edit'; import diffArray from 'diff-arrays-of-objects'; import _ from 'lodash'; +import clsx from 'clsx'; import {FormFooterMessage, MESSAGE_TYPE } from 'sources/components/FormComponents'; import { PrimaryButton, DefaultButton, PgIconButton } from 'sources/components/Buttons'; @@ -52,6 +53,9 @@ const useDialogStyles = makeStyles((theme)=>({ display: 'flex', flexDirection: 'column', }, + formProperties: { + backgroundColor: theme.palette.grey[400], + }, footer: { padding: theme.spacing(1), background: theme.otherVars.headerBg, @@ -990,7 +994,7 @@ function SchemaPropertiesView({ } title="Edit the object" /> - + {Object.keys(finalTabs).map((tabName)=>{ let id = tabName.replace(' ', ''); diff --git a/web/pgadmin/static/js/Theme/index.jsx b/web/pgadmin/static/js/Theme/index.jsx index 055775a33..980e0b3eb 100644 --- a/web/pgadmin/static/js/Theme/index.jsx +++ b/web/pgadmin/static/js/Theme/index.jsx @@ -515,6 +515,7 @@ function getFinalTheme(baseTheme) { root: { padding: '4px 8px', backgroundColor: baseTheme.otherVars.cardHeaderBg, + fontWeight: 'bold', ...mixins.panelBorder.bottom, } }, diff --git a/web/pgadmin/static/js/components/Menu.jsx b/web/pgadmin/static/js/components/Menu.jsx index 6d23c3b5b..7c185b598 100644 --- a/web/pgadmin/static/js/components/Menu.jsx +++ b/web/pgadmin/static/js/components/Menu.jsx @@ -86,7 +86,7 @@ PgMenu.propTypes = { className: CustomPropTypes.className, label: PropTypes.string, anchorRef: CustomPropTypes.ref, - menuButton: PropTypes.oneOfType([React.ReactNode, undefined]), + menuButton: PropTypes.element, }; export const PgSubMenu = applyStatics(SubMenu)(({label, ...props})=>{ diff --git a/web/pgadmin/static/js/csrf.js b/web/pgadmin/static/js/csrf.js index 1e38aded5..0a833f0ed 100644 --- a/web/pgadmin/static/js/csrf.js +++ b/web/pgadmin/static/js/csrf.js @@ -7,7 +7,6 @@ // ////////////////////////////////////////////////////////////// -import $ from 'jquery'; import axios from 'axios'; export function setPGCSRFToken(header, token) { @@ -16,14 +15,6 @@ export function setPGCSRFToken(header, token) { throw new Error('csrf-token meta tag has not been set'); } - // Configure jquery.ajax to set 'X-CSRFToken' request header for - // every requests. - $.ajaxSetup({ - beforeSend: function(xhr) { - xhr.setRequestHeader(header, token); - }, - }); - // Configure axios to set 'X-CSRFToken' request header for // every requests. axios.interceptors.request.use(function (config) { diff --git a/web/pgadmin/static/js/dialog_tab_navigator.js b/web/pgadmin/static/js/dialog_tab_navigator.js deleted file mode 100644 index bdfefaad9..000000000 --- a/web/pgadmin/static/js/dialog_tab_navigator.js +++ /dev/null @@ -1,154 +0,0 @@ -///////////////////////////////////////////////////////////// -// -// pgAdmin 4 - PostgreSQL Tools -// -// Copyright (C) 2013 - 2023, The pgAdmin Development Team -// This software is released under the PostgreSQL Licence -// -////////////////////////////////////////////////////////////// - -import $ from 'jquery'; -import Mousetrap from 'mousetrap'; -import { findAndSetFocus, parseShortcutValue } from './utils'; - -class dialogTabNavigator { - constructor(dialogContainer, backwardShortcut, forwardShortcut) { - - this.dialogContainer = dialogContainer; - - this.tabSwitching = false; - - this.tabs = this.dialogContainer.find('.nav-tabs:visible'); - - if (this.tabs.length > 0 ) { - this.tabs = this.tabs[0]; - } - - this.dialogTabBackward = parseShortcutValue(backwardShortcut); - this.dialogTabForward = parseShortcutValue(forwardShortcut); - - Mousetrap(this.dialogContainer[0]).bind(this.dialogTabBackward, this.onKeyboardEvent.bind(this)); - Mousetrap(this.dialogContainer[0]).bind(this.dialogTabForward, this.onKeyboardEvent.bind(this)); - - } - - onKeyboardEvent(event, shortcut) { - let currentTabPane = this.dialogContainer - .find('.tab-content:first > .tab-pane.active:first:visible'), - childTabData = this.isActivePaneHasChildTabs(currentTabPane); - - if (this.tabSwitching) { - return; - } - - this.tabSwitching = true; - - if(childTabData) { - let res = this.navigate(shortcut, childTabData.childTab, - childTabData.childTabPane, event); - - if (!res) { - this.navigate(shortcut, this.tabs, currentTabPane, event); - } - } else { - this.navigate(shortcut, this.tabs, currentTabPane, event); - } - } - - isActivePaneHasChildTabs(currentTabPane) { - let childTab = currentTabPane.find('.nav-tabs:first:visible'), - childTabPane; - - if (childTab.length > 0) { - childTabPane = currentTabPane - .find('.tab-content:first > .tab-pane.active:first:visible'); - - return { - 'childTab': childTab, - 'childTabPane': childTabPane, - }; - } - - return null; - } - - navigate(shortcut, tabs, tab_pane, event) { - if (shortcut == this.dialogTabBackward) { - return this.navigateBackward(tabs, tab_pane, event); - } else if (shortcut == this.dialogTabForward) { - return this.navigateForward(tabs, tab_pane, event); - } - return false; - } - - navigateBackward(tabs, tab_pane, event) { - let self = this, - nextTabPane, - innerTabContainer, - prevtab = $(tabs).find('li').has('a.active').prev('li'); - - if (prevtab.length > 0) { - prevtab.find('a').tab('show'); - - nextTabPane = tab_pane.prev(); - innerTabContainer = nextTabPane - .find('.tab-content:first > .tab-pane.active:first:visible'); - - if (innerTabContainer.length > 0) { - findAndSetFocus(innerTabContainer); - } else { - findAndSetFocus(nextTabPane); - } - - setTimeout(function() { - self.tabSwitching = false; - }, 200); - - event.stopPropagation(); - return true; - } - - this.tabSwitching = false; - return false; - } - - navigateForward(tabs, tab_pane, event) { - let self = this, - nextTabPane, - innerTabContainer, - nexttab = $(tabs).find('li').has('a.active').next('li'); - - if(nexttab.length > 0) { - nexttab.find('a').tab('show'); - - nextTabPane = tab_pane.next(); - innerTabContainer = nextTabPane - .find('.tab-content:first > .tab-pane.active:first:visible'); - - if (innerTabContainer.length > 0) { - findAndSetFocus(innerTabContainer); - } else { - findAndSetFocus(nextTabPane); - } - - setTimeout(function() { - self.tabSwitching = false; - }, 200); - - event.stopPropagation(); - - return true; - } - this.tabSwitching = false; - return false; - } - - detach() { - Mousetrap(this.dialogContainer[0]).unbind(this.dialogTabBackward); - Mousetrap(this.dialogContainer[0]).unbind(this.dialogTabForward); - } -} - -module.exports = { - dialogTabNavigator: dialogTabNavigator, -}; diff --git a/web/pgadmin/static/js/helpers/Notifier.jsx b/web/pgadmin/static/js/helpers/Notifier.jsx index 444aee1fe..a21419bf9 100644 --- a/web/pgadmin/static/js/helpers/Notifier.jsx +++ b/web/pgadmin/static/js/helpers/Notifier.jsx @@ -24,6 +24,7 @@ import gettext from 'sources/gettext'; import _ from 'lodash'; import pgWindow from 'sources/window'; import ModalProvider, { useModal } from './ModalProvider'; +import { parseApiError } from '../api_instance'; const AUTO_HIDE_DURATION = 3000; // In milliseconds @@ -150,76 +151,45 @@ let Notifier = { ); }, - pgRespErrorNotify(xhr, error, prefixMsg='') { - let contentType = xhr.getResponseHeader('Content-Type'); - if (xhr.status === 410) { - const pgBrowser = window.pgAdmin.Browser; - pgBrowser.report_error(gettext('Error: Object not found - %s.', xhr.statusText), xhr.responseJSON.errormsg); + pgRespErrorNotify(error, prefixMsg='') { + if (error.response?.status === 410) { + this.alert(gettext('Error: Object not found - %s.', error.response.statusText), parseApiError(error)); } else { - try { - if (xhr.status === 0) { - error = gettext('Connection to the server has been lost.'); - } else { - if(contentType){ - if(contentType.indexOf('application/json') >= 0) { - let resp = JSON.parse(xhr.responseText); - error = _.escape(resp.result) || _.escape(resp.errormsg) || gettext('Unknown error'); - } - } - if (contentType.indexOf('text/html') >= 0) { - error = gettext('INTERNAL SERVER ERROR'); - console.warn(xhr.responseText); - } - } - } - catch(e){ - error = e.message; - } - - this.error(prefixMsg + ' ' + error); + this.error(prefixMsg + ' ' + parseApiError(error)); } }, - pgNotifier(type, xhr, promptmsg, onJSONResult) { - let msg = xhr.responseText, - contentType = xhr.getResponseHeader('Content-Type'); + pgNotifier(type, error, promptmsg, onJSONResult) { + let msg; - if (xhr.status == 0) { - msg = gettext('Connection to the server has been lost.'); + if(!error.response) { + msg = parseApiError(error); promptmsg = gettext('Connection Lost'); } else { - if (contentType) { - try { - if (contentType.indexOf('application/json') == 0) { - let resp = JSON.parse(msg); - - if(resp.info == 'CRYPTKEY_MISSING') { - let pgBrowser = window.pgAdmin.Browser; - pgBrowser.set_master_password('', ()=> { - if(onJSONResult && typeof(onJSONResult) == 'function') { - onJSONResult('CRYPTKEY_SET'); - } - }, ()=> { - if(onJSONResult && typeof(onJSONResult) == 'function') { - onJSONResult('CRYPTKEY_NOT_SET'); - } - }); - return; - } else if (resp.result != null && (!resp.errormsg || resp.errormsg == '') && - onJSONResult && typeof(onJSONResult) == 'function') { - return onJSONResult(resp.result); + if(error.response.headers['content-type'] == 'application/json') { + let resp = error.response.data; + if(resp.info == 'CRYPTKEY_MISSING') { + let pgBrowser = window.pgAdmin.Browser; + pgBrowser.set_master_password('', ()=> { + if(onJSONResult && typeof(onJSONResult) == 'function') { + onJSONResult('CRYPTKEY_SET'); } - msg = _.escape(resp.result) || _.escape(resp.errormsg) || 'Unknown error'; - } - if (contentType.indexOf('text/html') == 0) { - if (type === 'error') { - this.alert('Error', promptmsg); + }, ()=> { + if(onJSONResult && typeof(onJSONResult) == 'function') { + onJSONResult('CRYPTKEY_NOT_SET'); } - return; - } - } catch (e) { - this.alert('Error', e.message); + }); + return; + } else if (resp.result != null && (!resp.errormsg || resp.errormsg == '') && + onJSONResult && typeof(onJSONResult) == 'function') { + return onJSONResult(resp.result); } + msg = _.escape(resp.result) || _.escape(resp.errormsg) || 'Unknown error'; + } else { + if (type === 'error') { + this.alert('Error', promptmsg); + } + return; } } this.alert(promptmsg, msg.replace(new RegExp(/\r?\n/, 'g'), '
')); diff --git a/web/pgadmin/static/js/helpers/wizard/Wizard.jsx b/web/pgadmin/static/js/helpers/wizard/Wizard.jsx index 462a16f30..e1edf9397 100644 --- a/web/pgadmin/static/js/helpers/wizard/Wizard.jsx +++ b/web/pgadmin/static/js/helpers/wizard/Wizard.jsx @@ -125,6 +125,9 @@ const useStyles = makeStyles((theme) => padding: '8px', display: 'flex', flexDirection: 'column', + }, + hidden: { + display: 'none', } }), ); @@ -198,7 +201,7 @@ function Wizard({ stepList, onStepChange, onSave, className, ...props }) { { React.Children.map(props.children, (child) => { return ( -