2019-01-02 04:24:12 -06:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2023-01-02 00:23:55 -06:00
|
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2019-01-02 04:24:12 -06:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
2022-03-30 01:36:59 -05:00
|
|
|
import {getPanelView} from './panel_view';
|
2022-09-08 04:46:48 -05:00
|
|
|
import _ from 'lodash';
|
2021-06-29 04:03:36 -05:00
|
|
|
|
2017-06-07 05:23:02 -05:00
|
|
|
define([
|
2022-09-08 04:46:48 -05:00
|
|
|
'sources/gettext', 'sources/pgadmin',
|
|
|
|
'sources/browser/generate_url',
|
2022-09-10 03:52:49 -05:00
|
|
|
'pgadmin.browser.node',
|
2022-09-08 04:46:48 -05:00
|
|
|
], function(gettext, pgAdmin, generateUrl) {
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
|
2015-11-17 00:21:09 -06:00
|
|
|
|
|
|
|
// It has already been defined.
|
|
|
|
// Avoid running this script again.
|
|
|
|
if (pgBrowser.Collection)
|
|
|
|
return pgBrowser.Collection;
|
|
|
|
|
2022-01-12 07:29:21 -06:00
|
|
|
pgBrowser.Collection = function() {/*This is intentional (SonarQube)*/};
|
2016-04-14 06:15:32 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
_.extend(
|
|
|
|
pgBrowser.Collection,
|
|
|
|
_.clone(pgBrowser.Node), {
|
|
|
|
///////
|
|
|
|
// Initialization function
|
|
|
|
// Generally - used to register the menus for this type of node.
|
|
|
|
//
|
|
|
|
// Also, look at pgAdmin.Browser.add_menus(...) function.
|
|
|
|
//
|
|
|
|
// Collection will not have 'Properties' menu.
|
|
|
|
//
|
|
|
|
// NOTE: Override this for each node for initialization purpose
|
|
|
|
Init: function() {
|
|
|
|
if (this.node_initialized)
|
|
|
|
return;
|
|
|
|
this.node_initialized = true;
|
2019-02-14 05:15:01 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
pgAdmin.Browser.add_menus([{
|
|
|
|
name: 'refresh', node: this.type, module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'refresh',
|
2022-02-14 00:43:48 -06:00
|
|
|
priority: 2, label: gettext('Refresh'),
|
2018-01-12 01:29:51 -06:00
|
|
|
}]);
|
2016-06-08 07:18:59 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// show query tool only in context menu of supported nodes.
|
2020-04-06 07:03:07 -05:00
|
|
|
if (pgAdmin.unsupported_nodes && _.indexOf(pgAdmin.unsupported_nodes, this.type) == -1) {
|
|
|
|
if ((this.type == 'database' && this.allowConn) || this.type != 'database') {
|
2018-01-12 01:29:51 -06:00
|
|
|
pgAdmin.Browser.add_menus([{
|
2020-04-20 08:20:20 -05:00
|
|
|
name: 'show_query_tool', node: this.type, module: this,
|
2018-01-12 01:29:51 -06:00
|
|
|
applies: ['context'], callback: 'show_query_tool',
|
2021-01-20 09:52:34 -06:00
|
|
|
priority: 998, label: gettext('Query Tool'),
|
2018-01-12 01:29:51 -06:00
|
|
|
}]);
|
2020-04-06 07:03:07 -05:00
|
|
|
|
|
|
|
// show search objects same as query tool
|
|
|
|
pgAdmin.Browser.add_menus([{
|
2020-04-20 08:20:20 -05:00
|
|
|
name: 'search_objects', node: this.type, module: this,
|
2020-04-06 07:03:07 -05:00
|
|
|
applies: ['context'], callback: 'show_search_objects',
|
|
|
|
priority: 997, label: gettext('Search Objects...'),
|
|
|
|
}]);
|
2021-05-25 09:42:57 -05:00
|
|
|
|
|
|
|
// show psql tool same as query tool.
|
2021-06-08 04:28:43 -05:00
|
|
|
if(pgAdmin['enable_psql']) {
|
2021-06-01 09:34:43 -05:00
|
|
|
pgAdmin.Browser.add_menus([{
|
|
|
|
name: 'show_psql_tool', node: this.type, module: this,
|
|
|
|
applies: ['context'], callback: 'show_psql_tool',
|
2021-09-23 05:47:39 -05:00
|
|
|
priority: 998, label: gettext('PSQL Tool'),
|
2021-06-01 09:34:43 -05:00
|
|
|
}]);
|
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
}
|
2016-06-08 07:18:59 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2018-10-31 05:30:36 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
hasId: false,
|
|
|
|
is_collection: true,
|
|
|
|
collection_node: true,
|
|
|
|
// A collection will always have a collection of statistics, when the node
|
|
|
|
// it represent will have some statistics.
|
|
|
|
hasCollectiveStatistics: true,
|
2018-10-31 05:30:36 -05:00
|
|
|
canDrop: true,
|
|
|
|
canDropCascade: true,
|
2021-08-25 06:31:48 -05:00
|
|
|
selectParentNodeOnDelete: false,
|
2018-01-12 01:29:51 -06:00
|
|
|
showProperties: function(item, data, panel) {
|
2022-04-04 07:12:42 -05:00
|
|
|
let container = panel.$container.find('.obj_properties').first();
|
2022-03-30 01:36:59 -05:00
|
|
|
getPanelView(
|
|
|
|
pgBrowser.tree,
|
2022-04-04 07:12:42 -05:00
|
|
|
container[0],
|
2022-03-30 01:36:59 -05:00
|
|
|
pgBrowser,
|
|
|
|
panel._type
|
2019-02-14 05:15:01 -06:00
|
|
|
);
|
2020-06-16 00:35:10 -05:00
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
generate_url: function(item, type) {
|
|
|
|
/*
|
|
|
|
* Using list, and collection functions of a node to get the nodes
|
|
|
|
* under the collection, and properties of the collection respectively.
|
|
|
|
*/
|
2022-09-08 07:38:58 -05:00
|
|
|
let opURL = {
|
2018-10-31 05:30:36 -05:00
|
|
|
'properties': 'obj',
|
|
|
|
'children': 'nodes',
|
|
|
|
'drop': 'obj',
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
self = this;
|
2022-09-08 07:38:58 -05:00
|
|
|
let collectionPickFunction = function (treeInfoValue, treeInfoKey) {
|
2018-01-12 01:29:51 -06:00
|
|
|
return (treeInfoKey != self.type);
|
|
|
|
};
|
2022-09-08 07:38:58 -05:00
|
|
|
let treeInfo = pgBrowser.tree.getTreeNodeHierarchy(item);
|
|
|
|
let actionType = type in opURL ? opURL[type] : type;
|
2018-01-12 01:29:51 -06:00
|
|
|
return generateUrl.generate_url(
|
|
|
|
pgAdmin.Browser.URL, treeInfo, actionType, self.node,
|
|
|
|
collectionPickFunction
|
|
|
|
);
|
|
|
|
},
|
2020-04-20 08:20:20 -05:00
|
|
|
show_query_tool: function() {
|
2022-04-07 07:06:56 -05:00
|
|
|
if(pgAdmin.Tools.SQLEditor) {
|
|
|
|
pgAdmin.Tools.SQLEditor.showQueryTool('', pgAdmin.Browser.tree.selected());
|
2020-04-20 08:20:20 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
show_search_objects: function() {
|
2022-08-30 06:38:12 -05:00
|
|
|
if(pgAdmin.Tools.SearchObjects) {
|
|
|
|
pgAdmin.Tools.SearchObjects.show_search_objects('', pgAdmin.Browser.tree.selected());
|
2020-04-20 08:20:20 -05:00
|
|
|
}
|
|
|
|
},
|
2021-05-25 09:42:57 -05:00
|
|
|
show_psql_tool: function(args) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2021-05-25 09:42:57 -05:00
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2021-05-25 09:42:57 -05:00
|
|
|
pgBrowser.psql.psql_tool(d, i, true);
|
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
});
|
2015-11-17 00:21:09 -06:00
|
|
|
|
2016-04-14 06:15:32 -05:00
|
|
|
return pgBrowser.Collection;
|
2015-11-17 00:21:09 -06:00
|
|
|
});
|