public inbox for [email protected]  
help / color / mirror / Atom feed
From: Murtuza Zabuawala <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4] [PATCH] Allow user to create ENUM type without any label
Date: Fri, 26 May 2017 17:29:01 +0530
Message-ID: <CAKKotZSMoG7hxq9V2EY8=V7tfJRfttwXCtb2JFEj1O=uv_Z_WA@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi,

PFA patch to address below,
1) Allow user to create ENUM type without any labels.
2) Allow user to add new label to existing enum type which do not have any
existing labels.
RM#2426

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
index 031e1b7..9c88c63 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
@@ -905,16 +905,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
                             'Composite types require at least two members.'
                         )
                     )
-            # If type is enum then check if it has minimum one label
-            if data and data[arg] == 'e':
-                if len(data['enum']) < 1:
-                    return make_json_response(
-                        status=410,
-                        success=0,
-                        errormsg=gettext(
-                            'Enumeration types require at least one label.'
-                        )
-                    )
             # If type is range then check if subtype is defined or not
             if data and data[arg] == 'r':
                 if data['typname'] is None:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js
index 9a195e6..4c101fd 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js
@@ -241,18 +241,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
       }
     }],
     validate: function() {
-      var err = {},
-          errmsg = null;
-
-      if (_.isUndefined(this.get('label') ||
-        _.isNull(this.get('label')) ||
-        String(this.get('label')).replace(/^\s+|\s+$/g, '') == '')) {
-          errmsg = '{{ _('Please specify the value for label.') }}';
-          this.errorModel.set('label', errmsg)
-          return errmsg;
-      } else {
-        this.errorModel.unset('label');
-      }
       return null;
     }
   });
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql
index 7f38e97..3a0a336 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql
@@ -87,7 +87,7 @@ ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }}
 {% if c_idx == 1 %}
 {# if first new element then add it after old data enum list#}
 ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }}
-    ADD VALUE {{r.label|qtLiteral}} AFTER {{o_data.enum[o_enum_len].label|qtLiteral }};
+    ADD VALUE {{r.label|qtLiteral}} {% if o_enum_len > 0 %}AFTER {{o_data.enum[o_enum_len].label|qtLiteral }}{% endif %};
 {% else %}
 {# if first new element then add it after new data enum list#}
 {% set p_idx = loop.index - 2 %}


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [text/plain] RM_2426.diff (3.1K, 3-RM_2426.diff)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
index 031e1b7..9c88c63 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
@@ -905,16 +905,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
                             'Composite types require at least two members.'
                         )
                     )
-            # If type is enum then check if it has minimum one label
-            if data and data[arg] == 'e':
-                if len(data['enum']) < 1:
-                    return make_json_response(
-                        status=410,
-                        success=0,
-                        errormsg=gettext(
-                            'Enumeration types require at least one label.'
-                        )
-                    )
             # If type is range then check if subtype is defined or not
             if data and data[arg] == 'r':
                 if data['typname'] is None:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js
index 9a195e6..4c101fd 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js
@@ -241,18 +241,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) {
       }
     }],
     validate: function() {
-      var err = {},
-          errmsg = null;
-
-      if (_.isUndefined(this.get('label') ||
-        _.isNull(this.get('label')) ||
-        String(this.get('label')).replace(/^\s+|\s+$/g, '') == '')) {
-          errmsg = '{{ _('Please specify the value for label.') }}';
-          this.errorModel.set('label', errmsg)
-          return errmsg;
-      } else {
-        this.errorModel.unset('label');
-      }
       return null;
     }
   });
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql
index 7f38e97..3a0a336 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/default/update.sql
@@ -87,7 +87,7 @@ ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }}
 {% if c_idx == 1 %}
 {# if first new element then add it after old data enum list#}
 ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }}
-    ADD VALUE {{r.label|qtLiteral}} AFTER {{o_data.enum[o_enum_len].label|qtLiteral }};
+    ADD VALUE {{r.label|qtLiteral}} {% if o_enum_len > 0 %}AFTER {{o_data.enum[o_enum_len].label|qtLiteral }}{% endif %};
 {% else %}
 {# if first new element then add it after new data enum list#}
 {% set p_idx = loop.index - 2 %}


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4] [PATCH] Allow user to create ENUM type without any label
  In-Reply-To: <CAKKotZSMoG7hxq9V2EY8=V7tfJRfttwXCtb2JFEj1O=uv_Z_WA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox