public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][PATCH] To fix the issue in index or exclusion contrarians node
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][PATCH] To fix the issue in index or exclusion contrarians node
@ 2017-05-31 12:31  Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Murtuza Zabuawala @ 2017-05-31 12:31 UTC (permalink / raw)
  To: pgadmin-hackers

Hi,

PFA patch to fix the issue in index or exclusion contrarians node where it
was throwing "can't execute an empty query" error due to incorrect
validation logic for edit mode.
RM#2113

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

diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js
index eee9ad2..5972c51 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js
@@ -24,7 +24,22 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
       },{
         id: 'oper_class', label:'{{ _('Operator class') }}', type:'text',
         node: 'table', url: 'get_oper_class', first_empty: true,
-        editable: true,
+        editable: function(m) {
+          if (m instanceof Backbone.Collection) {
+            return true;
+          } else if ((_.has(m.collection, 'handler') &&
+                !_.isUndefined(m.collection.handler) &&
+                !_.isUndefined(m.collection.handler.get('oid')))) {
+            return false;
+          } else if (_.has(m.collection, 'handler') &&
+                !_.isUndefined(m.collection.handler) &&
+                !_.isUndefined(m.collection.handler.get('amname')) &&
+                m.collection.handler.get('amname') != 'btree') {
+            // Disable if access method is not btree
+            return false;
+          }
+          return true;
+        },
         select2: {
           allowClear: true, width: 'style', tags: true,
           placeholder: '{{ _("Select the operator class") }}'
@@ -65,6 +80,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                   url: full_url,
                   success: function(res) {
                     data = res.data;
+                    self.column.set('options', data);
                   },
                   error: function() {
                     eventHandler.trigger('pgadmin:view:fetch:error', m, self.column);
@@ -72,18 +88,6 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                 });
                 eventHandler.trigger('pgadmin:view:fetched', m, self.column);
               }
-              /*
-               * Transform the data
-               */
-              transform = self.column.get('transform') || self.defaults.transform;
-              if (transform && _.isFunction(transform)) {
-                // We will transform the data later, when rendering.
-                // It will allow us to generate different data based on the
-                // dependencies.
-                self.column.set('options', transform.bind(self, data));
-              } else {
-                self.column.set('options', data);
-              }
             } else {
               self.column.set('options', []);
             }
@@ -94,49 +98,42 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
         options: {
           onText: 'ASC',
           offText: 'DESC',
-        },editable: function(m) {
+        },
+        editable: function(m) {
           if (m instanceof Backbone.Collection) {
             return true;
-          }
-          else {
-            if (m.top.get('amname') === 'btree') {
-              m.set('is_sort_nulls_applicable', true);
-              return true;
-            }
-            m.set('is_sort_nulls_applicable', false);
-            return false;
-          }
-          if ((_.has(m.collection, 'handler') &&
+          } else if ((_.has(m.collection, 'handler') &&
                 !_.isUndefined(m.collection.handler) &&
                 !_.isUndefined(m.collection.handler.get('oid')))) {
             return false;
+          } else if (m.top.get('amname') === 'btree') {
+            m.set('is_sort_nulls_applicable', true);
+            return true;
+          } else {
+            m.set('is_sort_nulls_applicable', false);
+            return false;
           }
-          return true;
         }
       },{
         id: 'nulls_order', label:'{{ _('NULLs order') }}', type:"switch",
         options: {
           onText: 'FIRST',
           offText: 'LAST',
-        },editable: function(m) {
+        },
+        editable: function(m) {
           if (m instanceof Backbone.Collection) {
             return true;
-          }
-          else {
-            if (m.top.get('amname') === 'btree') {
+          } else if ((_.has(m.collection, 'handler') &&
+                !_.isUndefined(m.collection.handler) &&
+                !_.isUndefined(m.collection.handler.get('oid')))) {
+            return false;
+          } else if (m.top.get('amname') === 'btree') {
               m.set('is_sort_nulls_applicable', true);
               return true;
-            }
+          } else {
             m.set('is_sort_nulls_applicable', false);
             return false;
           }
-
-          if ((_.has(m.collection, 'handler') &&
-                !_.isUndefined(m.collection.handler) &&
-                !_.isUndefined(m.collection.handler.get('oid')))) {
-            return false;
-          }
-          return true;
         }
       },{
         id: 'operator', label:'{{ _('Operator') }}', type: 'text',
@@ -184,6 +181,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                   url: full_url,
                   success: function(res) {
                     data = res.data;
+                    self.column.set('options', data);
                   },
                   error: function() {
                     eventHandler.trigger('pgadmin:view:fetch:error', m, self.column);
@@ -191,18 +189,6 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                 });
                 eventHandler.trigger('pgadmin:view:fetched', m, self.column);
               }
