diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py index 49d2c7b..5bcb456 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/__init__.py @@ -369,7 +369,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader): seclabels = [] for seclbls in data['seclabels']: k, v = seclbls.split('=') - seclabels.append({'provider': k, 'security_label': v}) + seclabels.append({'provider': k, 'label': v}) data['seclabels'] = seclabels diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js index 15716c8..688ac24 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js @@ -89,17 +89,21 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { 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 create table - if (_.indexOf(['view', 'mview'], d._type) > -1) { - return false; - } parents.push(d._type); i = t.hasParent(i) ? t.parent(i) : null; d = i ? t.itemData(i) : null; } - } - else { - return true; + + // 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 { + return false; } }, hasDepends: true, @@ -406,64 +410,73 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { canDelete: true },{ id: 'seclabels', label: '{{ _('Security Labels') }}', - model: Backform.SecurityModel, editable: false, type: 'collection', + model: pgAdmin.Browser.SecurityModel, + editable: false, type: 'collection', group: '{{ _('Security') }}', mode: ['edit', 'create'], - min_version: 90200, canAdd: true, + min_version: 90100, canAdd: true, canEdit: false, canDelete: true, control: 'unique-col-collection' } ], - validate: function() { + validate: function(keys) { var err = {}, changedAttrs = this.changed, msg = undefined; - this.errorModel.clear(); - if (_.has(changedAttrs,this.get('name')) - && _.isUndefined(this.get('name')) + // Nothing to validate + if (keys.length == 0) { + this.errorModel.clear(); + return null; + } else { + this.errorModel.clear(); + } + + if (_.isUndefined(this.get('name')) || String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') { msg = '{{ _('Column name can not be empty.') }}'; this.errorModel.set('name', msg); return msg; - } else if (_.has(changedAttrs,this.get('attowner')) - && _.isUndefined(this.get('attowner')) - || String(this.get('attowner')).replace(/^\s+|\s+$/g, '') == '') { - msg = '{{ _('Schema can not be empty.') }}'; - this.errorModel.set('attowner', msg); - return msg; - } else if (_.has(changedAttrs,this.get('attowner')) - && _.isUndefined(this.get('attowner')) - || String(this.get('attowner')).replace(/^\s+|\s+$/g, '') == '') { - msg = '{{ _('Owner can not be empty.') }}'; - this.errorModel.set('attowner', msg); + } + + if (_.isUndefined(this.get('cltype')) + || String(this.get('cltype')).replace(/^\s+|\s+$/g, '') == '') { + msg = '{{ _('Column type can not be empty.') }}'; + this.errorModel.set('cltype', msg); return msg; - } else if (_.has(changedAttrs,this.get('attlen')) - && _.isUndefined(this.get('attlen')) - || String(this.get('attlen')).replace(/^\s+|\s+$/g, '') == '') { + } + + if (!_.isUndefined(this.get('cltype')) + && !_.isUndefined(this.get('attlen')) + && !_.isNull(this.get('attlen')) + && this.get('attlen') !== '') { // Validation for Length field if (this.get('attlen') < this.get('min_val')) - msg = _("Length should not be less than " + this.get('min_val')) + msg = '{{ _('Length should not be less than: ') }}' + this.get('min_val'); if (this.get('attlen') > this.get('max_val')) - msg = _("Length should not be greater than " + this.get('max_val')) + msg = '{{ _('Length should not be greater than: ') }}' + this.get('max_val'); // If we have any error set then throw it to user if(msg) { this.errorModel.set('attlen', msg) return msg; } - } else if (_.has(changedAttrs,this.get('attprecision')) - && _.isUndefined(this.get('attprecision')) - || String(this.get('attprecision')).replace(/^\s+|\s+$/g, '') == '') { + } + + if (!_.isUndefined(this.get('cltype')) + && !_.isUndefined(this.get('attprecision')) + && !_.isNull(this.get('attprecision')) + && this.get('attprecision') !== '') { // Validation for precision field if (this.get('attprecision') < this.get('min_val')) - msg = _("Precision should not be less than " + this.get('min_val')) + msg = '{{ _('Precision should not be less than: ') }}' + this.get('min_val'); if (this.get('attprecision') > this.get('max_val')) - msg = _("Precision should not be greater than " + this.get('max_val')) + msg = '{{ _('Precision should not be greater than: ') }}' + this.get('max_val'); // If we have any error set then throw it to user if(msg) { this.errorModel.set('attprecision', msg) return msg; } - return null; - } + } + + return null; }, isInhertedColumn: function() { }, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js index 96882d7..56cc0df 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js @@ -75,6 +75,16 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { } } ], + validate: function() { + this.errorModel.clear(); + + if (_.isUndefined(this.get('colname')) + || String(this.get('colname')).replace(/^\s+|\s+$/g, '') == '') { + msg = '{{ _('Column Name can not be empty.') }}'; + this.errorModel.set('colname', msg); + return msg; + } + }, // We will check if we are under schema node inSchema: function() { if(this.node_info && 'catalog' in this.node_info) { @@ -165,7 +175,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { name: undefined, nspname: undefined, tabname: undefined, - spcname: undefined + spcname: 'pg_default', + amname: 'btree' }, schema: [{ id: 'name', label: '{{ _('Name') }}', cell: 'string', @@ -176,6 +187,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { },{ id: 'spcname', label:'{{ _('Tablespace') }}', cell: 'string', control: 'node-list-by-name', node: 'tablespace', + select2: {'allowClear': true}, type: 'text', mode: ['properties', 'create', 'edit'], disabled: 'inSchema', filter: function(d) { // If tablespace name is not "pg_global" then we need to exclude them @@ -189,7 +201,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { id: 'amname', label:'{{ _('Access Method') }}', cell: 'string', type: 'text', mode: ['properties', 'create', 'edit'], disabled: 'inSchemaWithModelCheck', url: 'get_access_methods', - group: '{{ _('Definition') }}', + group: '{{ _('Definition') }}', select2: {'allowClear': true}, control: Backform.NodeAjaxOptionsControl.extend({ // When access method changes we need to clear columns collection onChange: function() { @@ -199,7 +211,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { current_am = self.model.get('amname'), // previous access method previous_am = self.model.previous('amname'); - if (current_am != previous_am) { + if (current_am != previous_am && self.model.get('columns').length !== 0) { var msg = '{{ _('Changing access method will clear columns collection') }}'; alertify.confirm(msg, function (e) { // User clicks Ok, lets clear collection @@ -283,19 +295,50 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { disabled: 'inSchema' } ], - validate: function() { + validate: function(keys) { var err = {}, changedAttrs = this.changed, msg = undefined; - this.errorModel.clear(); - if (_.has(changedAttrs,this.get('name')) - && _.isUndefined(this.get('name')) + // Nothing to validate + if (keys.length == 0) { + this.errorModel.clear(); + return null; + } else { + this.errorModel.clear(); + } + + if (_.isUndefined(this.get('name')) || String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') { msg = '{{ _('Name can not be empty.') }}'; this.errorModel.set('name', msg); return msg; } + if (_.isUndefined(this.get('spcname')) + || String(this.get('spcname')).replace(/^\s+|\s+$/g, '') == '') { + msg = '{{ _('Tablespace can not be empty.') }}'; + this.errorModel.set('spcname', msg); + return msg; + } + if (_.isUndefined(this.get('amname')) + || String(this.get('amname')).replace(/^\s+|\s+$/g, '') == '') { + msg = '{{ _('Access method can not be empty.') }}'; + this.errorModel.set('amname', msg); + return msg; + } + // Checks if all columns has names + var cols = this.get('columns'); + if(cols && cols.length > 0) { + if(!_.every(cols.pluck('colname'))) { + msg = '{{ _('You must specify column name.') }}'; + this.errorModel.set('columns', msg); + return msg; + } + } else if(cols){ + msg = '{{ _('You must specify at least one column.') }}'; + this.errorModel.set('columns', msg); + return msg; + } return null; }, // We will check if we are under schema node & in 'create' mode diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql index 2098ddc..68a4444 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql @@ -5,7 +5,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} CLUSTER ON {{conn|qtIdent(data.name)}}; {% endif %} {## Changes description ##} -{% if data.description %} +{% if data.description is defined %} -COMMENT ON INDEX {{conn|qtIdent(data.name)}} +COMMENT ON INDEX {{conn|qtIdent(data.schema, data.name)}} IS {{data.description|qtLiteral}};{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/update.sql index cb8583b..f2acd6c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/update.sql @@ -14,11 +14,11 @@ ALTER INDEX {{conn|qtIdent(data.schema, data.name)}} SET TABLESPACE {{conn|qtIdent(data.spcname)}}; {% endif %} {## Alter index to use cluster type ##} -{% if data.indisclustered and o_data.indisclustered != data.indisclustered %} +{% if data.indisclustered is defined and o_data.indisclustered != data.indisclustered %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} CLUSTER ON {{conn|qtIdent(data.name)}}; {% endif %} {## Changes description ##} -{% if data.description and o_data.description != data.description %} +{% if data.description is defined and o_data.description != data.description %} COMMENT ON INDEX {{conn|qtIdent(data.schema, data.name)}} IS {{data.description|qtLiteral}};{% endif %} \ No newline at end of file