public inbox for [email protected]  
help / color / mirror / Atom feed
pgAdmin 4 commit: Improve handling of nulls and default values in the d
6+ messages / 3 participants
[nested] [flat]

* pgAdmin 4 commit: Improve handling of nulls and default values in the d
@ 2017-05-12 09:54  Dave Page <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Dave Page @ 2017-05-12 09:54 UTC (permalink / raw)
  To: pgadmin-hackers

Improve handling of nulls and default values in the data editor. Fixes #2257

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=4f9628ed436de53b1ab1a06b123755a86a8f...
Author: Surinder Kumar <[email protected]>

Modified Files
--------------
.../tables/templates/column/sql/9.2_plus/nodes.sql |  3 +-
.../tables/templates/column/sql/default/nodes.sql  |  3 +-
web/pgadmin/static/css/pgadmin.css                 |  2 +-
.../static/js/slickgrid/slick.pgadmin.editors.js   | 39 +++++++++++++++---
.../js/slickgrid/slick.pgadmin.formatters.js       | 46 ++++++++++++++++------
web/pgadmin/tools/sqleditor/__init__.py            | 25 +++++++++++-
web/pgadmin/tools/sqleditor/command.py             | 30 +++++++++++++-
.../tools/sqleditor/static/css/sqleditor.css       | 12 +++++-
.../sqleditor/templates/sqleditor/js/sqleditor.js  | 28 ++++++++++++-
9 files changed, 163 insertions(+), 25 deletions(-)


-- 
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] 6+ messages in thread

* Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
@ 2017-05-12 11:19  Harshal Dhumal <[email protected]>
  parent: Dave Page <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Harshal Dhumal @ 2017-05-12 11:19 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi,

Below code snippet from above commit assumes that we have to disable last
row after saving.

@@ -2320,6
<https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
+2340,10
<https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
@@ define(
                       grid.setSelectedRows([]);
                     }

+                    // Add last row(new row) to keep track of it
+                    if (is_added) {
+                      self.rows_to_disable.push(grid.getDataLength()-1);
+                    }

 However this is not the case all the time

For e.g
Table has some data already and If user adds new row (do not save) and then
copy past few exiting rows (at this point  newly added row no longer
remains at last position). And after saving it disable last row which is
not the newly added row.








-- 
*Harshal Dhumal*
*Sr. Software Engineer*

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

On Fri, May 12, 2017 at 3:24 PM, Dave Page <[email protected]> wrote:

> Improve handling of nulls and default values in the data editor. Fixes
> #2257
>
> Branch
> ------
> master
>
> Details
> -------
> https://git.postgresql.org/gitweb?p=pgadmin4.git;a=commitdiff;h=
> 4f9628ed436de53b1ab1a06b123755a86a8f2288
> Author: Surinder Kumar <[email protected]>
>
> Modified Files
> --------------
> .../tables/templates/column/sql/9.2_plus/nodes.sql |  3 +-
> .../tables/templates/column/sql/default/nodes.sql  |  3 +-
> web/pgadmin/static/css/pgadmin.css                 |  2 +-
> .../static/js/slickgrid/slick.pgadmin.editors.js   | 39 +++++++++++++++---
> .../js/slickgrid/slick.pgadmin.formatters.js       | 46
> ++++++++++++++++------
> web/pgadmin/tools/sqleditor/__init__.py            | 25 +++++++++++-
> web/pgadmin/tools/sqleditor/command.py             | 30 +++++++++++++-
> .../tools/sqleditor/static/css/sqleditor.css       | 12 +++++-
> .../sqleditor/templates/sqleditor/js/sqleditor.js  | 28 ++++++++++++-
> 9 files changed, 163 insertions(+), 25 deletions(-)
>
>
> --
> 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] 6+ messages in thread

* Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
@ 2017-05-12 11:30  Dave Page <[email protected]>
  parent: Harshal Dhumal <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Dave Page @ 2017-05-12 11:30 UTC (permalink / raw)
  To: Harshal Dhumal <[email protected]>; +Cc: pgadmin-hackers

On Fri, May 12, 2017 at 12:19 PM, Harshal Dhumal <
[email protected]> wrote:

> Hi,
>
> Below code snippet from above commit assumes that we have to disable last
> row after saving.
>
> @@ -2320,6
> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
> +2340,10
> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
> @@ define(
>                        grid.setSelectedRows([]);
>                      }
>
> +                    // Add last row(new row) to keep track of it
> +                    if (is_added) {
> +                      self.rows_to_disable.push(grid.getDataLength()-1);
> +                    }
>
>  However this is not the case all the time
>
> For e.g
> Table has some data already and If user adds new row (do not save) and
> then copy past few exiting rows (at this point  newly added row no longer
> remains at last position). And after saving it disable last row which is
> not the newly added row.
>

