Re: [pgAdmin4][Patch]: Switching between Tabs resets table viewport to first row in gird - Query tool

2017-11-23 Thread Dave Page
Thanks, applied.

On Thu, Nov 23, 2017 at 8:03 AM, Murtuza Zabuawala <
murtuza.zabuaw...@enterprisedb.com> wrote:

> Hi Dave,
>
> PFA updated patch.
>
>
> On Wed, Nov 22, 2017 at 10:26 PM, Dave Page  wrote:
>
>> Hi
>>
>> On Wed, Nov 22, 2017 at 3:18 PM, Murtuza Zabuawala <
>> murtuza.zabuaw...@enterprisedb.com> wrote:
>>
>>> Hi,
>>>
>>> PFA patch to fix the issue where while switching the tabs in query tool
>>> resets the position of the table viewport to the first row.
>>> RM#2875
>>>
>>> *Steps:*
>>> 1) Open query tool
>>> 2) Execute:
>>> select * from generate_series(1, 1000) as "column-1";
>>> 3) Scroll till the End OR till ~250 row
>>> 4) Click on 'Explain' Tab
>>> 5) Go back to 'Data output' Tab
>>>
>>
>> Hmm, minor issue; each time I return the to data tab, the data moves up
>> two rows! It's almost like it's calculating the viewport taking into
>> account the row header (e.g. row 250 is visible immediate below the
>> header), but then re-positioning without taking it into account (e.g. row
>> 250 is aligned with the top of the row header, thus making row 252 the
>> first visible one).
>>
> ​Fixed.​
>
>
>>
>> --
>> 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


Re: [pgAdmin4][Patch]: Switching between Tabs resets table viewport to first row in gird - Query tool

2017-11-23 Thread Murtuza Zabuawala
Hi Dave,

PFA updated patch.


On Wed, Nov 22, 2017 at 10:26 PM, Dave Page  wrote:

> Hi
>
> On Wed, Nov 22, 2017 at 3:18 PM, Murtuza Zabuawala  enterprisedb.com> wrote:
>
>> Hi,
>>
>> PFA patch to fix the issue where while switching the tabs in query tool
>> resets the position of the table viewport to the first row.
>> RM#2875
>>
>> *Steps:*
>> 1) Open query tool
>> 2) Execute:
>> select * from generate_series(1, 1000) as "column-1";
>> 3) Scroll till the End OR till ~250 row
>> 4) Click on 'Explain' Tab
>> 5) Go back to 'Data output' Tab
>>
>
> Hmm, minor issue; each time I return the to data tab, the data moves up
> two rows! It's almost like it's calculating the viewport taking into
> account the row header (e.g. row 250 is visible immediate below the
> header), but then re-positioning without taking it into account (e.g. row
> 250 is aligned with the top of the row header, thus making row 252 the
> first visible one).
>
​Fixed.​