-              /*
-               * Transform the data
-               */
-              transform = self.column.get('transform') || self.defaults.transform;
-              if (transform && _.isFunction(transform)) {
-                // We will transform the data later, when rendering.
-                // It will allow us to generate different data based on the
-                // dependencies.
-                self.column.set('options', transform.bind(self, data));
-              } else {
-                self.column.set('options', data);
-              }
             }
           }
         })
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 249fbaf..e19d054 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
@@ -84,7 +84,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             editable: function(m) {
                 // Header cell then skip
                 if (m instanceof Backbone.Collection) {
-                    return false;
+                  return false;
+                } else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
+                  return false;
                 }
                 return !(m.checkAccessMethod.apply(this, arguments));
             },
@@ -114,12 +116,12 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
               // Header cell then skip
               if (m instanceof Backbone.Collection) {
                   return false;
-              }
-              else {
-                if (m.top.get('amname') === 'btree') {
-                  m.set('is_sort_nulls_applicable', true);
-                  return true;
-                }
+              } else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
+                  return false;
+              } else if (m.top.get('amname') === 'btree') {
+                m.set('is_sort_nulls_applicable', true);
+                return true;
+              } else {
                 m.set('is_sort_nulls_applicable', false);
                 return false;
               }
@@ -136,14 +138,15 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             editable: function(m) {
               // Header cell then skip
               if (m instanceof Backbone.Collection) {
-                  return true;
-              } else {
-                  if (m.top.get('amname') === 'btree') {
-                    m.set('is_sort_nulls_applicable', true);
-                    return true;
-                  }
-                  m.set('is_sort_nulls_applicable', false);
                   return false;
+              } else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
+                  return false;
+              } else if (m.top.get('amname') === 'btree') {
+                m.set('is_sort_nulls_applicable', true);
+                return true;
+              } else {
+                m.set('is_sort_nulls_applicable', false);
+                return false;
               }
             },
             deps: ['amname', 'sort_order'],
