You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@chukwa.apache.org by ey...@apache.org on 2016/11/12 22:00:06 UTC

[2/2] chukwa git commit: CHUKWA-812. Added throttle to dashboard save. (Eric Yang)

CHUKWA-812.  Added throttle to dashboard save. (Eric Yang)


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

Branch: refs/heads/master
Commit: fcfcc088b61a262f81876e24ecce854e13cbd6c1
Parents: 20be5ae
Author: Eric Yang <ey...@apache.org>
Authored: Sat Nov 12 13:59:47 2016 -0800
Committer: Eric Yang <ey...@apache.org>
Committed: Sat Nov 12 13:59:47 2016 -0800

----------------------------------------------------------------------
 CHANGES.txt                           |  2 ++
 src/main/web/hicc/home/index.html     | 10 +++++-----
 src/main/web/hicc/home/js/throttle.js | 22 ++++++++++++++++++++++
 3 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/chukwa/blob/fcfcc088/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 44a5350..c7372d2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,8 @@ Trunk (unreleased changes)
 
   BUGS
 
+    CHUKWA-812.  Added throttle to dashboard save. (Eric Yang)
+
 Release 0.8 - 05/22/2016
 
   IMPROVEMENTS

http://git-wip-us.apache.org/repos/asf/chukwa/blob/fcfcc088/src/main/web/hicc/home/index.html
----------------------------------------------------------------------
diff --git a/src/main/web/hicc/home/index.html b/src/main/web/hicc/home/index.html
index aefe260..412a3ba 100755
--- a/src/main/web/hicc/home/index.html
+++ b/src/main/web/hicc/home/index.html
@@ -32,6 +32,7 @@
     <link rel="stylesheet" type="text/css" href="css/component.css" />
     <script src="js/modernizr.custom.js"></script>
     <script src="js/jquery.js" type="text/javascript"></script>
+    <script src="js/throttle.js" type="text/javascript"></script>
     <script src="js/jquery-ui.js"></script>
     <script src="js/lodash.min.js" type="text/javascript"></script>
     <script src="js/gridstack.min.js" type="text/javascript"></script>
@@ -207,11 +208,6 @@ function load() {
         gridstack.addWidget(buildWidget(this.src), this.col, this.row, this.size_x, this.size_y);
 
       });
-      // Bind save operation only after load operation has been
-      // completed to avoid race conditions.
-      $('.grid-stack').on('change', function(event, ui) {
-        save();
-      });
     }
   );
 
@@ -343,6 +339,10 @@ $(function(){ //DOM Ready
     }
   );
 
+  $('.grid-stack').on('change', throttle(function(event, ui) {
+    save();
+  }, 250));
+
 });
 
 function setTime() {

http://git-wip-us.apache.org/repos/asf/chukwa/blob/fcfcc088/src/main/web/hicc/home/js/throttle.js
----------------------------------------------------------------------
diff --git a/src/main/web/hicc/home/js/throttle.js b/src/main/web/hicc/home/js/throttle.js
new file mode 100644
index 0000000..f8f7ff0
--- /dev/null
+++ b/src/main/web/hicc/home/js/throttle.js
@@ -0,0 +1,22 @@
+function throttle(fn, threshhold, scope) {
+  threshhold || (threshhold = 250);
+  var last,
+      deferTimer;
+  return function () {
+    var context = scope || this;
+
+    var now = +new Date,
+        args = arguments;
+    if (last && now < last + threshhold) {
+      // hold on to it
+      clearTimeout(deferTimer);
+      deferTimer = setTimeout(function () {
+        last = now;
+        fn.apply(context, args);
+      }, threshhold);
+    } else {
+      last = now;
+      fn.apply(context, args);
+    }
+  };
+}