cleanup of unused code, small style changes

This commit is contained in:
Torkel Ödegaard
2014-05-27 18:18:05 +02:00
parent 8ca06e11de
commit e2dae1f484
6 changed files with 59 additions and 167 deletions

View File

@@ -18,12 +18,12 @@
"noempty": true, "noempty": true,
"undef": true, "undef": true,
"boss": true, "boss": true,
"trailing": false, "trailing": true,
"laxbreak": true, "laxbreak": true,
"laxcomma": true, "laxcomma": true,
"sub": true, "sub": true,
"unused": true, "unused": true,
"maxdepth": 5,
"maxlen": 140, "maxlen": 140,
"globals": { "globals": {

View File

@@ -294,79 +294,6 @@ function($, _, moment) {
return dateTime.toDate(); 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, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\r\n/g, '<br/>')
.replace(/\r/g, '<br/>')
.replace(/\n/g, '<br/>')
.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
.replace(/ /g, '&nbsp;&nbsp;')
.replace(/&lt;del&gt;/g, '<del>')
.replace(/&lt;\/del&gt;/g, '</del>');
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) { kbn.query_color_dot = function (color, diameter) {
return '<div class="icon-circle" style="' + [ return '<div class="icon-circle" style="' + [
'display:inline-block', 'display:inline-block',
@@ -375,42 +302,6 @@ function($, _, moment) {
].join(';') + '"></div>'; ].join(';') + '"></div>';
}; };
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<steps+1; i+=1) {
_p.push(i%2 ? ((i-1)*_d*-1)/2 : i*_d/2);
}
// Create the color range
return _.map(_p.sort(function(a,b){return a-b;}),function(v) {
return v<0 ? Chromath.darken(col,v*-1).toString() : Chromath.lighten(col,v).toString();
});
};
// Find the smallest missing number in an array
kbn.smallestMissing = function(arr,start,end) {
start = start || 0;
end = end || arr.length-1;
if(start > 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) { kbn.byteFormat = function(size, decimals) {
var ext, steps = 0; var ext, steps = 0;

View File

@@ -52,7 +52,7 @@ function (angular, _, config) {
$scope.loadAll = function() { $scope.loadAll = function() {
$scope.infoText = "Fetching all metrics from graphite..."; $scope.infoText = "Fetching all metrics from graphite...";
getFromEachGraphite( '/metrics/index.json', saveMetricsArray ) getFromEachGraphite('/metrics/index.json', saveMetricsArray)
.then( function() { .then( function() {
$scope.infoText = "Indexing complete!"; $scope.infoText = "Indexing complete!";
}).then(null, function(err) { }).then(null, function(err) {
@@ -60,7 +60,7 @@ 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 ) { return $q.all( _.map( config.datasources, function( datasource ) {
if ( datasource.type = 'graphite' ) { if ( datasource.type = 'graphite' ) {
return $http.get( datasource.url + request ) return $http.get( datasource.url + request )
@@ -69,8 +69,7 @@ function (angular, _, config) {
} ) ); } ) );
} }
function saveMetricsArray(data, currentIndex) function saveMetricsArray(data, currentIndex) {
{
if (!data && !data.data && data.data.length === 0) { if (!data && !data.data && data.data.length === 0) {
return $q.reject('No metrics from graphite'); return $q.reject('No metrics from graphite');
} }

View File

@@ -53,10 +53,12 @@ function (angular, app, _, moment, kbn) {
millisecond: /^[0-9]*$/ millisecond: /^[0-9]*$/
}; };
$scope.$on('refresh', function(){$scope.init();}); $scope.$on('refresh', function() {
$scope.init();
});
$scope.init = function() { $scope.init = function() {
var time = this.filter.timeRange( true ); var time = this.filter.timeRange(true);
if(time) { if(time) {
$scope.panel.now = this.filter.timeRange(false).to === "now" ? true : false; $scope.panel.now = this.filter.timeRange(false).to === "now" ? true : false;
$scope.time = getScopeTimeObj(time.from,time.to); $scope.time = getScopeTimeObj(time.from,time.to);

View File

@@ -3,12 +3,12 @@ define([
'jquery', 'jquery',
'services/all' 'services/all'
], ],
function( angular, $ ) { function(angular, $) {
"use strict"; "use strict";
var module = angular.module('kibana.services.dashboard'); var module = angular.module('kibana.services.dashboard');
module.service( 'dashboardKeybindings', function($rootScope, keyboardManager, dashboard) { module.service('dashboardKeybindings', function($rootScope, keyboardManager, dashboard) {
this.shortcuts = function() { this.shortcuts = function() {
$rootScope.$on('panel-fullscreen-enter', function() { $rootScope.$on('panel-fullscreen-enter', function() {
$rootScope.fullscreen = true; $rootScope.fullscreen = true;

View File

@@ -18,7 +18,7 @@ define([
var result = { var result = {
_updateTemplateData: function(initial) { _updateTemplateData: function(initial) {
var _templateData = {}; var _templateData = {};
_.each(this.templateParameters, function( templateParameter ) { _.each(this.templateParameters, function(templateParameter) {
if (initial) { if (initial) {
var urlValue = $routeParams[ templateParameter.name ]; var urlValue = $routeParams[ templateParameter.name ];
if (urlValue) { if (urlValue) {
@@ -40,8 +40,8 @@ define([
dashboard.refresh(); dashboard.refresh();
}, },
addTemplateParameter: function( templateParameter ) { addTemplateParameter: function(templateParameter) {
this.templateParameters.push( templateParameter ); this.templateParameters.push(templateParameter);
this._updateTemplateData(); this._updateTemplateData();
}, },