From e2dae1f484809c8c480b807937b88ab34fc11642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 27 May 2014 18:18:05 +0200 Subject: [PATCH] cleanup of unused code, small style changes --- .jshintrc | 4 +- src/app/components/kbn.js | 109 ------------------ src/app/controllers/metricKeys.js | 11 +- src/app/panels/timepicker/module.js | 6 +- .../dashboard/dashboardKeyBindings.js | 90 +++++++-------- src/app/services/filterSrv.js | 6 +- 6 files changed, 59 insertions(+), 167 deletions(-) diff --git a/.jshintrc b/.jshintrc index 4fb06a6f6ec..e8f044e1da9 100644 --- a/.jshintrc +++ b/.jshintrc @@ -18,12 +18,12 @@ "noempty": true, "undef": true, "boss": true, - "trailing": false, + "trailing": true, "laxbreak": true, "laxcomma": true, "sub": true, "unused": true, - + "maxdepth": 5, "maxlen": 140, "globals": { diff --git a/src/app/components/kbn.js b/src/app/components/kbn.js index 7baf48e4e1e..2ffa1d7cff9 100644 --- a/src/app/components/kbn.js +++ b/src/app/components/kbn.js @@ -294,79 +294,6 @@ function($, _, moment) { return dateTime.toDate(); }; - // LOL. hahahahaha. DIE. - kbn.flatten_json = function(object,root,array) { - if (typeof array === 'undefined') { - array = {}; - } - if (typeof root === 'undefined') { - root = ''; - } - for(var index in object) { - var obj = object[index]; - var rootname = root.length === 0 ? index : root + '.' + index; - if(typeof obj === 'object' ) { - if(_.isArray(obj)) { - if(obj.length > 0 && typeof obj[0] === 'object') { - var strval = ''; - for (var objidx = 0, objlen = obj.length; objidx < objlen; objidx++) { - if (objidx > 0) { - strval = strval + ', '; - } - - strval = strval + JSON.stringify(obj[objidx]); - } - array[rootname] = strval; - } else if(obj.length === 1 && _.isNumber(obj[0])) { - array[rootname] = parseFloat(obj[0]); - } else { - array[rootname] = typeof obj === 'undefined' ? null : obj; - } - } else { - kbn.flatten_json(obj,rootname,array); - } - } else { - array[rootname] = typeof obj === 'undefined' ? null : obj; - } - } - return kbn.sortObj(array); - }; - - kbn.xmlEnt = function(value) { - if(_.isString(value)) { - var stg1 = value.replace(//g, '>') - .replace(/\r\n/g, '
') - .replace(/\r/g, '
') - .replace(/\n/g, '
') - .replace(/\t/g, '    ') - .replace(/ /g, '  ') - .replace(/<del>/g, '') - .replace(/<\/del>/g, ''); - return stg1; - } else { - return value; - } - }; - - kbn.sortObj = function(arr) { - // Setup Arrays - var sortedKeys = []; - var sortedObj = {}; - var i; - // Separate keys and sort them - for (i in arr) { - sortedKeys.push(i); - } - sortedKeys.sort(); - - // Reconstruct sorted obj based on keys - for (i in sortedKeys) { - sortedObj[sortedKeys[i]] = arr[sortedKeys[i]]; - } - return sortedObj; - }; - kbn.query_color_dot = function (color, diameter) { return '
'; }; - kbn.colorSteps = function(col,steps) { - - var _d = steps > 5 ? 1.6/steps : 0.25, // distance between steps - _p = []; // adjustment percentage - - // Create a range of numbers between -0.8 and 0.8 - for(var i = 1; i end) { - return end + 1; - } - if(start !== arr[start]) { - return start; - } - var middle = Math.floor((start + end) / 2); - - if (arr[middle] > middle) { - return kbn.smallestMissing(arr, start, middle); - } else { - return kbn.smallestMissing(arr, middle + 1, end); - } - }; - kbn.byteFormat = function(size, decimals) { var ext, steps = 0; diff --git a/src/app/controllers/metricKeys.js b/src/app/controllers/metricKeys.js index fa39bfd4ad3..ae95327d80a 100644 --- a/src/app/controllers/metricKeys.js +++ b/src/app/controllers/metricKeys.js @@ -52,7 +52,7 @@ function (angular, _, config) { $scope.loadAll = function() { $scope.infoText = "Fetching all metrics from graphite..."; - getFromEachGraphite( '/metrics/index.json', saveMetricsArray ) + getFromEachGraphite('/metrics/index.json', saveMetricsArray) .then( function() { $scope.infoText = "Indexing complete!"; }).then(null, function(err) { @@ -60,17 +60,16 @@ function (angular, _, config) { }); }; - function getFromEachGraphite( request, data_callback, error_callback ) { + function getFromEachGraphite(request, data_callback, error_callback) { return $q.all( _.map( config.datasources, function( datasource ) { if ( datasource.type = 'graphite' ) { return $http.get( datasource.url + request ) .then( data_callback, error_callback ); - } + } } ) ); } - function saveMetricsArray(data, currentIndex) - { + function saveMetricsArray(data, currentIndex) { if (!data && !data.data && data.data.length === 0) { return $q.reject('No metrics from graphite'); } @@ -87,7 +86,7 @@ function (angular, _, config) { }); } - + function deleteIndex() { var deferred = $q.defer(); diff --git a/src/app/panels/timepicker/module.js b/src/app/panels/timepicker/module.js index a16ebc132d5..e3c0692c03b 100644 --- a/src/app/panels/timepicker/module.js +++ b/src/app/panels/timepicker/module.js @@ -53,10 +53,12 @@ function (angular, app, _, moment, kbn) { millisecond: /^[0-9]*$/ }; - $scope.$on('refresh', function(){$scope.init();}); + $scope.$on('refresh', function() { + $scope.init(); + }); $scope.init = function() { - var time = this.filter.timeRange( true ); + var time = this.filter.timeRange(true); if(time) { $scope.panel.now = this.filter.timeRange(false).to === "now" ? true : false; $scope.time = getScopeTimeObj(time.from,time.to); diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js index b399ca5bc5e..eb40a225794 100644 --- a/src/app/services/dashboard/dashboardKeyBindings.js +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -1,58 +1,58 @@ define([ - 'angular', - 'jquery', - 'services/all' + 'angular', + 'jquery', + 'services/all' ], -function( angular, $ ) { - "use strict"; +function(angular, $) { + "use strict"; - var module = angular.module('kibana.services.dashboard'); + var module = angular.module('kibana.services.dashboard'); - module.service( 'dashboardKeybindings', function($rootScope, keyboardManager, dashboard) { - this.shortcuts = function() { - $rootScope.$on('panel-fullscreen-enter', function() { - $rootScope.fullscreen = true; - }); + module.service('dashboardKeybindings', function($rootScope, keyboardManager, dashboard) { + this.shortcuts = function() { + $rootScope.$on('panel-fullscreen-enter', function() { + $rootScope.fullscreen = true; + }); - $rootScope.$on('panel-fullscreen-exit', function() { - $rootScope.fullscreen = false; - }); + $rootScope.$on('panel-fullscreen-exit', function() { + $rootScope.fullscreen = false; + }); - $rootScope.$on('dashboard-saved', function() { - if ($rootScope.fullscreen) { - $rootScope.$emit('panel-fullscreen-exit'); - } - }); + $rootScope.$on('dashboard-saved', function() { + if ($rootScope.fullscreen) { + $rootScope.$emit('panel-fullscreen-exit'); + } + }); - keyboardManager.bind('ctrl+f', function(evt) { - $rootScope.$emit('open-search', evt); - }, { inputDisabled: true }); + keyboardManager.bind('ctrl+f', function(evt) { + $rootScope.$emit('open-search', evt); + }, { inputDisabled: true }); - keyboardManager.bind('ctrl+h', function() { - var current = dashboard.current.hideControls; - dashboard.current.hideControls = !current; - dashboard.current.panel_hints = current; - }, { inputDisabled: true }); + keyboardManager.bind('ctrl+h', function() { + var current = dashboard.current.hideControls; + dashboard.current.hideControls = !current; + dashboard.current.panel_hints = current; + }, { inputDisabled: true }); - keyboardManager.bind('ctrl+s', function(evt) { - $rootScope.$emit('save-dashboard', evt); - }, { inputDisabled: true }); + keyboardManager.bind('ctrl+s', function(evt) { + $rootScope.$emit('save-dashboard', evt); + }, { inputDisabled: true }); - keyboardManager.bind('ctrl+r', function() { - dashboard.refresh(); - }, { inputDisabled: true }); + keyboardManager.bind('ctrl+r', function() { + dashboard.refresh(); + }, { inputDisabled: true }); - keyboardManager.bind('ctrl+z', function(evt) { - $rootScope.$emit('zoom-out', evt); - }, { inputDisabled: true }); + keyboardManager.bind('ctrl+z', function(evt) { + $rootScope.$emit('zoom-out', evt); + }, { inputDisabled: true }); - keyboardManager.bind('esc', function() { - var popups = $('.popover.in'); - if (popups.length > 0) { - return; - } - $rootScope.$emit('panel-fullscreen-exit'); - }, { inputDisabled: true }); - }; - }); + keyboardManager.bind('esc', function() { + var popups = $('.popover.in'); + if (popups.length > 0) { + return; + } + $rootScope.$emit('panel-fullscreen-exit'); + }, { inputDisabled: true }); + }; + }); }); diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index 6ab96055419..8e6a88c6a0b 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -18,7 +18,7 @@ define([ var result = { _updateTemplateData: function(initial) { var _templateData = {}; - _.each(this.templateParameters, function( templateParameter ) { + _.each(this.templateParameters, function(templateParameter) { if (initial) { var urlValue = $routeParams[ templateParameter.name ]; if (urlValue) { @@ -40,8 +40,8 @@ define([ dashboard.refresh(); }, - addTemplateParameter: function( templateParameter ) { - this.templateParameters.push( templateParameter ); + addTemplateParameter: function(templateParameter) { + this.templateParameters.push(templateParameter); this._updateTemplateData(); },