public inbox for [email protected]  
help / color / mirror / Atom feed
PATCH: To update table dialog column definition
2+ messages / 2 participants
[nested] [flat]

* PATCH: To update table dialog column definition
@ 2016-07-12 06:00  Murtuza Zabuawala <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Murtuza Zabuawala @ 2016-07-12 06:00 UTC (permalink / raw)
  To: pgadmin-hackers

Hi,

PFA patch to fix below issues

*1) User** cannot select a datatype without using the mouse.*

Fixed.

Remaining issue,
-----------------------
We are using Switch cell to select Not NULL & Is primary key options.
But as per Backgrid design we are not allowed to enter in edit mode
directly for BooleanCell (like we can for NumberCell) from which we are
Inherited our Switch cell, so user have to click once on this cell to go
into edit mode then only they can use keyborad to toggle the values of
switch cell.

I'll check with Ashesh if we can fix this issue.

*2) The Primary Key option in the grid cannot be toggled without opening
advanced options.*

This has been fixed already RM#1235, Once user provides column name it will
gets enable.

*3) Fields are missing from the grid: length, precision, not null.
Inherited from should not be there.*

Fixed


Please review.

--
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


Attachments:

  [application/octet-stream] RM_1394.patch (10.2K, 3-RM_1394.patch)
  download | inline diff:
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 1c5b9f6..cd8fa30 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
@@ -48,6 +48,29 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
     }
   });
 
+  // Integer Cell for Columns Length and Precision
+  var IntegerDepCell = Backgrid.Extension.IntegerDepCell =
+    Backgrid.IntegerCell.extend({
+      initialize: function() {
+        Backgrid.NumberCell.prototype.initialize.apply(this, arguments);
+        Backgrid.Extension.DependentCell.prototype.initialize.apply(this, arguments);
+      },
+      dependentChanged: function () {
+        this.$el.empty();
+        var model = this.model;
+        var column = this.column;
+        editable = this.column.get("editable");
+
+        is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable;
+        if (is_editable){ this.$el.addClass("editable"); }
+        else { this.$el.removeClass("editable"); }
+
+        this.delegateEvents();
+        return this;
+      },
+      remove: Backgrid.Extension.DependentCell.prototype.remove
+    });
+
   if (!pgBrowser.Nodes['column']) {
     pgBrowser.Nodes['column'] = pgBrowser.Node.extend({
       parent_type: ['table', 'view', 'mview'],
@@ -132,7 +155,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
           edit_types: undefined,
           is_primary_key: false,
           inheritedfrom: undefined,
-          attstattarget:undefined
+          attstattarget:undefined,
+          attnotnull: false
         },
         schema: [{
           id: 'name', label: '{{ _('Name') }}', cell: 'string',
@@ -144,10 +168,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
           // [in SubNode control]
           id: 'is_primary_key', label: '{{ _('Is primary key?') }}',
           cell: Backgrid.Extension.SwitchDepCell, type: 'switch', deps:['name'],
-          options: {
-            onText: 'Yes', offText: 'No', onColor: 'success',
-            offColor: 'primary', size: 'small'},
-          cellHeaderClasses:'width_percent_5',
+          cellHeaderClasses:'width_percent_10',
           visible: function(m) {
             return _.isUndefined(m.top.node_info['table'] || m.top.node_info['view'] || m.top.node_info['mview']);
           },
@@ -193,7 +214,25 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
           id: 'attnum', label:'{{ _('Position') }}', cell: 'string',
           type: 'text', disabled: 'notInSchema', mode: ['properties']
         },{
-          id: 'cltype', label:'{{ _('Data type') }}', cell: 'node-ajax-options',
+          id: 'cltype', label:'{{ _('Data type') }}',
+          cell: Backgrid.Extension.NodeAjaxOptionsCell.extend({
+            exitEditMode: function(e) {
+                this.$select.off('blur', this.exitEditMode);
+                this.$select.select2('close');
+                this.$el.removeClass('editor');
+                // Once user have selected a value
+                // we can shift to next cell if it is editable
+                var el_length_cell = this.$el.next();
+                if(el_length_cell && el_length_cell.hasClass('editable') && e) {
+                      e.preventDefault();
+                      e.stopPropagation();
+                      var command = new Backgrid.Command({key: "Tab", keyCode: 9, which: 9});
+                      this.model.trigger("backgrid:edited", this.model, this.column,
+                                        command);
+                      el_length_cell.focus();
+                }
+            }
+          }),
           type: 'text', disabled: 'inSchemaWithColumnCheck',
           control: 'node-ajax-options', url: 'get_types', node: 'table',
           cellHeaderClasses:'width_percent_30', first_empty: true,
@@ -248,13 +287,13 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
           // Need to show this field only when creating new table [in SubNode control]
           id: 'inheritedfrom', label: '{{ _('Inherited from table') }}',
           type: 'text', disabled: true, editable: false,
-          cellHeaderClasses:'width_percent_30',
+          cellHeaderClasses:'width_percent_10',
           visible: function(m) {
             return _.isUndefined(m.top.node_info['table'] || m.top.node_info['view'] || m.top.node_info['mview']);
           }
         },{
-          id: 'attlen', label:'{{ _('Length') }}', cell: 'string',
-           deps: ['cltype'], type: 'int', group: '{{ _('Definition') }}',
+          id: 'attlen', label:'{{ _('Length') }}', cell: IntegerDepCell,
+           deps: ['cltype'], type: 'int', group: '{{ _('Definition') }}', cellHeaderClasses:'width_percent_20',
            disabled: function(m) {
              var of_type = m.get('cltype'),
                flag = true;
@@ -276,10 +315,36 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
                 },10);
 
               return flag;
+           },
+           editable: function(m) {
+             // inheritedfrom has value then we should disable it
+             if(!_.isUndefined(m.get('inheritedfrom'))) {
+                return false;
+             }
+             var of_type = m.get('cltype'),
+               flag = false;
+              _.each(m.datatypes, function(o) {
+                if ( of_type == o.value ) {
+                    if(o.length)
+                    {
+                      m.set('min_val', o.min_val, {silent: true});
+                      m.set('max_val', o.max_val, {silent: true});
+                      flag = true;
+                    }
+                }
+              });
+
+              !flag && setTimeout(function() {
+                  if(m.get('attlen')) {
+                    m.set('attlen', null);
+                  }
+                },10);
+
+              return flag;
            }
         },{
-          id: 'attprecision', label:'{{ _('Precision') }}', cell: 'string',
-           deps: ['cltype'], type: 'int', group: '{{ _('Definition') }}',
+          id: 'attprecision', label:'{{ _('Precision') }}', cell: IntegerDepCell,
+           deps: ['cltype'], type: 'int', group: '{{ _('Definition') }}', cellHeaderClasses:'width_percent_20',
            disabled: function(m) {
              var of_type = m.get('cltype'),
                flag = true;
@@ -300,6 +365,33 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
                 }
               },10);
               return flag;
