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 2015/05/26 02:12:48 UTC

[13/19] chukwa git commit: CHUKWA-746. Redesigned Chukwa dashboard. (Eric Yang)

http://git-wip-us.apache.org/repos/asf/chukwa/blob/dfe84a2c/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
new file mode 100755
index 0000000..22a6e52
--- /dev/null
+++ b/src/main/web/hicc/home/index.html
@@ -0,0 +1,290 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<!DOCTYPE html>
+<html lang="en" class="no-js">
+  <head>
+    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
+    <meta http-equiv="Pragma" content="no-cache" />
+    <meta http-equiv="Expires" content="0" />
+    <meta charset="UTF-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
+    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
+    <title>Chukwa</title>
+    <link rel="shortcut icon" href="../favicon.ico">
+    <link rel="stylesheet" type="text/css" href="css/normalize.css" />
+    <link rel="stylesheet" type="text/css" href="css/jquery.gridster.css" />
+    <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/jquery.gridster.js" type="text/javascript" charset="utf-8"></script>
+    <script src="js/typeahead.bundle.js" type="text/javascript"></script>
+  </head>
+  <body>
+    <div id="glass" class="glass" onclick="toggleGlass()"></div>
+    <div class="frame">
+      <ul><li><iframe id="frame"></iframe></li></ul>
+    </div>
+
+		<div class="container">
+			<ul id="gn-menu" class="gn-menu-main">
+				<li class="gn-trigger">
+					<a class="gn-icon gn-icon-menu"><span>Menu</span></a>
+					<nav class="gn-menu-wrapper">
+						<div class="gn-scroller">
+							<ul class="gn-menu">
+								<li class="gn-search-item">
+									<input placeholder="Search" id="url" type="search" class="gn-search">
+									<a class="gn-icon gn-icon-search"><span>Search</span></a>
+								</li>
+								<li><a class="gn-icon gn-icon-illustrator" onclick="setDashboard('default')">User Activities</a></li>
+								<li><a class="gn-icon gn-icon-article" onclick="setDashboard('system')">System Activities</a></li>
+								<li><a class="gn-icon gn-icon-pictures" onclick="showFrame('graph-explorer.html')">Graph Explorer</a></li>
+								<li><a class="gn-icon gn-icon-cog" onclick="showFrame('settings')">Settings</a></li>
+								<li><a class="gn-icon gn-icon-help" onclick="showFrame('help')">Help</a></li>
+							</ul>
+						</div><!-- /gn-scroller -->
+					</nav>
+				</li>
+				<li><a href="index.html">Chukwa</a></li>
+				<li>
+                                    <div class="toggle-btn-grp">
+                                      <div><input type="radio" name="period" value="last1hr" onclick="setTime()" /><label class="toggle-btn">H</label></div>
+                                      <div><input type="radio" name="period" value="last24hr" onclick="setTime()" /><label class="toggle-btn">D</label></div>
+                                      <div><input type="radio" name="period" value="last30d" onclick="setTime()" /><label class="toggle-btn">M</label></div>
+                                      <div><input type="radio" name="period" value="lastyear" onclick="setTime()" /><label class="toggle-btn">Y</label></div>
+                                    </div>
+                                </li>
+                                <li><span id="username"></span></li>
+                                <li><a class="gn-icon-poweroff" onclick="logout()"><span> </span></a></li>
+			</ul>
+		</div><!-- /container -->
+  <div class="gridster">
+    <ul/>
+  </div>
+
+		<script src="js/classie.js"></script>
+		<script src="js/gnmenu.js"></script>
+		<script>
+
+var dashboard = 'default';
+var widgets = [];
+var widgetsToUrl = {};
+var grid_data = [];
+
+var substringMatcher = function(strs) {
+  return function findMatches(q, cb) {
+    var matches, substrRegex;
+
+    // an array that will be populated with substring matches
+    matches = [];
+
+    // regex used to determine if a string contains the substring `q`
+    substrRegex = new RegExp(q, 'i');
+
+    // iterate through the pool of strings and for any string that
+    // contains the substring `q`, add it to the `matches` array
+    $.each(strs, function(i, str) {
+      if (substrRegex.test(str)) {
+        // the typeahead jQuery plugin expects suggestions to a
+        // JavaScript object, refer to typeahead docs for more info
+        matches.push({ value: str });
+      }
+    });
+
+    cb(matches);
+  };
+};
+
+function toggleGlass() {
+  $('#glass').toggle();
+}
+
+// Load dashboard
+function load() {
+  $.getJSON('/hicc/v1/dashboard/load/'+dashboard,
+    function(data) {
+      grid_data = data.grid;
+      grid_data = Gridster.sort_by_row_and_col_asc(grid_data);
+      var overlay_fix_start = function() {
+        $('.overlay_fix').show();
+      }
+
+      var overlay_fix_stop = function() {
+        $('.overlay_fix').hide();
+        save();
+      };
+      var gridster = $(".gridster ul").gridster({
+        widget_margins: [10, 10],
+        widget_base_dimensions: [140, 140],
+        autogrow_cols: true,
+	max_cols: 9,
+        limit: true,
+        draggable: {
+          handle: 'header',
+          start: overlay_fix_start,
+          stop: overlay_fix_stop
+        },
+        resize: {
+          enabled: true,
+          start: overlay_fix_start,
+          stop: overlay_fix_stop
+        },
+        header: {
+          enabled: true
+        }
+      });
+
+      $.each(grid_data, function() {
+        var gridster = $(".gridster ul").gridster().data('gridster');
+        gridster.add_widget(this.src,
+          this.size_x,
+          this.size_y,
+          this.col,
+          this.row);
+      });
+    }
+  );
+
+  // Update searchable widget list
+  $.getJSON('/hicc/v1/widget/list',
+    function(data) {
+      widgets.length = 0;
+      widgetsToUrl.length = 0;
+      $.each( data, function( i, kv ) {
+        widgets.push(kv.title); 
+        widgetsToUrl[kv.title] = kv.src;
+      });
+
+      $('#url').typeahead({
+        hint: true,
+        highlight: true,
+        minLength: 1
+      },
+      {
+        name: 'widgets',
+        displayKey: 'value',
+        source: substringMatcher(widgets)
+      });
+    }
+  );
+
+}
+
+// Save Dashboard
+function save() {
+  var gridster = $(".gridster ul").gridster().data('gridster');
+  var s = gridster.serialize();
+  var data = { "grid" : s };
+  $.ajax({
+    url: '/hicc/v1/dashboard/save/'+dashboard,
+    type: 'PUT',
+    contentType: 'application/json',
+    data: JSON.stringify(data),
+  });
+}
+
+function setDashboard(value) {
+  dashboard = value;
+  var data = { dashboard : value };
+  $.ajax({
+    url: '/hicc/v1/session/save',
+    type: 'PUT',
+    contentType: 'application/json',
+    data: JSON.stringify(data)
+  });
+  var gridster = $(".gridster ul").gridster().data('gridster');
+  gridster.remove_all_widgets();
+  load();
+  showGrid();
+}
+
+function showGrid() {
+  $(".frame").hide();
+  $(".gridster ul").show();
+}
+
+function showFrame(target) {
+  $("#frame").attr("src", target);
+  $(".frame").show();
+  $(".gridster ul").hide();
+  gnMenu._closeMenu();
+}
+
+var gnMenu = new gnMenu( document.getElementById( 'gn-menu' ) );
+$(function(){ //DOM Ready
+
+$.getJSON('/hicc/v1/session/key/period',
+  function(data) {
+    var value = (data['period'] == null) ? "last1hr" : data['period'];
+    $("input[name=period][value=" + value + "]").attr('checked', 'checked');
+  }
+);
+
+$( "#url" ).keydown(function( event ) {
+  if ( event.which == 13 ) {
+    event.preventDefault();
+    var title = $('#url').val();
+    if(title in widgetsToUrl) {
+      var url = widgetsToUrl[title];
+      var gridster = $(".gridster ul").gridster().data('gridster');
+      gridster.add_widget(url, 1, 1, 1, 1);
+      setTimeout(function(){ save(); }, 3000);
+    }
+  }
+});
+
+$.ajax({
+    url: '/hicc/v1/dashboard/whoami',
+    cache: false
+  }).done(function( html ) {
+    $('#username').append(html);
+  });
+
+$.getJSON('/hicc/v1/session/key/dashboard',
+  function(data) {
+    var value = (data['dashboard'] == null) ? "default" : data['dashboard'];
+    dashboard = value;
+    load();
+  }
+);
+
+});
+
+function setTime() {
+  var data = {};
+  data['period'] = $('input[name=period]:checked').val();
+  console.log(data);
+  $.ajax({
+    url: '/hicc/v1/session/save',
+    type: 'PUT',
+    contentType: 'application/json',
+    data: JSON.stringify(data)
+  });
+}
+
+function logout() {
+  $.ajax({
+    url: '/hicc/logout',
+    success: function(data) {
+      document.cookie = 'JSESSIONID=;path=/hicc;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
+      window.location.assign("/hicc/login.jsp");
+    }
+  });
+}
+    </script>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/chukwa/blob/dfe84a2c/src/main/web/hicc/home/js/classie.js
----------------------------------------------------------------------
diff --git a/src/main/web/hicc/home/js/classie.js b/src/main/web/hicc/home/js/classie.js
new file mode 100755
index 0000000..a967554
--- /dev/null
+++ b/src/main/web/hicc/home/js/classie.js
@@ -0,0 +1,80 @@
+/*!
+ * classie - class helper functions
+ * from bonzo https://github.com/ded/bonzo
+ * 
+ * classie.has( elem, 'my-class' ) -> true/false
+ * classie.add( elem, 'my-new-class' )
+ * classie.remove( elem, 'my-unwanted-class' )
+ * classie.toggle( elem, 'my-class' )
+ */
+
+/*jshint browser: true, strict: true, undef: true */
+/*global define: false */
+
+( function( window ) {
+
+'use strict';
+
+// class helper functions from bonzo https://github.com/ded/bonzo
+
+function classReg( className ) {
+  return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
+}
+
+// classList support for class management
+// altho to be fair, the api sucks because it won't accept multiple classes at once
+var hasClass, addClass, removeClass;
+
+if ( 'classList' in document.documentElement ) {
+  hasClass = function( elem, c ) {
+    return elem.classList.contains( c );
+  };
+  addClass = function( elem, c ) {
+    elem.classList.add( c );
+  };
+  removeClass = function( elem, c ) {
+    elem.classList.remove( c );
+  };
+}
+else {
+  hasClass = function( elem, c ) {
+    return classReg( c ).test( elem.className );
+  };
+  addClass = function( elem, c ) {
+    if ( !hasClass( elem, c ) ) {
+      elem.className = elem.className + ' ' + c;
+    }
+  };
+  removeClass = function( elem, c ) {
+    elem.className = elem.className.replace( classReg( c ), ' ' );
+  };
+}
+
+function toggleClass( elem, c ) {
+  var fn = hasClass( elem, c ) ? removeClass : addClass;
+  fn( elem, c );
+}
+
+var classie = {
+  // full names
+  hasClass: hasClass,
+  addClass: addClass,
+  removeClass: removeClass,
+  toggleClass: toggleClass,
+  // short names
+  has: hasClass,
+  add: addClass,
+  remove: removeClass,
+  toggle: toggleClass
+};
+
+// transport
+if ( typeof define === 'function' && define.amd ) {
+  // AMD
+  define( classie );
+} else {
+  // browser global
+  window.classie = classie;
+}
+
+})( window );

