mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
cleanup of unused code, small style changes
This commit is contained in:
parent
8ca06e11de
commit
e2dae1f484
@ -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": {
|
||||
|
@ -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(/>/g, '>')
|
||||
.replace(/\r\n/g, '<br/>')
|
||||
.replace(/\r/g, '<br/>')
|
||||
.replace(/\n/g, '<br/>')
|
||||
.replace(/\t/g, ' ')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/<del>/g, '<del>')
|
||||
.replace(/<\/del>/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) {
|
||||
return '<div class="icon-circle" style="' + [
|
||||
'display:inline-block',
|
||||
@ -375,42 +302,6 @@ function($, _, moment) {
|
||||
].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) {
|
||||
var ext, steps = 0;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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 });
|
||||
};
|
||||
});
|
||||
});
|
||||
|
@ -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();
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user