[ARVADOS] updated: 9ad6d61c1576b604b936eb981683941078d79d8e

git at public.curoverse.com git at public.curoverse.com
Wed Oct 29 07:20:13 EDT 2014


Summary of changes:
 .../app/assets/javascripts/infinite_scroll.js      | 64 ++++++++++++++++++----
 .../app/views/projects/_show_tab_contents.html.erb |  4 +-
 2 files changed, 54 insertions(+), 14 deletions(-)

       via  9ad6d61c1576b604b936eb981683941078d79d8e (commit)
      from  d0e60c70302c1b7ec84110cad0545924605c95bb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 9ad6d61c1576b604b936eb981683941078d79d8e
Author: Phil Hodgson <bitbucket at philhodgson.net>
Date:   Wed Oct 29 12:20:08 2014 +0100

    3618: store in the browser history state the current sort settings for each tab

diff --git a/apps/workbench/app/assets/javascripts/infinite_scroll.js b/apps/workbench/app/assets/javascripts/infinite_scroll.js
index 67a7b52..b5255fb 100644
--- a/apps/workbench/app/assets/javascripts/infinite_scroll.js
+++ b/apps/workbench/app/assets/javascripts/infinite_scroll.js
@@ -147,6 +147,27 @@ function mergeInfiniteContentParams($container) {
     return params;
 }
 
+function setColumnSort( $container, $header, direction ) {
+    // $container should be the tbody or whatever has all the infinite table data attributes
+    // $header should be the th with a preset data-sort-order attribute
+    // direction should be "asc" or "desc"
+    // This function returns the order by clause for this column header as a string
+
+    // First reset all sort directions
+    $('th[data-sort-order]').removeData('sort-order-direction');
+    // set the current one
+    $header.data('sort-order-direction', direction);
+    // change the ordering parameter
+    var paramsAttr = 'infinite-content-params-' + $container.data('infinite-content-params-attr');
+    var params = $container.data(paramsAttr) || {};
+    params.order = $header.data('sort-order').split(",").join( ' ' + direction + ', ' ) + ' ' + direction;
+    $container.data(paramsAttr, params);
+    // show the right icon next to the column header
+    $container.trigger('sortIcons');
+
+    return params.order;
+}
+
 $(document).
     on('click', 'div.infinite-retry button', function() {
         var $retry_div = $(this).closest('.infinite-retry');
@@ -174,6 +195,20 @@ $(document).
                 return;
             $(this).addClass('infinite-scroller-ready');
 
+            // deal with sorting if was set on this page for this tab already
+            var tabId = $(this).closest('div.tab-pane').attr('id');
+            if( typeof(history.state.order) !== 'undefined' && typeof(history.state.order[tabId]) !== 'undefined' ) {
+                // we will use the list of one or more table columns associated with this header to find the right element
+                // see sortable_columns as it is passed to render_pane in the various tab .erbs (e.g. _show_jobs_and_pipelines.html.erb)
+                var strippedColumns = history.state.order[tabId].replace(/\s|asc|desc/g,'');
+                var sortDirection = history.state.order[tabId].split(" ")[1].replace(/,/,'');
+                $columnHeader = $(this).closest('table').find('[data-sort-order="'+ strippedColumns +'"]');
+                setColumnSort( $(this), $columnHeader, sortDirection );
+            } else {
+                // otherwise just reset the sort icons
+                $(this).trigger('sortIcons');
+            }
+
             // $scroller is the DOM element that hears "scroll"
             // events: sometimes it's a div, sometimes it's
             // window. Here, "this" is the DOM element containing the
@@ -197,19 +232,24 @@ $(document).
         } else {
             direction = 'desc';
         }
-        // reset all sort directions
-        $('th[data-sort-order]').removeData('sort-order-direction');
-        // set the current one
-        $(this).data('sort-order-direction', direction);
-        // change the ordering parameter and refresh the data display with the new order
-        var $target = $(this).closest('table').find('[data-infinite-content-params-attr]');
-        var params_attr = 'infinite-content-params-' + $target.data('infinite-content-params-attr');
-        var params = $target.data(params_attr) || {};
-        params.order = $(this).data('sort-order').split(",").join( ' ' + direction + ', ' ) + ' ' + direction;
-        $target.data(params_attr, params);
-        $target.trigger('refresh-content');
+
+        var $container = $(this).closest('table').find('[data-infinite-content-params-attr]');
+
+        var order = setColumnSort( $container, $(this), direction );
+
+        // put it in the browser history state
+        var tabId = $(this).closest('div.tab-pane').attr('id');
+        var state =  history.state;
+        if( typeof(state.order) === 'undefined') {
+            state.order = {};
+        }
+        state.order[tabId] = order;
+        history.replaceState( state, null, null );
+
+        $container.trigger('refresh-content');
     }).
-    on('ready arv:pane:loaded refresh-content', function() {
+    on('sortIcons', function() {
+        // set or reset the icon next to each sortable column header according to the current direction attribute
         $('th[data-sort-order]').each(function() {
             $(this).find('i').remove();
             var direction = $(this).data('sort-order-direction');
diff --git a/apps/workbench/app/views/projects/_show_tab_contents.html.erb b/apps/workbench/app/views/projects/_show_tab_contents.html.erb
index 0382d4f..a3ca3d1 100644
--- a/apps/workbench/app/views/projects/_show_tab_contents.html.erb
+++ b/apps/workbench/app/views/projects/_show_tab_contents.html.erb
@@ -84,13 +84,13 @@
         <th></th>
         <th></th>
         <th></th>
-        <% sort_order = sortable_columns['name'] %>
+        <% sort_order = sortable_columns['name'].gsub(/\s/,'') %>
         <th <% if !sort_order.nil? %>
               data-sort-order='<%= sort_order %>'
             <% end %> >
           name
         </th>
-        <% sort_order = sortable_columns['description'] %>
+        <% sort_order = sortable_columns['description'].gsub(/\s/,'') %>
         <th <% if !sort_order.nil? %>
               data-sort-order='<%= sort_order %>'
             <% end %> >

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list