Skip to content

Commit e2dae1f

Browse files
committed
cleanup of unused code, small style changes
1 parent 8ca06e1 commit e2dae1f

File tree

6 files changed

+69
-177
lines changed

6 files changed

+69
-177
lines changed

.jshintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"noempty": true,
1919
"undef": true,
2020
"boss": true,
21-
"trailing": false,
21+
"trailing": true,
2222
"laxbreak": true,
2323
"laxcomma": true,
2424
"sub": true,
2525
"unused": true,
26-
26+
"maxdepth": 5,
2727
"maxlen": 140,
2828

2929
"globals": {

src/app/components/kbn.js

-109
Original file line numberDiff line numberDiff line change
@@ -294,79 +294,6 @@ function($, _, moment) {
294294
return dateTime.toDate();
295295
};
296296

297-
// LOL. hahahahaha. DIE.
298-
kbn.flatten_json = function(object,root,array) {
299-
if (typeof array === 'undefined') {
300-
array = {};
301-
}
302-
if (typeof root === 'undefined') {
303-
root = '';
304-
}
305-
for(var index in object) {
306-
var obj = object[index];
307-
var rootname = root.length === 0 ? index : root + '.' + index;
308-
if(typeof obj === 'object' ) {
309-
if(_.isArray(obj)) {
310-
if(obj.length > 0 && typeof obj[0] === 'object') {
311-
var strval = '';
312-
for (var objidx = 0, objlen = obj.length; objidx < objlen; objidx++) {
313-
if (objidx > 0) {
314-
strval = strval + ', ';
315-
}
316-
317-
strval = strval + JSON.stringify(obj[objidx]);
318-
}
319-
array[rootname] = strval;
320-
} else if(obj.length === 1 && _.isNumber(obj[0])) {
321-
array[rootname] = parseFloat(obj[0]);
322-
} else {
323-
array[rootname] = typeof obj === 'undefined' ? null : obj;
324-
}
325-
} else {
326-
kbn.flatten_json(obj,rootname,array);
327-
}
328-
} else {
329-
array[rootname] = typeof obj === 'undefined' ? null : obj;
330-
}
331-
}
332-
return kbn.sortObj(array);
333-
};
334-
335-
kbn.xmlEnt = function(value) {
336-
if(_.isString(value)) {
337-
var stg1 = value.replace(/</g, '&lt;')
338-
.replace(/>/g, '&gt;')
339-
.replace(/\r\n/g, '<br/>')
340-
.replace(/\r/g, '<br/>')
341-
.replace(/\n/g, '<br/>')
342-
.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
343-
.replace(/ /g, '&nbsp;&nbsp;')
344-
.replace(/&lt;del&gt;/g, '<del>')
345-
.replace(/&lt;\/del&gt;/g, '</del>');
346-
return stg1;
347-
} else {
348-
return value;
349-
}
350-
};
351-
352-
kbn.sortObj = function(arr) {
353-
// Setup Arrays
354-
var sortedKeys = [];
355-
var sortedObj = {};
356-
var i;
357-
// Separate keys and sort them
358-
for (i in arr) {
359-
sortedKeys.push(i);
360-
}
361-
sortedKeys.sort();
362-
363-
// Reconstruct sorted obj based on keys
364-
for (i in sortedKeys) {
365-
sortedObj[sortedKeys[i]] = arr[sortedKeys[i]];
366-
}
367-
return sortedObj;
368-
};
369-
370297
kbn.query_color_dot = function (color, diameter) {
371298
return '<div class="icon-circle" style="' + [
372299
'display:inline-block',
@@ -375,42 +302,6 @@ function($, _, moment) {
375302
].join(';') + '"></div>';
376303
};
377304

378-
kbn.colorSteps = function(col,steps) {
379-
380-
var _d = steps > 5 ? 1.6/steps : 0.25, // distance between steps
381-
_p = []; // adjustment percentage
382-
383-
// Create a range of numbers between -0.8 and 0.8
384-
for(var i = 1; i<steps+1; i+=1) {
385-
_p.push(i%2 ? ((i-1)*_d*-1)/2 : i*_d/2);
386-
}
387-
388-
// Create the color range
389-
return _.map(_p.sort(function(a,b){return a-b;}),function(v) {
390-
return v<0 ? Chromath.darken(col,v*-1).toString() : Chromath.lighten(col,v).toString();
391-
});
392-
};
393-
394-
// Find the smallest missing number in an array
395-
kbn.smallestMissing = function(arr,start,end) {
396-
start = start || 0;
397-
end = end || arr.length-1;
398-
399-
if(start > end) {
400-
return end + 1;
401-
}
402-
if(start !== arr[start]) {
403-
return start;
404-
}
405-
var middle = Math.floor((start + end) / 2);
406-
407-
if (arr[middle] > middle) {
408-
return kbn.smallestMissing(arr, start, middle);
409-
} else {
410-
return kbn.smallestMissing(arr, middle + 1, end);
411-
}
412-
};
413-
414305
kbn.byteFormat = function(size, decimals) {
415306
var ext, steps = 0;
416307

src/app/controllers/metricKeys.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,24 @@ function (angular, _, config) {
5252
$scope.loadAll = function() {
5353
$scope.infoText = "Fetching all metrics from graphite...";
5454

55-
getFromEachGraphite( '/metrics/index.json', saveMetricsArray )
55+
getFromEachGraphite('/metrics/index.json', saveMetricsArray)
5656
.then( function() {
5757
$scope.infoText = "Indexing complete!";
5858
}).then(null, function(err) {
5959
$scope.errorText = err;
6060
});
6161
};
6262

63-
function getFromEachGraphite( request, data_callback, error_callback ) {
63+
function getFromEachGraphite(request, data_callback, error_callback) {
6464
return $q.all( _.map( config.datasources, function( datasource ) {
6565
if ( datasource.type = 'graphite' ) {
6666
return $http.get( datasource.url + request )
6767
.then( data_callback, error_callback );
68-
}
68+
}
6969
} ) );
7070
}
7171

72-
function saveMetricsArray(data, currentIndex)
73-
{
72+
function saveMetricsArray(data, currentIndex) {
7473
if (!data && !data.data && data.data.length === 0) {
7574
return $q.reject('No metrics from graphite');
7675
}
@@ -87,7 +86,7 @@ function (angular, _, config) {
8786
});
8887
}
8988

90-
89+
9190
function deleteIndex()
9291
{
9392
var deferred = $q.defer();

src/app/panels/timepicker/module.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ function (angular, app, _, moment, kbn) {
5353
millisecond: /^[0-9]*$/
5454
};
5555

56-
$scope.$on('refresh', function(){$scope.init();});
56+
$scope.$on('refresh', function() {
57+
$scope.init();
58+
});
5759

5860
$scope.init = function() {
59-
var time = this.filter.timeRange( true );
61+
var time = this.filter.timeRange(true);
6062
if(time) {
6163
$scope.panel.now = this.filter.timeRange(false).to === "now" ? true : false;
6264
$scope.time = getScopeTimeObj(time.from,time.to);
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
define([
2-
'angular',
3-
'jquery',
4-
'services/all'
2+
'angular',
3+
'jquery',
4+
'services/all'
55
],
6-
function( angular, $ ) {
7-
"use strict";
8-
9-
var module = angular.module('kibana.services.dashboard');
10-
11-
module.service( 'dashboardKeybindings', function($rootScope, keyboardManager, dashboard) {
12-
this.shortcuts = function() {
13-
$rootScope.$on('panel-fullscreen-enter', function() {
14-
$rootScope.fullscreen = true;
15-
});
16-
17-
$rootScope.$on('panel-fullscreen-exit', function() {
18-
$rootScope.fullscreen = false;
19-
});
20-
21-
$rootScope.$on('dashboard-saved', function() {
22-
if ($rootScope.fullscreen) {
23-
$rootScope.$emit('panel-fullscreen-exit');
24-
}
25-
});
26-
27-
keyboardManager.bind('ctrl+f', function(evt) {
28-
$rootScope.$emit('open-search', evt);
29-
}, { inputDisabled: true });
30-
31-
keyboardManager.bind('ctrl+h', function() {
32-
var current = dashboard.current.hideControls;
33-
dashboard.current.hideControls = !current;
34-
dashboard.current.panel_hints = current;
35-
}, { inputDisabled: true });
36-
37-
keyboardManager.bind('ctrl+s', function(evt) {
38-
$rootScope.$emit('save-dashboard', evt);
39-
}, { inputDisabled: true });
40-
41-
keyboardManager.bind('ctrl+r', function() {
42-
dashboard.refresh();
43-
}, { inputDisabled: true });
44-
45-
keyboardManager.bind('ctrl+z', function(evt) {
46-
$rootScope.$emit('zoom-out', evt);
47-
}, { inputDisabled: true });
48-
49-
keyboardManager.bind('esc', function() {
50-
var popups = $('.popover.in');
51-
if (popups.length > 0) {
52-
return;
53-
}
54-
$rootScope.$emit('panel-fullscreen-exit');
55-
}, { inputDisabled: true });
56-
};
57-
});
6+
function(angular, $) {
7+
"use strict";
8+
9+
var module = angular.module('kibana.services.dashboard');
10+
11+
module.service('dashboardKeybindings', function($rootScope, keyboardManager, dashboard) {
12+
this.shortcuts = function() {
13+
$rootScope.$on('panel-fullscreen-enter', function() {
14+
$rootScope.fullscreen = true;
15+
});
16+
17+
$rootScope.$on('panel-fullscreen-exit', function() {
18+
$rootScope.fullscreen = false;
19+
});
20+
21+
$rootScope.$on('dashboard-saved', function() {
22+
if ($rootScope.fullscreen) {
23+
$rootScope.$emit('panel-fullscreen-exit');
24+
}
25+
});
26+
27+
keyboardManager.bind('ctrl+f', function(evt) {
28+
$rootScope.$emit('open-search', evt);
29+
}, { inputDisabled: true });
30+
31+
keyboardManager.bind('ctrl+h', function() {
32+
var current = dashboard.current.hideControls;
33+
dashboard.current.hideControls = !current;
34+
dashboard.current.panel_hints = current;
35+
}, { inputDisabled: true });
36+
37+
keyboardManager.bind('ctrl+s', function(evt) {
38+
$rootScope.$emit('save-dashboard', evt);
39+
}, { inputDisabled: true });
40+
41+
keyboardManager.bind('ctrl+r', function() {
42+
dashboard.refresh();
43+
}, { inputDisabled: true });
44+
45+
keyboardManager.bind('ctrl+z', function(evt) {
46+
$rootScope.$emit('zoom-out', evt);
47+
}, { inputDisabled: true });
48+
49+
keyboardManager.bind('esc', function() {
50+
var popups = $('.popover.in');
51+
if (popups.length > 0) {
52+
return;
53+
}
54+
$rootScope.$emit('panel-fullscreen-exit');
55+
}, { inputDisabled: true });
56+
};
57+
});
5858
});

src/app/services/filterSrv.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define([
1818
var result = {
1919
_updateTemplateData: function(initial) {
2020
var _templateData = {};
21-
_.each(this.templateParameters, function( templateParameter ) {
21+
_.each(this.templateParameters, function(templateParameter) {
2222
if (initial) {
2323
var urlValue = $routeParams[ templateParameter.name ];
2424
if (urlValue) {
@@ -40,8 +40,8 @@ define([
4040
dashboard.refresh();
4141
},
4242

43-
addTemplateParameter: function( templateParameter ) {
44-
this.templateParameters.push( templateParameter );
43+
addTemplateParameter: function(templateParameter) {
44+
this.templateParameters.push(templateParameter);
4545
this._updateTemplateData();
4646
},
4747

0 commit comments

Comments
 (0)