@@ -187,11 +190,10 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
         checkAccessMethod: function(m) {
         //Access method is empty or btree then do not disable field
           var parent_model = m.top;
-          if(!m.inSchemaWithModelCheck.apply(this, [m]) &&
-              (_.isUndefined(parent_model.get('amname')) ||
+          if(_.isUndefined(parent_model.get('amname')) ||
                _.isNull(parent_model.get('amname')) ||
                String(parent_model.get('amname')).replace(/^\s+|\s+$/g, '') == '' ||
-               parent_model.get('amname') === 'btree')) {
+               parent_model.get('amname') === 'btree') {
             // We need to set nulls to true if sort_order is set to desc
             // nulls first is default for desc
             if(m.get('sort_order') == true && m.previous('sort_order') ==  false) {
@@ -202,7 +204,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             m.set('is_sort_nulls_applicable', false);
           }
           return false;
-        },
+        }
     });
 
   if (!pgBrowser.Nodes['index']) {


-- 
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_2113.diff (10.2K, 3-RM_2113.diff)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js
index eee9ad2..5972c51 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js
@@ -24,7 +24,22 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
       },{
         id: 'oper_class', label:'{{ _('Operator class') }}', type:'text',
         node: 'table', url: 'get_oper_class', first_empty: true,
-        editable: true,
+        editable: function(m) {
+          if (m instanceof Backbone.Collection) {
+            return true;
+          } else if ((_.has(m.collection, 'handler') &&
+                !_.isUndefined(m.collection.handler) &&
+                !_.isUndefined(m.collection.handler.get('oid')))) {
+            return false;
+          } else if (_.has(m.collection, 'handler') &&
+                !_.isUndefined(m.collection.handler) &&
+                !_.isUndefined(m.collection.handler.get('amname')) &&
+                m.collection.handler.get('amname') != 'btree') {
+            // Disable if access method is not btree
+            return false;
+          }
+          return true;
+        },
         select2: {
           allowClear: true, width: 'style', tags: true,
           placeholder: '{{ _("Select the operator class") }}'
@@ -65,6 +80,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                   url: full_url,
                   success: function(res) {
                     data = res.data;
+                    self.column.set('options', data);
                   },
                   error: function() {
                     eventHandler.trigger('pgadmin:view:fetch:error', m, self.column);
@@ -72,18 +88,6 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                 });
                 eventHandler.trigger('pgadmin:view:fetched', m, self.column);
               }
-              /*
-               * Transform the data
-               */
-              transform = self.column.get('transform') || self.defaults.transform;
-              if (transform && _.isFunction(transform)) {
-                // We will transform the data later, when rendering.
-                // It will allow us to generate different data based on the
-                // dependencies.
-                self.column.set('options', transform.bind(self, data));
-              } else {
-                self.column.set('options', data);
-              }
             } else {
               self.column.set('options', []);
             }
@@ -94,49 +98,42 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
         options: {
           onText: 'ASC',
           offText: 'DESC',
-        },editable: function(m) {
+        },
+        editable: function(m) {
           if (m instanceof Backbone.Collection) {
             return true;
-          }
-          else {
-            if (m.top.get('amname') === 'btree') {
-              m.set('is_sort_nulls_applicable', true);
-              return true;
-            }
-            m.set('is_sort_nulls_applicable', false);
-            return false;
-          }
-          if ((_.has(m.collection, 'handler') &&
+          } else if ((_.has(m.collection, 'handler') &&
                 !_.isUndefined(m.collection.handler) &&
                 !_.isUndefined(m.collection.handler.get('oid')))) {
             return false;
+          } else if (m.top.get('amname') === 'btree') {
+            m.set('is_sort_nulls_applicable', true);
+            return true;
+          } else {
+            m.set('is_sort_nulls_applicable', false);
+            return false;
           }
-          return true;
         }
       },{
         id: 'nulls_order', label:'{{ _('NULLs order') }}', type:"switch",
         options: {
           onText: 'FIRST',
           offText: 'LAST',
-        },editable: function(m) {
+        },
+        editable: function(m) {
           if (m instanceof Backbone.Collection) {
             return true;
-          }
-          else {
-            if (m.top.get('amname') === 'btree') {
+          } else if ((_.has(m.collection, 'handler') &&
+                !_.isUndefined(m.collection.handler) &&
+                !_.isUndefined(m.collection.handler.get('oid')))) {
+            return false;
+          } else if (m.top.get('amname') === 'btree') {
               m.set('is_sort_nulls_applicable', true);
               return true;
-            }
+          } else {
             m.set('is_sort_nulls_applicable', false);
             return false;
           }
-
-          if ((_.has(m.collection, 'handler') &&
-                !_.isUndefined(m.collection.handler) &&
-                !_.isUndefined(m.collection.handler.get('oid')))) {
-            return false;
-          }
-          return true;
         }
       },{
         id: 'operator', label:'{{ _('Operator') }}', type: 'text',
@@ -184,6 +181,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                   url: full_url,
                   success: function(res) {
                     data = res.data;
+                    self.column.set('options', data);
                   },
                   error: function() {
                     eventHandler.trigger('pgadmin:view:fetch:error', m, self.column);
@@ -191,18 +189,6 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
                 });
                 eventHandler.trigger('pgadmin:view:fetched', m, self.column);
               }
