incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject git commit: Started a refactor of how the js files are organized
Date Fri, 30 May 2014 02:19:21 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/console-v2 7b6d5e8dc -> de24dc21f


Started a refactor of how the js files are organized


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

Branch: refs/heads/console-v2
Commit: de24dc21f871311919e76bdb79ef920a473efc6e
Parents: 7b6d5e8
Author: Chris Rohr <rohr.chris@gmail.com>
Authored: Thu May 29 22:19:07 2014 -0400
Committer: Chris Rohr <rohr.chris@gmail.com>
Committed: Thu May 29 22:19:07 2014 -0400

----------------------------------------------------------------------
 .../src/main/webapp/js/blurconsole.b_utils.js   |  19 +--
 .../src/main/webapp/js/blurconsole.dashboard.js | 166 ++++++++++---------
 .../src/main/webapp/js/blurconsole.data.js      |  51 +++---
 3 files changed, 120 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de24dc21/contrib/blur-console/src/main/webapp/js/blurconsole.b_utils.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.b_utils.js b/contrib/blur-console/src/main/webapp/js/blurconsole.b_utils.js
index 1903782..8ffd146 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.b_utils.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.b_utils.js
@@ -20,9 +20,8 @@ under the License.
 /*global blurconsole:false */
 blurconsole.browserUtils = (function(){
 	'use strict';
-	var table, modal, cleanId, booleanImg;
 
-	table = function(def, data) {
+	function table(def, data) {
 		var tableMarkup;
 
 		tableMarkup = '<table class="table table-bordered table-condensed table-hover table-striped"><thead><tr>';
@@ -55,9 +54,9 @@ blurconsole.browserUtils = (function(){
 
 		tableMarkup += '</tbody></table>';
 		return tableMarkup;
-	};
+	}
 
-	modal = function(id, title, content, buttons, size) {
+	function modal(id, title, content, buttons, size) {
 		var mSize, markup, mButtons = buttons;
 
 		switch(size) {
@@ -91,7 +90,7 @@ blurconsole.browserUtils = (function(){
 						markup += 'data-' + key + '="' + dataAttr + '" ';
 					});
 				}
-				
+
 				markup += '>' + button.label + '</button> ';
 			});
 			markup += '</div>';
@@ -100,18 +99,18 @@ blurconsole.browserUtils = (function(){
 		markup += '</div></div></div>';
 
 		return markup;
-	};
+	}
 
-	cleanId = function(str) {
+	function cleanId(str) {
 		return str.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '_');
-	};
+	}
 
-	booleanImg = function(val) {
+	function booleanImg(val) {
 		if (val && (val === true || val === 'yes' || val === 'true')) {
 			return '<div class="label label-success"><i class="glyphicon glyphicon-ok-sign"></i></div>';
 		}
 		return '<div class="label label-danger"><i class="glyphicon glyphicon-minus-sign"></i></div>';
-	};
+	}
 
 	return {
 		table: table,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de24dc21/contrib/blur-console/src/main/webapp/js/blurconsole.dashboard.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.dashboard.js b/contrib/blur-console/src/main/webapp/js/blurconsole.dashboard.js
index 965d151..005645f 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.dashboard.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.dashboard.js
@@ -25,6 +25,7 @@ under the License.
 /*global blurconsole:false */
 blurconsole.dashboard = (function () {
 	'use strict';
+	//------------------- Configuration and State -------------------------
 	var
 		configMap = {
 			view: 'views/dashboard.tpl.html',
@@ -54,12 +55,10 @@ blurconsole.dashboard = (function () {
 			zookeeperNodes: 'chart',
 			controllerNodes: 'chart'
 		},
-		jqueryMap = {},
-		setJqueryMap, initModule, unloadModule, updateNodeCharts, adjustChartsSizes, adjustChartSize,
-		loadZkPieChart,	loadControllerPieChart, loadShardsPieChart, loadTableColumnChart, loadQueryPerfLineChart,
-		buildNodeTable, checkForSlowQueries, updateAllCharts;
+		jqueryMap = {};
 
-	setJqueryMap = function() {
+	//--------------------- Utilities ---------------------
+	function _setJqueryMap() {
 		var $container = stateMap.$container;
 		jqueryMap = {
 			$container : $container,
@@ -71,59 +70,70 @@ blurconsole.dashboard = (function () {
 			$tableChartHolder : $('#tableCounts'),
 			$queryLoadChartHolder : $('#queryLoad')
 		};
-	};
+	}
 
-	unloadModule = function() {
-		$.gevent.unsubscribe(jqueryMap.$container, 'node-status-updated');
-		$.gevent.unsubscribe(jqueryMap.$container, 'tables-updated');
-		$.gevent.unsubscribe(jqueryMap.$container, 'query-perf-updated');
-		$.gevent.unsubscribe(jqueryMap.$container, 'queries-updated');
-	};
+	function _registerPageEvents() {
+		$(document).on('click', '.swapper-trigger', _swapNodeChartAndData);
+		$(window).on('resize', _adjustChartsSizes);
+	}
 
-	updateAllCharts = function() {
-		updateNodeCharts();
-		loadTableColumnChart();
-		loadQueryPerfLineChart();
-	};
+	function _unregisterPageEvents() {
+		$(document).off('click', '.swapper-trigger');
+		$(window).off('resize');
+	}
+
+	//----------------------- Event Handlers and DOM Modifiers ------------------
+	function _updateAllCharts() {
+		_updateNodeCharts();
+		_loadTableColumnChart();
+		_loadQueryPerfLineChart();
+	}
 
-	updateNodeCharts = function() {
+	function _updateNodeCharts() {
 		if (blurconsole.model.nodes.isDataLoaded()) {
-			loadZkPieChart();
-			loadControllerPieChart();
-			loadShardsPieChart();
+			_loadZkPieChart();
+			_loadControllerPieChart();
+			_loadShardsPieChart();
 		}
-	};
+	}
+
+	function _swapNodeChartAndData(evt) {
+		var parent = $(evt.currentTarget).closest('div.swapper-parent');
+		var chart = parent.find('.swapper-chart');
+		var info = parent.find('.swapper-info');
 
-	loadZkPieChart = function() {
+		chart.toggleClass('hidden');
+		info.toggleClass('hidden');
+	}
+
+	function _loadZkPieChart() {
 		$.plot(jqueryMap.$zkChartHolder, blurconsole.model.metrics.getZookeeperChartData(), configMap.pieOptions);
-		jqueryMap.$zkInfoHolder.html(buildNodeTable(blurconsole.model.nodes.getOnlineZookeeperNodes(),
blurconsole.model.nodes.getOfflineZookeeperNodes()));
-	};
+		jqueryMap.$zkInfoHolder.html(_buildNodeTable(blurconsole.model.nodes.getOnlineZookeeperNodes(),
blurconsole.model.nodes.getOfflineZookeeperNodes()));
+	}
 
-	loadControllerPieChart = function() {
+	function _loadControllerPieChart() {
 		$.plot(jqueryMap.$controllerChartHolder, blurconsole.model.metrics.getControllerChartData(),
configMap.pieOptions);
-		jqueryMap.$controllerInfoHolder.html(buildNodeTable(blurconsole.model.nodes.getOnlineControllerNodes(),
blurconsole.model.nodes.getOfflineControllerNodes()));
-	};
+		jqueryMap.$controllerInfoHolder.html(_buildNodeTable(blurconsole.model.nodes.getOnlineControllerNodes(),
blurconsole.model.nodes.getOfflineControllerNodes()));
+	}
 
-	loadShardsPieChart = function() {
+	function _loadShardsPieChart() {
 		if (jqueryMap.$shardChartHolder.find('img').length > 0) {
 			jqueryMap.$shardChartHolder.html('');
 		}
 
 		$.each(blurconsole.model.metrics.getClusters(), function(idx, cluster) {
-			var clusterData, clusterHolder, clusterInfo, parentSize;
-
-			clusterData = blurconsole.model.metrics.getShardChartData(cluster);
+			var clusterData = blurconsole.model.metrics.getShardChartData(cluster);
 
 			if (clusterData) {
-				clusterHolder = jqueryMap.$shardChartHolder.find('#cluster_' + cluster + '_chart_holder');
-				clusterInfo = jqueryMap.$shardChartHolder.find('#cluster_' + cluster + '_info');
+				var clusterHolder = jqueryMap.$shardChartHolder.find('#cluster_' + cluster + '_chart_holder');
+				var clusterInfo = jqueryMap.$shardChartHolder.find('#cluster_' + cluster + '_info');
 
 				if (clusterHolder.length === 0) {
 					var wrapper = $('<div class="swapper-parent"></div>');
 					wrapper.append($('<div class="text-center"><strong>' + cluster + '</strong>
<small class="text-muted"><i class="glyphicon glyphicon-retweet swapper-trigger"
title="Swap Chart/Info"></i></small></div>'));
 					clusterHolder = $('<div id="cluster_'+ cluster + '_chart_holder" class="shardClusterChartHolder
simple-chart swapper-chart"></div>');
 					wrapper.append(clusterHolder);
-					parentSize = jqueryMap.$shardChartHolder.parent()[0].clientWidth - 150;
+					var parentSize = jqueryMap.$shardChartHolder.parent()[0].clientWidth - 150;
 					clusterHolder.css({
 						'height' : parentSize,
 						'width' : parentSize
@@ -135,12 +145,12 @@ blurconsole.dashboard = (function () {
 				}
 
 				$.plot(clusterHolder, clusterData, configMap.pieOptions);
-				clusterInfo.html(buildNodeTable([], blurconsole.model.nodes.getOfflineShardNodes(cluster)));
+				clusterInfo.html(_buildNodeTable([], blurconsole.model.nodes.getOfflineShardNodes(cluster)));
 			}
 		});
-	};
+	}
 
-	loadTableColumnChart = function() {
+	function _loadTableColumnChart() {
 		if (blurconsole.model.tables.isDataLoaded()) {
 			$.plot(jqueryMap.$tableChartHolder, blurconsole.model.metrics.getTableChartData(), {
 				bars : {
@@ -157,9 +167,9 @@ blurconsole.dashboard = (function () {
 				}
 			});
 		}
-	};
+	}
 
-	loadQueryPerfLineChart = function() {
+	function _loadQueryPerfLineChart() {
 		$.plot(jqueryMap.$queryLoadChartHolder, blurconsole.model.metrics.getQueryLoadChartData(),
{
 			series : {
 				shadowSize : 0
@@ -171,9 +181,9 @@ blurconsole.dashboard = (function () {
 				show : false
 			}
 		});
-	};
+	}
 
-	buildNodeTable = function(online, offline) {
+	function _buildNodeTable(online, offline) {
 		var table = '<table class="table table-condensed"><thead><tr><th>Offline
Node</th></tr></thead><tbody>';
 		if (offline.length === 0) {
 			table += '<tr><td>Everything is Online!</td></tr>';
@@ -192,69 +202,67 @@ blurconsole.dashboard = (function () {
 			table += '</tbody></table>';
 		}
 		return $(table);
-	};
+	}
 
-	adjustChartSize = function(holder) {
+	function _adjustChartSize(holder) {
 		var size;
 		size = jqueryMap[holder].parent()[0].clientWidth - 150;
 		jqueryMap[holder].css({
 			'height' : size,
 			'width' : size
 		});
-	};
-
-	adjustChartsSizes = function() {
-		var size, shardCharts;
+	}
 
-		adjustChartSize('$zkChartHolder');
-		adjustChartSize('$controllerChartHolder');
-		adjustChartSize('$tableChartHolder');
-		adjustChartSize('$queryLoadChartHolder');
+	function _adjustChartsSizes() {
+		_adjustChartSize('$zkChartHolder');
+		_adjustChartSize('$controllerChartHolder');
+		_adjustChartSize('$tableChartHolder');
+		_adjustChartSize('$queryLoadChartHolder');
 
-		size = jqueryMap.$shardChartHolder.parent()[0].clientWidth - 150;
-		shardCharts = jqueryMap.$shardChartHolder.find('.shardClusterChartHolder');
+		var size = jqueryMap.$shardChartHolder.parent()[0].clientWidth - 150;
+		var shardCharts = jqueryMap.$shardChartHolder.find('.shardClusterChartHolder');
 		shardCharts.each(function(){
 			$(this).css({
 				'height' : size,
 				'width' : size
 			});
 		});
-		updateAllCharts();
-	};
+		_updateAllCharts();
+	}
 
-	checkForSlowQueries = function() {
+	function _checkForSlowQueries() {
 		if (blurconsole.model.metrics.getSlowQueryWarnings()) {
 			$('#slow-query-warnings').slideDown();
 		} else {
 			$('#slow-query-warnings').slideUp();
 		}
-	};
+	}
 
-	initModule = function( $container ) {
+	//----------------------- Public API ----------------------------
+
+	function initModule( $container ) {
 		$container.load ( configMap.view, function() {
 			stateMap.$container = $container;
-			setJqueryMap();
-			updateAllCharts();
-			checkForSlowQueries();
-			$.gevent.subscribe(jqueryMap.$container, 'node-status-updated', updateNodeCharts);
-			$.gevent.subscribe(jqueryMap.$container, 'tables-updated', loadTableColumnChart);
-			$.gevent.subscribe(jqueryMap.$container, 'query-perf-updated', loadQueryPerfLineChart);
-			$.gevent.subscribe(jqueryMap.$container, 'queries-updated', checkForSlowQueries);
-			adjustChartsSizes();
-			$(document).on('click', '.swapper-trigger', function() {
-			    console.log(this);
-				var parent = $(this).closest('div.swapper-parent');
-				console.log(parent);
-				var chart = parent.find('.swapper-chart');
-				var info = parent.find('.swapper-info');
-
-				chart.toggleClass('hidden');
-				info.toggleClass('hidden');
-			});
+			_setJqueryMap();
+			_updateAllCharts();
+			_checkForSlowQueries();
+			$.gevent.subscribe(jqueryMap.$container, 'node-status-updated', _updateNodeCharts);
+			$.gevent.subscribe(jqueryMap.$container, 'tables-updated', _loadTableColumnChart);
+			$.gevent.subscribe(jqueryMap.$container, 'query-perf-updated', _loadQueryPerfLineChart);
+			$.gevent.subscribe(jqueryMap.$container, 'queries-updated', _checkForSlowQueries);
+			_adjustChartsSizes();
+			_registerPageEvents();
 		});
-		$(window).resize(adjustChartsSizes);
 		return true;
-	};
+	}
+
+	function unloadModule() {
+		$.gevent.unsubscribe(jqueryMap.$container, 'node-status-updated');
+		$.gevent.unsubscribe(jqueryMap.$container, 'tables-updated');
+		$.gevent.unsubscribe(jqueryMap.$container, 'query-perf-updated');
+		$.gevent.unsubscribe(jqueryMap.$container, 'queries-updated');
+		_unregisterPageEvents();
+	}
 
 	return {
 		initModule   : initModule,

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de24dc21/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/webapp/js/blurconsole.data.js b/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
index 54a1024..9710ddc 100644
--- a/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
+++ b/contrib/blur-console/src/main/webapp/js/blurconsole.data.js
@@ -20,34 +20,31 @@ under the License.
 /*global blurconsole:false */
 blurconsole.data = (function() {
 	'use strict';
-	var getTableList, getNodeList, getQueryPerformance, getQueries, cancelQuery, disableTable,
enableTable, deleteTable, getSchema, findTerms, sendSearch,
-		logError;
 
-	getTableList = function(callback) {
+	function getTableList(callback) {
 		$.getJSON('/service/tables', callback).fail(function(xhr) {
 			logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
-	};
+	}
 
-	getNodeList = function(callback) {
+	function getNodeList(callback) {
 		$.getJSON('/service/nodes', callback).fail(function(xhr) {
 			logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
-	};
-
-	getQueryPerformance = function(callback) {
+	}
+	function getQueryPerformance(callback) {
 		$.getJSON('/service/queries/performance', callback).fail(function(xhr) {
 			logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
-	};
+	}
 
-	getQueries = function(callback) {
+	function getQueries(callback) {
 		$.getJSON('/service/queries', callback).fail(function(xhr) {
 			logError(xhr.responseText, xhr.status, 'tables', callback);
 		});
-	};
+	}
 
-	cancelQuery = function(table, uuid) {
+	function cancelQuery(table, uuid) {
 		$.ajax('/service/queries/' + uuid + '/cancel', {
 			data: {
 				table: table
@@ -56,25 +53,25 @@ blurconsole.data = (function() {
 				logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
-	};
+	}
 
-	disableTable = function(table) {
+	function disableTable(table) {
 		$.ajax('/service/tables/' + table + '/disable', {
 			error: function(xhr) {
 				logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
-	};
+	}
 
-	enableTable = function(table) {
+	function enableTable (table){
 		$.ajax('/service/tables/' + table + '/enable', {
 			error: function(xhr) {
 				logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
-	};
+	}
 
-	deleteTable = function(table, includeFiles) {
+	function deleteTable (table, includeFiles) {
 		$.ajax('/service/tables/' + table + '/delete', {
 			data: {
 				includeFiles: includeFiles
@@ -83,21 +80,21 @@ blurconsole.data = (function() {
 				logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
-	};
+	}
 
-	getSchema = function(table, callback) {
+	function getSchema(table, callback) {
 		$.getJSON('/service/tables/' + table + '/schema', callback).fail(function(xhr) {
 			logError(xhr.responseText, xhr.status, 'tables');
 		});
-	};
+	}
 
-	findTerms = function(table, family, column, startsWith, callback) {
+	function findTerms (table, family, column, startsWith, callback) {
 		$.getJSON('/service/tables/' + table + '/' + family + '/' + column + '/terms', {startsWith:
startsWith}, callback).fail(function(xhr) {
 			logError(xhr.responseText, xhr.status, 'tables');
 		});
-	};
+	}
 
-	sendSearch = function(query, table, args, callback) {
+	function sendSearch(query, table, args, callback) {
 		var params = $.extend({table:table, query:query}, args);
 		$.ajax('/service/search', {
 			'type': 'POST',
@@ -107,14 +104,14 @@ blurconsole.data = (function() {
 				logError(xhr.responseText, xhr.status, 'tables');
 			}
 		});
-	};
+	}
 
-	logError = function(errorMsg, status, module, callback) {
+	function logError (errorMsg, status, module, callback) {
 		blurconsole.model.logs.logError(status + ' - ' + errorMsg, module);
 		if (callback) {
 			callback('error');
 		}
-	};
+	}
 
 	return {
 		getTableList : getTableList,


Mime
View raw message