diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index 753f7a5a330..50ff55f3083 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -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); }); } diff --git a/public/app/core/components/colorpicker/spectrum_picker.ts b/public/app/core/components/colorpicker/spectrum_picker.ts index 6e93a4f39f4..4576648df83 100644 --- a/public/app/core/components/colorpicker/spectrum_picker.ts +++ b/public/app/core/components/colorpicker/spectrum_picker.ts @@ -13,7 +13,7 @@ export function spectrumPicker() { scope: true, replace: true, template: '', - link: function(scope, element, attrs, ngModel) { + link: (scope, element, attrs, ngModel) => { scope.ngModel = ngModel; scope.onColorChange = color => { ngModel.$setViewValue(color); diff --git a/public/app/core/components/json_explorer/json_explorer.ts b/public/app/core/components/json_explorer/json_explorer.ts index 779e5a93cba..9a344d3195b 100644 --- a/public/app/core/components/json_explorer/json_explorer.ts +++ b/public/app/core/components/json_explorer/json_explorer.ts @@ -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; diff --git a/public/app/core/components/jsontree/jsontree.ts b/public/app/core/components/jsontree/jsontree.ts index 5fbda5560b3..4bcb2f632c2 100644 --- a/public/app/core/components/jsontree/jsontree.ts +++ b/public/app/core/components/jsontree/jsontree.ts @@ -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, }); diff --git a/public/app/core/directives/dash_class.ts b/public/app/core/directives/dash_class.ts index 031338d3c5b..224bc2c772d 100644 --- a/public/app/core/directives/dash_class.ts +++ b/public/app/core/directives/dash_class.ts @@ -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 { diff --git a/public/app/core/directives/dropdown_typeahead.ts b/public/app/core/directives/dropdown_typeahead.ts index af8c4ddc3bb..cdba0f3e3c2 100644 --- a/public/app/core/directives/dropdown_typeahead.ts +++ b/public/app/core/directives/dropdown_typeahead.ts @@ -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); }); diff --git a/public/app/core/directives/give_focus.ts b/public/app/core/directives/give_focus.ts index 9b2cf01750e..4ef574ec68e 100644 --- a/public/app/core/directives/give_focus.ts +++ b/public/app/core/directives/give_focus.ts @@ -1,18 +1,18 @@ 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) { diff --git a/public/app/core/directives/metric_segment.ts b/public/app/core/directives/metric_segment.ts index 117f776f487..7759e14f2cc 100644 --- a/public/app/core/directives/metric_segment.ts +++ b/public/app/core/directives/metric_segment.ts @@ -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(); }); }); diff --git a/public/app/core/directives/misc.ts b/public/app/core/directives/misc.ts index 07ba3263763..192e2df4167 100644 --- a/public/app/core/directives/misc.ts +++ b/public/app/core/directives/misc.ts @@ -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 = '' + attrs.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); diff --git a/public/app/core/directives/ng_model_on_blur.ts b/public/app/core/directives/ng_model_on_blur.ts index 2818f620dde..7e903c1f889 100644 --- a/public/app/core/directives/ng_model_on_blur.ts +++ b/public/app/core/directives/ng_model_on_blur.ts @@ -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; } diff --git a/public/app/core/directives/rebuild_on_change.ts b/public/app/core/directives/rebuild_on_change.ts index 72b9c05064a..378c32b14f7 100644 --- a/public/app/core/directives/rebuild_on_change.ts +++ b/public/app/core/directives/rebuild_on_change.ts @@ -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 }; diff --git a/public/app/core/directives/tags.ts b/public/app/core/directives/tags.ts index 00da9105e5f..33a2252a683 100644 --- a/public/app/core/directives/tags.ts +++ b/public/app/core/directives/tags.ts @@ -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 = []; } diff --git a/public/app/core/directives/value_select_dropdown.ts b/public/app/core/directives/value_select_dropdown.ts index 69504c1bb1b..a75ecd46ad0 100644 --- a/public/app/core/directives/value_select_dropdown.ts +++ b/public/app/core/directives/value_select_dropdown.ts @@ -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(); }); } diff --git a/public/app/core/jquery_extended.ts b/public/app/core/jquery_extended.ts index 241baa1af22..fa9b1aeb823 100644 --- a/public/app/core/jquery_extended.ts +++ b/public/app/core/jquery_extended.ts @@ -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); diff --git a/public/app/core/partials.ts b/public/app/core/partials.ts index 64b0b11b8ca..864a3dcfa8a 100644 --- a/public/app/core/partials.ts +++ b/public/app/core/partials.ts @@ -1,4 +1,4 @@ let templates = (require as any).context('../', true, /\.html$/); -templates.keys().forEach(function(key) { +templates.keys().forEach(key => { templates(key); }); diff --git a/public/app/core/profiler.ts b/public/app/core/profiler.ts index 9ad451353d2..0e738dd3da1 100644 --- a/public/app/core/profiler.ts +++ b/public/app/core/profiler.ts @@ -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)); }); }; diff --git a/public/app/core/services/analytics.ts b/public/app/core/services/analytics.ts index a0faf4016fd..d50140bbd75 100644 --- a/public/app/core/services/analytics.ts +++ b/public/app/core/services/analytics.ts @@ -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(); diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index c40fbff2ab2..c4134598175 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -64,6 +64,6 @@ export class ContextSrv { const contextSrv = new ContextSrv(); export { contextSrv }; -coreModule.factory('contextSrv', function() { +coreModule.factory('contextSrv', () => { return contextSrv; }); diff --git a/public/app/core/services/ng_react.ts b/public/app/core/services/ng_react.ts index 4036b4bd1fd..643e34dd62e 100644 --- a/public/app/core/services/ng_react.ts +++ b/public/app/core/services/ng_react.ts @@ -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) { // // // -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]; }); diff --git a/public/app/core/table_model.ts b/public/app/core/table_model.ts index 0c85a0293dd..f8b96d0537b 100644 --- a/public/app/core/table_model.ts +++ b/public/app/core/table_model.ts @@ -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 diff --git a/public/app/core/utils/file_export.ts b/public/app/core/utils/file_export.ts index 298a06c64fd..4fbdea0f953 100644 --- a/public/app/core/utils/file_export.ts +++ b/public/app/core/utils/file_export.ts @@ -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]; }) ), diff --git a/public/app/core/utils/flatten.ts b/public/app/core/utils/flatten.ts index 3350f5f6c33..38601f463aa 100644 --- a/public/app/core/utils/flatten.ts +++ b/public/app/core/utils/flatten.ts @@ -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); diff --git a/public/app/core/utils/kbn.ts b/public/app/core/utils/kbn.ts index 8b276acb539..bd69f2e89d9 100644 --- a/public/app/core/utils/kbn.ts +++ b/public/app/core/utils/kbn.ts @@ -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 ( '