-              /*
-               * Transform the data
-               */
-              transform = self.column.get('transform') || self.defaults.transform;
-              if (transform && _.isFunction(transform)) {
-                // We will transform the data later, when rendering.
-                // It will allow us to generate different data based on the
-                // dependencies.
-                self.column.set('options', transform.bind(self, data));
-              } else {
-                self.column.set('options', data);
-              }
             }
           }
         })
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 249fbaf..e19d054 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
@@ -84,7 +84,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             editable: function(m) {
                 // Header cell then skip
                 if (m instanceof Backbone.Collection) {
-                    return false;
+                  return false;
+                } else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
+                  return false;
                 }
                 return !(m.checkAccessMethod.apply(this, arguments));
             },
@@ -114,12 +116,12 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
               // Header cell then skip
               if (m instanceof Backbone.Collection) {
                   return false;
-              }
-              else {
-                if (m.top.get('amname') === 'btree') {
-                  m.set('is_sort_nulls_applicable', true);
-                  return true;
-                }
+              } else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
+                  return false;
+              } else if (m.top.get('amname') === 'btree') {
+                m.set('is_sort_nulls_applicable', true);
+                return true;
+              } else {
                 m.set('is_sort_nulls_applicable', false);
                 return false;
               }
@@ -136,14 +138,15 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             editable: function(m) {
               // Header cell then skip
               if (m instanceof Backbone.Collection) {
-                  return true;
-              } else {
-                  if (m.top.get('amname') === 'btree') {
-                    m.set('is_sort_nulls_applicable', true);
-                    return true;
-                  }
-                  m.set('is_sort_nulls_applicable', false);
                   return false;
+              } else if (m.inSchemaWithModelCheck.apply(this, arguments)) {
+                  return false;
+              } else if (m.top.get('amname') === 'btree') {
+                m.set('is_sort_nulls_applicable', true);
+                return true;
+              } else {
+                m.set('is_sort_nulls_applicable', false);
+                return false;
               }
             },
             deps: ['amname', 'sort_order'],
@@ -187,11 +190,10 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
         checkAccessMethod: function(m) {
         //Access method is empty or btree then do not disable field
           var parent_model = m.top;
-          if(!m.inSchemaWithModelCheck.apply(this, [m]) &&
-              (_.isUndefined(parent_model.get('amname')) ||
+          if(_.isUndefined(parent_model.get('amname')) ||
                _.isNull(parent_model.get('amname')) ||
                String(parent_model.get('amname')).replace(/^\s+|\s+$/g, '') == '' ||
-               parent_model.get('amname') === 'btree')) {
+               parent_model.get('amname') === 'btree') {
             // We need to set nulls to true if sort_order is set to desc
             // nulls first is default for desc
             if(m.get('sort_order') == true && m.previous('sort_order') ==  false) {
@@ -202,7 +204,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             m.set('is_sort_nulls_applicable', false);
           }
           return false;
-        },
+        }
     });
 
   if (!pgBrowser.Nodes['index']) {


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

* Re: [pgAdmin4][PATCH] To fix the issue in index or exclusion contrarians node
@ 2017-06-06 10:16  Dave Page <[email protected]>
  parent: Murtuza Zabuawala <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

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

Thanks applied.

On Wed, May 31, 2017 at 1:31 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi,
>
> PFA patch to fix the issue in index or exclusion contrarians node where it
> was throwing "can't execute an empty query" error due to incorrect
> validation logic for edit mode.
> RM#2113
>
> --
> 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-06-06 10:16 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-31 12:31 [pgAdmin4][PATCH] To fix the issue in index or exclusion contrarians node Murtuza Zabuawala <[email protected]>
2017-06-06 10:16 ` 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