Hmm, good point. Can you/Surinder work up a fix for that in time for the
release please?

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

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


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

* Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
@ 2017-05-12 11:49  Surinder Kumar <[email protected]>
  parent: Dave Page <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Surinder Kumar @ 2017-05-12 11:49 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: Harshal Dhumal <[email protected]>; pgadmin-hackers

On Fri, May 12, 2017 at 5:00 PM, Dave Page <[email protected]> wrote:

>
>
> On Fri, May 12, 2017 at 12:19 PM, Harshal Dhumal <
> [email protected]> wrote:
>
>> Hi,
>>
>> Below code snippet from above commit assumes that we have to disable last
>> row after saving.
>>
>> @@ -2320,6
>> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
>> +2340,10
>> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
>> @@ define(
>>                        grid.setSelectedRows([]);
>>                      }
>>
>> +                    // Add last row(new row) to keep track of it
>> +                    if (is_added) {
>> +                      self.rows_to_disable.push(grid.getDataLength()-1);
>> +                    }
>>
>>  However this is not the case all the time
>>
>> For e.g
>> Table has some data already and If user adds new row (do not save) and
>> then copy past few exiting rows (at this point  newly added row no longer
>> remains at last position). And after saving it disable last row which is
>> not the newly added row.
>>
>
> Hmm, good point. Can you/Surinder work up a fix for that in time for the
> release please?
>
​Sure Dave, I am working on it.​

>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


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

* Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
@ 2017-05-12 14:20  Surinder Kumar <[email protected]>
  parent: Surinder Kumar <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Surinder Kumar @ 2017-05-12 14:20 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: Harshal Dhumal <[email protected]>; pgadmin-hackers

Hi Dave,

Please find attached patch and review.

Also, I found an issue <https://redmine.postgresql.org/issues/2399; which
logged and will work on it.

On Fri, May 12, 2017 at 5:19 PM, Surinder Kumar <
[email protected]> wrote:

> On Fri, May 12, 2017 at 5:00 PM, Dave Page <[email protected]> wrote:
>
>>
>>
>> On Fri, May 12, 2017 at 12:19 PM, Harshal Dhumal <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>> Below code snippet from above commit assumes that we have to disable
>>> last row after saving.
>>>
>>> @@ -2320,6
>>> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
>>> +2340,10
>>> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
>>> @@ define(
>>>                        grid.setSelectedRows([]);
>>>                      }
>>>
>>> +                    // Add last row(new row) to keep track of it
>>> +                    if (is_added) {
>>> +                      self.rows_to_disable.push(grid.getDat
>>> aLength()-1);
>>> +                    }
>>>
>>>  However this is not the case all the time
>>>
>>> For e.g
>>> Table has some data already and If user adds new row (do not save) and
>>> then copy past few exiting rows (at this point  newly added row no longer
>>> remains at last position). And after saving it disable last row which is
>>> not the newly added row.
>>>
>>
>> Hmm, good point. Can you/Surinder work up a fix for that in time for the
>> release please?
>>
> ​Sure Dave, I am working on it.​
>
>>
>> --
>> 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


Attachments:

  [application/octet-stream] fix_disable_row_after_paste_row.patch (3.8K, 3-fix_disable_row_after_paste_row.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index ba9dd43..57caa76 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -822,6 +822,25 @@ define(
           $("#btn-save").prop('disabled', false);
         }.bind(editor_data));
 