+           },
+           editable: function(m) {
+             // inheritedfrom has value then we should disable it
+             if(!_.isUndefined(m.get('inheritedfrom'))) {
+                return false;
+             }
+
+             var of_type = m.get('cltype'),
+               flag = false;
+              _.each(m.datatypes, function(o) {
+                if ( of_type == o.value ) {
+                    if(o.precision)
+                    {
+                      m.set('min_val', o.min_val, {silent: true});
+                      m.set('max_val', o.max_val, {silent: true});
+                      flag = true;
+                    }
+                }
+              });
+
+              !flag && setTimeout(function() {
+                if(m.get('attprecision')) {
+                  m.set('attprecision', null);
+                }
+              },10);
+
+              return flag;
            }
          },{
           id: 'collspcname', label:'{{ _('Collation') }}', cell: 'string',
@@ -336,9 +428,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
             }
           }
         },{
-          id: 'attnotnull', label:'{{ _('Not NULL?') }}', cell: 'string',
-          type: 'switch', disabled: 'inSchemaWithColumnCheck',
-          group: '{{ _('Definition') }}'
+          id: 'attnotnull', label:'{{ _('Not NULL?') }}', cell: 'switch',
+          type: 'switch', disabled: 'inSchemaWithColumnCheck', cellHeaderClasses:'width_percent_20',
+          group: '{{ _('Definition') }}', editable: 'editable_check_for_table'
         },{
           id: 'attstattarget', label:'{{ _('Statistics') }}', cell: 'string',
           type: 'text', disabled: 'inSchemaWithColumnCheck', mode: ['properties', 'edit'],
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/js/table.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/js/table.js
index ab16f4a..95464fe 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/js/table.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/js/table.js
@@ -427,7 +427,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           canEditRow: 'check_grid_row_edit_delete',
           canDeleteRow: 'check_grid_row_edit_delete',
           uniqueCol : ['name'],
-          columns : ['name' , 'cltype', 'is_primary_key', 'inheritedfrom'],
+          columns : ['name' , 'cltype', 'attlen', 'attprecision', 'attnotnull', 'is_primary_key'],
           control: Backform.UniqueColCollectionControl.extend({
             initialize: function() {
               Backform.UniqueColCollectionControl.prototype.initialize.apply(this, arguments);
diff --git a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
index 51c4199..ccb5e76 100644
--- a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
+++ b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
@@ -407,11 +407,13 @@
       if (!this.$el.hasClass('editor'))
         this.$el.addClass('editor');
       this.$select.select2('focus');
+      this.$select.select2('open');
       this.$select.on('blur', this.exitEditMode);
     },
 
     exitEditMode: function() {
       this.$select.off('blur', this.exitEditMode);
+      this.$select.select2('close');
       this.$el.removeClass('editor');
     },
 
@@ -539,7 +541,7 @@
       }
       this.$el.empty();
       Backgrid.SelectCell.prototype.remove.apply(this, arguments);
-     }
+    }
   });
 
   /**


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

* Re: PATCH: To update table dialog column definition
@ 2016-07-15 09:12  Dave Page <[email protected]>
  parent: Murtuza Zabuawala <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2016-07-15 09:12 UTC (permalink / raw)
  To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied with minor changes to the labelling of the switches in the grid.

On Tue, Jul 12, 2016 at 7:00 AM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi,
>
> PFA patch to fix below issues
>
> 1) User cannot select a datatype without using the mouse.
>
> Fixed.
>
> Remaining issue,
> -----------------------
> We are using Switch cell to select Not NULL & Is primary key options.
> But as per Backgrid design we are not allowed to enter in edit mode directly
> for BooleanCell (like we can for NumberCell) from which we are Inherited our
> Switch cell, so user have to click once on this cell to go into edit mode
> then only they can use keyborad to toggle the values of switch cell.
>
> I'll check with Ashesh if we can fix this issue.
>
> 2) The Primary Key option in the grid cannot be toggled without opening
> advanced options.
>
> This has been fixed already RM#1235, Once user provides column name it will
> gets enable.
>
> 3) Fields are missing from the grid: length, precision, not null. Inherited
> from should not be there.
>
> Fixed
>
>
> Please review.
>
> --
> 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:[~2016-07-15 09:12 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12 06:00 PATCH: To update table dialog column definition Murtuza Zabuawala <[email protected]>
2016-07-15 09:12 ` 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