Hi, Please find the attached updated patch which includes following fixes:
1. The plus button to add a constraint with the domain dialogue doesn't work. 2. The Domain Constraint node doesn't load. 3. On update, the domain constraint node name doesn't change. Thanks, Khushboo On Mon, Jul 3, 2017 at 7:52 PM, Dave Page <dp...@pgadmin.org> wrote: > Hi > > On Mon, Jul 3, 2017 at 6:10 AM, Khushboo Vashi < > khushboo.va...@enterprisedb.com> wrote: > >> >> >> On Mon, Jul 3, 2017 at 1:10 PM, Khushboo Vashi < >> khushboo.va...@enterprisedb.com> wrote: >> >>> Hi, >>> >>> The Domain Constraint module doesn't load as it can not find the >>> domain_constraints.js file. >>> To fix this issue, renamed the domain_constraint.js to >>> domain_constraints.js. >>> >>> RM #2529 <https://redmine.postgresql.org/issues/2529> created for the >> same. >> >>> Please find the attached fix. >>> >>> >> > I think this is still broken. If I try to create a new domain called abc, > with a basetype of text, then hit the + button to add a constraint, I get: > > > domain.js:24 Uncaught TypeError: Cannot read property 'server' of > undefined at s.initialize (domain.js:24) at s.e.Model (backbone-min.js:1) > at s [as constructor] (backbone-min.js:1) at new s (backbone-min.js:1) at > s._prepareModel (backbone-min.js:1) at set (backbone-min.js:1) at s.add ( > backbone-min.js:1) at s.insertRow (backgrid.min.js:8) at s.insertRow ( > backgrid.min.js:8) at HTMLButtonElement.<anonymous> ( > backform.pgadmin.js:1347) > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: http://www.enterprisedb.com > The Enterprise PostgreSQL Company >
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py index 85cd1c0..b20cb38 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py @@ -410,7 +410,7 @@ class DomainConstraintView(PGChildNodeView): """ data = self.request try: - status, SQL = self.get_sql(gid, sid, data, scid, doid) + status, SQL, name = self.get_sql(gid, sid, data, scid, doid) if not status: return SQL @@ -517,7 +517,7 @@ class DomainConstraintView(PGChildNodeView): coid: Domain Constraint Id """ data = self.request - status, SQL = self.get_sql(gid, sid, data, scid, doid, coid) + status, SQL, name = self.get_sql(gid, sid, data, scid, doid, coid) if not status: return SQL @@ -534,18 +534,13 @@ class DomainConstraintView(PGChildNodeView): else: icon = '' - return make_json_response( - success=1, - info="Domain Constraint updated", - data={ - 'id': coid, - 'doid': doid, - 'scid': scid, - 'sid': sid, - 'gid': gid, - 'did': did, - 'icon': icon - } + return jsonify( + node=self.blueprint.generate_browser_node( + coid, + doid, + name, + icon=icon + ) ) else: return make_json_response( @@ -629,7 +624,7 @@ class DomainConstraintView(PGChildNodeView): """ data = self.request - status, SQL = self.get_sql(gid, sid, data, scid, doid, coid) + status, SQL, name = self.get_sql(gid, sid, data, scid, doid, coid) if status and SQL: return make_json_response( data=SQL, @@ -677,9 +672,9 @@ class DomainConstraintView(PGChildNodeView): SQL = render_template("/".join([self.template_path, 'create.sql']), data=data, domain=domain, schema=schema) - return True, SQL.strip('\n') + return True, SQL.strip('\n'), data['name'] if 'name' in data else old_data['name'] except Exception as e: - return False, internal_server_error(errormsg=str(e)) + return False, internal_server_error(errormsg=str(e)), None def _get_domain(self, doid): """ diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraint.js deleted file mode 100644 index 61d0553..0000000 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraint.js +++ /dev/null @@ -1,146 +0,0 @@ -// Domain Constraint Module: Collection and Node -define('pgadmin.node.domain_constraints', [ - 'sources/gettext', 'sources/url_for', 'jquery', 'underscore', - 'underscore.string', 'pgadmin', 'pgadmin.browser', 'alertify', - 'pgadmin.browser.collection' -], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, alertify) { - - // Define Domain Constraint Collection Node - if (!pgBrowser.Nodes['coll-domain_constraints']) { - var domain_constraints = pgAdmin.Browser.Nodes['coll-domain_constraints'] = - pgAdmin.Browser.Collection.extend({ - node: 'domain_constraints', - label: gettext('Domain Constraints'), - type: 'coll-domain_constraints', - columns: ['name', 'description'] - }); - }; - - // Domain Constraint Node - if (!pgBrowser.Nodes['domain_constraints']) { - pgAdmin.Browser.Nodes['domain_constraints'] = pgBrowser.Node.extend({ - type: 'domain_constraints', - sqlAlterHelp: 'sql-alterdomain.html', - sqlCreateHelp: 'sql-alterdomain.html', - dialogHelp: url_for('help.static', {'filename': 'domain_constraint_dialog.html'}), - label: gettext('Domain Constraints'), - collection_type: 'coll-domain_constraints', - hasSQL: true, - hasDepends: true, - parent_type: ['domain'], - Init: function() { - // Avoid mulitple registration of menus - if (this.initialized) - return; - - this.initialized = true; - - pgBrowser.add_menus([{ - name: 'create_domain_on_coll', node: 'coll-domain_constraints', module: this, - applies: ['object', 'context'], callback: 'show_obj_properties', - category: 'create', priority: 5, label: gettext('Domain Constraint...'), - icon: 'wcTabIcon icon-domain_constraints', data: {action: 'create', check: true}, - enable: 'canCreate' - },{ - name: 'create_domain_constraints', node: 'domain_constraints', module: this, - applies: ['object', 'context'], callback: 'show_obj_properties', - category: 'create', priority: 5, label: gettext('Domain Constraint...'), - icon: 'wcTabIcon icon-domain_constraints', data: {action: 'create', check: true}, - enable: 'canCreate' - },{ - name: 'create_domain_constraints', node: 'domain', module: this, - applies: ['object', 'context'], callback: 'show_obj_properties', - category: 'create', priority: 5, label: gettext('Domain Constraint...'), - icon: 'wcTabIcon icon-domain_constraints', data: {action: 'create', check: false}, - enable: 'canCreate' - } - ]); - - }, - canDrop: pgBrowser.Nodes['schema'].canChildDrop, - model: pgAdmin.Browser.Node.Model.extend({ - defaults: { - name: undefined, - oid: undefined, - description: undefined, - consrc: undefined, - connoinherit: undefined, - convalidated: true - }, - // Domain Constraint Schema - schema: [{ - id: 'name', label: gettext('Name'), type:'text', cell:'string', - disabled: 'isDisabled' - },{ - id: 'oid', label: gettext('OID'), cell: 'string', - type: 'text' , mode: ['properties'] - },{ - id: 'description', label: gettext('Comment'), type: 'multiline', cell: - 'string', mode: ['properties', 'create', 'edit'], min_version: 90500, - },{ - id: 'consrc', label: gettext('Check'), type: 'multiline', cel: - 'string', group: gettext('Definition'), mode: ['properties', - 'create', 'edit'], disabled: function(m) { return !m.isNew(); } - },{ - id: 'connoinherit', label: gettext('No inherit'), type: - 'switch', cell: 'boolean', group: gettext('Definition'), mode: - ['properties', 'create', 'edit'], disabled: 'isDisabled', - visible: false - },{ - id: 'convalidated', label: gettext("Validate?"), type: 'switch', cell: - 'boolean', group: gettext('Definition'), min_version: 90200, - disabled: function(m) { - if (!m.isNew()) { - var server = this.node_info.server; - if (server.version < 90200) { return true; - } - else if(m.get('convalidated')) { - return true; - } - return false; - } - return false; - }, - mode: ['properties', 'create', 'edit'] - }], - // Client Side Validation - validate: function() { - var err = {}, - errmsg; - - if (_.isUndefined(this.get('name')) || String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') { - err['name'] = gettext('Name cannot be empty.'); - errmsg = errmsg || err['name']; - } - - if (_.isUndefined(this.get('consrc')) || String(this.get('consrc')).replace(/^\s+|\s+$/g, '') == '') { - err['consrc'] = gettext('Check cannot be empty.'); - errmsg = errmsg || err['consrc']; - } - - this.errorModel.clear().set(err); - - if (_.size(err)) { - this.trigger('on-status', {msg: errmsg}); - return errmsg; - } - - return null; - - }, - isDisabled: function(m){ - if (!m.isNew()) { - var server = this.node_info.server; - if (server.version < 90200) - { - return true; - } - } - return false; - } - }), - }); - } - - return pgBrowser.Nodes['domain']; -}); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraints.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraints.js new file mode 100644 index 0000000..61d0553 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraints.js @@ -0,0 +1,146 @@ +// Domain Constraint Module: Collection and Node +define('pgadmin.node.domain_constraints', [ + 'sources/gettext', 'sources/url_for', 'jquery', 'underscore', + 'underscore.string', 'pgadmin', 'pgadmin.browser', 'alertify', + 'pgadmin.browser.collection' +], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, alertify) { + + // Define Domain Constraint Collection Node + if (!pgBrowser.Nodes['coll-domain_constraints']) { + var domain_constraints = pgAdmin.Browser.Nodes['coll-domain_constraints'] = + pgAdmin.Browser.Collection.extend({ + node: 'domain_constraints', + label: gettext('Domain Constraints'), + type: 'coll-domain_constraints', + columns: ['name', 'description'] + }); + }; + + // Domain Constraint Node + if (!pgBrowser.Nodes['domain_constraints']) { + pgAdmin.Browser.Nodes['domain_constraints'] = pgBrowser.Node.extend({ + type: 'domain_constraints', + sqlAlterHelp: 'sql-alterdomain.html', + sqlCreateHelp: 'sql-alterdomain.html', + dialogHelp: url_for('help.static', {'filename': 'domain_constraint_dialog.html'}), + label: gettext('Domain Constraints'), + collection_type: 'coll-domain_constraints', + hasSQL: true, + hasDepends: true, + parent_type: ['domain'], + Init: function() { + // Avoid mulitple registration of menus + if (this.initialized) + return; + + this.initialized = true; + + pgBrowser.add_menus([{ + name: 'create_domain_on_coll', node: 'coll-domain_constraints', module: this, + applies: ['object', 'context'], callback: 'show_obj_properties', + category: 'create', priority: 5, label: gettext('Domain Constraint...'), + icon: 'wcTabIcon icon-domain_constraints', data: {action: 'create', check: true}, + enable: 'canCreate' + },{ + name: 'create_domain_constraints', node: 'domain_constraints', module: this, + applies: ['object', 'context'], callback: 'show_obj_properties', + category: 'create', priority: 5, label: gettext('Domain Constraint...'), + icon: 'wcTabIcon icon-domain_constraints', data: {action: 'create', check: true}, + enable: 'canCreate' + },{ + name: 'create_domain_constraints', node: 'domain', module: this, + applies: ['object', 'context'], callback: 'show_obj_properties', + category: 'create', priority: 5, label: gettext('Domain Constraint...'), + icon: 'wcTabIcon icon-domain_constraints', data: {action: 'create', check: false}, + enable: 'canCreate' + } + ]); + + }, + canDrop: pgBrowser.Nodes['schema'].canChildDrop, + model: pgAdmin.Browser.Node.Model.extend({ + defaults: { + name: undefined, + oid: undefined, + description: undefined, + consrc: undefined, + connoinherit: undefined, + convalidated: true + }, + // Domain Constraint Schema + schema: [{ + id: 'name', label: gettext('Name'), type:'text', cell:'string', + disabled: 'isDisabled' + },{ + id: 'oid', label: gettext('OID'), cell: 'string', + type: 'text' , mode: ['properties'] + },{ + id: 'description', label: gettext('Comment'), type: 'multiline', cell: + 'string', mode: ['properties', 'create', 'edit'], min_version: 90500, + },{ + id: 'consrc', label: gettext('Check'), type: 'multiline', cel: + 'string', group: gettext('Definition'), mode: ['properties', + 'create', 'edit'], disabled: function(m) { return !m.isNew(); } + },{ + id: 'connoinherit', label: gettext('No inherit'), type: + 'switch', cell: 'boolean', group: gettext('Definition'), mode: + ['properties', 'create', 'edit'], disabled: 'isDisabled', + visible: false + },{ + id: 'convalidated', label: gettext("Validate?"), type: 'switch', cell: + 'boolean', group: gettext('Definition'), min_version: 90200, + disabled: function(m) { + if (!m.isNew()) { + var server = this.node_info.server; + if (server.version < 90200) { return true; + } + else if(m.get('convalidated')) { + return true; + } + return false; + } + return false; + }, + mode: ['properties', 'create', 'edit'] + }], + // Client Side Validation + validate: function() { + var err = {}, + errmsg; + + if (_.isUndefined(this.get('name')) || String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') { + err['name'] = gettext('Name cannot be empty.'); + errmsg = errmsg || err['name']; + } + + if (_.isUndefined(this.get('consrc')) || String(this.get('consrc')).replace(/^\s+|\s+$/g, '') == '') { + err['consrc'] = gettext('Check cannot be empty.'); + errmsg = errmsg || err['consrc']; + } + + this.errorModel.clear().set(err); + + if (_.size(err)) { + this.trigger('on-status', {msg: errmsg}); + return errmsg; + } + + return null; + + }, + isDisabled: function(m){ + if (!m.isNew()) { + var server = this.node_info.server; + if (server.version < 90200) + { + return true; + } + } + return false; + } + }), + }); + } + + return pgBrowser.Nodes['domain']; +}); diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.js index 61ebe7b..03fcb5d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.js @@ -19,15 +19,7 @@ define('pgadmin.node.domain', [ var ConstraintModel = pgBrowser.Node.Model.extend({ idAttribute: 'conoid', initialize: function(attrs, args) { - if (_.size(attrs) === 0) { - var userInfo = pgBrowser.serverInfo[ - args.node_info.server._id - ].user, - schemaInfo = args.node_info.schema; - this.set({ - 'owner': userInfo.name, 'schema': schemaInfo._label - }, {silent: true}); - } else { + if (!_.size(attrs) === 0) { this.convalidated_default = this.get('convalidated') } pgBrowser.Node.Model.prototype.initialize.apply(this, arguments);