public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4] [PATCH] Allow user to create ENUM type without any label
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4] [PATCH] Allow user to create ENUM type without any label
@ 2017-05-26 11:59  Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Murtuza Zabuawala @ 2017-05-26 11:59 UTC (permalink / raw)
  To: pgadmin-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 %}


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin4] [PATCH] Allow user to create ENUM type without any label
@ 2017-05-26 16:21  Dave Page <[email protected]>
  parent: Murtuza Zabuawala <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2017-05-26 16:21 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Fri, May 26, 2017 at 7:59 AM, Murtuza Zabuawala
<[email protected]> wrote:
> 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
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2017-05-26 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-26 11:59 [pgAdmin4] [PATCH] Allow user to create ENUM type without any label Murtuza Zabuawala <[email protected]>
2017-05-26 16:21 ` Dave Page <[email protected]>

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