+
+        // Listener function which will be called after cell is changed
+        grid.onActiveCellChanged.subscribe(function (e, args) {
+          // Access to row/cell value after a cell is changed.
+          // The purpose is to remove row_id from temp_new_row
+          // if new row has primary key instead of [default_value]
+          // so that cell edit is enabled for that row.
+          var grid = args.grid,
+            row_data = grid.getDataItem(args.row),
+            primary_key = row_data && row_data[0];
+
+          if (!_.isUndefined(primary_key)) {
+            var index = self.handler.temp_new_rows.indexOf(args.row);
+            if (index > -1) {
+              self.handler.temp_new_rows.splice(index, 1);
+            }
+          }
+        });
+
         // Listener function which will be called when user adds new rows
         grid.onAddNewRow.subscribe(function (e, args) {
           // self.handler.data_store.added will holds all the newly added rows/data
@@ -829,6 +848,11 @@ define(
             column = args.column,
             item = args.item, data_length = this.grid.getDataLength();
 
+          // Add new row in list to keep track of it
+          if (_.isUndefined(item[0])) {
+            self.handler.temp_new_rows.push(data_length);
+          }
+
           if(item) {
             item.__temp_PK = _key;
           }
@@ -1647,6 +1671,8 @@ define(
           self._init_polling_flags();
           // keep track of newly added rows
           self.rows_to_disable = new Array();
+          // Temporarily hold new rows added
+          self.temp_new_rows = new Array();
 
           self.trigger(
             'pgadmin-sqleditor:loading-icon:show',
@@ -2340,10 +2366,15 @@ define(
                       grid.setSelectedRows([]);
                     }
 
-                    // Add last row(new row) to keep track of it
+                    // whether a cell is editable or not is decided in
+                    // grid.onBeforeEditCell function (on cell click)
+                    // but this function should do its job after save
+                    // operation. So assign list of added rows to original
+                    // rows_to_disable array.
                     if (is_added) {
-                      self.rows_to_disable.push(grid.getDataLength()-1);
+                       self.rows_to_disable = _.clone(self.temp_new_rows);
                     }
+
                     // Reset data store
                     self.data_store = {
                       'added': {},
@@ -2370,6 +2401,12 @@ define(
                       (!_.isUndefined(res.data._rowid)|| !_.isNull(res.data._rowid))) {
                     var _row_index = self._find_rowindex(res.data._rowid);
                     if(_row_index in self.data_store.added_index) {
+                      // Remove new row index from temp_list if save operation
+                      // fails
+                      var index = self.handler.temp_new_rows.indexOf(_rowid);
+                      if (index > -1) {
+                         self.handler.temp_new_rows.splice(index, 1);
+                      }
                      self.data_store.added[self.data_store.added_index[_row_index]].err = true
                     } else if (_row_index in self.data_store.updated_index) {
                      self.data_store.updated[self.data_store.updated_index[_row_index]].err = true


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

* Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
@ 2017-05-12 15:49  Dave Page <[email protected]>
  parent: Surinder Kumar <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Dave Page @ 2017-05-12 15:49 UTC (permalink / raw)
  To: Surinder Kumar <[email protected]>; +Cc: Harshal Dhumal <[email protected]>; pgadmin-hackers

Hi

On Fri, May 12, 2017 at 3:20 PM, Surinder Kumar <
[email protected]> wrote:

> Hi Dave,
>
> Please find attached patch and review.
>

Thanks, committed.


>
> Also, I found an issue <https://redmine.postgresql.org/issues/2399; which
> logged and will work on it.
>

Yes, I also saw that, though I found the colour was lost on paste, not
save. I also found another issue -
https://redmine.postgresql.org/issues/2400. Can you fix that too please?

Thanks.



>
> On Fri, May 12, 2017 at 5:19 PM, Surinder Kumar <
> [email protected]> wrote:
>
>> On Fri, May 12, 2017 at 5:00 PM, Dave Page <[email protected]> wrote:
>>
>>>
>>>
>>> On Fri, May 12, 2017 at 12:19 PM, Harshal Dhumal <
>>> [email protected]> wrote:
>>>
>>>> Hi,
>>>>
>>>> Below code snippet from above commit assumes that we have to disable
>>>> last row after saving.
>>>>
>>>> @@ -2320,6
>>>> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
>>>> +2340,10
>>>> <https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=blob;f=web/pgadmin/tools/sqleditor/templates/sql...;
>>>> @@ define(
>>>>                        grid.setSelectedRows([]);
>>>>                      }
>>>>
>>>> +                    // Add last row(new row) to keep track of it
>>>> +                    if (is_added) {
>>>> +                      self.rows_to_disable.push(grid.getDat
>>>> aLength()-1);
>>>> +                    }
>>>>
>>>>  However this is not the case all the time
>>>>
>>>> For e.g
>>>> Table has some data already and If user adds new row (do not save) and
>>>> then copy past few exiting rows (at this point  newly added row no longer
>>>> remains at last position). And after saving it disable last row which is
>>>> not the newly added row.
>>>>
>>>
>>> Hmm, good point. Can you/Surinder work up a fix for that in time for the
>>> release please?
>>>
>> ​Sure Dave, I am working on it.​
>>
>>>
>>> --
>>> Dave Page
>>> Blog: http://pgsnake.blogspot.com
>>> Twitter: @pgsnake
>>>
>>> EnterpriseDB UK: http://www.enterprisedb.com
>>> The Enterprise PostgreSQL Company
>>>
>>
>>
>


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

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


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


end of thread, other threads:[~2017-05-12 15:49 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-12 09:54 pgAdmin 4 commit: Improve handling of nulls and default values in the d Dave Page <[email protected]>
2017-05-12 11:19 ` Harshal Dhumal <[email protected]>
2017-05-12 11:30   ` Dave Page <[email protected]>
2017-05-12 11:49     ` Surinder Kumar <[email protected]>
2017-05-12 14:20       ` Surinder Kumar <[email protected]>
2017-05-12 15:49         ` 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