public inbox for [email protected]
help / color / mirror / Atom feedFrom: Surinder Kumar <[email protected]>
To: Dave Page <[email protected]>
Cc: Harshal Dhumal <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
Date: Fri, 12 May 2017 19:50:28 +0530
Message-ID: <CAM5-9D9CHN7BRcaL1-qCSJ7859Yh2PE93-mJMGCi7Z-QMZ2yVA@mail.gmail.com> (raw)
In-Reply-To: <CAM5-9D8X_YDaj15VyM-YN_37Bgg1LASk=-3TmZe3Dwzd8-bdcQ@mail.gmail.com>
References: <[email protected]>
<CAFiP3vz0Gxnj9oexauxkVttZx5_su2PqEXnqN1OPKTgB_mOT-g@mail.gmail.com>
<CA+OCxoydonNXGzXe5LrzGG+XSisEcYDhOTENe0F3hd5xjmERww@mail.gmail.com>
<CAM5-9D8X_YDaj15VyM-YN_37Bgg1LASk=-3TmZe3Dwzd8-bdcQ@mail.gmail.com>
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-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
view thread (6+ 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], [email protected], [email protected]
Subject: Re: pgAdmin 4 commit: Improve handling of nulls and default values in the d
In-Reply-To: <CAM5-9D9CHN7BRcaL1-qCSJ7859Yh2PE93-mJMGCi7Z-QMZ2yVA@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