Repository: storm
Updated Branches:
  refs/heads/1.x-branch 14595f385 -> 38ccb3e10


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/cef93ec4
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/cef93ec4
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/cef93ec4

Branch: refs/heads/1.x-branch
Commit: cef93ec4f1dd99045a674e4936ea189ed4aab085
Parents: 14595f3
Author: Alessandro Bellina <abell...@yahoo-inc.com>
Authored: Thu Sep 1 08:10:45 2016 -0500
Committer: Jungtaek Lim <kabh...@gmail.com>
Committed: Fri Sep 23 11:13:56 2016 +0900

----------------------------------------------------------------------
 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/cef93ec4/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 fcdd75a..326a8df 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);
@@ -391,25 +392,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();
         }
     });
 
@@ -421,6 +425,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