http://git-wip-us.apache.org/repos/asf/chukwa/blob/dfe84a2c/src/main/web/hicc/home/js/gnmenu.js
----------------------------------------------------------------------
diff --git a/src/main/web/hicc/home/js/gnmenu.js b/src/main/web/hicc/home/js/gnmenu.js
new file mode 100644
index 0000000..f04a2d5
--- /dev/null
+++ b/src/main/web/hicc/home/js/gnmenu.js
@@ -0,0 +1,94 @@
+/**
+ * gnmenu.js v1.0.0
+ * http://www.codrops.com
+ *
+ * Licensed under the MIT license.
+ * http://www.opensource.org/licenses/mit-license.php
+ * 
+ * Copyright 2013, Codrops
+ * http://www.codrops.com
+ */
+;( function( window ) {
+	
+	'use strict';
+
+	// http://stackoverflow.com/a/11381730/989439
+	function mobilecheck() {
+		var check = false;
+		(function(a){if(/(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kdd
 i|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = tru
 e})(navigator.userAgent||navigator.vendor||window.opera);
+		return check;
+	}
+
+	function gnMenu( el, options ) {	
+		this.el = el;
+		this._init();
+	}
+
+	gnMenu.prototype = {
+		_init : function() {
+			this.trigger = this.el.querySelector( 'a.gn-icon-menu' );
+			this.menu = this.el.querySelector( 'nav.gn-menu-wrapper' );
+			this.isMenuOpen = false;
+			this.eventtype = mobilecheck() ? 'touchstart' : 'click';
+			this._initEvents();
+
+			var self = this;
+			this.bodyClickFn = function() {
+				self._closeMenu();
+				this.removeEventListener( self.eventtype, self.bodyClickFn );
+			};
+		},
+		_initEvents : function() {
+			var self = this;
+
+			if( !mobilecheck() ) {
+				this.trigger.addEventListener( 'mouseover', function(ev) { self._openIconMenu(); } );
+				this.trigger.addEventListener( 'mouseout', function(ev) { self._closeIconMenu(); } );
+			
+				this.menu.addEventListener( 'mouseover', function(ev) {
+					self._openMenu(); 
+					document.addEventListener( self.eventtype, self.bodyClickFn ); 
+				} );
+			}
+			this.trigger.addEventListener( this.eventtype, function( ev ) {
+				ev.stopPropagation();
+				ev.preventDefault();
+				if( self.isMenuOpen ) {
+					self._closeMenu();
+					document.removeEventListener( self.eventtype, self.bodyClickFn );
+				}
+				else {
+					self._openMenu();
+					document.addEventListener( self.eventtype, self.bodyClickFn );
+				}
+			} );
+			this.menu.addEventListener( this.eventtype, function(ev) { ev.stopPropagation(); } );
+		},
+		_openIconMenu : function() {
+			classie.add( this.menu, 'gn-open-part' );
+		},
+		_closeIconMenu : function() {
+			classie.remove( this.menu, 'gn-open-part' );
+		},
+		_openMenu : function() {
+			if( this.isMenuOpen ) return;
+			classie.add( this.trigger, 'gn-selected' );
+			this.isMenuOpen = true;
+			classie.add( this.menu, 'gn-open-all' );
+			this._closeIconMenu();
+			$('#glass').show();
+		},
+		_closeMenu : function() {
+			if( !this.isMenuOpen ) return;
+			classie.remove( this.trigger, 'gn-selected' );
+			this.isMenuOpen = false;
+			classie.remove( this.menu, 'gn-open-all' );
+			this._closeIconMenu();
+			$('#glass').hide();
+		}
+	}
+
+	// add to global namespace
+	window.gnMenu = gnMenu;
+
+} )( window );