Commit 00c0b71f by Torkel Ödegaard

Merge branch '12918-only-arrow-functions4'

parents 99133c4f dc4f547a
......@@ -97,7 +97,7 @@ function link(scope, elem, attrs) {
textarea.addClass('gf-form-input');
if (scope.codeEditorFocus) {
setTimeout(function() {
setTimeout(() => {
textarea.focus();
const domEl = textarea[0];
if (domEl.setSelectionRange) {
......@@ -119,7 +119,7 @@ function link(scope, elem, attrs) {
scope.$watch('content', (newValue, oldValue) => {
const editorValue = codeEditor.getValue();
if (newValue !== editorValue && newValue !== oldValue) {
scope.$$postDigest(function() {
scope.$$postDigest(() => {
setEditorContent(newValue);
});
}
......
......@@ -13,7 +13,7 @@ export function spectrumPicker() {
scope: true,
replace: true,
template: '<color-picker color="ngModel.$viewValue" onChange="onColorChange"></color-picker>',
link: function(scope, element, attrs, ngModel) {
link: (scope, element, attrs, ngModel) => {
scope.ngModel = ngModel;
scope.onColorChange = color => {
ngModel.$setViewValue(color);
......
......@@ -14,10 +14,10 @@ const MAX_ANIMATED_TOGGLE_ITEMS = 10;
const requestAnimationFrame =
window.requestAnimationFrame ||
function(cb: () => void) {
((cb: () => void) => {
cb();
return 0;
};
});
export interface JsonExplorerConfig {
animateOpen?: boolean;
......
......@@ -10,7 +10,7 @@ coreModule.directive('jsonTree', [
startExpanded: '@',
rootName: '@',
},
link: function(scope, elem) {
link: (scope, elem) => {
const jsonExp = new JsonExplorer(scope.object, 3, {
animateOpen: true,
});
......
......@@ -4,19 +4,19 @@ import coreModule from '../core_module';
/** @ngInject */
export function dashClass() {
return {
link: function($scope, elem) {
$scope.onAppEvent('panel-fullscreen-enter', function() {
link: ($scope, elem) => {
$scope.onAppEvent('panel-fullscreen-enter', () => {
elem.toggleClass('panel-in-fullscreen', true);
});
$scope.onAppEvent('panel-fullscreen-exit', function() {
$scope.onAppEvent('panel-fullscreen-exit', () => {
elem.toggleClass('panel-in-fullscreen', false);
});
$scope.$watch('ctrl.dashboardViewState.state.editview', function(newValue) {
$scope.$watch('ctrl.dashboardViewState.state.editview', newValue => {
if (newValue) {
elem.toggleClass('dashboard-page--settings-opening', _.isString(newValue));
setTimeout(function() {
setTimeout(() => {
elem.toggleClass('dashboard-page--settings-open', _.isString(newValue));
}, 10);
} else {
......
......@@ -20,7 +20,7 @@ export function dropdownTypeahead($compile) {
dropdownTypeaheadOnSelect: '&dropdownTypeaheadOnSelect',
model: '=ngModel',
},
link: function($scope, elem, attrs) {
link: ($scope, elem, attrs) => {
const $input = $(inputTemplate);
const $button = $(buttonTemplate);
$input.appendTo(elem);
......@@ -31,9 +31,9 @@ export function dropdownTypeahead($compile) {
}
if (attrs.ngModel) {
$scope.$watch('model', function(newValue) {
_.each($scope.menuItems, function(item) {
_.each(item.submenu, function(subItem) {
$scope.$watch('model', newValue => {
_.each($scope.menuItems, item => {
_.each(item.submenu, subItem => {
if (subItem.value === newValue) {
$button.html(subItem.text);
}
......@@ -44,12 +44,12 @@ export function dropdownTypeahead($compile) {
const typeaheadValues = _.reduce(
$scope.menuItems,
function(memo, value, index) {
(memo, value, index) => {
if (!value.submenu) {
value.click = 'menuItemSelected(' + index + ')';
memo.push(value.text);
} else {
_.each(value.submenu, function(item, subIndex) {
_.each(value.submenu, (item, subIndex) => {
item.click = 'menuItemSelected(' + index + ',' + subIndex + ')';
memo.push(value.text + ' ' + item.text);
});
......@@ -59,7 +59,7 @@ export function dropdownTypeahead($compile) {
[]
);
$scope.menuItemSelected = function(index, subIndex) {
$scope.menuItemSelected = (index, subIndex) => {
const menuItem = $scope.menuItems[index];
const payload: any = { $item: menuItem };
if (menuItem.submenu && subIndex !== void 0) {
......@@ -73,10 +73,10 @@ export function dropdownTypeahead($compile) {
source: typeaheadValues,
minLength: 1,
items: 10,
updater: function(value) {
updater: value => {
const result: any = {};
_.each($scope.menuItems, function(menuItem) {
_.each(menuItem.submenu, function(submenuItem) {
_.each($scope.menuItems, menuItem => {
_.each(menuItem.submenu, submenuItem => {
if (value === menuItem.text + ' ' + submenuItem.text) {
result.$subItem = submenuItem;
result.$item = menuItem;
......@@ -85,7 +85,7 @@ export function dropdownTypeahead($compile) {
});
if (result.$item) {
$scope.$apply(function() {
$scope.$apply(() => {
$scope.dropdownTypeaheadOnSelect(result);
});
}
......@@ -95,24 +95,24 @@ export function dropdownTypeahead($compile) {
},
});
$button.click(function() {
$button.click(() => {
$button.hide();
$input.show();
$input.focus();
});
$input.keyup(function() {
$input.keyup(() => {
elem.toggleClass('open', $input.val() === '');
});
$input.blur(function() {
$input.blur(() => {
$input.hide();
$input.val('');
$button.show();
$button.focus();
// clicking the function dropdown menu won't
// work if you remove class at once
setTimeout(function() {
setTimeout(() => {
elem.removeClass('open');
}, 200);
});
......@@ -138,7 +138,7 @@ export function dropdownTypeahead2($compile) {
dropdownTypeaheadOnSelect: '&dropdownTypeaheadOnSelect',
model: '=ngModel',
},
link: function($scope, elem, attrs) {
link: ($scope, elem, attrs) => {
const $input = $(inputTemplate);
const $button = $(buttonTemplate);
$input.appendTo(elem);
......@@ -149,9 +149,9 @@ export function dropdownTypeahead2($compile) {
}
if (attrs.ngModel) {
$scope.$watch('model', function(newValue) {
_.each($scope.menuItems, function(item) {
_.each(item.submenu, function(subItem) {
$scope.$watch('model', newValue => {
_.each($scope.menuItems, item => {
_.each(item.submenu, subItem => {
if (subItem.value === newValue) {
$button.html(subItem.text);
}
......@@ -162,12 +162,12 @@ export function dropdownTypeahead2($compile) {
const typeaheadValues = _.reduce(
$scope.menuItems,
function(memo, value, index) {
(memo, value, index) => {
if (!value.submenu) {
value.click = 'menuItemSelected(' + index + ')';
memo.push(value.text);
} else {
_.each(value.submenu, function(item, subIndex) {
_.each(value.submenu, (item, subIndex) => {
item.click = 'menuItemSelected(' + index + ',' + subIndex + ')';
memo.push(value.text + ' ' + item.text);
});
......@@ -177,7 +177,7 @@ export function dropdownTypeahead2($compile) {
[]
);
$scope.menuItemSelected = function(index, subIndex) {
$scope.menuItemSelected = (index, subIndex) => {
const menuItem = $scope.menuItems[index];
const payload: any = { $item: menuItem };
if (menuItem.submenu && subIndex !== void 0) {
......@@ -191,10 +191,10 @@ export function dropdownTypeahead2($compile) {
source: typeaheadValues,
minLength: 1,
items: 10,
updater: function(value) {
updater: value => {
const result: any = {};
_.each($scope.menuItems, function(menuItem) {
_.each(menuItem.submenu, function(submenuItem) {
_.each($scope.menuItems, menuItem => {
_.each(menuItem.submenu, submenuItem => {
if (value === menuItem.text + ' ' + submenuItem.text) {
result.$subItem = submenuItem;
result.$item = menuItem;
......@@ -203,7 +203,7 @@ export function dropdownTypeahead2($compile) {
});
if (result.$item) {
$scope.$apply(function() {
$scope.$apply(() => {
$scope.dropdownTypeaheadOnSelect(result);
});
}
......@@ -213,24 +213,24 @@ export function dropdownTypeahead2($compile) {
},
});
$button.click(function() {
$button.click(() => {
$button.hide();
$input.show();
$input.focus();
});
$input.keyup(function() {
$input.keyup(() => {
elem.toggleClass('open', $input.val() === '');
});
$input.blur(function() {
$input.blur(() => {
$input.hide();
$input.val('');
$button.show();
$button.focus();
// clicking the function dropdown menu won't
// work if you remove class at once
setTimeout(function() {
setTimeout(() => {
elem.removeClass('open');
}, 200);
});
......
import coreModule from '../core_module';
coreModule.directive('giveFocus', function() {
return function(scope, element, attrs) {
element.click(function(e) {
coreModule.directive('giveFocus', () => {
return (scope, element, attrs) => {
element.click(e => {
e.stopPropagation();
});
scope.$watch(
attrs.giveFocus,
function(newValue) {
newValue => {
if (!newValue) {
return;
}
setTimeout(function() {
setTimeout(() => {
element.focus();
const domEl = element[0];
if (domEl.setSelectionRange) {
......
......@@ -24,7 +24,7 @@ export function metricSegment($compile, $sce) {
onChange: '&',
debounce: '@',
},
link: function($scope, elem) {
link: ($scope, elem) => {
const $input = $(inputTemplate);
const segment = $scope.segment;
const $button = $(segment.selectMode ? selectTemplate : linkTemplate);
......@@ -36,14 +36,14 @@ export function metricSegment($compile, $sce) {
$input.appendTo(elem);
$button.appendTo(elem);
$scope.updateVariableValue = function(value) {
$scope.updateVariableValue = value => {
if (value === '' || segment.value === value) {
return;
}
value = _.unescape(value);
$scope.$apply(function() {
$scope.$apply(() => {
const selected = _.find($scope.altSegments, { value: value });
if (selected) {
segment.value = selected.value;
......@@ -65,7 +65,7 @@ export function metricSegment($compile, $sce) {
});
};
$scope.switchToLink = function(fromClick) {
$scope.switchToLink = fromClick => {
if (linkMode && !fromClick) {
return;
}
......@@ -78,17 +78,17 @@ export function metricSegment($compile, $sce) {
$scope.updateVariableValue($input.val());
};
$scope.inputBlur = function() {
$scope.inputBlur = () => {
// happens long before the click event on the typeahead options
// need to have long delay because the blur
cancelBlur = setTimeout($scope.switchToLink, 200);
};
$scope.source = function(query, callback) {
$scope.$apply(function() {
$scope.getOptions({ $query: query }).then(function(altSegments) {
$scope.source = (query, callback) => {
$scope.$apply(() => {
$scope.getOptions({ $query: query }).then(altSegments => {
$scope.altSegments = altSegments;
options = _.map($scope.altSegments, function(alt) {
options = _.map($scope.altSegments, alt => {
return _.escape(alt.value);
});
......@@ -104,7 +104,7 @@ export function metricSegment($compile, $sce) {
});
};
$scope.updater = function(value) {
$scope.updater = value => {
if (value === segment.value) {
clearTimeout(cancelBlur);
$input.focus();
......@@ -152,14 +152,14 @@ export function metricSegment($compile, $sce) {
typeahead.lookup = _.debounce(typeahead.lookup, 500, { leading: true });
}
$button.keydown(function(evt) {
$button.keydown(evt => {
// trigger typeahead on down arrow or enter key
if (evt.keyCode === 40 || evt.keyCode === 13) {
$button.click();
}
});
$button.click(function() {
$button.click(() => {
options = null;
$input.css('width', Math.max($button.width(), 80) + 16 + 'px');
......@@ -199,7 +199,7 @@ export function metricSegmentModel(uiSegmentSrv, $q) {
pre: function postLink($scope, elem, attrs) {
let cachedOptions;
$scope.valueToSegment = function(value) {
$scope.valueToSegment = value => {
const option = _.find($scope.options, { value: value });
const segment = {
cssClass: attrs.cssClass,
......@@ -211,18 +211,18 @@ export function metricSegmentModel(uiSegmentSrv, $q) {
return uiSegmentSrv.newSegment(segment);
};
$scope.getOptionsInternal = function() {
$scope.getOptionsInternal = () => {
if ($scope.options) {
cachedOptions = $scope.options;
return $q.when(
_.map($scope.options, function(option) {
_.map($scope.options, option => {
return { value: option.text };
})
);
} else {
return $scope.getOptions().then(function(options) {
return $scope.getOptions().then(options => {
cachedOptions = options;
return _.map(options, function(option) {
return _.map(options, option => {
if (option.html) {
return option;
}
......@@ -232,7 +232,7 @@ export function metricSegmentModel(uiSegmentSrv, $q) {
}
};
$scope.onSegmentChange = function() {
$scope.onSegmentChange = () => {
if (cachedOptions) {
const option = _.find(cachedOptions, { text: $scope.segment.value });
if (option && option.value !== $scope.property) {
......@@ -246,8 +246,8 @@ export function metricSegmentModel(uiSegmentSrv, $q) {
// needs to call this after digest so
// property is synced with outerscope
$scope.$$postDigest(function() {
$scope.$apply(function() {
$scope.$$postDigest(() => {
$scope.$apply(() => {
$scope.onChange();
});
});
......
......@@ -8,7 +8,7 @@ import { appEvents } from 'app/core/core';
function tip($compile) {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
link: (scope, elem, attrs) => {
let _t =
'<i class="grafana-tip fa fa-' +
(attrs.icon || 'question-circle') +
......@@ -26,9 +26,9 @@ function clipboardButton() {
scope: {
getText: '&clipboardButton',
},
link: function(scope, elem) {
link: (scope, elem) => {
scope.clipboard = new Clipboard(elem[0], {
text: function() {
text: () => {
return scope.getText();
},
});
......@@ -37,7 +37,7 @@ function clipboardButton() {
appEvents.emit('alert-success', ['Content copied to clipboard']);
});
scope.$on('$destroy', function() {
scope.$on('$destroy', () => {
if (scope.clipboard) {
scope.clipboard.destroy();
}
......@@ -50,12 +50,12 @@ function clipboardButton() {
function compile($compile) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
link: (scope, element, attrs) => {
scope.$watch(
function(scope) {
scope => {
return scope.$eval(attrs.compile);
},
function(value) {
value => {
element.html(value);
$compile(element.contents())(scope);
}
......@@ -67,9 +67,9 @@ function compile($compile) {
function watchChange() {
return {
scope: { onchange: '&watchChange' },
link: function(scope, element) {
element.on('input', function() {
scope.$apply(function() {
link: (scope, element) => {
element.on('input', () => {
scope.$apply(() => {
scope.onchange({ inputValue: element.val() });
});
});
......@@ -81,7 +81,7 @@ function watchChange() {
function editorOptBool($compile) {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
link: (scope, elem, attrs) => {
const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : '';
const tip = attrs.tip ? ' <tip>' + attrs.tip + '</tip>' : '';
const showIf = attrs.showIf ? ' ng-show="' + attrs.showIf + '" ' : '';
......@@ -118,7 +118,7 @@ function editorOptBool($compile) {
function editorCheckbox($compile, $interpolate) {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
link: (scope, elem, attrs) => {
const text = $interpolate(attrs.text)(scope);
const model = $interpolate(attrs.model)(scope);
const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : '';
......@@ -194,7 +194,7 @@ function gfDropdown($parse, $compile, $timeout) {
link: function postLink(scope, iElement, iAttrs) {
const getter = $parse(iAttrs.gfDropdown),
items = getter(scope);
$timeout(function() {
$timeout(() => {
const placement = iElement.data('placement');
const dropdown = angular.element(buildTemplate(items, placement).join(''));
dropdown.insertAfter(iElement);
......
......@@ -6,14 +6,14 @@ function ngModelOnBlur() {
restrict: 'A',
priority: 1,
require: 'ngModel',
link: function(scope, elm, attr, ngModelCtrl) {
link: (scope, elm, attr, ngModelCtrl) => {
if (attr.type === 'radio' || attr.type === 'checkbox') {
return;
}
elm.off('input keydown change');
elm.bind('blur', function() {
scope.$apply(function() {
elm.bind('blur', () => {
scope.$apply(() => {
ngModelCtrl.$setViewValue(elm.val());
});
});
......@@ -25,8 +25,8 @@ function emptyToNull() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$parsers.push(function(viewValue) {
link: (scope, elm, attrs, ctrl) => {
ctrl.$parsers.push(viewValue => {
if (viewValue === '') {
return null;
}
......@@ -39,8 +39,8 @@ function emptyToNull() {
function validTimeSpan() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.integer = function(modelValue, viewValue) {
link: (scope, elm, attrs, ctrl) => {
ctrl.$validators.integer = (modelValue, viewValue) => {
if (ctrl.$isEmpty(modelValue)) {
return true;
}
......
......@@ -26,7 +26,7 @@ function rebuildOnChange($animate) {
transclude: true,
priority: 600,
restrict: 'E',
link: function(scope, elem, attrs, ctrl, transclude) {
link: (scope, elem, attrs, ctrl, transclude) => {
let block, childScope, previousElements;
function cleanUp() {
......@@ -40,7 +40,7 @@ function rebuildOnChange($animate) {
}
if (block) {
previousElements = getBlockNodes(block.clone);
$animate.leave(previousElements).then(function() {
$animate.leave(previousElements).then(() => {
previousElements = null;
});
block = null;
......@@ -53,7 +53,7 @@ function rebuildOnChange($animate) {
}
if (!childScope && (value || attrs.showNull)) {
transclude(function(clone, newScope) {
transclude((clone, newScope) => {
childScope = newScope;
clone[clone.length++] = document.createComment(' end rebuild on change ');
block = { clone: clone };
......
......@@ -13,7 +13,7 @@ function setColor(name, element) {
function tagColorFromName() {
return {
scope: { tagColorFromName: '=' },
link: function(scope, element) {
link: (scope, element) => {
setColor(scope.tagColorFromName, element);
},
};
......@@ -29,7 +29,7 @@ function bootstrapTagsinput() {
return scope.$parent[property];
}
return function(item) {
return item => {
return item[property];
};
}
......@@ -64,7 +64,7 @@ function bootstrapTagsinput() {
itemText: getItemProperty(scope, attrs.itemtext),
tagClass: angular.isFunction(scope.$parent[attrs.tagclass])
? scope.$parent[attrs.tagclass]
: function() {
: () => {
return attrs.tagclass;
},
});
......@@ -85,7 +85,7 @@ function bootstrapTagsinput() {
setColor(event.item, tagElement);
});
select.on('itemRemoved', function(event) {
select.on('itemRemoved', event => {
const idx = scope.model.indexOf(event.item);
if (idx !== -1) {
scope.model.splice(idx, 1);
......@@ -97,7 +97,7 @@ function bootstrapTagsinput() {
scope.$watch(
'model',
function() {
() => {
if (!angular.isArray(scope.model)) {
scope.model = [];
}
......
......@@ -245,7 +245,7 @@ export function valueSelectDropdown($compile, $window, $timeout, $rootScope) {
controller: 'ValueSelectDropdownCtrl',
controllerAs: 'vm',
bindToController: true,
link: function(scope, elem) {
link: (scope, elem) => {
const bodyEl = angular.element($window.document.body);
const linkEl = elem.find('.variable-value-link');
const inputEl = elem.find('input');
......@@ -258,7 +258,7 @@ export function valueSelectDropdown($compile, $window, $timeout, $rootScope) {
inputEl.focus();
$timeout(
function() {
() => {
bodyEl.on('click', bodyOnClick);
},
0,
......@@ -274,7 +274,7 @@ export function valueSelectDropdown($compile, $window, $timeout, $rootScope) {
function bodyOnClick(e) {
if (elem.has(e.target).length === 0) {
scope.$apply(function() {
scope.$apply(() => {
scope.vm.commitChanges();
});
}
......
......@@ -4,7 +4,7 @@ import _ from 'lodash';
const $win = $(window);
$.fn.place_tt = (function() {
$.fn.place_tt = (() => {
const defaults = {
offset: 5,
};
......@@ -28,7 +28,7 @@ $.fn.place_tt = (function() {
.invoke([
'$compile',
'$rootScope',
function($compile, $rootScope) {
($compile, $rootScope) => {
const tmpScope = $rootScope.$new(true);
_.extend(tmpScope, opts.scopeData);
......
let templates = (require as any).context('../', true, /\.html$/);
templates.keys().forEach(function(key) {
templates.keys().forEach(key => {
templates(key);
});
......@@ -82,15 +82,15 @@ export class Profiler {
let scopes = 0;
const root = $(document.getElementsByTagName('body'));
const f = function(element) {
const f = element => {
if (element.data().hasOwnProperty('$scope')) {
scopes++;
angular.forEach(element.data().$scope.$$watchers, function() {
angular.forEach(element.data().$scope.$$watchers, () => {
count++;
});
}
angular.forEach(element.children(), function(childElement) {
angular.forEach(element.children(), childElement => {
f($(childElement));
});
};
......
......@@ -15,6 +15,7 @@ export class Analytics {
const ga = ((window as any).ga =
(window as any).ga ||
function() {
//tslint:disable-line:only-arrow-functions
(ga.q = ga.q || []).push(arguments);
});
ga.l = +new Date();
......
......@@ -64,6 +64,6 @@ export class ContextSrv {
const contextSrv = new ContextSrv();
export { contextSrv };
coreModule.factory('contextSrv', function() {
coreModule.factory('contextSrv', () => {
return contextSrv;
});
......@@ -34,7 +34,7 @@ function getReactComponent(name, $injector) {
if (!reactComponent) {
try {
reactComponent = name.split('.').reduce(function(current, namePart) {
reactComponent = name.split('.').reduce((current, namePart) => {
return current[namePart];
}, window);
} catch (e) {}
......@@ -53,12 +53,13 @@ function applied(fn, scope) {
return fn;
}
const wrapped: any = function() {
//tslint:disable-line:only-arrow-functions
const args = arguments;
const phase = scope.$root.$$phase;
if (phase === '$apply' || phase === '$digest') {
return fn.apply(null, args);
} else {
return scope.$apply(function() {
return scope.$apply(() => {
return fn.apply(null, args);
});
}
......@@ -80,7 +81,7 @@ function applied(fn, scope) {
* @returns {Object} props with the functions wrapped in scope.$apply
*/
function applyFunctions(obj, scope, propsConfig?) {
return Object.keys(obj || {}).reduce(function(prev, key) {
return Object.keys(obj || {}).reduce((prev, key) => {
const value = obj[key];
const config = (propsConfig || {})[key] || {};
/**
......@@ -108,7 +109,7 @@ function watchProps(watchDepth, scope, watchExpressions, listener) {
const watchGroupExpressions = [];
watchExpressions.forEach(function(expr) {
watchExpressions.forEach(expr => {
const actualExpr = getPropExpression(expr);
const exprWatchDepth = getPropWatchDepth(watchDepth, expr);
......@@ -134,7 +135,7 @@ function watchProps(watchDepth, scope, watchExpressions, listener) {
// render React component, with scope[attrs.props] being passed in as the component props
function renderComponent(component, props, scope, elem) {
scope.$evalAsync(function() {
scope.$evalAsync(() => {
ReactDOM.render(React.createElement(component, props), elem[0]);
});
}
......@@ -156,7 +157,7 @@ function getPropExpression(prop) {
// find the normalized attribute knowing that React props accept any type of capitalization
function findAttribute(attrs, propName) {
const index = Object.keys(attrs).filter(function(attr) {
const index = Object.keys(attrs).filter(attr => {
return attr.toLowerCase() === propName.toLowerCase();
})[0];
return attrs[index];
......@@ -186,14 +187,14 @@ function getPropWatchDepth(defaultWatch, prop) {
// }
// }));
//
const reactComponent = function($injector) {
const reactComponent = $injector => {
return {
restrict: 'E',
replace: true,
link: function(scope, elem, attrs) {
const reactComponent = getReactComponent(attrs.name, $injector);
const renderMyComponent = function() {
const renderMyComponent = () => {
const scopeProps = scope.$eval(attrs.props);
const props = applyFunctions(scopeProps, scope);
......@@ -243,8 +244,8 @@ const reactComponent = function($injector) {
//
// <hello name="name"/>
//
const reactDirective = function($injector) {
return function(reactComponentName, props, conf, injectableProps) {
const reactDirective = $injector => {
return (reactComponentName, props, conf, injectableProps) => {
const directive = {
restrict: 'E',
replace: true,
......@@ -255,11 +256,11 @@ const reactDirective = function($injector) {
props = props || Object.keys(reactComponent.propTypes || {});
// for each of the properties, get their scope value and set it to scope.props
const renderMyComponent = function() {
const renderMyComponent = () => {
let scopeProps = {};
const config = {};
props.forEach(function(prop) {
props.forEach(prop => {
const propName = getPropName(prop);
scopeProps[propName] = scope.$eval(findAttribute(attrs, propName));
config[propName] = getPropConfig(prop);
......@@ -272,7 +273,7 @@ const reactDirective = function($injector) {
// watch each property name and trigger an update whenever something changes,
// to update scope.props with new values
const propExpressions = props.map(function(prop) {
const propExpressions = props.map(prop => {
return Array.isArray(prop) ? [attrs[getPropName(prop)], getPropConfig(prop)] : attrs[prop];
});
......
......@@ -26,7 +26,7 @@ export default class TableModel {
return;
}
this.rows.sort(function(a, b) {
this.rows.sort((a, b) => {
a = a[options.col];
b = b[options.col];
// Sort null or undefined seperately from comparable values
......
......@@ -84,7 +84,7 @@ export function convertSeriesListToCsvColumns(seriesList, dateTimeFormat = DEFAU
formatSpecialHeader(excel) +
formatRow(
['Time'].concat(
seriesList.map(function(val) {
seriesList.map(val => {
return val.alias;
})
)
......@@ -97,7 +97,7 @@ export function convertSeriesListToCsvColumns(seriesList, dateTimeFormat = DEFAU
const timestamp = moment(seriesList[0].datapoints[i][POINT_TIME_INDEX]).format(dateTimeFormat);
text += formatRow(
[timestamp].concat(
seriesList.map(function(series) {
seriesList.map(series => {
return series.datapoints[i][POINT_VALUE_INDEX];
})
),
......
......@@ -10,7 +10,7 @@ export default function flatten(target, opts): any {
const output = {};
function step(object, prev) {
Object.keys(object).forEach(function(key) {
Object.keys(object).forEach(key => {
const value = object[key];
const isarray = opts.safe && Array.isArray(value);
const type = Object.prototype.toString.call(value);
......
......@@ -5,13 +5,13 @@ const kbn: any = {};
kbn.valueFormats = {};
kbn.regexEscape = function(value) {
kbn.regexEscape = value => {
return value.replace(/[\\^$*+?.()|[\]{}\/]/g, '\\$&');
};
///// HELPER FUNCTIONS /////
kbn.round_interval = function(interval) {
kbn.round_interval = interval => {
switch (true) {
// 0.015s
case interval < 15:
......@@ -102,7 +102,7 @@ kbn.round_interval = function(interval) {
}
};
kbn.secondsToHms = function(seconds) {
kbn.secondsToHms = seconds => {
const numyears = Math.floor(seconds / 31536000);
if (numyears) {
return numyears + 'y';
......@@ -131,7 +131,7 @@ kbn.secondsToHms = function(seconds) {
return 'less than a millisecond'; //'just now' //or other string you like;
};
kbn.secondsToHhmmss = function(seconds) {
kbn.secondsToHhmmss = seconds => {
const strings = [];
const numhours = Math.floor(seconds / 3600);
const numminutes = Math.floor((seconds % 3600) / 60);
......@@ -142,11 +142,11 @@ kbn.secondsToHhmmss = function(seconds) {
return strings.join(':');
};
kbn.to_percent = function(nr, outof) {
kbn.to_percent = (nr, outof) => {
return Math.floor(nr / outof * 10000) / 100 + '%';
};
kbn.addslashes = function(str) {
kbn.addslashes = str => {
str = str.replace(/\\/g, '\\\\');
str = str.replace(/\'/g, "\\'");
str = str.replace(/\"/g, '\\"');
......@@ -168,7 +168,7 @@ kbn.intervals_in_seconds = {
ms: 0.001,
};
kbn.calculateInterval = function(range, resolution, lowLimitInterval) {
kbn.calculateInterval = (range, resolution, lowLimitInterval) => {
let lowLimitMs = 1; // 1 millisecond default low limit
let intervalMs;
......@@ -190,7 +190,7 @@ kbn.calculateInterval = function(range, resolution, lowLimitInterval) {
};
};
kbn.describe_interval = function(str) {
kbn.describe_interval = str => {
const matches = str.match(kbn.interval_regex);
if (!matches || !_.has(kbn.intervals_in_seconds, matches[2])) {
throw new Error('Invalid interval string, expecting a number followed by one of "Mwdhmsy"');
......@@ -203,17 +203,17 @@ kbn.describe_interval = function(str) {
}
};
kbn.interval_to_ms = function(str) {
kbn.interval_to_ms = str => {
const info = kbn.describe_interval(str);
return info.sec * 1000 * info.count;
};
kbn.interval_to_seconds = function(str) {
kbn.interval_to_seconds = str => {
const info = kbn.describe_interval(str);
return info.sec * info.count;
};
kbn.query_color_dot = function(color, diameter) {
kbn.query_color_dot = (color, diameter) => {
return (
'<div class="icon-circle" style="' +
['display:inline-block', 'color:' + color, 'font-size:' + diameter + 'px'].join(';') +
......@@ -221,14 +221,14 @@ kbn.query_color_dot = function(color, diameter) {
);
};
kbn.slugifyForUrl = function(str) {
kbn.slugifyForUrl = str => {
return str
.toLowerCase()
.replace(/[^\w ]+/g, '')
.replace(/ +/g, '-');
};
kbn.stringToJsRegex = function(str) {
kbn.stringToJsRegex = str => {
if (str[0] !== '/') {
return new RegExp('^' + str + '$');
}
......@@ -237,7 +237,7 @@ kbn.stringToJsRegex = function(str) {
return new RegExp(match[1], match[2]);
};
kbn.toFixed = function(value, decimals) {
kbn.toFixed = (value, decimals) => {
if (value === null) {
return '';
}
......@@ -263,7 +263,7 @@ kbn.toFixed = function(value, decimals) {
return formatted;
};
kbn.toFixedScaled = function(value, decimals, scaledDecimals, additionalDecimals, ext) {
kbn.toFixedScaled = (value, decimals, scaledDecimals, additionalDecimals, ext) => {
if (scaledDecimals === null) {
return kbn.toFixed(value, decimals) + ext;
} else {
......@@ -271,7 +271,7 @@ kbn.toFixedScaled = function(value, decimals, scaledDecimals, additionalDecimals
}
};
kbn.roundValue = function(num, decimals) {
kbn.roundValue = (num, decimals) => {
if (num === null) {
return null;
}
......@@ -286,8 +286,8 @@ kbn.formatBuilders = {};
// Formatter which always appends a fixed unit string to the value. No
// scaling of the value is performed.
kbn.formatBuilders.fixedUnit = function(unit) {
return function(size, decimals) {
kbn.formatBuilders.fixedUnit = unit => {
return (size, decimals) => {
if (size === null) {
return '';
}
......@@ -298,8 +298,8 @@ kbn.formatBuilders.fixedUnit = function(unit) {
// Formatter which scales the unit string geometrically according to the given
// numeric factor. Repeatedly scales the value down by the factor until it is
// less than the factor in magnitude, or the end of the array is reached.
kbn.formatBuilders.scaledUnits = function(factor, extArray) {
return function(size, decimals, scaledDecimals) {
kbn.formatBuilders.scaledUnits = (factor, extArray) => {
return (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -327,10 +327,10 @@ kbn.formatBuilders.scaledUnits = function(factor, extArray) {
// Extension of the scaledUnits builder which uses SI decimal prefixes. If an
// offset is given, it adjusts the starting units at the given prefix; a value
// of 0 starts at no scale; -3 drops to nano, +2 starts at mega, etc.
kbn.formatBuilders.decimalSIPrefix = function(unit, offset) {
kbn.formatBuilders.decimalSIPrefix = (unit, offset) => {
let prefixes = ['n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
prefixes = prefixes.slice(3 + (offset || 0));
const units = prefixes.map(function(p) {
const units = prefixes.map(p => {
return ' ' + p + unit;
});
return kbn.formatBuilders.scaledUnits(1000, units);
......@@ -339,9 +339,9 @@ kbn.formatBuilders.decimalSIPrefix = function(unit, offset) {
// Extension of the scaledUnits builder which uses SI binary prefixes. If
// offset is given, it starts the units at the given prefix; otherwise, the
// offset defaults to zero and the initial unit is not prefixed.
kbn.formatBuilders.binarySIPrefix = function(unit, offset) {
kbn.formatBuilders.binarySIPrefix = (unit, offset) => {
const prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset);
const units = prefixes.map(function(p) {
const units = prefixes.map(p => {
return ' ' + p + unit;
});
return kbn.formatBuilders.scaledUnits(1024, units);
......@@ -349,10 +349,10 @@ kbn.formatBuilders.binarySIPrefix = function(unit, offset) {
// Currency formatter for prefixing a symbol onto a number. Supports scaling
// up to the trillions.
kbn.formatBuilders.currency = function(symbol) {
kbn.formatBuilders.currency = symbol => {
const units = ['', 'K', 'M', 'B', 'T'];
const scaler = kbn.formatBuilders.scaledUnits(1000, units);
return function(size, decimals, scaledDecimals) {
return (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -361,10 +361,10 @@ kbn.formatBuilders.currency = function(symbol) {
};
};
kbn.formatBuilders.simpleCountUnit = function(symbol) {
kbn.formatBuilders.simpleCountUnit = symbol => {
const units = ['', 'K', 'M', 'B', 'T'];
const scaler = kbn.formatBuilders.scaledUnits(1000, units);
return function(size, decimals, scaledDecimals) {
return (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -390,14 +390,14 @@ kbn.valueFormats.short = kbn.formatBuilders.scaledUnits(1000, [
]);
kbn.valueFormats.dB = kbn.formatBuilders.fixedUnit('dB');
kbn.valueFormats.percent = function(size, decimals) {
kbn.valueFormats.percent = (size, decimals) => {
if (size === null) {
return '';
}
return kbn.toFixed(size, decimals) + '%';
};
kbn.valueFormats.percentunit = function(size, decimals) {
kbn.valueFormats.percentunit = (size, decimals) => {
if (size === null) {
return '';
}
......@@ -407,7 +407,7 @@ kbn.valueFormats.percentunit = function(size, decimals) {
/* Formats the value to hex. Uses float if specified decimals are not 0.
* There are two options, one with 0x, and one without */
kbn.valueFormats.hex = function(value, decimals) {
kbn.valueFormats.hex = (value, decimals) => {
if (value == null) {
return '';
}
......@@ -416,7 +416,7 @@ kbn.valueFormats.hex = function(value, decimals) {
.toUpperCase();
};
kbn.valueFormats.hex0x = function(value, decimals) {
kbn.valueFormats.hex0x = (value, decimals) => {
if (value == null) {
return '';
}
......@@ -427,11 +427,11 @@ kbn.valueFormats.hex0x = function(value, decimals) {
return '0x' + hexString;
};
kbn.valueFormats.sci = function(value, decimals) {
kbn.valueFormats.sci = (value, decimals) => {
return value.toExponential(decimals);
};
kbn.valueFormats.locale = function(value, decimals) {
kbn.valueFormats.locale = (value, decimals) => {
return value.toLocaleString(undefined, { maximumFractionDigits: decimals });
};
......@@ -618,7 +618,7 @@ kbn.valueFormats.congNm3 = kbn.formatBuilders.fixedUnit('g/Nm³');
// Time
kbn.valueFormats.hertz = kbn.formatBuilders.decimalSIPrefix('Hz');
kbn.valueFormats.ms = function(size, decimals, scaledDecimals) {
kbn.valueFormats.ms = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -642,7 +642,7 @@ kbn.valueFormats.ms = function(size, decimals, scaledDecimals) {
return kbn.toFixedScaled(size / 31536000000, decimals, scaledDecimals, 10, ' year');
};
kbn.valueFormats.s = function(size, decimals, scaledDecimals) {
kbn.valueFormats.s = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -679,7 +679,7 @@ kbn.valueFormats.s = function(size, decimals, scaledDecimals) {
return kbn.toFixedScaled(size / 3.15569e7, decimals, scaledDecimals, 7, ' year');
};
kbn.valueFormats['µs'] = function(size, decimals, scaledDecimals) {
kbn.valueFormats['µs'] = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -693,7 +693,7 @@ kbn.valueFormats['µs'] = function(size, decimals, scaledDecimals) {
}
};
kbn.valueFormats.ns = function(size, decimals, scaledDecimals) {
kbn.valueFormats.ns = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -711,7 +711,7 @@ kbn.valueFormats.ns = function(size, decimals, scaledDecimals) {
}
};
kbn.valueFormats.m = function(size, decimals, scaledDecimals) {
kbn.valueFormats.m = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -729,7 +729,7 @@ kbn.valueFormats.m = function(size, decimals, scaledDecimals) {
}
};
kbn.valueFormats.h = function(size, decimals, scaledDecimals) {
kbn.valueFormats.h = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -745,7 +745,7 @@ kbn.valueFormats.h = function(size, decimals, scaledDecimals) {
}
};
kbn.valueFormats.d = function(size, decimals, scaledDecimals) {
kbn.valueFormats.d = (size, decimals, scaledDecimals) => {
if (size === null) {
return '';
}
......@@ -759,7 +759,7 @@ kbn.valueFormats.d = function(size, decimals, scaledDecimals) {
}
};
kbn.toDuration = function(size, decimals, timeScale) {
kbn.toDuration = (size, decimals, timeScale) => {
if (size === null) {
return '';
}
......@@ -784,7 +784,7 @@ kbn.toDuration = function(size, decimals, timeScale) {
// intervals_in_seconds uses seconds (duh), convert them to milliseconds here to minimize floating point errors
size *=
kbn.intervals_in_seconds[
units.find(function(e) {
units.find(e => {
return e.long === timeScale;
}).short
] * 1000;
......@@ -808,23 +808,23 @@ kbn.toDuration = function(size, decimals, timeScale) {
return strings.join(', ');
};
kbn.valueFormats.dtdurationms = function(size, decimals) {
kbn.valueFormats.dtdurationms = (size, decimals) => {
return kbn.toDuration(size, decimals, 'millisecond');
};
kbn.valueFormats.dtdurations = function(size, decimals) {
kbn.valueFormats.dtdurations = (size, decimals) => {
return kbn.toDuration(size, decimals, 'second');
};
kbn.valueFormats.dthms = function(size, decimals) {
kbn.valueFormats.dthms = (size, decimals) => {
return kbn.secondsToHhmmss(size);
};
kbn.valueFormats.timeticks = function(size, decimals, scaledDecimals) {
kbn.valueFormats.timeticks = (size, decimals, scaledDecimals) => {
return kbn.valueFormats.s(size / 100, decimals, scaledDecimals);
};
kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) {
kbn.valueFormats.dateTimeAsIso = (epoch, isUtc) => {
const time = isUtc ? moment.utc(epoch) : moment(epoch);
if (moment().isSame(epoch, 'day')) {
......@@ -833,7 +833,7 @@ kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) {
return time.format('YYYY-MM-DD HH:mm:ss');
};
kbn.valueFormats.dateTimeAsUS = function(epoch, isUtc) {
kbn.valueFormats.dateTimeAsUS = (epoch, isUtc) => {
const time = isUtc ? moment.utc(epoch) : moment(epoch);
if (moment().isSame(epoch, 'day')) {
......@@ -842,14 +842,14 @@ kbn.valueFormats.dateTimeAsUS = function(epoch, isUtc) {
return time.format('MM/DD/YYYY h:mm:ss a');
};
kbn.valueFormats.dateTimeFromNow = function(epoch, isUtc) {
kbn.valueFormats.dateTimeFromNow = (epoch, isUtc) => {
const time = isUtc ? moment.utc(epoch) : moment(epoch);
return time.fromNow();
};
///// FORMAT MENU /////
kbn.getUnitFormats = function() {
kbn.getUnitFormats = () => {
return [
{
text: 'none',
......
......@@ -5,7 +5,7 @@ function outlineFixer() {
const styleElement = d.createElement('STYLE');
const domEvents = 'addEventListener' in d;
const addEventListener = function(type, callback) {
const addEventListener = (type, callback) => {
// Basic cross-browser event handling
if (domEvents) {
d.addEventListener(type, callback);
......@@ -14,7 +14,7 @@ function outlineFixer() {
}
};
const setCss = function(cssText) {
const setCss = cssText => {
// Handle setting of <style> element contents in IE8
!!styleElement.styleSheet ? (styleElement.styleSheet.cssText = cssText) : (styleElement.innerHTML = cssText);
};
......@@ -22,11 +22,11 @@ function outlineFixer() {
d.getElementsByTagName('HEAD')[0].appendChild(styleElement);
// Using mousedown instead of mouseover, so that previously focused elements don't lose focus ring on mouse move
addEventListener('mousedown', function() {
addEventListener('mousedown', () => {
setCss(':focus{outline:0 !important}::-moz-focus-inner{border:0;}');
});
addEventListener('keydown', function() {
addEventListener('keydown', () => {
setCss('');
});
}
......
......@@ -61,7 +61,7 @@ const rangeOptions = [
const absoluteFormat = 'MMM D, YYYY HH:mm:ss';
const rangeIndex = {};
_.each(rangeOptions, function(frame) {
_.each(rangeOptions, frame => {
rangeIndex[frame.from + ' to ' + frame.to] = frame;
});
......
......@@ -6,11 +6,11 @@ export function toUrlParams(a) {
const s = [];
const rbracket = /\[\]$/;
const isArray = function(obj) {
const isArray = obj => {
return Object.prototype.toString.call(obj) === '[object Array]';
};
const add = function(k, v) {
const add = (k, v) => {
v = typeof v === 'function' ? v() : v === null ? '' : v === undefined ? '' : v;
if (typeof v !== 'boolean') {
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
......@@ -19,7 +19,7 @@ export function toUrlParams(a) {
}
};
const buildParams = function(prefix, obj) {
const buildParams = (prefix, obj) => {
let i, len, key;
if (prefix) {
......
......@@ -36,7 +36,7 @@ export class DashboardMigrator {
}
}
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
// rename panel type
if (panel.type === 'graphite') {
panel.type = 'graph';
......@@ -84,7 +84,7 @@ export class DashboardMigrator {
if (oldVersion < 3) {
// ensure panel ids
let maxId = this.dashboard.getNextPanelId();
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
if (!panel.id) {
panel.id = maxId;
maxId += 1;
......@@ -95,11 +95,11 @@ export class DashboardMigrator {
// schema version 4 changes
if (oldVersion < 4) {
// move aliasYAxis changes
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
if (panel.type !== 'graph') {
return;
}
_.each(panel.aliasYAxis, function(value, key) {
_.each(panel.aliasYAxis, (value, key) => {
panel.seriesOverrides = [{ alias: key, yaxis: value }];
});
delete panel.aliasYAxis;
......@@ -150,15 +150,15 @@ export class DashboardMigrator {
}
if (oldVersion < 8) {
panelUpgrades.push(function(panel) {
_.each(panel.targets, function(target) {
panelUpgrades.push(panel => {
_.each(panel.targets, target => {
// update old influxdb query schema
if (target.fields && target.tags && target.groupBy) {
if (target.rawQuery) {
delete target.fields;
delete target.fill;
} else {
target.select = _.map(target.fields, function(field) {
target.select = _.map(target.fields, field => {
const parts = [];
parts.push({ type: 'field', params: [field.name] });
parts.push({ type: field.func, params: [] });
......@@ -171,7 +171,7 @@ export class DashboardMigrator {
return parts;
});
delete target.fields;
_.each(target.groupBy, function(part) {
_.each(target.groupBy, part => {
if (part.type === 'time' && part.interval) {
part.params = [part.interval];
delete part.interval;
......@@ -195,7 +195,7 @@ export class DashboardMigrator {
// schema version 9 changes
if (oldVersion < 9) {
// move aliasYAxis changes
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
if (panel.type !== 'singlestat' && panel.thresholds !== '') {
return;
}
......@@ -214,12 +214,12 @@ export class DashboardMigrator {
// schema version 10 changes
if (oldVersion < 10) {
// move aliasYAxis changes
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
if (panel.type !== 'table') {
return;
}
_.each(panel.styles, function(style) {
_.each(panel.styles, style => {
if (style.thresholds && style.thresholds.length >= 3) {
const k = style.thresholds;
k.shift();
......@@ -231,7 +231,7 @@ export class DashboardMigrator {
if (oldVersion < 12) {
// update template variables
_.each(this.dashboard.templating.list, function(templateVariable) {
_.each(this.dashboard.templating.list, templateVariable => {
if (templateVariable.refresh) {
templateVariable.refresh = 1;
}
......@@ -248,7 +248,7 @@ export class DashboardMigrator {
if (oldVersion < 12) {
// update graph yaxes changes
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
if (panel.type !== 'graph') {
return;
}
......@@ -297,7 +297,7 @@ export class DashboardMigrator {
if (oldVersion < 13) {
// update graph yaxes changes
panelUpgrades.push(function(panel) {
panelUpgrades.push(panel => {
if (panel.type !== 'graph') {
return;
}
......
......@@ -258,7 +258,7 @@ export class DashboardModel {
}
sortPanelsByGridPos() {
this.panels.sort(function(panelA, panelB) {
this.panels.sort((panelA, panelB) => {
if (panelA.gridPos.y === panelB.gridPos.y) {
return panelA.gridPos.x - panelB.gridPos.x;
} else {
......@@ -775,8 +775,8 @@ export class DashboardModel {
getNextQueryLetter(panel) {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return _.find(letters, function(refId) {
return _.every(panel.targets, function(other) {
return _.find(letters, refId => {
return _.every(panel.targets, other => {
return other.refId !== refId;
});
});
......
......@@ -126,7 +126,7 @@ export class PanelCtrl {
const editorTab = { title, directiveFn };
if (_.isString(directiveFn)) {
editorTab.directiveFn = function() {
editorTab.directiveFn = () => {
return { templateUrl: directiveFn };
};
}
......
......@@ -24,7 +24,7 @@ export function graphiteAddFunc($compile) {
$input.appendTo(elem);
$button.appendTo(elem);
ctrl.datasource.getFuncDefs().then(function(funcDefs) {
ctrl.datasource.getFuncDefs().then(funcDefs => {
const allFunctions = _.map(funcDefs, 'name').sort();
$scope.functionMenu = createFunctionDropDownMenu(funcDefs);
......@@ -34,12 +34,12 @@ export function graphiteAddFunc($compile) {
source: allFunctions,
minLength: 1,
items: 10,
updater: function(value) {
updater: value => {
let funcDef = ctrl.datasource.getFuncDef(value);
if (!funcDef) {
// try find close match
value = value.toLowerCase();
funcDef = _.find(allFunctions, function(funcName) {
funcDef = _.find(allFunctions, funcName => {
return funcName.toLowerCase().indexOf(value) === 0;
});
......@@ -48,7 +48,7 @@ export function graphiteAddFunc($compile) {
}
}
$scope.$apply(function() {
$scope.$apply(() => {
ctrl.addFunction(funcDef);
});
......@@ -57,20 +57,20 @@ export function graphiteAddFunc($compile) {
},
});
$button.click(function() {
$button.click(() => {
$button.hide();
$input.show();
$input.focus();
});
$input.keyup(function() {
$input.keyup(() => {
elem.toggleClass('open', $input.val() === '');
});
$input.blur(function() {
$input.blur(() => {
// clicking the function dropdown menu won't
// work if you remove class at once
setTimeout(function() {
setTimeout(() => {
$input.val('');
$input.hide();
$button.show();
......@@ -82,7 +82,7 @@ export function graphiteAddFunc($compile) {
});
let drop;
const cleanUpDrop = function() {
const cleanUpDrop = () => {
if (drop) {
drop.destroy();
drop = null;
......@@ -121,7 +121,7 @@ export function graphiteAddFunc($compile) {
});
}
})
.on('mouseout', 'ul.dropdown-menu li', function() {
.on('mouseout', 'ul.dropdown-menu li', () => {
cleanUpDrop();
});
......@@ -135,7 +135,7 @@ angular.module('grafana.directives').directive('graphiteAddFunc', graphiteAddFun
function createFunctionDropDownMenu(funcDefs) {
const categories = {};
_.forEach(funcDefs, function(funcDef) {
_.forEach(funcDefs, funcDef => {
if (!funcDef.category) {
return;
}
......@@ -149,7 +149,7 @@ function createFunctionDropDownMenu(funcDefs) {
});
return _.sortBy(
_.map(categories, function(submenu, category) {
_.map(categories, (submenu, category) => {
return {
text: category,
submenu: _.sortBy(submenu, 'text'),
......
......@@ -16,7 +16,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
this.funcDefs = null;
this.funcDefsPromise = null;
this.getQueryOptionsInfo = function() {
this.getQueryOptionsInfo = () => {
return {
maxDataPoints: true,
cacheTimeout: true,
......@@ -70,7 +70,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
}
};
this.convertDataPointsToMs = function(result) {
this.convertDataPointsToMs = result => {
if (!result || !result.data) {
return [];
}
......@@ -83,7 +83,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
return result;
};
this.parseTags = function(tagString) {
this.parseTags = tagString => {
let tags = [];
tags = tagString.split(',');
if (tags.length === 1) {
......@@ -106,7 +106,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
maxDataPoints: 100,
};
return this.query(graphiteQuery).then(function(result) {
return this.query(graphiteQuery).then(result => {
const list = [];
for (let i = 0; i < result.data.length; i++) {
......@@ -175,11 +175,11 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
}
};
this.targetContainsTemplate = function(target) {
this.targetContainsTemplate = target => {
return templateSrv.variableExists(target.target);
};
this.translateTime = function(date, roundUp) {
this.translateTime = (date, roundUp) => {
if (_.isString(date)) {
if (date === 'now') {
return 'now';
......@@ -467,7 +467,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
targets: [{ target: 'constantLine(100)' }],
maxDataPoints: 300,
};
return this.query(query).then(function() {
return this.query(query).then(() => {
return { status: 'success', message: 'Data source is working' };
});
};
......@@ -539,7 +539,7 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv,
}
}
_.each(options, function(value, key) {
_.each(options, (value, key) => {
if (_.indexOf(graphiteOptions, key) === -1) {
return;
}
......
......@@ -57,7 +57,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
if (!scheduledRelink) {
scheduledRelink = true;
setTimeout(function() {
setTimeout(() => {
relink();
scheduledRelink = false;
}, 200);
......@@ -93,7 +93,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
scheduledRelinkIfNeeded();
$scope.$apply(function() {
$scope.$apply(() => {
ctrl.targetChanged();
});
......@@ -113,7 +113,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
const inputElem = this;
// happens long before the click event on the typeahead options
// need to have long delay because the blur
cancelBlur = setTimeout(function() {
cancelBlur = setTimeout(() => {
switchToLink(inputElem, paramIndex);
}, 200);
}
......@@ -135,7 +135,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
let options = paramDef(paramIndex).options;
if (paramDef(paramIndex).type === 'int') {
options = _.map(options, function(val) {
options = _.map(options, val => {
return val.toString();
});
}
......@@ -144,7 +144,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
source: options,
minLength: 0,
items: 20,
updater: function(value) {
updater: value => {
$input.val(value);
switchToLink($input[0], paramIndex);
return value;
......@@ -185,7 +185,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
defParams.push(_.assign({}, lastParam, { optional: true }));
}
_.each(defParams, function(param, index) {
_.each(defParams, (param, index) => {
if (param.optional && func.params.length < index) {
return false;
}
......@@ -236,7 +236,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
function ifJustAddedFocusFirstParam() {
if ($scope.func.added) {
$scope.func.added = false;
setTimeout(function() {
setTimeout(() => {
elem
.find('.graphite-func-param-link')
.first()
......@@ -250,18 +250,18 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
}
function registerFuncControlsActions() {
$funcControls.click(function(e) {
$funcControls.click(e => {
const $target = $(e.target);
if ($target.hasClass('fa-remove')) {
toggleFuncControls();
$scope.$apply(function() {
$scope.$apply(() => {
ctrl.removeFunction($scope.func);
});
return;
}
if ($target.hasClass('fa-arrow-left')) {
$scope.$apply(function() {
$scope.$apply(() => {
_.move(ctrl.queryModel.functions, $scope.$index, $scope.$index - 1);
ctrl.targetChanged();
});
......@@ -269,7 +269,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
}
if ($target.hasClass('fa-arrow-right')) {
$scope.$apply(function() {
$scope.$apply(() => {
_.move(ctrl.queryModel.functions, $scope.$index, $scope.$index + 1);
ctrl.targetChanged();
});
......
......@@ -1058,10 +1058,10 @@ function getFuncDef(name, idx?) {
function getFuncDefs(graphiteVersion, idx?) {
const funcs = {};
_.forEach(idx || index, function(funcDef) {
_.forEach(idx || index, funcDef => {
if (isVersionRelatedFunction(funcDef, graphiteVersion)) {
funcs[funcDef.name] = _.assign({}, funcDef, {
params: _.filter(funcDef.params, function(param) {
params: _.filter(funcDef.params, param => {
return isVersionRelatedFunction(param, graphiteVersion);
}),
});
......
......@@ -20,16 +20,16 @@ describe('opentsdb', () => {
let requestOptions;
beforeEach(async () => {
ctx.backendSrv.datasourceRequest = await function(options) {
ctx.backendSrv.datasourceRequest = await (options => {
requestOptions = options;
return Promise.resolve({
data: [{ target: 'prod1.count', datapoints: [[10, 1], [12, 1]] }],
});
};
});
});
it('metrics() should generate api suggest query', () => {
ctx.ctrl.metricFindQuery('metrics(pew)').then(function(data) {
ctx.ctrl.metricFindQuery('metrics(pew)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/suggest');
......@@ -39,7 +39,7 @@ describe('opentsdb', () => {
});
it('tag_names(cpu) should generate lookup query', () => {
ctx.ctrl.metricFindQuery('tag_names(cpu)').then(function(data) {
ctx.ctrl.metricFindQuery('tag_names(cpu)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/search/lookup');
......@@ -47,7 +47,7 @@ describe('opentsdb', () => {
});
it('tag_values(cpu, test) should generate lookup query', () => {
ctx.ctrl.metricFindQuery('tag_values(cpu, hostname)').then(function(data) {
ctx.ctrl.metricFindQuery('tag_values(cpu, hostname)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/search/lookup');
......@@ -55,7 +55,7 @@ describe('opentsdb', () => {
});
it('tag_values(cpu, test) should generate lookup query', () => {
ctx.ctrl.metricFindQuery('tag_values(cpu, hostname, env=$env)').then(function(data) {
ctx.ctrl.metricFindQuery('tag_values(cpu, hostname, env=$env)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/search/lookup');
......@@ -63,7 +63,7 @@ describe('opentsdb', () => {
});
it('tag_values(cpu, test) should generate lookup query', () => {
ctx.ctrl.metricFindQuery('tag_values(cpu, hostname, env=$env, region=$region)').then(function(data) {
ctx.ctrl.metricFindQuery('tag_values(cpu, hostname, env=$env, region=$region)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/search/lookup');
......@@ -71,7 +71,7 @@ describe('opentsdb', () => {
});
it('suggest_tagk() should generate api suggest query', () => {
ctx.ctrl.metricFindQuery('suggest_tagk(foo)').then(function(data) {
ctx.ctrl.metricFindQuery('suggest_tagk(foo)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/suggest');
......@@ -80,7 +80,7 @@ describe('opentsdb', () => {
});
it('suggest_tagv() should generate api suggest query', () => {
ctx.ctrl.metricFindQuery('suggest_tagv(bar)').then(function(data) {
ctx.ctrl.metricFindQuery('suggest_tagv(bar)').then(data => {
results = data;
});
expect(requestOptions.url).toBe('/api/suggest');
......
......@@ -36,7 +36,7 @@ export const FolderStore = types
return res;
}),
setTitle: function(originalTitle: string, title: string) {
setTitle: (originalTitle: string, title: string) => {
self.folder.title = title;
self.folder.hasChanged = originalTitle.toLowerCase() !== title.trim().toLowerCase() && title.trim().length > 0;
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment