Repository: storm
Updated Branches:
  refs/heads/master eb02edeaa -> d2ca97f3e


STORM-2078: enable paging in worker datatable


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/3cfa00eb
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/3cfa00eb
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/3cfa00eb

Branch: refs/heads/master
Commit: 3cfa00eb2cf1b3c56c9904cf7fc76cb3c5384086
Parents: 97f0cba
Author: Alessandro Bellina <abell...@yahoo-inc.com>
Authored: Thu Sep 1 08:10:45 2016 -0500
Committer: Alessandro Bellina <abell...@yahoo-inc.com>
Committed: Thu Sep 1 09:13:52 2016 -0500

----------------------------------------------------------------------
 storm-core/src/ui/public/js/script.js | 37 +++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/3cfa00eb/storm-core/src/ui/public/js/script.js
----------------------------------------------------------------------
diff --git a/storm-core/src/ui/public/js/script.js 
b/storm-core/src/ui/public/js/script.js
index ad739a5..5f312d0 100644
--- a/storm-core/src/ui/public/js/script.js
+++ b/storm-core/src/ui/public/js/script.js
@@ -54,8 +54,9 @@ $.extend( $.fn.dataTableExt.oSort, {
     }
 });
 
+var minEntriesToShowPagination = 20;
 function dtAutoPage(selector, conf) {
-  if ($(selector.concat(" tr")).length <= 20) {
+  if ($(selector.concat(" tr")).length <= minEntriesToShowPagination) {
     $.extend(conf, {paging: false});
   }
   return $(selector).DataTable(conf);
@@ -389,25 +390,28 @@ var makeWorkerStatsTable = function (response, elId, 
parentId, type) {
             break;
     }
 
-    var workerStatsTable = dtAutoPage(elId, {
+    var initializeComponents = function (){
+        var show = $.cookies.get("showComponents") || false;
+
+        // toggle all components visibile/invisible
+        $(elId + ' tr').each(function (){
+            var dt = $(elId).dataTable();
+            showComponents(dt.api().row(this), show);
+        });
+    };
+
+    var pagingEnabled = response && response.workers && 
+                            response.workers.length > 
minEntriesToShowPagination;
+
+    var workerStatsTable = $(elId).DataTable({
+        paging: pagingEnabled,
         data: response.workers,
         autoWidth: false,
         columns: columns,
         initComplete: function (){
             // add a "Toggle Components" button
             renderToggleComponents ($(elId + '_filter'), elId);
-            var show = $.cookies.get("showComponents") || false;
-
-            // if the cookie is false, then we are done
-            if (!show) {
-                return;
-            }
-
-            // toggle all components visibile
-            $(elId + ' tr').each(function (){
-                var dt = $(elId).dataTable();
-                showComponents(dt.api().row(this), true);
-            });
+            initializeComponents();
         }
     });
 
@@ -419,6 +423,11 @@ var makeWorkerStatsTable = function (response, elId, 
parentId, type) {
         showComponents(row, !row.child.isShown());
     });
 
+    $(elId + '_paginate').on('click', function(){
+        // when we change pages, re-initialize components
+        initializeComponents();
+    });
+
     $(parentId + ' #toggle-on-components-btn').on('click', 'input', function 
(){
         toggleComponents(elId);
     });

Reply via email to