mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Extract the tests and refactor some of the methods.
Extract some of the ACI Tree functionalities, and decouple it from the main source. Also - create some abstractions from the repeated code around the enable/disable the schema children object create/edit/delete functionalities, and also created the dialog wrappers for backup and restore dialogs. Reviewed by: Khushboo and Ashesh Refactored by: Ashesh
This commit is contained in:
committed by
Ashesh Vashi
parent
920934759f
commit
7dd6372eeb
@@ -1,8 +1,8 @@
|
||||
define('pgadmin.node.collation', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser',
|
||||
'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser) {
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, schemaChild) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-collation']) {
|
||||
pgAdmin.Browser.Nodes['coll-collation'] =
|
||||
@@ -15,7 +15,7 @@ define('pgadmin.node.collation', [
|
||||
}
|
||||
|
||||
if (!pgBrowser.Nodes['collation']) {
|
||||
pgAdmin.Browser.Nodes['collation'] = pgBrowser.Node.extend({
|
||||
pgAdmin.Browser.Nodes['collation'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'collation',
|
||||
sqlAlterHelp: 'sql-altercollation.html',
|
||||
sqlCreateHelp: 'sql-createcollation.html',
|
||||
@@ -222,34 +222,6 @@ define('pgadmin.node.collation', [
|
||||
return true;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create collation
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-collation' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
define('pgadmin.node.domain', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform', 'pgadmin.backgrid',
|
||||
'pgadmin.browser.collection',
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, Backgrid
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, Backgrid,
|
||||
schemaChild
|
||||
) {
|
||||
|
||||
// Define Domain Collection Node
|
||||
@@ -79,7 +80,7 @@ define('pgadmin.node.domain', [
|
||||
|
||||
// Domain Node
|
||||
if (!pgBrowser.Nodes['domain']) {
|
||||
pgBrowser.Nodes['domain'] = pgBrowser.Node.extend({
|
||||
pgBrowser.Nodes['domain'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'domain',
|
||||
sqlAlterHelp: 'sql-alterdomain.html',
|
||||
sqlCreateHelp: 'sql-createdomain.html',
|
||||
@@ -88,7 +89,6 @@ define('pgadmin.node.domain', [
|
||||
collection_type: 'coll-domain',
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
parent_type: ['schema', 'catalog'],
|
||||
Init: function() {
|
||||
// Avoid mulitple registration of menus
|
||||
if (this.initialized)
|
||||
@@ -118,8 +118,6 @@ define('pgadmin.node.domain', [
|
||||
]);
|
||||
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
// Domain Node Model
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
initialize: function(attrs, args) {
|
||||
@@ -296,34 +294,6 @@ define('pgadmin.node.domain', [
|
||||
return errmsg;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create domain
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-domain' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
isDisabled: function(m){
|
||||
if (!m.isNew()) {
|
||||
var server = this.node_info.server;
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
define('pgadmin.node.foreign_table', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform', 'pgadmin.backgrid',
|
||||
'pgadmin.browser.collection',
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, Backgrid
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, Backgrid,
|
||||
schemaChild
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-foreign_table']) {
|
||||
@@ -469,7 +470,7 @@ define('pgadmin.node.foreign_table', [
|
||||
|
||||
|
||||
if (!pgBrowser.Nodes['foreign_table']) {
|
||||
pgBrowser.Nodes['foreign_table'] = pgBrowser.Node.extend({
|
||||
pgBrowser.Nodes['foreign_table'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'foreign_table',
|
||||
sqlAlterHelp: 'sql-alterforeigntable.html',
|
||||
sqlCreateHelp: 'sql-createforeigntable.html',
|
||||
@@ -509,8 +510,6 @@ define('pgadmin.node.foreign_table', [
|
||||
]);
|
||||
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
initialize: function(attrs, args) {
|
||||
var isNew = (_.size(attrs) === 0);
|
||||
@@ -659,34 +658,6 @@ define('pgadmin.node.foreign_table', [
|
||||
return errmsg;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create foreign table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-foreign_table' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
define('pgadmin.node.fts_configuration', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform', 'pgadmin.backgrid',
|
||||
'pgadmin.browser.collection',
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, Backgrid
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, Backgrid,
|
||||
schemaChild
|
||||
) {
|
||||
|
||||
// Model for tokens control
|
||||
@@ -410,14 +411,11 @@ define('pgadmin.node.fts_configuration', [
|
||||
|
||||
// Extend the node class for FTS Configuration
|
||||
if (!pgBrowser.Nodes['fts_configuration']) {
|
||||
pgAdmin.Browser.Nodes['fts_configuration'] = pgAdmin.Browser.Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
pgAdmin.Browser.Nodes['fts_configuration'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'fts_configuration',
|
||||
sqlAlterHelp: 'sql-altertsconfig.html',
|
||||
sqlCreateHelp: 'sql-createtsconfig.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'fts_configuration_dialog.html'}),
|
||||
canDrop: true,
|
||||
canDropCascade: true,
|
||||
label: gettext('FTS Configuration'),
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
@@ -577,34 +575,6 @@ define('pgadmin.node.fts_configuration', [
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create fts configuration
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-fts_configuration' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
define('pgadmin.node.fts_dictionary', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform',
|
||||
'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform) {
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform, schemaChild
|
||||
) {
|
||||
|
||||
// Extend the browser's node model class to create a option/value pair
|
||||
var OptionLabelModel = pgAdmin.Browser.Node.Model.extend({
|
||||
@@ -55,14 +57,11 @@ define('pgadmin.node.fts_dictionary', [
|
||||
|
||||
// Extend the node class for FTS Dictionary
|
||||
if (!pgBrowser.Nodes['fts_dictionary']) {
|
||||
pgAdmin.Browser.Nodes['fts_dictionary'] = pgAdmin.Browser.Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
pgAdmin.Browser.Nodes['fts_dictionary'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'fts_dictionary',
|
||||
sqlAlterHelp: 'sql-altertsdictionary.html',
|
||||
sqlCreateHelp: 'sql-createtsdictionary.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'fts_dictionary_dialog.html'}),
|
||||
canDrop: true,
|
||||
canDropCascade: true,
|
||||
label: gettext('FTS Dictionary'),
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
@@ -186,34 +185,6 @@ define('pgadmin.node.fts_dictionary', [
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create fts dictionary
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-fts_dictionary' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
define('pgadmin.node.fts_parser', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser) {
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.node.schema.dir/child',
|
||||
'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser, schemaChild) {
|
||||
|
||||
// Extend the collection class for fts parser
|
||||
if (!pgBrowser.Nodes['coll-fts_parser']) {
|
||||
@@ -16,14 +17,11 @@ define('pgadmin.node.fts_parser', [
|
||||
|
||||
// Extend the node class for fts parser
|
||||
if (!pgBrowser.Nodes['fts_parser']) {
|
||||
pgAdmin.Browser.Nodes['fts_parser'] = pgAdmin.Browser.Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
pgAdmin.Browser.Nodes['fts_parser'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'fts_parser',
|
||||
sqlAlterHelp: 'sql-altertsparser.html',
|
||||
sqlCreateHelp: 'sql-createtsparser.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'fts_parser_dialog.html'}),
|
||||
canDrop: true,
|
||||
canDropCascade: true,
|
||||
label: gettext('FTS Parser'),
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
@@ -199,34 +197,6 @@ define('pgadmin.node.fts_parser', [
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create fts parser
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-fts_parser' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
define('pgadmin.node.fts_template', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser) {
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.node.schema.dir/child',
|
||||
'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser, schemaChild) {
|
||||
|
||||
// Extend the collection class for fts template
|
||||
if (!pgBrowser.Nodes['coll-fts_template']) {
|
||||
@@ -16,14 +17,11 @@ define('pgadmin.node.fts_template', [
|
||||
|
||||
// Extend the node class for fts template
|
||||
if (!pgBrowser.Nodes['fts_template']) {
|
||||
pgAdmin.Browser.Nodes['fts_template'] = pgAdmin.Browser.Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
pgAdmin.Browser.Nodes['fts_template'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'fts_template',
|
||||
sqlAlterHelp: 'sql-altertstemplate.html',
|
||||
sqlCreateHelp: 'sql-createtstemplate.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'fts_template_dialog.html'}),
|
||||
canDrop: true,
|
||||
canDropCascade: true,
|
||||
label: gettext('FTS Template'),
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
@@ -139,34 +137,6 @@ define('pgadmin.node.fts_template', [
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create fts fts_template
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-fts_template' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
define('pgadmin.node.function', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform',
|
||||
'pgadmin.browser.collection', 'pgadmin.browser.server.privilege',
|
||||
], function(gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform) {
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
'pgadmin.browser.server.privilege',
|
||||
], function(
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Backform, schemaChild
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-function']) {
|
||||
pgBrowser.Nodes['coll-function'] =
|
||||
@@ -83,7 +86,8 @@ define('pgadmin.node.function', [
|
||||
});
|
||||
|
||||
if (!pgBrowser.Nodes['function']) {
|
||||
pgBrowser.Nodes['function'] = pgBrowser.Node.extend({
|
||||
|
||||
pgBrowser.Nodes['function'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'function',
|
||||
sqlAlterHelp: 'sql-alterfunction.html',
|
||||
sqlCreateHelp: 'sql-createfunction.html',
|
||||
@@ -96,7 +100,6 @@ define('pgadmin.node.function', [
|
||||
return treeInformation.server.server_type !== 'gpdb';
|
||||
},
|
||||
hasScriptTypes: ['create', 'select'],
|
||||
parent_type: ['schema', 'catalog'],
|
||||
Init: function() {
|
||||
/* Avoid mulitple registration of menus */
|
||||
if (this.initialized)
|
||||
@@ -126,8 +129,6 @@ define('pgadmin.node.function', [
|
||||
]);
|
||||
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
initialize: function(attrs, args) {
|
||||
var isNew = (_.size(attrs) === 0);
|
||||
@@ -438,34 +439,6 @@ define('pgadmin.node.function', [
|
||||
return true;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create Function
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-function' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
define('pgadmin.node.trigger_function', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform',
|
||||
'pgadmin.browser.collection', 'pgadmin.browser.server.privilege',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser, Backform) {
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
'pgadmin.browser.server.privilege',
|
||||
], function(
|
||||
gettext, url_for, $, _, pgAdmin, pgBrowser, Backform, schemaChild
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-trigger_function']) {
|
||||
pgBrowser.Nodes['coll-trigger_function'] =
|
||||
@@ -17,7 +20,7 @@ define('pgadmin.node.trigger_function', [
|
||||
}
|
||||
|
||||
if (!pgBrowser.Nodes['trigger_function']) {
|
||||
pgBrowser.Nodes['trigger_function'] = pgBrowser.Node.extend({
|
||||
pgBrowser.Nodes['trigger_function'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'trigger_function',
|
||||
sqlAlterHelp: 'plpgsql-trigger.html',
|
||||
sqlCreateHelp: 'plpgsql-trigger.html',
|
||||
@@ -27,7 +30,6 @@ define('pgadmin.node.trigger_function', [
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
hasStatistics: true,
|
||||
parent_type: ['schema', 'catalog'],
|
||||
Init: function() {
|
||||
/* Avoid mulitple registration of menus */
|
||||
if (this.initialized)
|
||||
@@ -57,8 +59,6 @@ define('pgadmin.node.trigger_function', [
|
||||
]);
|
||||
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
initialize: function(attrs, args) {
|
||||
var isNew = (_.size(attrs) === 0);
|
||||
@@ -357,34 +357,6 @@ define('pgadmin.node.trigger_function', [
|
||||
return !(this.node_info && 'catalog' in this.node_info);
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create Function
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-trigger_function' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
define('pgadmin.node.sequence', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform',
|
||||
'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform) {
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform, schemaChild
|
||||
) {
|
||||
|
||||
// Extend the browser's collection class for sequence collection
|
||||
if (!pgBrowser.Nodes['coll-sequence']) {
|
||||
@@ -18,7 +20,7 @@ define('pgadmin.node.sequence', [
|
||||
|
||||
// Extend the browser's node class for sequence node
|
||||
if (!pgBrowser.Nodes['sequence']) {
|
||||
pgBrowser.Nodes['sequence'] = pgBrowser.Node.extend({
|
||||
pgBrowser.Nodes['sequence'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'sequence',
|
||||
sqlAlterHelp: 'sql-altersequence.html',
|
||||
sqlCreateHelp: 'sql-createsequence.html',
|
||||
@@ -28,7 +30,6 @@ define('pgadmin.node.sequence', [
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
hasStatistics: true,
|
||||
parent_type: ['schema', 'catalog'],
|
||||
Init: function() {
|
||||
/* Avoid mulitple registration of menus */
|
||||
if (this.initialized)
|
||||
@@ -58,36 +59,6 @@ define('pgadmin.node.sequence', [
|
||||
]);
|
||||
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create collation
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-sequence' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we want to allow create menu
|
||||
return true;
|
||||
},
|
||||
// Define the model for sequence node.
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
defaults: {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
import * as Node from 'pgbrowser/node';
|
||||
import {
|
||||
isTreeItemOfChildOfSchema, childCreateMenuEnabled,
|
||||
} from './schema_child_tree_node';
|
||||
|
||||
let SchemaChildNode = Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
canDrop: isTreeItemOfChildOfSchema,
|
||||
canDropCascade: isTreeItemOfChildOfSchema,
|
||||
canCreate: childCreateMenuEnabled,
|
||||
}, false);
|
||||
|
||||
export {SchemaChildNode};
|
||||
@@ -425,54 +425,10 @@ define('pgadmin.node.schema', [
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
// This function will checks whether we can allow user to
|
||||
// drop object or not based on location within schema & catalog
|
||||
canChildDrop: function(itemData, item) {
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create collation
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if(prev_d && prev_d._type == 'catalog') {
|
||||
return false;
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
pgBrowser.tableChildTreeNodeHierarchy = function(i) {
|
||||
var idx = 0,
|
||||
res = {},
|
||||
t = pgBrowser.tree;
|
||||
|
||||
do {
|
||||
var d = t.itemData(i);
|
||||
if (
|
||||
d._type in pgBrowser.Nodes && pgBrowser.Nodes[d._type].hasId
|
||||
) {
|
||||
if (d._type === 'partition' || d._type === 'table') {
|
||||
if (!('table' in res)) {
|
||||
res['table'] = _.extend({}, d, {'priority': idx});
|
||||
idx -= 1;
|
||||
}
|
||||
} else {
|
||||
res[d._type] = _.extend({}, d, {'priority': idx});
|
||||
idx -= 1;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
} while (i);
|
||||
|
||||
return res;
|
||||
return this.getTreeNodeHierarchy(i);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
import * as pgBrowser from 'pgbrowser/browser';
|
||||
|
||||
export function childCreateMenuEnabled(itemData, item, data) {
|
||||
// If check is false then , we will allow create menu
|
||||
if (data && data.check === false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let node = pgBrowser.treeMenu.findNodeByDomElement(item);
|
||||
|
||||
if (node)
|
||||
return node.anyFamilyMember(
|
||||
(node) => (node.getData()._type === 'schema')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isTreeItemOfChildOfSchema(itemData, item) {
|
||||
let node = pgBrowser.treeMenu.findNodeByDomElement(item);
|
||||
|
||||
if (node)
|
||||
return isTreeNodeOfSchemaChild(node);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isTreeNodeOfSchemaChild(node) {
|
||||
return node.anyParent(
|
||||
(parentNode) => (parentNode.getData()._type === 'schema')
|
||||
);
|
||||
}
|
||||
@@ -88,7 +88,6 @@ define('pgadmin.node.column', [
|
||||
|
||||
if (!pgBrowser.Nodes['column']) {
|
||||
pgBrowser.Nodes['column'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
parent_type: ['table', 'view', 'mview'],
|
||||
collection_type: ['coll-table', 'coll-view', 'coll-mview'],
|
||||
type: 'column',
|
||||
@@ -97,27 +96,24 @@ define('pgadmin.node.column', [
|
||||
sqlAlterHelp: 'sql-altertable.html',
|
||||
sqlCreateHelp: 'sql-altertable.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'column_dialog.html'}),
|
||||
canDrop: function(itemData, item, data){
|
||||
if (pgBrowser.Nodes['schema'].canChildDrop.apply(this, [itemData, item, data])) {
|
||||
var t = pgBrowser.tree, i = item, d = itemData, parents = [];
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
parents.push(d._type);
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
canDrop: function(itemData, item){
|
||||
let node = pgBrowser.treeMenu.findNodeByDomElement(item);
|
||||
|
||||
// Check if menu is allowed ?
|
||||
if(_.indexOf(parents, 'catalog') > -1 ||
|
||||
_.indexOf(parents, 'view') > -1 ||
|
||||
_.indexOf(parents, 'mview') > -1) {
|
||||
return false;
|
||||
} else if(_.indexOf(parents, 'table') > -1) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!node)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only a column of a table can be droped, and only when it is not of
|
||||
// catalog.
|
||||
return node.anyParent(
|
||||
(parentNode) => (
|
||||
parentNode.getData()._type === 'table' &&
|
||||
!parentNode.anyParent(
|
||||
(grandParentNode) => (
|
||||
grandParentNode.getData()._type === 'catalog'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
hasDepends: true,
|
||||
hasStatistics: true,
|
||||
|
||||
@@ -8,7 +8,6 @@ define('pgadmin.node.check_constraint', [
|
||||
// Check Constraint Node
|
||||
if (!pgBrowser.Nodes['check_constraint']) {
|
||||
pgAdmin.Browser.Nodes['check_constraint'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
type: 'check_constraint',
|
||||
label: gettext('Check'),
|
||||
collection_type: 'coll-constraints',
|
||||
|
||||
@@ -605,7 +605,6 @@ define('pgadmin.node.exclusion_constraint', [
|
||||
// Extend the browser's node class for exclusion constraint node
|
||||
if (!pgBrowser.Nodes['exclusion_constraint']) {
|
||||
pgAdmin.Browser.Nodes['exclusion_constraint'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
type: 'exclusion_constraint',
|
||||
label: gettext('Exclusion constraint'),
|
||||
collection_type: 'coll-constraints',
|
||||
|
||||
@@ -603,7 +603,6 @@ define('pgadmin.node.foreign_key', [
|
||||
// Extend the browser's node class for foreign key node
|
||||
if (!pgBrowser.Nodes['foreign_key']) {
|
||||
pgAdmin.Browser.Nodes['foreign_key'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
type: 'foreign_key',
|
||||
label: gettext('Foreign key'),
|
||||
collection_type: 'coll-constraints',
|
||||
|
||||
@@ -20,7 +20,6 @@ define('pgadmin.node.primary_key', [
|
||||
parent_type: ['table','partition'],
|
||||
canDrop: true,
|
||||
canDropCascade: true,
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
Init: function() {
|
||||
/* Avoid multiple registration of menus */
|
||||
if (this.initialized)
|
||||
|
||||
@@ -20,7 +20,6 @@ define('pgadmin.node.unique_constraint', [
|
||||
parent_type: ['table','partition'],
|
||||
canDrop: true,
|
||||
canDropCascade: true,
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
Init: function() {
|
||||
/* Avoid multiple registration of menus */
|
||||
if (this.initialized)
|
||||
|
||||
@@ -12,14 +12,12 @@ define('pgadmin.node.constraints', [
|
||||
node: 'constraints',
|
||||
label: gettext('Constraints'),
|
||||
type: 'coll-constraints',
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
columns: ['name', 'comment'],
|
||||
});
|
||||
}
|
||||
|
||||
if (!pgBrowser.Nodes['constraints']) {
|
||||
pgAdmin.Browser.Nodes['constraints'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
type: 'constraints',
|
||||
label: gettext('Constraints'),
|
||||
collection_type: 'coll-constraints',
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
define('pgadmin.node.index', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'backbone', 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.alertifyjs',
|
||||
'pgadmin.backform', 'pgadmin.backgrid', 'pgadmin.browser.collection',
|
||||
'pgadmin.backform', 'pgadmin.backgrid',
|
||||
'pgadmin.node.schema.dir/schema_child_tree_node',
|
||||
'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Alertify, Backform,
|
||||
Backgrid
|
||||
Backgrid, SchemaChildTreeNode
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-index']) {
|
||||
@@ -13,7 +15,6 @@ define('pgadmin.node.index', [
|
||||
node: 'index',
|
||||
label: gettext('Indexes'),
|
||||
type: 'coll-index',
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
sqlAlterHelp: 'sql-alterindex.html',
|
||||
sqlCreateHelp: 'sql-createindex.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'index_dialog.html'}),
|
||||
@@ -215,7 +216,6 @@ define('pgadmin.node.index', [
|
||||
|
||||
if (!pgBrowser.Nodes['index']) {
|
||||
pgAdmin.Browser.Nodes['index'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
parent_type: ['table', 'view', 'mview', 'partition'],
|
||||
collection_type: ['coll-table', 'coll-view'],
|
||||
sqlAlterHelp: 'sql-alterindex.html',
|
||||
@@ -266,8 +266,8 @@ define('pgadmin.node.index', [
|
||||
},
|
||||
]);
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDrop: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
canDropCascade: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
model: pgAdmin.Browser.Node.Model.extend({
|
||||
idAttribute: 'oid',
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ define([
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser',
|
||||
'pgadmin.alertifyjs', 'pgadmin.backform', 'pgadmin.backgrid',
|
||||
'pgadmin.node.schema.dir/schema_child_tree_node',
|
||||
'pgadmin.browser.collection', 'pgadmin.browser.table.partition.utils',
|
||||
],
|
||||
function(
|
||||
gettext, url_for, $, _, S, pgAdmin, pgBrowser, Alertify, Backform, Backgrid
|
||||
gettext, url_for, $, _, S, pgAdmin, pgBrowser, Alertify, Backform, Backgrid,
|
||||
SchemaChildTreeNode
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-partition']) {
|
||||
@@ -13,7 +15,6 @@ function(
|
||||
pgAdmin.Browser.Collection.extend({
|
||||
node: 'partition',
|
||||
label: gettext('Partitions'),
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
type: 'coll-partition',
|
||||
columns: [
|
||||
'name', 'schema', 'partition_value', 'is_partitioned', 'description',
|
||||
@@ -80,36 +81,6 @@ function(
|
||||
},
|
||||
]);
|
||||
},
|
||||
getTreeNodeHierarchy: function(i) {
|
||||
var idx = 0,
|
||||
res = {},
|
||||
t = pgBrowser.tree;
|
||||
|
||||
do {
|
||||
var d = t.itemData(i);
|
||||
if (
|
||||
d._type in pgBrowser.Nodes && pgBrowser.Nodes[d._type].hasId
|
||||
) {
|
||||
if (d._type == 'partition' && 'partition' in res) {
|
||||
if (!('table' in res)) {
|
||||
res['table'] = _.extend({}, d, {'priority': idx});
|
||||
idx -= 1;
|
||||
}
|
||||
} else if (d._type == 'table') {
|
||||
if (!('table' in res)) {
|
||||
res['table'] = _.extend({}, d, {'priority': idx});
|
||||
idx -= 1;
|
||||
}
|
||||
} else {
|
||||
res[d._type] = _.extend({}, d, {'priority': idx});
|
||||
idx -= 1;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
} while (i);
|
||||
|
||||
return res;
|
||||
},
|
||||
generate_url: function(item, type, d, with_id, info) {
|
||||
if (_.indexOf([
|
||||
'stats', 'statistics', 'dependency', 'dependent', 'reset',
|
||||
@@ -133,8 +104,8 @@ function(
|
||||
encodeURIComponent(info['partition']._id)
|
||||
).value();
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDrop: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
canDropCascade: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
callbacks: {
|
||||
/* Enable trigger(s) on table */
|
||||
enable_triggers_on_table: function(args) {
|
||||
@@ -1189,34 +1160,7 @@ function(
|
||||
return data;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-table' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null;
|
||||
var prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
canCreate: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
// Check to whether table has disable trigger(s)
|
||||
canCreate_with_trigger_enable: function(itemData, item, data) {
|
||||
if(this.canCreate.apply(this, [itemData, item, data])) {
|
||||
|
||||
@@ -16,7 +16,6 @@ define('pgadmin.node.rule', [
|
||||
node: 'rule',
|
||||
label: gettext('Rules'),
|
||||
type: 'coll-rule',
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
columns: ['name', 'owner', 'comment'],
|
||||
});
|
||||
}
|
||||
@@ -35,7 +34,6 @@ define('pgadmin.node.rule', [
|
||||
*/
|
||||
if (!pgBrowser.Nodes['rule']) {
|
||||
pgAdmin.Browser.Nodes['rule'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
parent_type: ['table','view', 'partition'],
|
||||
type: 'rule',
|
||||
sqlAlterHelp: 'sql-alterrule.html',
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
export function disableTriggers(tree, alertify, generateUrl, args) {
|
||||
return setTriggers(tree, alertify, generateUrl, args, {enable: 'false' });
|
||||
}
|
||||
export function enableTriggers(tree, alertify, generateUrl, args) {
|
||||
return setTriggers(tree, alertify, generateUrl, args, {enable: 'true' });
|
||||
}
|
||||
|
||||
function setTriggers(tree, alertify, generateUrl, args, params) {
|
||||
const treeNode = retrieveTreeNode(args, tree);
|
||||
|
||||
if (!treeNode || treeNode.getData() === null || treeNode.getData() === undefined)
|
||||
return false;
|
||||
|
||||
axios.put(
|
||||
generateUrl(treeNode.getHtmlIdentifier(), 'set_trigger', treeNode.getData(), true),
|
||||
params
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.data.success === 1) {
|
||||
alertify.success(res.data.info);
|
||||
treeNode.reload(tree);
|
||||
}
|
||||
})
|
||||
.catch((xhr) => {
|
||||
try {
|
||||
const err = xhr.response.data;
|
||||
if (err.success === 0) {
|
||||
alertify.error(err.errormsg);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
treeNode.unload(tree);
|
||||
});
|
||||
}
|
||||
|
||||
function retrieveTreeNode(args, tree) {
|
||||
const input = args || {};
|
||||
const domElementIdentifier = input.item || tree.selected();
|
||||
return tree.findNodeByDomElement(domElementIdentifier);
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
define('pgadmin.node.table', [
|
||||
'pgadmin.tables.js/enable_disable_triggers',
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser',
|
||||
'pgadmin.alertifyjs', 'pgadmin.backform', 'pgadmin.backgrid',
|
||||
'pgadmin.tables.js/show_advanced_tab',
|
||||
'pgadmin.browser.collection', 'pgadmin.node.column',
|
||||
'pgadmin.node.constraints', 'pgadmin.browser.table.partition.utils',
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.collection',
|
||||
'pgadmin.node.column', 'pgadmin.node.constraints',
|
||||
'pgadmin.browser.table.partition.utils',
|
||||
], function(
|
||||
tableFunctions,
|
||||
gettext, url_for, $, _, S, pgAdmin, pgBrowser, Alertify, Backform, Backgrid,
|
||||
ShowAdvancedTab
|
||||
ShowAdvancedTab, SchemaChild
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-table']) {
|
||||
@@ -25,8 +28,7 @@ define('pgadmin.node.table', [
|
||||
}
|
||||
|
||||
if (!pgBrowser.Nodes['table']) {
|
||||
pgBrowser.Nodes['table'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
pgBrowser.Nodes['table'] = SchemaChild.SchemaChildNode.extend({
|
||||
type: 'table',
|
||||
label: gettext('Table'),
|
||||
collection_type: 'coll-table',
|
||||
@@ -39,7 +41,6 @@ define('pgadmin.node.table', [
|
||||
sqlAlterHelp: 'sql-altertable.html',
|
||||
sqlCreateHelp: 'sql-createtable.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'table_dialog.html'}),
|
||||
parent_type: ['schema', 'catalog'],
|
||||
hasScriptTypes: ['create', 'select', 'insert', 'update', 'delete'],
|
||||
height: '95%',
|
||||
width: '85%',
|
||||
@@ -113,51 +114,24 @@ define('pgadmin.node.table', [
|
||||
this.handle_cache, this
|
||||
);
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
callbacks: {
|
||||
/* Enable trigger(s) on table */
|
||||
enable_triggers_on_table: function(args) {
|
||||
var params = {'enable': true };
|
||||
this.callbacks.set_triggers.apply(this, [args, params]);
|
||||
tableFunctions.enableTriggers(
|
||||
pgBrowser.treeMenu,
|
||||
Alertify,
|
||||
this.generate_url.bind(this),
|
||||
args
|
||||
);
|
||||
},
|
||||
/* Disable trigger(s) on table */
|
||||
disable_triggers_on_table: function(args) {
|
||||
var params = {'enable': false };
|
||||
this.callbacks.set_triggers.apply(this, [args, params]);
|
||||
},
|
||||
set_triggers: function(args, params) {
|
||||
// This function will send request to enable or
|
||||
// disable triggers on table level
|
||||
var input = args || {},
|
||||
obj = this,
|
||||
t = pgBrowser.tree,
|
||||
i = input.item || t.selected(),
|
||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
||||
if (!d)
|
||||
return false;
|
||||
|
||||
$.ajax({
|
||||
url: obj.generate_url(i, 'set_trigger' , d, true),
|
||||
type:'PUT',
|
||||
data: params,
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if (res.success == 1) {
|
||||
Alertify.success(res.info);
|
||||
t.unload(i);
|
||||
t.setInode(i);
|
||||
t.deselect(i);
|
||||
setTimeout(function() {
|
||||
t.select(i);
|
||||
}, 10);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
Alertify.pgRespErrorNotify(xhr, error);
|
||||
t.unload(i);
|
||||
},
|
||||
});
|
||||
tableFunctions.disableTriggers(
|
||||
pgBrowser.treeMenu,
|
||||
Alertify,
|
||||
this.generate_url.bind(this),
|
||||
args
|
||||
);
|
||||
},
|
||||
/* Truncate table */
|
||||
truncate_table: function(args) {
|
||||
@@ -1299,55 +1273,15 @@ define('pgadmin.node.table', [
|
||||
return data;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-table' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
// Check to whether table has disable trigger(s)
|
||||
canCreate_with_trigger_enable: function(itemData, item, data) {
|
||||
if(this.canCreate.apply(this, [itemData, item, data])) {
|
||||
// We are here means we can create menu, now let's check condition
|
||||
if(itemData.tigger_count > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return itemData.tigger_count > 0 &&
|
||||
this.canCreate.apply(this, [itemData, item, data]);
|
||||
},
|
||||
// Check to whether table has enable trigger(s)
|
||||
canCreate_with_trigger_disable: function(itemData, item, data) {
|
||||
if(this.canCreate.apply(this, [itemData, item, data])) {
|
||||
// We are here means we can create menu, now let's check condition
|
||||
if(itemData.tigger_count > 0 && itemData.has_enable_triggers > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return itemData.tigger_count > 0 && itemData.has_enable_triggers > 0 &&
|
||||
this.canCreate.apply(this, [itemData, item, data]);
|
||||
},
|
||||
onTableUpdated: function(_node, _oldNodeData, _newNodeData) {
|
||||
var key, childIDs;
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
define('pgadmin.node.trigger', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser', 'backform', 'pgadmin.alertifyjs',
|
||||
'underscore.string', 'sources/pgadmin', 'pgadmin.browser',
|
||||
'pgadmin.backform', 'pgadmin.alertifyjs',
|
||||
'pgadmin.node.schema.dir/schema_child_tree_node',
|
||||
'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
||||
], function(
|
||||
gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform, alertify,
|
||||
SchemaChildTreeNode
|
||||
) {
|
||||
|
||||
Backform.CustomSwitchControl = Backform.SwitchControl.extend({
|
||||
template: _.template([
|
||||
@@ -29,14 +34,12 @@ define('pgadmin.node.trigger', [
|
||||
node: 'trigger',
|
||||
label: gettext('Triggers'),
|
||||
type: 'coll-trigger',
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
columns: ['name', 'description'],
|
||||
});
|
||||
}
|
||||
|
||||
if (!pgBrowser.Nodes['trigger']) {
|
||||
pgAdmin.Browser.Nodes['trigger'] = pgBrowser.Node.extend({
|
||||
getTreeNodeHierarchy: pgBrowser.tableChildTreeNodeHierarchy,
|
||||
parent_type: ['table', 'view', 'partition'],
|
||||
collection_type: ['coll-table', 'coll-view'],
|
||||
type: 'trigger',
|
||||
@@ -175,8 +178,8 @@ define('pgadmin.node.trigger', [
|
||||
});
|
||||
},
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDrop: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
canDropCascade: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
model: pgAdmin.Browser.Node.Model.extend({
|
||||
defaults: {
|
||||
name: undefined,
|
||||
@@ -618,50 +621,16 @@ define('pgadmin.node.trigger', [
|
||||
return flag;
|
||||
},
|
||||
}),
|
||||
// Below function will enable right click menu for creating column
|
||||
canCreate: function(itemData, item, data) {
|
||||
// If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData, parents = [];
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to c reate table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
parents.push(d._type);
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// If node is under catalog then do not allow 'create' menu
|
||||
if (_.indexOf(parents, 'catalog') > -1) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
canCreate: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
|
||||
// Check to whether trigger is disable ?
|
||||
canCreate_with_trigger_enable: function(itemData, item, data) {
|
||||
if(this.canCreate.apply(this, [itemData, item, data])) {
|
||||
// We are here means we can create menu, now let's check condition
|
||||
if(itemData.icon === 'icon-trigger-bad') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return itemData.icon === 'icon-trigger-bad' &&
|
||||
this.canCreate.apply(this, [itemData, item, data]);
|
||||
},
|
||||
// Check to whether trigger is enable ?
|
||||
canCreate_with_trigger_disable: function(itemData, item, data) {
|
||||
if(this.canCreate.apply(this, [itemData, item, data])) {
|
||||
// We are here means we can create menu, now let's check condition
|
||||
if(itemData.icon === 'icon-trigger') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return itemData.icon === 'icon-trigger' &&
|
||||
this.canCreate.apply(this, [itemData, item, data]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
define('pgadmin.node.type', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform',
|
||||
'pgadmin.backgrid', 'pgadmin.browser.collection',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser, Backform, Backgrid) {
|
||||
'pgadmin.backgrid', 'pgadmin.node.schema.dir/child',
|
||||
'pgadmin.browser.collection',
|
||||
], function(
|
||||
gettext, url_for, $, _, pgAdmin, pgBrowser, Backform, Backgrid,
|
||||
schemaChild
|
||||
) {
|
||||
|
||||
if (!pgBrowser.Nodes['coll-type']) {
|
||||
pgBrowser.Nodes['coll-type'] =
|
||||
@@ -245,7 +249,7 @@ define('pgadmin.node.type', [
|
||||
});
|
||||
|
||||
if (!pgBrowser.Nodes['type']) {
|
||||
pgBrowser.Nodes['type'] = pgBrowser.Node.extend({
|
||||
pgBrowser.Nodes['type'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'type',
|
||||
sqlAlterHelp: 'sql-altertype.html',
|
||||
sqlCreateHelp: 'sql-createtype.html',
|
||||
@@ -254,7 +258,6 @@ define('pgadmin.node.type', [
|
||||
collection_type: 'coll-type',
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
parent_type: ['schema', 'catalog'],
|
||||
Init: function() {
|
||||
/* Avoid multiple registration of menus */
|
||||
if (this.initialized)
|
||||
@@ -284,8 +287,6 @@ define('pgadmin.node.type', [
|
||||
]);
|
||||
|
||||
},
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
ext_funcs: undefined,
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
defaults: {
|
||||
@@ -911,34 +912,6 @@ define('pgadmin.node.type', [
|
||||
return result;
|
||||
},
|
||||
}),
|
||||
canCreate: function(itemData, item, data) {
|
||||
//If check is false then , we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
// If it is schema then allow user to create table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-type' == d._type) {
|
||||
//Check if we are not child of catalog
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
return pgBrowser.Nodes['type'];
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
define('pgadmin.node.mview', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'sources/pgadmin', 'pgadmin.alertifyjs', 'pgadmin.browser',
|
||||
'pgadmin.backform', 'pgadmin.browser.server.privilege',
|
||||
], function(gettext, url_for, $, _, pgAdmin, Alertify, pgBrowser, Backform) {
|
||||
'pgadmin.backform', 'pgadmin.node.schema.dir/child',
|
||||
'pgadmin.browser.server.privilege',
|
||||
], function(
|
||||
gettext, url_for, $, _, pgAdmin, Alertify, pgBrowser, Backform,
|
||||
schemaChild
|
||||
) {
|
||||
|
||||
/**
|
||||
Create and add a view collection into nodes
|
||||
@@ -33,19 +37,16 @@ define('pgadmin.node.mview', [
|
||||
view option in the context menu
|
||||
*/
|
||||
if (!pgBrowser.Nodes['mview']) {
|
||||
pgBrowser.Nodes['mview'] = pgBrowser.Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
pgBrowser.Nodes['mview'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'mview',
|
||||
sqlAlterHelp: 'sql-altermaterializedview.html',
|
||||
sqlCreateHelp: 'sql-creatematerializedview.html',
|
||||
dialogHelp: url_for('help.static', {'filename': 'materialized_view_dialog.html'}),
|
||||
label: gettext('Materialized View'),
|
||||
hasSQL: true,
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
hasScriptTypes: ['create', 'select'],
|
||||
collection_type: 'coll-mview',
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
Init: function() {
|
||||
|
||||
// Avoid mulitple registration of menus
|
||||
@@ -236,43 +237,6 @@ define('pgadmin.node.mview', [
|
||||
|
||||
}),
|
||||
|
||||
/**
|
||||
Show or hide create view menu option on parent node
|
||||
and hide for system view in catalogs.
|
||||
*/
|
||||
canCreate: function(itemData, item, data) {
|
||||
|
||||
// If check is false then, we will allow create menu
|
||||
if (data && data.check === false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
|
||||
// If it is schema then allow user to create view
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-mview' == d._type) {
|
||||
|
||||
// Check if we are not child of view
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
},
|
||||
refresh_mview: function(args) {
|
||||
var input = args || {},
|
||||
obj = this,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
define('pgadmin.node.view', [
|
||||
'sources/gettext',
|
||||
'sources/url_for', 'jquery', 'underscore', 'sources/pgadmin',
|
||||
'pgadmin.browser', 'pgadmin.backform', 'pgadmin.browser.server.privilege',
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.backform',
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.browser.server.privilege',
|
||||
'pgadmin.node.rule',
|
||||
], function(gettext, url_for, $, _, pgAdmin, pgBrowser, Backform) {
|
||||
], function(
|
||||
gettext, url_for, $, _, pgAdmin, pgBrowser, Backform, schemaChild
|
||||
) {
|
||||
|
||||
|
||||
/**
|
||||
Create and add a view collection into nodes
|
||||
@@ -28,14 +31,9 @@ define('pgadmin.node.view', [
|
||||
under which this node to display
|
||||
@param {variable} type - Type of Node
|
||||
@param {variable} hasSQL - To show SQL tab
|
||||
@param {variable} canDrop - Adds drop view option
|
||||
in the context menu
|
||||
@param {variable} canDropCascade - Adds drop Cascade
|
||||
view option in the context menu
|
||||
*/
|
||||
if (!pgBrowser.Nodes['view']) {
|
||||
pgBrowser.Nodes['view'] = pgBrowser.Node.extend({
|
||||
parent_type: ['schema', 'catalog'],
|
||||
pgBrowser.Nodes['view'] = schemaChild.SchemaChildNode.extend({
|
||||
type: 'view',
|
||||
sqlAlterHelp: 'sql-alterview.html',
|
||||
sqlCreateHelp: 'sql-createview.html',
|
||||
@@ -45,8 +43,6 @@ define('pgadmin.node.view', [
|
||||
hasDepends: true,
|
||||
hasScriptTypes: ['create', 'select', 'insert'],
|
||||
collection_type: 'coll-view',
|
||||
canDrop: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
canDropCascade: pgBrowser.Nodes['schema'].canChildDrop,
|
||||
Init: function() {
|
||||
|
||||
// Avoid mulitple registration of menus
|
||||
@@ -197,45 +193,6 @@ define('pgadmin.node.view', [
|
||||
return false;
|
||||
},
|
||||
}),
|
||||
|
||||
/**
|
||||
Show or hide create view menu option on parent node
|
||||
and hide for system view in catalogs.
|
||||
*/
|
||||
canCreate: function(itemData, item, data) {
|
||||
|
||||
// If check is false then, we will allow create menu
|
||||
if (data && data.check == false)
|
||||
return true;
|
||||
|
||||
var t = pgBrowser.tree, i = item, d = itemData;
|
||||
|
||||
// To iterate over tree to check parent node
|
||||
while (i) {
|
||||
|
||||
// If it is schema then allow user to create view
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return true;
|
||||
|
||||
if ('coll-view' == d._type) {
|
||||
|
||||
// Check if we are not child of view
|
||||
var prev_i = t.hasParent(i) ? t.parent(i) : null,
|
||||
prev_d = prev_i ? t.itemData(prev_i) : null;
|
||||
if( prev_d._type == 'catalog') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
}
|
||||
|
||||
// by default we do not want to allow create menu
|
||||
return true;
|
||||
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user