>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js 
b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index ba0ce67..f3d4267 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -917,7 +917,8 @@ define('tools.querytool', [
   // fetch asynchronous
   setTimeout(self.fetch_next.bind(self));
 }
-  })
+  });
+
   // Resize SlickGrid when window resize
   $(window).resize(function () {
 // Resize grid only when 'Data Output' panel is visible.
@@ -1025,9 +1026,36 @@ define('tools.querytool', [
 
 /* This function is responsible to render output grid */
 grid_resize: function (grid) {
-  var h = $($('#editor-panel').find('.wcFrame')[1]).height() - 35;
-  $('#datagrid').css({'height': h + 'px'});
+  var prev_height = $('#datagrid').height(),
+h = $($('#editor-panel').find('.wcFrame')[1]).height() - 35,
+prev_viewport = grid.getViewport(),
+prev_viewport_rows = grid.getRenderedRange(),
+prev_cell = grid.getActiveCell();
+
+  // Apply css only if necessary, To avoid DOM operation
+  if (prev_height != h) {
+$('#datagrid').css({'height': h + 'px'});
+  }
+
   grid.resizeCanvas();
+
+  /*
+   * If there is an active cell from user then we have to go to that cell
+   */
+  if(prev_cell) {
+grid.scrollCellIntoView(prev_cell.row, prev_cell.cell);
+  }
+
+  // If already displaying from first row
+  if (prev_viewport.top == prev_viewport_rows.top) {
+return
+  }
+  // if user has scroll to the end/last row
+  else if (prev_viewport.bottom - 2 == prev_viewport_rows.bottom) {
+grid.scrollRowIntoView(prev_viewport.bottom);
+  } else {
+grid.scrollRowIntoView(prev_viewport.bottom - 2);
+  }
 },
 
 /* This function is responsible to create and render the


Re: [pgAdmin4][Patch]: Switching between Tabs resets table viewport to first row in gird - Query tool

2017-11-22 Thread Dave Page
Hi

On Wed, Nov 22, 2017 at 3:18 PM, Murtuza Zabuawala <
murtuza.zabuaw...@enterprisedb.com> wrote:

> Hi,
>
> PFA patch to fix the issue where while switching the tabs in query tool
> resets the position of the table viewport to the first row.
> RM#2875
>
> *Steps:*
> 1) Open query tool
> 2) Execute:
> select * from generate_series(1, 1000) as "column-1";
> 3) Scroll till the End OR till ~250 row
> 4) Click on 'Explain' Tab
> 5) Go back to 'Data output' Tab
>

Hmm, minor issue; each time I return the to data tab, the data moves up two
rows! It's almost like it's calculating the viewport taking into account
the row header (e.g. row 250 is visible immediate below the header), but
then re-positioning without taking it into account (e.g. row 250 is aligned
with the top of the row header, thus making row 252 the first visible one).

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

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


[pgAdmin4][Patch]: Switching between Tabs resets table viewport to first row in gird - Query tool

2017-11-22 Thread Murtuza Zabuawala
Hi,

PFA patch to fix the issue where while switching the tabs in query tool
resets the position of the table viewport to the first row.
RM#2875

*Steps:*
1) Open query tool
2) Execute:
select * from generate_series(1, 1000) as "column-1";
3) Scroll till the End OR till ~250 row
4) Click on 'Explain' Tab
5) Go back to 'Data output' Tab


--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js 
b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 9a0c3de..df9e980 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -914,7 +914,8 @@ define('tools.querytool', [
   // fetch asynchronous
   setTimeout(self.fetch_next.bind(self));
 }
-  })
+  });
+
   // Resize SlickGrid when window resize
   $(window).resize(function () {
 // Resize grid only when 'Data Output' panel is visible.
@@ -1022,9 +1023,31 @@ define('tools.querytool', [
 
 /* This function is responsible to render output grid */
 grid_resize: function (grid) {
-  var h = $($('#editor-panel').find('.wcFrame')[1]).height() - 35;
-  $('#datagrid').css({'height': h + 'px'});
+  var prev_height = $('#datagrid').height(),
+h = $($('#editor-panel').find('.wcFrame')[1]).height() - 35,
+prev_viewport = grid.getViewport(),
+prev_cell = grid.getActiveCell();
+
+  // Apply css only if necessary, To avoid DOM operation
+  if (prev_height != h) {
+$('#datagrid').css({'height': h + 'px'});
+  }
+
   grid.resizeCanvas();
+
+  /*
+   * Lets scroll to previously displayed rows
+   * If there is an active cell from user then we have to go to that cell
+   */
+  if(prev_cell) {
+grid.scrollCellIntoView(prev_cell.row, prev_cell.cell);
+  } else {
+/*
+ * Display approximate viewport but we do not have any exact cell 
information
+ * to display so we will start displaying from first column only
+ */
+grid.scrollRowIntoView(prev_viewport.bottom)
+  }
 },
 
 /* This function is responsible to create and render the