From e1beaaa0f72dd3238dfda17bf31b82fb71a2ccc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 26 Aug 2018 21:52:57 +0200 Subject: [PATCH] tslint: tslint to const fixes part3 (#13036) --- public/app/app.ts | 10 +- public/app/containers/Explore/Explore.tsx | 7 +- public/app/containers/Explore/Graph.tsx | 8 +- .../core/components/PageHeader/PageHeader.tsx | 4 +- .../components/form_dropdown/form_dropdown.ts | 10 +- .../manage_dashboards/manage_dashboards.ts | 2 +- public/app/core/controllers/inspect_ctrl.ts | 10 +- .../app/core/controllers/json_editor_ctrl.ts | 2 +- public/app/core/controllers/login_ctrl.ts | 2 +- .../core/controllers/reset_password_ctrl.ts | 2 +- public/app/core/controllers/signup_ctrl.ts | 2 +- public/app/core/filters/filters.ts | 4 +- public/app/core/services/alert_srv.ts | 4 +- public/app/core/services/analytics.ts | 6 +- .../core/services/dynamic_directive_srv.ts | 2 +- public/app/core/services/keybindingSrv.ts | 10 +- public/app/core/services/popover_srv.ts | 8 +- public/app/core/services/util_srv.ts | 4 +- public/app/core/specs/datemath.test.ts | 30 +-- public/app/core/specs/emitter.test.ts | 16 +- public/app/core/specs/flatten.test.ts | 2 +- public/app/core/specs/kbn.test.ts | 176 +++++++++--------- public/app/core/specs/rangeutil.test.ts | 36 ++-- public/app/core/specs/table_model.test.ts | 6 +- public/app/core/specs/time_series.test.ts | 6 +- public/app/core/utils/css_loader.ts | 26 +-- public/app/core/utils/flatten.ts | 18 +- public/app/core/utils/kbn.ts | 82 ++++---- public/app/core/utils/rangeutil.ts | 18 +- .../app/features/dashboard/dashboard_ctrl.ts | 4 +- .../dashboard/dashboard_loader_srv.ts | 10 +- .../dashboard/dashgrid/PanelLoader.ts | 4 +- .../app/features/dashboard/dashnav/dashnav.ts | 4 +- .../app/features/dashboard/save_as_modal.ts | 2 +- public/app/features/dashboard/save_modal.ts | 6 +- .../dashboard/save_provisioned_modal.ts | 2 +- .../app/features/dashboard/shareModalCtrl.ts | 6 +- .../features/dashboard/share_snapshot_ctrl.ts | 12 +- .../app/features/dashboard/submenu/submenu.ts | 2 +- .../app/features/dashboard/view_state_srv.ts | 20 +- public/app/features/dashlinks/module.ts | 8 +- public/app/features/panellinks/module.ts | 4 +- public/app/features/plugins/ds_edit_ctrl.ts | 2 +- .../plugins/import_list/import_list.ts | 2 +- .../app/features/plugins/plugin_component.ts | 12 +- .../app/features/plugins/plugin_edit_ctrl.ts | 6 +- .../app/features/plugins/plugin_page_ctrl.ts | 2 +- .../app/features/templating/adhoc_variable.ts | 2 +- .../templating/datasource_variable.ts | 6 +- public/app/features/templating/editor_ctrl.ts | 8 +- .../features/templating/interval_variable.ts | 2 +- .../app/features/templating/query_variable.ts | 12 +- .../app/features/templating/template_srv.ts | 18 +- .../app/features/templating/variable_srv.ts | 22 +-- public/app/routes/dashboard_loaders.ts | 2 +- public/test/lib/common.ts | 29 +-- 56 files changed, 359 insertions(+), 363 deletions(-) diff --git a/public/app/app.ts b/public/app/app.ts index 9ac76b8ec91..d9e31018af9 100644 --- a/public/app/app.ts +++ b/public/app/app.ts @@ -53,7 +53,7 @@ export class GrafanaApp { } init() { - var app = angular.module('grafana', []); + const app = angular.module('grafana', []); moment.locale(config.bootData.user.locale); @@ -77,7 +77,7 @@ export class GrafanaApp { '$delegate', '$templateCache', function($delegate, $templateCache) { - var get = $delegate.get; + const get = $delegate.get; $delegate.get = function(url, config) { if (url.match(/\.html$/)) { // some template's already exist in the cache @@ -105,10 +105,10 @@ export class GrafanaApp { 'react', ]; - var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes']; + const module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes']; _.each(module_types, type => { - var moduleName = 'grafana.' + type; + const moduleName = 'grafana.' + type; this.useModule(angular.module(moduleName, [])); }); @@ -119,7 +119,7 @@ export class GrafanaApp { coreModule.config(setupAngularRoutes); registerAngularDirectives(); - var preBootRequires = [System.import('app/features/all')]; + const preBootRequires = [System.import('app/features/all')]; Promise.all(preBootRequires) .then(() => { diff --git a/public/app/containers/Explore/Explore.tsx b/public/app/containers/Explore/Explore.tsx index e06f4e7042e..92712709858 100644 --- a/public/app/containers/Explore/Explore.tsx +++ b/public/app/containers/Explore/Explore.tsx @@ -346,19 +346,24 @@ export class Explore extends React.Component { onQuerySuccess(datasourceId: string, queries: any[]): void { // save queries to history - let { datasource, history } = this.state; + let { history } = this.state; + const { datasource } = this.state; + if (datasource.meta.id !== datasourceId) { // Navigated away, queries did not matter return; } + const ts = Date.now(); queries.forEach(q => { const { query } = q; history = [{ query, ts }, ...history]; }); + if (history.length > MAX_HISTORY_ITEMS) { history = history.slice(0, MAX_HISTORY_ITEMS); } + // Combine all queries of a datasource type into one history const historyKey = `grafana.explore.history.${datasourceId}`; store.setObject(historyKey, history); diff --git a/public/app/containers/Explore/Graph.tsx b/public/app/containers/Explore/Graph.tsx index 171be9da6ba..9243f612466 100644 --- a/public/app/containers/Explore/Graph.tsx +++ b/public/app/containers/Explore/Graph.tsx @@ -12,10 +12,10 @@ import Legend from './Legend'; // Copied from graph.ts function time_format(ticks, min, max) { if (min && max && ticks) { - var range = max - min; - var secPerTick = range / ticks / 1000; - var oneDay = 86400000; - var oneYear = 31536000000; + const range = max - min; + const secPerTick = range / ticks / 1000; + const oneDay = 86400000; + const oneYear = 31536000000; if (secPerTick <= 45) { return '%H:%M:%S'; diff --git a/public/app/core/components/PageHeader/PageHeader.tsx b/public/app/core/components/PageHeader/PageHeader.tsx index 1d744b7e609..b7bef2495bb 100644 --- a/public/app/core/components/PageHeader/PageHeader.tsx +++ b/public/app/core/components/PageHeader/PageHeader.tsx @@ -15,8 +15,8 @@ const SelectNav = ({ main, customCss }: { main: NavModelItem; customCss: string }); const gotoUrl = evt => { - var element = evt.target; - var url = element.options[element.selectedIndex].value; + const element = evt.target; + const url = element.options[element.selectedIndex].value; appEvents.emit('location-change', { href: url }); }; diff --git a/public/app/core/components/form_dropdown/form_dropdown.ts b/public/app/core/components/form_dropdown/form_dropdown.ts index 007c7c3acb1..4604e1d7838 100644 --- a/public/app/core/components/form_dropdown/form_dropdown.ts +++ b/public/app/core/components/form_dropdown/form_dropdown.ts @@ -67,7 +67,7 @@ export class FormDropdownCtrl { // modify typeahead lookup // this = typeahead - var typeahead = this.inputElement.data('typeahead'); + const typeahead = this.inputElement.data('typeahead'); typeahead.lookup = function() { this.query = this.$element.val() || ''; this.source(this.query, this.process.bind(this)); @@ -100,7 +100,7 @@ export class FormDropdownCtrl { } getOptionsInternal(query) { - var result = this.getOptions({ $query: query }); + const result = this.getOptions({ $query: query }); if (this.isPromiseLike(result)) { return result; } @@ -118,7 +118,7 @@ export class FormDropdownCtrl { // if we have text use it if (this.lookupText) { this.getOptionsInternal('').then(options => { - var item = _.find(options, { value: this.model }); + const item = _.find(options, { value: this.model }); this.updateDisplay(item ? item.text : this.model); }); } else { @@ -186,7 +186,7 @@ export class FormDropdownCtrl { } this.$scope.$apply(() => { - var option = _.find(this.optionCache, { text: text }); + const option = _.find(this.optionCache, { text: text }); if (option) { if (_.isObject(this.model)) { @@ -228,7 +228,7 @@ export class FormDropdownCtrl { this.linkElement.hide(); this.linkMode = false; - var typeahead = this.inputElement.data('typeahead'); + const typeahead = this.inputElement.data('typeahead'); if (typeahead) { this.inputElement.val(''); typeahead.lookup(); diff --git a/public/app/core/components/manage_dashboards/manage_dashboards.ts b/public/app/core/components/manage_dashboards/manage_dashboards.ts index 59a34d08c12..0016305e617 100644 --- a/public/app/core/components/manage_dashboards/manage_dashboards.ts +++ b/public/app/core/components/manage_dashboards/manage_dashboards.ts @@ -238,7 +238,7 @@ export class ManageDashboardsCtrl { } onTagFilterChange() { - var res = this.filterByTag(this.selectedTagFilter.term); + const res = this.filterByTag(this.selectedTagFilter.term); this.selectedTagFilter = this.tagFilterOptions[0]; return res; } diff --git a/public/app/core/controllers/inspect_ctrl.ts b/public/app/core/controllers/inspect_ctrl.ts index 5dd4cb3d06f..612b9cac42e 100644 --- a/public/app/core/controllers/inspect_ctrl.ts +++ b/public/app/core/controllers/inspect_ctrl.ts @@ -6,7 +6,7 @@ import coreModule from '../core_module'; export class InspectCtrl { /** @ngInject */ constructor($scope, $sanitize) { - var model = $scope.inspector; + const model = $scope.inspector; $scope.init = function() { $scope.editor = { index: 0 }; @@ -53,10 +53,10 @@ export class InspectCtrl { }; } getParametersFromQueryString(queryString) { - var result = []; - var parameters = queryString.split('&'); - for (var i = 0; i < parameters.length; i++) { - var keyValue = parameters[i].split('='); + const result = []; + const parameters = queryString.split('&'); + for (let i = 0; i < parameters.length; i++) { + const keyValue = parameters[i].split('='); if (keyValue[1].length > 0) { result.push({ key: keyValue[0], diff --git a/public/app/core/controllers/json_editor_ctrl.ts b/public/app/core/controllers/json_editor_ctrl.ts index d369fe8b3c0..3260f6ff537 100644 --- a/public/app/core/controllers/json_editor_ctrl.ts +++ b/public/app/core/controllers/json_editor_ctrl.ts @@ -9,7 +9,7 @@ export class JsonEditorCtrl { $scope.canCopy = $scope.enableCopy; $scope.update = function() { - var newObject = angular.fromJson($scope.json); + const newObject = angular.fromJson($scope.json); $scope.updateHandler(newObject, $scope.object); }; diff --git a/public/app/core/controllers/login_ctrl.ts b/public/app/core/controllers/login_ctrl.ts index 6662686b238..daf562c65da 100644 --- a/public/app/core/controllers/login_ctrl.ts +++ b/public/app/core/controllers/login_ctrl.ts @@ -118,7 +118,7 @@ export class LoginCtrl { }; $scope.toGrafana = function() { - var params = $location.search(); + const params = $location.search(); if (params.redirect && params.redirect[0] === '/') { window.location.href = config.appSubUrl + params.redirect; diff --git a/public/app/core/controllers/reset_password_ctrl.ts b/public/app/core/controllers/reset_password_ctrl.ts index 360c5bf8071..244f0307150 100644 --- a/public/app/core/controllers/reset_password_ctrl.ts +++ b/public/app/core/controllers/reset_password_ctrl.ts @@ -7,7 +7,7 @@ export class ResetPasswordCtrl { $scope.formModel = {}; $scope.mode = 'send'; - var params = $location.search(); + const params = $location.search(); if (params.code) { $scope.mode = 'reset'; $scope.formModel.code = params.code; diff --git a/public/app/core/controllers/signup_ctrl.ts b/public/app/core/controllers/signup_ctrl.ts index ad23e0f7f22..5a85e1605b7 100644 --- a/public/app/core/controllers/signup_ctrl.ts +++ b/public/app/core/controllers/signup_ctrl.ts @@ -9,7 +9,7 @@ export class SignUpCtrl { $scope.formModel = {}; - var params = $location.search(); + const params = $location.search(); // validate email is semi ok if (params.email && !params.email.match(/^\S+@\S+$/)) { diff --git a/public/app/core/filters/filters.ts b/public/app/core/filters/filters.ts index c6aea32d38d..098bda58de9 100644 --- a/public/app/core/filters/filters.ts +++ b/public/app/core/filters/filters.ts @@ -38,7 +38,7 @@ coreModule.filter('moment', function() { }); coreModule.filter('noXml', function() { - var noXml = function(text) { + const noXml = function(text) { return _.isString(text) ? text .replace(/&/g, '&') @@ -55,7 +55,7 @@ coreModule.filter('noXml', function() { /** @ngInject */ function interpolateTemplateVars(templateSrv) { - var filterFunc: any = function(text, scope) { + const filterFunc: any = function(text, scope) { var scopedVars; if (scope.ctrl) { scopedVars = (scope.ctrl.panel || scope.ctrl.row).scopedVars; diff --git a/public/app/core/services/alert_srv.ts b/public/app/core/services/alert_srv.ts index fc76ef9e371..19ad81667d7 100644 --- a/public/app/core/services/alert_srv.ts +++ b/public/app/core/services/alert_srv.ts @@ -60,14 +60,14 @@ export class AlertSrv { } } - var newAlert = { + const newAlert = { title: title || '', text: text || '', severity: severity || 'info', icon: this.getIconForSeverity(severity), }; - var newAlertJson = angular.toJson(newAlert); + const newAlertJson = angular.toJson(newAlert); // remove same alert if it already exists _.remove(this.list, function(value) { diff --git a/public/app/core/services/analytics.ts b/public/app/core/services/analytics.ts index d1998f44cbc..c3936f45451 100644 --- a/public/app/core/services/analytics.ts +++ b/public/app/core/services/analytics.ts @@ -12,7 +12,7 @@ export class Analytics { dataType: 'script', cache: true, }); - var ga = ((window).ga = + const ga = ((window).ga = (window).ga || function() { (ga.q = ga.q || []).push(arguments); @@ -25,8 +25,8 @@ export class Analytics { init() { this.$rootScope.$on('$viewContentLoaded', () => { - var track = { page: this.$location.url() }; - var ga = (window).ga || this.gaInit(); + const track = { page: this.$location.url() }; + const ga = (window).ga || this.gaInit(); ga('set', track); ga('send', 'pageview'); }); diff --git a/public/app/core/services/dynamic_directive_srv.ts b/public/app/core/services/dynamic_directive_srv.ts index de06daf2c1a..ccd86856755 100644 --- a/public/app/core/services/dynamic_directive_srv.ts +++ b/public/app/core/services/dynamic_directive_srv.ts @@ -6,7 +6,7 @@ class DynamicDirectiveSrv { constructor(private $compile, private $rootScope) {} addDirective(element, name, scope) { - var child = angular.element(document.createElement(name)); + const child = angular.element(document.createElement(name)); this.$compile(child)(scope); element.empty(); diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index 5405a347ba0..cad538d13aa 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -70,7 +70,7 @@ export class KeybindingSrv { } exit() { - var popups = $('.popover.in'); + const popups = $('.popover.in'); if (popups.length > 0) { return; } @@ -89,7 +89,7 @@ export class KeybindingSrv { } // close settings view - var search = this.$location.search(); + const search = this.$location.search(); if (search.editview) { delete search.editview; this.$location.search(search); @@ -123,7 +123,7 @@ export class KeybindingSrv { } showDashEditView() { - var search = _.extend(this.$location.search(), { editview: 'settings' }); + const search = _.extend(this.$location.search(), { editview: 'settings' }); this.$location.search(search); } @@ -218,8 +218,8 @@ export class KeybindingSrv { // share panel this.bind('p s', () => { if (dashboard.meta.focusPanelId) { - var shareScope = scope.$new(); - var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); + const shareScope = scope.$new(); + const panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); shareScope.panel = panelInfo.panel; shareScope.dashboard = dashboard; diff --git a/public/app/core/services/popover_srv.ts b/public/app/core/services/popover_srv.ts index 113e1e5fae7..33568cda8d3 100644 --- a/public/app/core/services/popover_srv.ts +++ b/public/app/core/services/popover_srv.ts @@ -18,10 +18,10 @@ function popoverSrv($compile, $rootScope, $timeout) { openDrop = null; } - var scope = _.extend($rootScope.$new(true), options.model); - var drop; + const scope = _.extend($rootScope.$new(true), options.model); + let drop; - var cleanUp = () => { + const cleanUp = () => { setTimeout(() => { scope.$destroy(); @@ -41,7 +41,7 @@ function popoverSrv($compile, $rootScope, $timeout) { drop.close(); }; - var contentElement = document.createElement('div'); + const contentElement = document.createElement('div'); contentElement.innerHTML = options.template; $compile(contentElement)(scope); diff --git a/public/app/core/services/util_srv.ts b/public/app/core/services/util_srv.ts index 1afae0a02f4..da598fbb127 100644 --- a/public/app/core/services/util_srv.ts +++ b/public/app/core/services/util_srv.ts @@ -33,7 +33,7 @@ export class UtilSrv { this.modalScope = this.$rootScope.$new(); } - var modal = this.$modal({ + const modal = this.$modal({ modalClass: options.modalClass, template: options.src, templateHtml: options.templateHtml, @@ -50,7 +50,7 @@ export class UtilSrv { } showConfirmModal(payload) { - var scope = this.$rootScope.$new(); + const scope = this.$rootScope.$new(); scope.onConfirm = function() { payload.onConfirm(); diff --git a/public/app/core/specs/datemath.test.ts b/public/app/core/specs/datemath.test.ts index 820c53486db..cca6eb31593 100644 --- a/public/app/core/specs/datemath.test.ts +++ b/public/app/core/specs/datemath.test.ts @@ -5,11 +5,11 @@ import moment from 'moment'; import _ from 'lodash'; describe('DateMath', () => { - var spans = ['s', 'm', 'h', 'd', 'w', 'M', 'y']; - var anchor = '2014-01-01T06:06:06.666Z'; - var unix = moment(anchor).valueOf(); - var format = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; - var clock; + const spans = ['s', 'm', 'h', 'd', 'w', 'M', 'y']; + const anchor = '2014-01-01T06:06:06.666Z'; + const unix = moment(anchor).valueOf(); + const format = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; + let clock; describe('errors', () => { it('should return undefined if passed something falsy', () => { @@ -36,21 +36,21 @@ describe('DateMath', () => { }); it('now/d should set to start of current day', () => { - var expected = new Date(); + const expected = new Date(); expected.setHours(0); expected.setMinutes(0); expected.setSeconds(0); expected.setMilliseconds(0); - var startOfDay = dateMath.parse('now/d', false).valueOf(); + const startOfDay = dateMath.parse('now/d', false).valueOf(); expect(startOfDay).toBe(expected.getTime()); }); it('now/d on a utc dashboard should be start of the current day in UTC time', () => { - var today = new Date(); - var expected = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), 0, 0, 0, 0)); + const today = new Date(); + const expected = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), 0, 0, 0, 0)); - var startOfDay = dateMath.parse('now/d', false, 'utc').valueOf(); + const startOfDay = dateMath.parse('now/d', false, 'utc').valueOf(); expect(startOfDay).toBe(expected.getTime()); }); @@ -65,8 +65,8 @@ describe('DateMath', () => { }); _.each(spans, span => { - var nowEx = 'now-5' + span; - var thenEx = anchor + '||-5' + span; + const nowEx = 'now-5' + span; + const thenEx = anchor + '||-5' + span; it('should return 5' + span + ' ago', () => { expect(dateMath.parse(nowEx).format(format)).toEqual(now.subtract(5, span).format(format)); @@ -116,17 +116,17 @@ describe('DateMath', () => { describe('relative time to date parsing', function() { it('should handle negative time', function() { - var date = dateMath.parseDateMath('-2d', moment([2014, 1, 5])); + const date = dateMath.parseDateMath('-2d', moment([2014, 1, 5])); expect(date.valueOf()).toEqual(moment([2014, 1, 3]).valueOf()); }); it('should handle multiple math expressions', function() { - var date = dateMath.parseDateMath('-2d-6h', moment([2014, 1, 5])); + const date = dateMath.parseDateMath('-2d-6h', moment([2014, 1, 5])); expect(date.valueOf()).toEqual(moment([2014, 1, 2, 18]).valueOf()); }); it('should return false when invalid expression', function() { - var date = dateMath.parseDateMath('2', moment([2014, 1, 5])); + const date = dateMath.parseDateMath('2', moment([2014, 1, 5])); expect(date).toEqual(undefined); }); }); diff --git a/public/app/core/specs/emitter.test.ts b/public/app/core/specs/emitter.test.ts index a819cf0ede2..549dcb2d84a 100644 --- a/public/app/core/specs/emitter.test.ts +++ b/public/app/core/specs/emitter.test.ts @@ -3,9 +3,9 @@ import { Emitter } from '../utils/emitter'; describe('Emitter', () => { describe('given 2 subscribers', () => { it('should notfiy subscribers', () => { - var events = new Emitter(); - var sub1Called = false; - var sub2Called = false; + const events = new Emitter(); + let sub1Called = false; + let sub2Called = false; events.on('test', () => { sub1Called = true; @@ -21,8 +21,8 @@ describe('Emitter', () => { }); it('when subscribing twice', () => { - var events = new Emitter(); - var sub1Called = 0; + const events = new Emitter(); + let sub1Called = 0; function handler() { sub1Called += 1; @@ -37,9 +37,9 @@ describe('Emitter', () => { }); it('should handle errors', () => { - var events = new Emitter(); - var sub1Called = 0; - var sub2Called = 0; + const events = new Emitter(); + let sub1Called = 0; + let sub2Called = 0; events.on('test', () => { sub1Called++; diff --git a/public/app/core/specs/flatten.test.ts b/public/app/core/specs/flatten.test.ts index 7c7f4816d94..f1c5237802d 100644 --- a/public/app/core/specs/flatten.test.ts +++ b/public/app/core/specs/flatten.test.ts @@ -2,7 +2,7 @@ import flatten from 'app/core/utils/flatten'; describe('flatten', () => { it('should return flatten object', () => { - var flattened = flatten( + const flattened = flatten( { level1: 'level1-value', deeper: { diff --git a/public/app/core/specs/kbn.test.ts b/public/app/core/specs/kbn.test.ts index 9c62990615c..b4072adf7cf 100644 --- a/public/app/core/specs/kbn.test.ts +++ b/public/app/core/specs/kbn.test.ts @@ -3,7 +3,7 @@ import * as dateMath from '../utils/datemath'; import moment from 'moment'; describe('unit format menu', function() { - var menu = kbn.getUnitFormats(); + const menu = kbn.getUnitFormats(); menu.map(function(submenu) { describe('submenu ' + submenu.text, function() { it('should have a title', function() { @@ -34,8 +34,8 @@ describe('unit format menu', function() { function describeValueFormat(desc, value, tickSize, tickDecimals, result) { describe('value format: ' + desc, function() { it('should translate ' + value + ' as ' + result, function() { - var scaledDecimals = tickDecimals - Math.floor(Math.log(tickSize) / Math.LN10); - var str = kbn.valueFormats[desc](value, tickDecimals, scaledDecimals); + const scaledDecimals = tickDecimals - Math.floor(Math.log(tickSize) / Math.LN10); + const str = kbn.valueFormats[desc](value, tickDecimals, scaledDecimals); expect(str).toBe(result); }); }); @@ -106,177 +106,177 @@ describe('date time formats', function() { const browserTime = moment(epoch); it('should format as iso date', function() { - var expected = browserTime.format('YYYY-MM-DD HH:mm:ss'); - var actual = kbn.valueFormats.dateTimeAsIso(epoch); + const expected = browserTime.format('YYYY-MM-DD HH:mm:ss'); + const actual = kbn.valueFormats.dateTimeAsIso(epoch); expect(actual).toBe(expected); }); it('should format as iso date (in UTC)', function() { - var expected = utcTime.format('YYYY-MM-DD HH:mm:ss'); - var actual = kbn.valueFormats.dateTimeAsIso(epoch, true); + const expected = utcTime.format('YYYY-MM-DD HH:mm:ss'); + const actual = kbn.valueFormats.dateTimeAsIso(epoch, true); expect(actual).toBe(expected); }); it('should format as iso date and skip date when today', function() { - var now = moment(); - var expected = now.format('HH:mm:ss'); - var actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), false); + const now = moment(); + const expected = now.format('HH:mm:ss'); + const actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), false); expect(actual).toBe(expected); }); it('should format as iso date (in UTC) and skip date when today', function() { - var now = moment.utc(); - var expected = now.format('HH:mm:ss'); - var actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), true); + const now = moment.utc(); + const expected = now.format('HH:mm:ss'); + const actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), true); expect(actual).toBe(expected); }); it('should format as US date', function() { - var expected = browserTime.format('MM/DD/YYYY h:mm:ss a'); - var actual = kbn.valueFormats.dateTimeAsUS(epoch, false); + const expected = browserTime.format('MM/DD/YYYY h:mm:ss a'); + const actual = kbn.valueFormats.dateTimeAsUS(epoch, false); expect(actual).toBe(expected); }); it('should format as US date (in UTC)', function() { - var expected = utcTime.format('MM/DD/YYYY h:mm:ss a'); - var actual = kbn.valueFormats.dateTimeAsUS(epoch, true); + const expected = utcTime.format('MM/DD/YYYY h:mm:ss a'); + const actual = kbn.valueFormats.dateTimeAsUS(epoch, true); expect(actual).toBe(expected); }); it('should format as US date and skip date when today', function() { - var now = moment(); - var expected = now.format('h:mm:ss a'); - var actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), false); + const now = moment(); + const expected = now.format('h:mm:ss a'); + const actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), false); expect(actual).toBe(expected); }); it('should format as US date (in UTC) and skip date when today', function() { - var now = moment.utc(); - var expected = now.format('h:mm:ss a'); - var actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), true); + const now = moment.utc(); + const expected = now.format('h:mm:ss a'); + const actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), true); expect(actual).toBe(expected); }); it('should format as from now with days', function() { - var daysAgo = moment().add(-7, 'd'); - var expected = '7 days ago'; - var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false); + const daysAgo = moment().add(-7, 'd'); + const expected = '7 days ago'; + const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false); expect(actual).toBe(expected); }); it('should format as from now with days (in UTC)', function() { - var daysAgo = moment.utc().add(-7, 'd'); - var expected = '7 days ago'; - var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true); + const daysAgo = moment.utc().add(-7, 'd'); + const expected = '7 days ago'; + const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true); expect(actual).toBe(expected); }); it('should format as from now with minutes', function() { - var daysAgo = moment().add(-2, 'm'); - var expected = '2 minutes ago'; - var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false); + const daysAgo = moment().add(-2, 'm'); + const expected = '2 minutes ago'; + const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false); expect(actual).toBe(expected); }); it('should format as from now with minutes (in UTC)', function() { - var daysAgo = moment.utc().add(-2, 'm'); - var expected = '2 minutes ago'; - var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true); + const daysAgo = moment.utc().add(-2, 'm'); + const expected = '2 minutes ago'; + const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true); expect(actual).toBe(expected); }); }); describe('kbn.toFixed and negative decimals', function() { it('should treat as zero decimals', function() { - var str = kbn.toFixed(186.123, -2); + const str = kbn.toFixed(186.123, -2); expect(str).toBe('186'); }); }); describe('kbn ms format when scaled decimals is null do not use it', function() { it('should use specified decimals', function() { - var str = kbn.valueFormats['ms'](10000086.123, 1, null); + const str = kbn.valueFormats['ms'](10000086.123, 1, null); expect(str).toBe('2.8 hour'); }); }); describe('kbn kbytes format when scaled decimals is null do not use it', function() { it('should use specified decimals', function() { - var str = kbn.valueFormats['kbytes'](10000000, 3, null); + const str = kbn.valueFormats['kbytes'](10000000, 3, null); expect(str).toBe('9.537 GiB'); }); }); describe('kbn deckbytes format when scaled decimals is null do not use it', function() { it('should use specified decimals', function() { - var str = kbn.valueFormats['deckbytes'](10000000, 3, null); + const str = kbn.valueFormats['deckbytes'](10000000, 3, null); expect(str).toBe('10.000 GB'); }); }); describe('kbn roundValue', function() { it('should should handle null value', function() { - var str = kbn.roundValue(null, 2); + const str = kbn.roundValue(null, 2); expect(str).toBe(null); }); it('should round value', function() { - var str = kbn.roundValue(200.877, 2); + const str = kbn.roundValue(200.877, 2); expect(str).toBe(200.88); }); }); describe('calculateInterval', function() { it('1h 100 resultion', function() { - var range = { from: dateMath.parse('now-1h'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 100, null); + const range = { from: dateMath.parse('now-1h'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 100, null); expect(res.interval).toBe('30s'); }); it('10m 1600 resolution', function() { - var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 1600, null); + const range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 1600, null); expect(res.interval).toBe('500ms'); expect(res.intervalMs).toBe(500); }); it('fixed user min interval', function() { - var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 1600, '10s'); + const range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 1600, '10s'); expect(res.interval).toBe('10s'); expect(res.intervalMs).toBe(10000); }); it('short time range and user low limit', function() { - var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 1600, '>10s'); + const range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 1600, '>10s'); expect(res.interval).toBe('10s'); }); it('large time range and user low limit', function() { - var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 1000, '>10s'); + const range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 1000, '>10s'); expect(res.interval).toBe('20m'); }); it('10s 900 resolution and user low limit in ms', function() { - var range = { from: dateMath.parse('now-10s'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 900, '>15ms'); + const range = { from: dateMath.parse('now-10s'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 900, '>15ms'); expect(res.interval).toBe('15ms'); }); it('1d 1 resolution', function() { - var range = { from: dateMath.parse('now-1d'), to: dateMath.parse('now') }; - var res = kbn.calculateInterval(range, 1, null); + const range = { from: dateMath.parse('now-1d'), to: dateMath.parse('now') }; + const res = kbn.calculateInterval(range, 1, null); expect(res.interval).toBe('1d'); expect(res.intervalMs).toBe(86400000); }); it('86399s 1 resolution', function() { - var range = { + const range = { from: dateMath.parse('now-86390s'), to: dateMath.parse('now'), }; - var res = kbn.calculateInterval(range, 1, null); + const res = kbn.calculateInterval(range, 1, null); expect(res.interval).toBe('12h'); expect(res.intervalMs).toBe(43200000); }); @@ -284,139 +284,139 @@ describe('calculateInterval', function() { describe('hex', function() { it('positive integer', function() { - var str = kbn.valueFormats.hex(100, 0); + const str = kbn.valueFormats.hex(100, 0); expect(str).toBe('64'); }); it('negative integer', function() { - var str = kbn.valueFormats.hex(-100, 0); + const str = kbn.valueFormats.hex(-100, 0); expect(str).toBe('-64'); }); it('null', function() { - var str = kbn.valueFormats.hex(null, 0); + const str = kbn.valueFormats.hex(null, 0); expect(str).toBe(''); }); it('positive float', function() { - var str = kbn.valueFormats.hex(50.52, 1); + const str = kbn.valueFormats.hex(50.52, 1); expect(str).toBe('32.8'); }); it('negative float', function() { - var str = kbn.valueFormats.hex(-50.333, 2); + const str = kbn.valueFormats.hex(-50.333, 2); expect(str).toBe('-32.547AE147AE14'); }); }); describe('hex 0x', function() { it('positive integeter', function() { - var str = kbn.valueFormats.hex0x(7999, 0); + const str = kbn.valueFormats.hex0x(7999, 0); expect(str).toBe('0x1F3F'); }); it('negative integer', function() { - var str = kbn.valueFormats.hex0x(-584, 0); + const str = kbn.valueFormats.hex0x(-584, 0); expect(str).toBe('-0x248'); }); it('null', function() { - var str = kbn.valueFormats.hex0x(null, 0); + const str = kbn.valueFormats.hex0x(null, 0); expect(str).toBe(''); }); it('positive float', function() { - var str = kbn.valueFormats.hex0x(74.443, 3); + const str = kbn.valueFormats.hex0x(74.443, 3); expect(str).toBe('0x4A.716872B020C4'); }); it('negative float', function() { - var str = kbn.valueFormats.hex0x(-65.458, 1); + const str = kbn.valueFormats.hex0x(-65.458, 1); expect(str).toBe('-0x41.8'); }); }); describe('duration', function() { it('null', function() { - var str = kbn.toDuration(null, 0, 'millisecond'); + const str = kbn.toDuration(null, 0, 'millisecond'); expect(str).toBe(''); }); it('0 milliseconds', function() { - var str = kbn.toDuration(0, 0, 'millisecond'); + const str = kbn.toDuration(0, 0, 'millisecond'); expect(str).toBe('0 milliseconds'); }); it('1 millisecond', function() { - var str = kbn.toDuration(1, 0, 'millisecond'); + const str = kbn.toDuration(1, 0, 'millisecond'); expect(str).toBe('1 millisecond'); }); it('-1 millisecond', function() { - var str = kbn.toDuration(-1, 0, 'millisecond'); + const str = kbn.toDuration(-1, 0, 'millisecond'); expect(str).toBe('1 millisecond ago'); }); it('seconds', function() { - var str = kbn.toDuration(1, 0, 'second'); + const str = kbn.toDuration(1, 0, 'second'); expect(str).toBe('1 second'); }); it('minutes', function() { - var str = kbn.toDuration(1, 0, 'minute'); + const str = kbn.toDuration(1, 0, 'minute'); expect(str).toBe('1 minute'); }); it('hours', function() { - var str = kbn.toDuration(1, 0, 'hour'); + const str = kbn.toDuration(1, 0, 'hour'); expect(str).toBe('1 hour'); }); it('days', function() { - var str = kbn.toDuration(1, 0, 'day'); + const str = kbn.toDuration(1, 0, 'day'); expect(str).toBe('1 day'); }); it('weeks', function() { - var str = kbn.toDuration(1, 0, 'week'); + const str = kbn.toDuration(1, 0, 'week'); expect(str).toBe('1 week'); }); it('months', function() { - var str = kbn.toDuration(1, 0, 'month'); + const str = kbn.toDuration(1, 0, 'month'); expect(str).toBe('1 month'); }); it('years', function() { - var str = kbn.toDuration(1, 0, 'year'); + const str = kbn.toDuration(1, 0, 'year'); expect(str).toBe('1 year'); }); it('decimal days', function() { - var str = kbn.toDuration(1.5, 2, 'day'); + const str = kbn.toDuration(1.5, 2, 'day'); expect(str).toBe('1 day, 12 hours, 0 minutes'); }); it('decimal months', function() { - var str = kbn.toDuration(1.5, 3, 'month'); + const str = kbn.toDuration(1.5, 3, 'month'); expect(str).toBe('1 month, 2 weeks, 1 day, 0 hours'); }); it('no decimals', function() { - var str = kbn.toDuration(38898367008, 0, 'millisecond'); + const str = kbn.toDuration(38898367008, 0, 'millisecond'); expect(str).toBe('1 year'); }); it('1 decimal', function() { - var str = kbn.toDuration(38898367008, 1, 'millisecond'); + const str = kbn.toDuration(38898367008, 1, 'millisecond'); expect(str).toBe('1 year, 2 months'); }); it('too many decimals', function() { - var str = kbn.toDuration(38898367008, 20, 'millisecond'); + const str = kbn.toDuration(38898367008, 20, 'millisecond'); expect(str).toBe('1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, 7 seconds, 8 milliseconds'); }); it('floating point error', function() { - var str = kbn.toDuration(36993906007, 8, 'millisecond'); + const str = kbn.toDuration(36993906007, 8, 'millisecond'); expect(str).toBe('1 year, 2 months, 0 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds'); }); }); describe('volume', function() { it('1000m3', function() { - var str = kbn.valueFormats['m3'](1000, 1, null); + const str = kbn.valueFormats['m3'](1000, 1, null); expect(str).toBe('1000.0 m³'); }); }); describe('hh:mm:ss', function() { it('00:04:06', function() { - var str = kbn.valueFormats['dthms'](246, 1); + const str = kbn.valueFormats['dthms'](246, 1); expect(str).toBe('00:04:06'); }); it('24:00:00', function() { - var str = kbn.valueFormats['dthms'](86400, 1); + const str = kbn.valueFormats['dthms'](86400, 1); expect(str).toBe('24:00:00'); }); it('6824413:53:20', function() { - var str = kbn.valueFormats['dthms'](24567890000, 1); + const str = kbn.valueFormats['dthms'](24567890000, 1); expect(str).toBe('6824413:53:20'); }); }); diff --git a/public/app/core/specs/rangeutil.test.ts b/public/app/core/specs/rangeutil.test.ts index 6bfc0503900..4c0d3dc90c8 100644 --- a/public/app/core/specs/rangeutil.test.ts +++ b/public/app/core/specs/rangeutil.test.ts @@ -5,7 +5,7 @@ import moment from 'moment'; describe('rangeUtil', () => { describe('Can get range grouped list of ranges', () => { it('when custom settings should return default range list', () => { - var groups = rangeUtil.getRelativeTimesList({ time_options: [] }, 'Last 5 minutes'); + const groups = rangeUtil.getRelativeTimesList({ time_options: [] }, 'Last 5 minutes'); expect(_.keys(groups).length).toBe(4); expect(groups[3][0].active).toBe(true); }); @@ -13,62 +13,62 @@ describe('rangeUtil', () => { describe('Can get range text described', () => { it('should handle simple old expression with only amount and unit', () => { - var info = rangeUtil.describeTextRange('5m'); + const info = rangeUtil.describeTextRange('5m'); expect(info.display).toBe('Last 5 minutes'); }); it('should have singular when amount is 1', () => { - var info = rangeUtil.describeTextRange('1h'); + const info = rangeUtil.describeTextRange('1h'); expect(info.display).toBe('Last 1 hour'); }); it('should handle non default amount', () => { - var info = rangeUtil.describeTextRange('13h'); + const info = rangeUtil.describeTextRange('13h'); expect(info.display).toBe('Last 13 hours'); expect(info.from).toBe('now-13h'); }); it('should handle non default future amount', () => { - var info = rangeUtil.describeTextRange('+3h'); + const info = rangeUtil.describeTextRange('+3h'); expect(info.display).toBe('Next 3 hours'); expect(info.from).toBe('now'); expect(info.to).toBe('now+3h'); }); it('should handle now/d', () => { - var info = rangeUtil.describeTextRange('now/d'); + const info = rangeUtil.describeTextRange('now/d'); expect(info.display).toBe('Today so far'); }); it('should handle now/w', () => { - var info = rangeUtil.describeTextRange('now/w'); + const info = rangeUtil.describeTextRange('now/w'); expect(info.display).toBe('This week so far'); }); it('should handle now/M', () => { - var info = rangeUtil.describeTextRange('now/M'); + const info = rangeUtil.describeTextRange('now/M'); expect(info.display).toBe('This month so far'); }); it('should handle now/y', () => { - var info = rangeUtil.describeTextRange('now/y'); + const info = rangeUtil.describeTextRange('now/y'); expect(info.display).toBe('This year so far'); }); }); describe('Can get date range described', () => { it('Date range with simple ranges', () => { - var text = rangeUtil.describeTimeRange({ from: 'now-1h', to: 'now' }); + const text = rangeUtil.describeTimeRange({ from: 'now-1h', to: 'now' }); expect(text).toBe('Last 1 hour'); }); it('Date range with rounding ranges', () => { - var text = rangeUtil.describeTimeRange({ from: 'now/d+6h', to: 'now' }); + const text = rangeUtil.describeTimeRange({ from: 'now/d+6h', to: 'now' }); expect(text).toBe('now/d+6h to now'); }); it('Date range with absolute to now', () => { - var text = rangeUtil.describeTimeRange({ + const text = rangeUtil.describeTimeRange({ from: moment([2014, 10, 10, 2, 3, 4]), to: 'now', }); @@ -76,7 +76,7 @@ describe('rangeUtil', () => { }); it('Date range with absolute to relative', () => { - var text = rangeUtil.describeTimeRange({ + const text = rangeUtil.describeTimeRange({ from: moment([2014, 10, 10, 2, 3, 4]), to: 'now-1d', }); @@ -84,7 +84,7 @@ describe('rangeUtil', () => { }); it('Date range with relative to absolute', () => { - var text = rangeUtil.describeTimeRange({ + const text = rangeUtil.describeTimeRange({ from: 'now-7d', to: moment([2014, 10, 10, 2, 3, 4]), }); @@ -92,17 +92,17 @@ describe('rangeUtil', () => { }); it('Date range with non matching default ranges', () => { - var text = rangeUtil.describeTimeRange({ from: 'now-13h', to: 'now' }); + const text = rangeUtil.describeTimeRange({ from: 'now-13h', to: 'now' }); expect(text).toBe('Last 13 hours'); }); it('Date range with from and to both are in now-* format', () => { - var text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now-3h' }); + const text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now-3h' }); expect(text).toBe('now-6h to now-3h'); }); it('Date range with from and to both are either in now-* or now/* format', () => { - var text = rangeUtil.describeTimeRange({ + const text = rangeUtil.describeTimeRange({ from: 'now/d+6h', to: 'now-3h', }); @@ -110,7 +110,7 @@ describe('rangeUtil', () => { }); it('Date range with from and to both are either in now-* or now+* format', () => { - var text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now+1h' }); + const text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now+1h' }); expect(text).toBe('now-6h to now+1h'); }); }); diff --git a/public/app/core/specs/table_model.test.ts b/public/app/core/specs/table_model.test.ts index 3d4c526cfea..b88bad12227 100644 --- a/public/app/core/specs/table_model.test.ts +++ b/public/app/core/specs/table_model.test.ts @@ -1,8 +1,8 @@ import TableModel from 'app/core/table_model'; describe('when sorting table desc', () => { - var table; - var panel = { + let table; + const panel = { sort: { col: 0, desc: true }, }; @@ -27,7 +27,7 @@ describe('when sorting table desc', () => { describe('when sorting table asc', () => { var table; - var panel = { + const panel = { sort: { col: 1, desc: false }, }; diff --git a/public/app/core/specs/time_series.test.ts b/public/app/core/specs/time_series.test.ts index 35b75b3da5e..605c8fd0a2e 100644 --- a/public/app/core/specs/time_series.test.ts +++ b/public/app/core/specs/time_series.test.ts @@ -2,9 +2,9 @@ import TimeSeries from 'app/core/time_series2'; import { updateLegendValues } from 'app/core/time_series2'; describe('TimeSeries', function() { - var points, series; - var yAxisFormats = ['short', 'ms']; - var testData; + let points, series; + const yAxisFormats = ['short', 'ms']; + let testData; beforeEach(function() { testData = { diff --git a/public/app/core/utils/css_loader.ts b/public/app/core/utils/css_loader.ts index ba8623df842..b8aaef47085 100644 --- a/public/app/core/utils/css_loader.ts +++ b/public/app/core/utils/css_loader.ts @@ -1,18 +1,18 @@ -var waitSeconds = 100; -var head = document.getElementsByTagName('head')[0]; +const waitSeconds = 100; +const head = document.getElementsByTagName('head')[0]; // get all link tags in the page -var links = document.getElementsByTagName('link'); -var linkHrefs = []; -for (var i = 0; i < links.length; i++) { +const links = document.getElementsByTagName('link'); +const linkHrefs = []; +for (let i = 0; i < links.length; i++) { linkHrefs.push(links[i].href); } -var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/); -var webkitLoadCheck = function(link, callback) { +const isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/); +const webkitLoadCheck = function(link, callback) { setTimeout(function() { for (var i = 0; i < document.styleSheets.length; i++) { - var sheet = document.styleSheets[i]; + const sheet = document.styleSheets[i]; if (sheet.href === link.href) { return callback(); } @@ -21,16 +21,16 @@ var webkitLoadCheck = function(link, callback) { }, 10); }; -var noop = function() {}; +const noop = function() {}; -var loadCSS = function(url) { +const loadCSS = function(url) { return new Promise(function(resolve, reject) { - var link = document.createElement('link'); - var timeout = setTimeout(function() { + const link = document.createElement('link'); + const timeout = setTimeout(function() { reject('Unable to load CSS'); }, waitSeconds * 1000); - var _callback = function(error) { + const _callback = function(error) { clearTimeout(timeout); link.onload = link.onerror = noop; setTimeout(function() { diff --git a/public/app/core/utils/flatten.ts b/public/app/core/utils/flatten.ts index 150017e34f8..3350f5f6c33 100644 --- a/public/app/core/utils/flatten.ts +++ b/public/app/core/utils/flatten.ts @@ -4,19 +4,19 @@ export default function flatten(target, opts): any { opts = opts || {}; - var delimiter = opts.delimiter || '.'; - var maxDepth = opts.maxDepth || 3; - var currentDepth = 1; - var output = {}; + const delimiter = opts.delimiter || '.'; + let maxDepth = opts.maxDepth || 3; + let currentDepth = 1; + const output = {}; function step(object, prev) { Object.keys(object).forEach(function(key) { - var value = object[key]; - var isarray = opts.safe && Array.isArray(value); - var type = Object.prototype.toString.call(value); - var isobject = type === '[object Object]'; + const value = object[key]; + const isarray = opts.safe && Array.isArray(value); + const type = Object.prototype.toString.call(value); + const isobject = type === '[object Object]'; - var newKey = prev ? prev + delimiter + key : key; + const newKey = prev ? prev + delimiter + key : key; if (!opts.maxDepth) { maxDepth = currentDepth + 1; diff --git a/public/app/core/utils/kbn.ts b/public/app/core/utils/kbn.ts index c2764670b95..9f30972bc61 100644 --- a/public/app/core/utils/kbn.ts +++ b/public/app/core/utils/kbn.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import moment from 'moment'; -var kbn: any = {}; +const kbn: any = {}; kbn.valueFormats = {}; @@ -103,27 +103,27 @@ kbn.round_interval = function(interval) { }; kbn.secondsToHms = function(seconds) { - var numyears = Math.floor(seconds / 31536000); + const numyears = Math.floor(seconds / 31536000); if (numyears) { return numyears + 'y'; } - var numdays = Math.floor((seconds % 31536000) / 86400); + const numdays = Math.floor((seconds % 31536000) / 86400); if (numdays) { return numdays + 'd'; } - var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600); + const numhours = Math.floor(((seconds % 31536000) % 86400) / 3600); if (numhours) { return numhours + 'h'; } - var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60); + const numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60); if (numminutes) { return numminutes + 'm'; } - var numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60); + const numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60); if (numseconds) { return numseconds + 's'; } - var nummilliseconds = Math.floor(seconds * 1000.0); + const nummilliseconds = Math.floor(seconds * 1000.0); if (nummilliseconds) { return nummilliseconds + 'ms'; } @@ -132,10 +132,10 @@ kbn.secondsToHms = function(seconds) { }; kbn.secondsToHhmmss = function(seconds) { - var strings = []; - var numhours = Math.floor(seconds / 3600); - var numminutes = Math.floor((seconds % 3600) / 60); - var numseconds = Math.floor((seconds % 3600) % 60); + const strings = []; + const numhours = Math.floor(seconds / 3600); + const numminutes = Math.floor((seconds % 3600) / 60); + const numseconds = Math.floor((seconds % 3600) % 60); numhours > 9 ? strings.push('' + numhours) : strings.push('0' + numhours); numminutes > 9 ? strings.push('' + numminutes) : strings.push('0' + numminutes); numseconds > 9 ? strings.push('' + numseconds) : strings.push('0' + numseconds); @@ -191,7 +191,7 @@ kbn.calculateInterval = function(range, resolution, lowLimitInterval) { }; kbn.describe_interval = function(str) { - var matches = str.match(kbn.interval_regex); + 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"'); } else { @@ -204,12 +204,12 @@ kbn.describe_interval = function(str) { }; kbn.interval_to_ms = function(str) { - var info = kbn.describe_interval(str); + const info = kbn.describe_interval(str); return info.sec * 1000 * info.count; }; kbn.interval_to_seconds = function(str) { - var info = kbn.describe_interval(str); + const info = kbn.describe_interval(str); return info.sec * info.count; }; @@ -233,7 +233,7 @@ kbn.stringToJsRegex = function(str) { return new RegExp('^' + str + '$'); } - var match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$')); + const match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$')); return new RegExp(match[1], match[2]); }; @@ -242,8 +242,8 @@ kbn.toFixed = function(value, decimals) { return ''; } - var factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1; - var formatted = String(Math.round(value * factor) / factor); + const factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1; + const formatted = String(Math.round(value * factor) / factor); // if exponent return directly if (formatted.indexOf('e') !== -1 || value === 0) { @@ -253,8 +253,8 @@ kbn.toFixed = function(value, decimals) { // If tickDecimals was specified, ensure that we have exactly that // much precision; otherwise default to the value's own precision. if (decimals != null) { - var decimalPos = formatted.indexOf('.'); - var precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1; + const decimalPos = formatted.indexOf('.'); + const precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1; if (precision < decimals) { return (precision ? formatted : formatted + '.') + String(factor).substr(1, decimals - precision); } @@ -275,8 +275,8 @@ kbn.roundValue = function(num, decimals) { if (num === null) { return null; } - var n = Math.pow(10, decimals); - var formatted = (n * num).toFixed(decimals); + const n = Math.pow(10, decimals); + const formatted = (n * num).toFixed(decimals); return Math.round(parseFloat(formatted)) / n; }; @@ -305,7 +305,7 @@ kbn.formatBuilders.scaledUnits = function(factor, extArray) { } var steps = 0; - var limit = extArray.length; + const limit = extArray.length; while (Math.abs(size) >= factor) { steps++; @@ -330,7 +330,7 @@ kbn.formatBuilders.scaledUnits = function(factor, extArray) { kbn.formatBuilders.decimalSIPrefix = function(unit, offset) { var prefixes = ['n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; prefixes = prefixes.slice(3 + (offset || 0)); - var units = prefixes.map(function(p) { + const units = prefixes.map(function(p) { return ' ' + p + unit; }); return kbn.formatBuilders.scaledUnits(1000, units); @@ -340,8 +340,8 @@ kbn.formatBuilders.decimalSIPrefix = function(unit, offset) { // 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) { - var prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset); - var units = prefixes.map(function(p) { + const prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset); + const units = prefixes.map(function(p) { return ' ' + p + unit; }); return kbn.formatBuilders.scaledUnits(1024, units); @@ -350,25 +350,25 @@ 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) { - var units = ['', 'K', 'M', 'B', 'T']; - var scaler = kbn.formatBuilders.scaledUnits(1000, units); + const units = ['', 'K', 'M', 'B', 'T']; + const scaler = kbn.formatBuilders.scaledUnits(1000, units); return function(size, decimals, scaledDecimals) { if (size === null) { return ''; } - var scaled = scaler(size, decimals, scaledDecimals); + const scaled = scaler(size, decimals, scaledDecimals); return symbol + scaled; }; }; kbn.formatBuilders.simpleCountUnit = function(symbol) { - var units = ['', 'K', 'M', 'B', 'T']; - var scaler = kbn.formatBuilders.scaledUnits(1000, units); + const units = ['', 'K', 'M', 'B', 'T']; + const scaler = kbn.formatBuilders.scaledUnits(1000, units); return function(size, decimals, scaledDecimals) { if (size === null) { return ''; } - var scaled = scaler(size, decimals, scaledDecimals); + const scaled = scaler(size, decimals, scaledDecimals); return scaled + ' ' + symbol; }; }; @@ -420,7 +420,7 @@ kbn.valueFormats.hex0x = function(value, decimals) { if (value == null) { return ''; } - var hexString = kbn.valueFormats.hex(value, decimals); + const hexString = kbn.valueFormats.hex(value, decimals); if (hexString.substring(0, 1) === '-') { return '-0x' + hexString.substring(1); } @@ -769,7 +769,7 @@ kbn.toDuration = function(size, decimals, timeScale) { return kbn.toDuration(-size, decimals, timeScale) + ' ago'; } - var units = [ + const units = [ { short: 'y', long: 'year' }, { short: 'M', long: 'month' }, { short: 'w', long: 'week' }, @@ -788,16 +788,16 @@ kbn.toDuration = function(size, decimals, timeScale) { }).short ] * 1000; - var strings = []; + const strings = []; // after first value >= 1 print only $decimals more var decrementDecimals = false; for (var i = 0; i < units.length && decimals >= 0; i++) { - var interval = kbn.intervals_in_seconds[units[i].short] * 1000; - var value = size / interval; + const interval = kbn.intervals_in_seconds[units[i].short] * 1000; + const value = size / interval; if (value >= 1 || decrementDecimals) { decrementDecimals = true; - var floor = Math.floor(value); - var unit = units[i].long + (floor !== 1 ? 's' : ''); + const floor = Math.floor(value); + const unit = units[i].long + (floor !== 1 ? 's' : ''); strings.push(floor + ' ' + unit); size = size % interval; decimals--; @@ -824,7 +824,7 @@ kbn.valueFormats.timeticks = function(size, decimals, scaledDecimals) { }; kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) { - var time = isUtc ? moment.utc(epoch) : moment(epoch); + const time = isUtc ? moment.utc(epoch) : moment(epoch); if (moment().isSame(epoch, 'day')) { return time.format('HH:mm:ss'); @@ -833,7 +833,7 @@ kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) { }; kbn.valueFormats.dateTimeAsUS = function(epoch, isUtc) { - var time = isUtc ? moment.utc(epoch) : moment(epoch); + const time = isUtc ? moment.utc(epoch) : moment(epoch); if (moment().isSame(epoch, 'day')) { return time.format('h:mm:ss a'); @@ -842,7 +842,7 @@ kbn.valueFormats.dateTimeAsUS = function(epoch, isUtc) { }; kbn.valueFormats.dateTimeFromNow = function(epoch, isUtc) { - var time = isUtc ? moment.utc(epoch) : moment(epoch); + const time = isUtc ? moment.utc(epoch) : moment(epoch); return time.fromNow(); }; diff --git a/public/app/core/utils/rangeutil.ts b/public/app/core/utils/rangeutil.ts index 8e0f87df686..bda861e4b9f 100644 --- a/public/app/core/utils/rangeutil.ts +++ b/public/app/core/utils/rangeutil.ts @@ -2,7 +2,7 @@ import _ from 'lodash'; import moment from 'moment'; import * as dateMath from './datemath'; -var spans = { +const spans = { s: { display: 'second' }, m: { display: 'minute' }, h: { display: 'hour' }, @@ -12,7 +12,7 @@ var spans = { y: { display: 'year' }, }; -var rangeOptions = [ +const rangeOptions = [ { from: 'now/d', to: 'now/d', display: 'Today', section: 2 }, { from: 'now/d', to: 'now', display: 'Today so far', section: 2 }, { from: 'now/w', to: 'now/w', display: 'This week', section: 2 }, @@ -58,15 +58,15 @@ var rangeOptions = [ { from: 'now-5y', to: 'now', display: 'Last 5 years', section: 0 }, ]; -var absoluteFormat = 'MMM D, YYYY HH:mm:ss'; +const absoluteFormat = 'MMM D, YYYY HH:mm:ss'; -var rangeIndex = {}; +const rangeIndex = {}; _.each(rangeOptions, function(frame) { rangeIndex[frame.from + ' to ' + frame.to] = frame; }); export function getRelativeTimesList(timepickerSettings, currentDisplay) { - var groups = _.groupBy(rangeOptions, (option: any) => { + const groups = _.groupBy(rangeOptions, (option: any) => { option.active = option.display === currentDisplay; return option.section; }); @@ -130,7 +130,7 @@ export function describeTextRange(expr: any) { } export function describeTimeRange(range) { - var option = rangeIndex[range.from.toString() + ' to ' + range.to.toString()]; + const option = rangeIndex[range.from.toString() + ' to ' + range.to.toString()]; if (option) { return option.display; } @@ -140,17 +140,17 @@ export function describeTimeRange(range) { } if (moment.isMoment(range.from)) { - var toMoment = dateMath.parse(range.to, true); + const toMoment = dateMath.parse(range.to, true); return formatDate(range.from) + ' to ' + toMoment.fromNow(); } if (moment.isMoment(range.to)) { - var from = dateMath.parse(range.from, false); + const from = dateMath.parse(range.from, false); return from.fromNow() + ' to ' + formatDate(range.to); } if (range.to.toString() === 'now') { - var res = describeTextRange(range.from); + const res = describeTextRange(range.from); return res.display; } diff --git a/public/app/features/dashboard/dashboard_ctrl.ts b/public/app/features/dashboard/dashboard_ctrl.ts index c6bb6492172..5524b55e3dd 100644 --- a/public/app/features/dashboard/dashboard_ctrl.ts +++ b/public/app/features/dashboard/dashboard_ctrl.ts @@ -106,7 +106,7 @@ export class DashboardCtrl implements PanelContainer { } showJsonEditor(evt, options) { - var editScope = this.$rootScope.$new(); + const editScope = this.$rootScope.$new(); editScope.object = options.object; editScope.updateHandler = options.updateHandler; this.$scope.appEvent('show-dash-editor', { @@ -137,7 +137,7 @@ export class DashboardCtrl implements PanelContainer { return; } - var panelInfo = this.dashboard.getPanelInfoById(options.panelId); + const panelInfo = this.dashboard.getPanelInfoById(options.panelId); this.removePanel(panelInfo.panel, true); } diff --git a/public/app/features/dashboard/dashboard_loader_srv.ts b/public/app/features/dashboard/dashboard_loader_srv.ts index 9e458c4e4bb..cbf753c0124 100644 --- a/public/app/features/dashboard/dashboard_loader_srv.ts +++ b/public/app/features/dashboard/dashboard_loader_srv.ts @@ -71,7 +71,7 @@ export class DashboardLoaderSrv { } _loadScriptedDashboard(file) { - var url = 'public/dashboards/' + file.replace(/\.(?!js)/, '/') + '?' + new Date().getTime(); + const url = 'public/dashboards/' + file.replace(/\.(?!js)/, '/') + '?' + new Date().getTime(); return this.$http({ url: url, method: 'GET' }) .then(this._executeScript.bind(this)) @@ -99,14 +99,14 @@ export class DashboardLoaderSrv { } _executeScript(result) { - var services = { + const services = { dashboardSrv: this.dashboardSrv, datasourceSrv: this.datasourceSrv, $q: this.$q, }; /*jshint -W054 */ - var script_func = new Function( + const script_func = new Function( 'ARGS', 'kbn', 'dateMath', @@ -119,11 +119,11 @@ export class DashboardLoaderSrv { 'services', result.data ); - var script_result = script_func(this.$routeParams, kbn, dateMath, _, moment, window, document, $, $, services); + const script_result = script_func(this.$routeParams, kbn, dateMath, _, moment, window, document, $, $, services); // Handle async dashboard scripts if (_.isFunction(script_result)) { - var deferred = this.$q.defer(); + const deferred = this.$q.defer(); script_result(dashboard => { this.$timeout(() => { deferred.resolve({ data: dashboard }); diff --git a/public/app/features/dashboard/dashgrid/PanelLoader.ts b/public/app/features/dashboard/dashgrid/PanelLoader.ts index beda30bdff7..c654b756085 100644 --- a/public/app/features/dashboard/dashgrid/PanelLoader.ts +++ b/public/app/features/dashboard/dashgrid/PanelLoader.ts @@ -10,8 +10,8 @@ export class PanelLoader { constructor(private $compile, private $rootScope) {} load(elem, panel, dashboard): AttachedPanel { - var template = ''; - var panelScope = this.$rootScope.$new(); + const template = ''; + const panelScope = this.$rootScope.$new(); panelScope.panel = panel; panelScope.dashboard = dashboard; diff --git a/public/app/features/dashboard/dashnav/dashnav.ts b/public/app/features/dashboard/dashnav/dashnav.ts index a83efe7d390..6d6373c7e82 100644 --- a/public/app/features/dashboard/dashnav/dashnav.ts +++ b/public/app/features/dashboard/dashnav/dashnav.ts @@ -13,7 +13,7 @@ export class DashNavCtrl { appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope); if (this.dashboard.meta.isSnapshot) { - var meta = this.dashboard.meta; + const meta = this.dashboard.meta; this.titleTooltip = 'Created:  ' + moment(meta.created).calendar(); if (meta.expires) { this.titleTooltip += '
Expires:  ' + moment(meta.expires).fromNow() + '
'; @@ -49,7 +49,7 @@ export class DashNavCtrl { } shareDashboard(tabIndex) { - var modalScope = this.$scope.$new(); + const modalScope = this.$scope.$new(); modalScope.tabIndex = tabIndex; modalScope.dashboard = this.dashboard; diff --git a/public/app/features/dashboard/save_as_modal.ts b/public/app/features/dashboard/save_as_modal.ts index 60f6fb4c1da..4649bc18f9f 100644 --- a/public/app/features/dashboard/save_as_modal.ts +++ b/public/app/features/dashboard/save_as_modal.ts @@ -46,7 +46,7 @@ export class SaveDashboardAsModalCtrl { /** @ngInject */ constructor(private dashboardSrv) { - var dashboard = this.dashboardSrv.getCurrent(); + const dashboard = this.dashboardSrv.getCurrent(); this.clone = dashboard.getSaveModelClone(); this.clone.id = null; this.clone.uid = ''; diff --git a/public/app/features/dashboard/save_modal.ts b/public/app/features/dashboard/save_modal.ts index 3afcbab707c..88fba13f711 100644 --- a/public/app/features/dashboard/save_modal.ts +++ b/public/app/features/dashboard/save_modal.ts @@ -94,14 +94,14 @@ export class SaveDashboardModalCtrl { return; } - var options = { + const options = { saveVariables: this.saveVariables, saveTimerange: this.saveTimerange, message: this.message, }; - var dashboard = this.dashboardSrv.getCurrent(); - var saveModel = dashboard.getSaveModelClone(options); + const dashboard = this.dashboardSrv.getCurrent(); + const saveModel = dashboard.getSaveModelClone(options); this.isSaving = true; diff --git a/public/app/features/dashboard/save_provisioned_modal.ts b/public/app/features/dashboard/save_provisioned_modal.ts index 3f2dcd0f57b..d165ba8fef5 100644 --- a/public/app/features/dashboard/save_provisioned_modal.ts +++ b/public/app/features/dashboard/save_provisioned_modal.ts @@ -52,7 +52,7 @@ export class SaveProvisionedDashboardModalCtrl { } save() { - var blob = new Blob([angular.toJson(this.dash, true)], { + const blob = new Blob([angular.toJson(this.dash, true)], { type: 'application/json;charset=utf-8', }); saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json'); diff --git a/public/app/features/dashboard/shareModalCtrl.ts b/public/app/features/dashboard/shareModalCtrl.ts index fff307c2510..694329c3102 100644 --- a/public/app/features/dashboard/shareModalCtrl.ts +++ b/public/app/features/dashboard/shareModalCtrl.ts @@ -36,15 +36,15 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv, $scope.buildUrl = function() { var baseUrl = $location.absUrl(); - var queryStart = baseUrl.indexOf('?'); + const queryStart = baseUrl.indexOf('?'); if (queryStart !== -1) { baseUrl = baseUrl.substring(0, queryStart); } - var params = angular.copy($location.search()); + const params = angular.copy($location.search()); - var range = timeSrv.timeRange(); + const range = timeSrv.timeRange(); params.from = range.from.valueOf(); params.to = range.to.valueOf(); params.orgId = config.bootData.user.orgId; diff --git a/public/app/features/dashboard/share_snapshot_ctrl.ts b/public/app/features/dashboard/share_snapshot_ctrl.ts index 7d5bd112dfd..c470ddb47dd 100644 --- a/public/app/features/dashboard/share_snapshot_ctrl.ts +++ b/public/app/features/dashboard/share_snapshot_ctrl.ts @@ -55,16 +55,16 @@ export class ShareSnapshotCtrl { }; $scope.saveSnapshot = function(external) { - var dash = $scope.dashboard.getSaveModelClone(); + const dash = $scope.dashboard.getSaveModelClone(); $scope.scrubDashboard(dash); - var cmdData = { + const cmdData = { dashboard: dash, name: dash.title, expires: $scope.snapshot.expires, }; - var postUrl = external ? $scope.externalUrl + $scope.apiUrl : $scope.apiUrl; + const postUrl = external ? $scope.externalUrl + $scope.apiUrl : $scope.apiUrl; backendSrv.post(postUrl, cmdData).then( function(results) { @@ -75,8 +75,8 @@ export class ShareSnapshotCtrl { $scope.snapshotUrl = results.url; $scope.saveExternalSnapshotRef(cmdData, results); } else { - var url = $location.url(); - var baseUrl = $location.absUrl(); + const url = $location.url(); + let baseUrl = $location.absUrl(); if (url !== '/') { baseUrl = baseUrl.replace(url, '') + '/'; @@ -139,7 +139,7 @@ export class ShareSnapshotCtrl { // snapshot single panel if ($scope.modeSharePanel) { - var singlePanel = $scope.panel.getSaveModel(); + const singlePanel = $scope.panel.getSaveModel(); singlePanel.gridPos.w = 24; singlePanel.gridPos.x = 0; singlePanel.gridPos.y = 0; diff --git a/public/app/features/dashboard/submenu/submenu.ts b/public/app/features/dashboard/submenu/submenu.ts index ecf9616cf75..e1288b2b2ed 100644 --- a/public/app/features/dashboard/submenu/submenu.ts +++ b/public/app/features/dashboard/submenu/submenu.ts @@ -21,7 +21,7 @@ export class SubmenuCtrl { } openEditView(editview) { - var search = _.extend(this.$location.search(), { editview: editview }); + const search = _.extend(this.$location.search(), { editview: editview }); this.$location.search(search); } } diff --git a/public/app/features/dashboard/view_state_srv.ts b/public/app/features/dashboard/view_state_srv.ts index 5bd4db6fddc..773ec6ec711 100644 --- a/public/app/features/dashboard/view_state_srv.ts +++ b/public/app/features/dashboard/view_state_srv.ts @@ -16,14 +16,14 @@ export class DashboardViewState { /** @ngInject */ constructor($scope, private $location, private $timeout, private $rootScope) { - var self = this; + const self = this; self.state = {}; self.panelScopes = []; self.$scope = $scope; self.dashboard = $scope.dashboard; $scope.onAppEvent('$routeUpdate', function() { - var urlState = self.getQueryStringState(); + const urlState = self.getQueryStringState(); if (self.needsSync(urlState)) { self.update(urlState, true); } @@ -48,7 +48,7 @@ export class DashboardViewState { } getQueryStringState() { - var state = this.$location.search(); + const state = this.$location.search(); state.panelId = parseInt(state.panelId) || null; state.fullscreen = state.fullscreen ? true : null; state.edit = state.edit === 'true' || state.edit === true || null; @@ -58,7 +58,7 @@ export class DashboardViewState { } serializeToUrl() { - var urlState = _.clone(this.state); + const urlState = _.clone(this.state); urlState.fullscreen = this.state.fullscreen ? true : null; urlState.edit = this.state.edit ? true : null; return urlState; @@ -129,7 +129,7 @@ export class DashboardViewState { } if (this.dashboard.meta.fullscreen) { - var panelScope = this.getPanelScope(this.state.panelId); + const panelScope = this.getPanelScope(this.state.panelId); if (!panelScope) { return; } @@ -162,8 +162,8 @@ export class DashboardViewState { } leaveFullscreen(render) { - var self = this; - var ctrl = self.fullscreenPanel.ctrl; + const self = this; + const ctrl = self.fullscreenPanel.ctrl; ctrl.editMode = false; ctrl.fullscreen = false; @@ -188,7 +188,7 @@ export class DashboardViewState { } enterFullscreen(panelScope) { - var ctrl = panelScope.ctrl; + const ctrl = panelScope.ctrl; ctrl.editMode = this.state.edit && this.dashboard.meta.canEdit; ctrl.fullscreen = true; @@ -203,7 +203,7 @@ export class DashboardViewState { } registerPanel(panelScope) { - var self = this; + const self = this; self.panelScopes.push(panelScope); if (!self.dashboard.meta.soloMode) { @@ -216,7 +216,7 @@ export class DashboardViewState { } } - var unbind = panelScope.$on('$destroy', function() { + const unbind = panelScope.$on('$destroy', function() { self.panelScopes = _.without(self.panelScopes, panelScope); unbind(); }); diff --git a/public/app/features/dashlinks/module.ts b/public/app/features/dashlinks/module.ts index 4d80f3632e6..492ed81a31e 100644 --- a/public/app/features/dashlinks/module.ts +++ b/public/app/features/dashlinks/module.ts @@ -19,7 +19,7 @@ function dashLink($compile, $sanitize, linkSrv) { return { restrict: 'E', link: function(scope, elem) { - var link = scope.link; + const link = scope.link; var template = '
' + ' { child.attr(key, value); }); @@ -228,8 +228,8 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $ } if (!componentInfo.Component.registered) { - var directiveName = attrs.$normalize(componentInfo.name); - var directiveFn = getPluginComponentDirective(componentInfo); + const directiveName = attrs.$normalize(componentInfo.name); + const directiveFn = getPluginComponentDirective(componentInfo); coreModule.directive(directiveName, directiveFn); componentInfo.Component.registered = true; } diff --git a/public/app/features/plugins/plugin_edit_ctrl.ts b/public/app/features/plugins/plugin_edit_ctrl.ts index 93c2008651d..44d3d31f996 100644 --- a/public/app/features/plugins/plugin_edit_ctrl.ts +++ b/public/app/features/plugins/plugin_edit_ctrl.ts @@ -97,7 +97,7 @@ export class PluginEditCtrl { initReadme() { return this.backendSrv.get(`/api/plugins/${this.pluginId}/markdown/readme`).then(res => { - var md = new Remarkable({ + const md = new Remarkable({ linkify: true, }); this.readmeHtml = this.$sce.trustAsHtml(md.render(res)); @@ -124,7 +124,7 @@ export class PluginEditCtrl { update() { this.preUpdateHook() .then(() => { - var updateCmd = _.extend( + const updateCmd = _.extend( { enabled: this.model.enabled, pinned: this.model.pinned, @@ -154,7 +154,7 @@ export class PluginEditCtrl { } updateAvailable() { - var modalScope = this.$scope.$new(true); + const modalScope = this.$scope.$new(true); modalScope.plugin = this.model; this.$rootScope.appEvent('show-modal', { diff --git a/public/app/features/plugins/plugin_page_ctrl.ts b/public/app/features/plugins/plugin_page_ctrl.ts index a2920e55a2a..8ea099e1905 100644 --- a/public/app/features/plugins/plugin_page_ctrl.ts +++ b/public/app/features/plugins/plugin_page_ctrl.ts @@ -1,7 +1,7 @@ import angular from 'angular'; import _ from 'lodash'; -var pluginInfoCache = {}; +const pluginInfoCache = {}; export class AppPageCtrl { page: any; diff --git a/public/app/features/templating/adhoc_variable.ts b/public/app/features/templating/adhoc_variable.ts index 9f8bd4c39a7..3e5b2af8b6b 100644 --- a/public/app/features/templating/adhoc_variable.ts +++ b/public/app/features/templating/adhoc_variable.ts @@ -43,7 +43,7 @@ export class AdhocVariable implements Variable { } this.filters = urlValue.map(item => { - var values = item.split('|').map(value => { + const values = item.split('|').map(value => { return this.unescapeDelimiter(value); }); return { diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index 519ce21e4d4..366d2f89b68 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -41,8 +41,8 @@ export class DatasourceVariable implements Variable { } updateOptions() { - var options = []; - var sources = this.datasourceSrv.getMetricSources({ skipVariables: true }); + const options = []; + const sources = this.datasourceSrv.getMetricSources({ skipVariables: true }); var regex; if (this.regex) { @@ -51,7 +51,7 @@ export class DatasourceVariable implements Variable { } for (var i = 0; i < sources.length; i++) { - var source = sources[i]; + const source = sources[i]; // must match on type if (source.meta.id !== this.query) { continue; diff --git a/public/app/features/templating/editor_ctrl.ts b/public/app/features/templating/editor_ctrl.ts index 75a84cca2bf..1222af7f93c 100644 --- a/public/app/features/templating/editor_ctrl.ts +++ b/public/app/features/templating/editor_ctrl.ts @@ -64,7 +64,7 @@ export class VariableEditorCtrl { return false; } - var sameName = _.find($scope.variables, { name: $scope.current.name }); + const sameName = _.find($scope.variables, { name: $scope.current.name }); if (sameName && sameName !== $scope.current) { appEvents.emit('alert-warning', ['Validation', 'Variable with the same name already exists']); return false; @@ -114,7 +114,7 @@ export class VariableEditorCtrl { }; $scope.duplicate = function(variable) { - var clone = _.cloneDeep(variable.getSaveModel()); + const clone = _.cloneDeep(variable.getSaveModel()); $scope.current = variableSrv.createVariableFromModel(clone); $scope.current.name = 'copy_of_' + variable.name; variableSrv.addVariable($scope.current); @@ -148,7 +148,7 @@ export class VariableEditorCtrl { }; $scope.typeChanged = function() { - var old = $scope.current; + const old = $scope.current; $scope.current = variableSrv.createVariableFromModel({ type: $scope.current.type, }); @@ -156,7 +156,7 @@ export class VariableEditorCtrl { $scope.current.hide = old.hide; $scope.current.label = old.label; - var oldIndex = _.indexOf(this.variables, old); + const oldIndex = _.indexOf(this.variables, old); if (oldIndex !== -1) { this.variables[oldIndex] = $scope.current; } diff --git a/public/app/features/templating/interval_variable.ts b/public/app/features/templating/interval_variable.ts index b932819a7b7..e6ee861f828 100644 --- a/public/app/features/templating/interval_variable.ts +++ b/public/app/features/templating/interval_variable.ts @@ -57,7 +57,7 @@ export class IntervalVariable implements Variable { }); } - var res = kbn.calculateInterval(this.timeSrv.timeRange(), this.auto_count, this.auto_min); + const res = kbn.calculateInterval(this.timeSrv.timeRange(), this.auto_count, this.auto_min); this.templateSrv.setGrafanaVariable('$__auto_interval_' + this.name, res.interval); // for backward compatibility, to be removed eventually this.templateSrv.setGrafanaVariable('$__auto_interval', res.interval); diff --git a/public/app/features/templating/query_variable.ts b/public/app/features/templating/query_variable.ts index 827fd80a176..fc51b44ca04 100644 --- a/public/app/features/templating/query_variable.ts +++ b/public/app/features/templating/query_variable.ts @@ -105,7 +105,7 @@ export class QueryVariable implements Variable { getValuesForTag(tagKey) { return this.datasourceSrv.get(this.datasource).then(datasource => { - var query = this.tagValuesQuery.replace('$tag', tagKey); + const query = this.tagValuesQuery.replace('$tag', tagKey); return this.metricFindQuery(datasource, query).then(function(results) { return _.map(results, function(value) { return value.text; @@ -128,7 +128,7 @@ export class QueryVariable implements Variable { } metricFindQuery(datasource, query) { - var options = { range: undefined, variable: this }; + const options = { range: undefined, variable: this }; if (this.refresh === 2) { options.range = this.timeSrv.timeRange(); @@ -149,7 +149,7 @@ export class QueryVariable implements Variable { regex = kbn.stringToJsRegex(this.templateSrv.replace(this.regex, {}, 'regex')); } for (i = 0; i < metricNames.length; i++) { - var item = metricNames[i]; + const item = metricNames[i]; var text = item.text === undefined || item.text === null ? item.value : item.text; var value = item.value === undefined || item.value === null ? item.text : item.value; @@ -185,14 +185,14 @@ export class QueryVariable implements Variable { return options; } - var sortType = Math.ceil(sortOrder / 2); - var reverseSort = sortOrder % 2 === 0; + const sortType = Math.ceil(sortOrder / 2); + const reverseSort = sortOrder % 2 === 0; if (sortType === 1) { options = _.sortBy(options, 'text'); } else if (sortType === 2) { options = _.sortBy(options, opt => { - var matches = opt.text.match(/.*?(\d+).*/); + const matches = opt.text.match(/.*?(\d+).*/); if (!matches || matches.length < 2) { return -1; } else { diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 5bbf5effa66..8e716a9f5d9 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -33,7 +33,7 @@ export class TemplateSrv { this.index = {}; for (var i = 0; i < this.variables.length; i++) { - var variable = this.variables[i]; + const variable = this.variables[i]; if (!variable.current || (!variable.current.isNone && !variable.current.value)) { continue; @@ -51,7 +51,7 @@ export class TemplateSrv { var filters = []; for (var i = 0; i < this.variables.length; i++) { - var variable = this.variables[i]; + const variable = this.variables[i]; if (variable.type !== 'adhoc') { continue; } @@ -77,7 +77,7 @@ export class TemplateSrv { if (value instanceof Array && value.length === 0) { return '__empty__'; } - var quotedValues = _.map(value, function(val) { + const quotedValues = _.map(value, function(val) { return '"' + luceneEscape(val) + '"'; }); return '(' + quotedValues.join(' OR ') + ')'; @@ -97,7 +97,7 @@ export class TemplateSrv { return kbn.regexEscape(value); } - var escapedValues = _.map(value, kbn.regexEscape); + const escapedValues = _.map(value, kbn.regexEscape); if (escapedValues.length === 1) { return escapedValues[0]; } @@ -139,7 +139,7 @@ export class TemplateSrv { getVariableName(expression) { this.regex.lastIndex = 0; - var match = this.regex.exec(expression); + const match = this.regex.exec(expression); if (!match) { return null; } @@ -147,7 +147,7 @@ export class TemplateSrv { } variableExists(expression) { - var name = this.getVariableName(expression); + const name = this.getVariableName(expression); return name && this.index[name] !== void 0; } @@ -170,7 +170,7 @@ export class TemplateSrv { if (variable.allValue) { return variable.allValue; } - var values = []; + const values = []; for (var i = 1; i < variable.options.length; i++) { values.push(variable.options[i].value); } @@ -213,7 +213,7 @@ export class TemplateSrv { } } - var res = this.formatValue(value, fmt, variable); + const res = this.formatValue(value, fmt, variable); return res; }); } @@ -232,7 +232,7 @@ export class TemplateSrv { return target.replace(this.regex, (match, var1, var2, fmt2, var3) => { if (scopedVars) { - var option = scopedVars[var1 || var2 || var3]; + const option = scopedVars[var1 || var2 || var3]; if (option) { return option.text; } diff --git a/public/app/features/templating/variable_srv.ts b/public/app/features/templating/variable_srv.ts index e3e75d6a036..55294d6fea2 100644 --- a/public/app/features/templating/variable_srv.ts +++ b/public/app/features/templating/variable_srv.ts @@ -27,7 +27,7 @@ export class VariableSrv { variable.initLock = this.$q.defer(); } - var queryParams = this.$location.search(); + const queryParams = this.$location.search(); return this.$q .all( this.variables.map(variable => { @@ -44,8 +44,8 @@ export class VariableSrv { return Promise.resolve({}); } - var promises = this.variables.filter(variable => variable.refresh === 2).map(variable => { - var previousOptions = variable.options.slice(); + const promises = this.variables.filter(variable => variable.refresh === 2).map(variable => { + const previousOptions = variable.options.slice(); return variable.updateOptions().then(() => { if (angular.toJson(previousOptions) !== angular.toJson(variable.options)) { @@ -58,7 +58,7 @@ export class VariableSrv { } processVariable(variable, queryParams) { - var dependencies = []; + const dependencies = []; for (const otherVariable of this.variables) { if (variable.dependsOn(otherVariable)) { @@ -69,7 +69,7 @@ export class VariableSrv { return this.$q .all(dependencies) .then(() => { - var urlValue = queryParams['var-' + variable.name]; + const urlValue = queryParams['var-' + variable.name]; if (urlValue !== void 0) { return variable.setValueFromUrl(urlValue).then(variable.initLock.resolve); } @@ -87,14 +87,14 @@ export class VariableSrv { } createVariableFromModel(model) { - var ctor = variableTypes[model.type].ctor; + const ctor = variableTypes[model.type].ctor; if (!ctor) { throw { message: 'Unable to find variable constructor for ' + model.type, }; } - var variable = this.$injector.instantiate(ctor, { model: model }); + const variable = this.$injector.instantiate(ctor, { model: model }); return variable; } @@ -105,7 +105,7 @@ export class VariableSrv { } removeVariable(variable) { - var index = _.indexOf(this.variables, variable); + const index = _.indexOf(this.variables, variable); this.variables.splice(index, 1); this.templateSrv.updateTemplateData(); this.dashboard.updateSubmenuVisibility(); @@ -139,7 +139,7 @@ export class VariableSrv { selectOptionsForCurrentValue(variable) { var i, y, value, option; - var selected: any = []; + const selected: any = []; for (i = 0; i < variable.options.length; i++) { option = variable.options[i]; @@ -185,7 +185,7 @@ export class VariableSrv { return variable.setValue(selected); } else { - var currentOption = _.find(variable.options, { + const currentOption = _.find(variable.options, { text: variable.current.text, }); if (currentOption) { @@ -246,7 +246,7 @@ export class VariableSrv { updateUrlParamsWithCurrentVariables() { // update url - var params = this.$location.search(); + const params = this.$location.search(); // remove variable params _.each(params, function(value, key) { diff --git a/public/app/routes/dashboard_loaders.ts b/public/app/routes/dashboard_loaders.ts index b33d5b6afb1..d8a66185d96 100644 --- a/public/app/routes/dashboard_loaders.ts +++ b/public/app/routes/dashboard_loaders.ts @@ -11,7 +11,7 @@ export class LoadDashboardCtrl { if (homeDash.redirectUri) { $location.path(homeDash.redirectUri); } else { - var meta = homeDash.meta; + const meta = homeDash.meta; meta.canSave = meta.canShare = meta.canStar = false; $scope.initDashboard(homeDash, $scope); } diff --git a/public/test/lib/common.ts b/public/test/lib/common.ts index c6b74fc7ecb..ac05f83391c 100644 --- a/public/test/lib/common.ts +++ b/public/test/lib/common.ts @@ -1,24 +1,15 @@ -var _global = (window); -var beforeEach = _global.beforeEach; -var afterEach = _global.afterEach; -var before = _global.before; -var describe = _global.describe; -var it = _global.it; -var sinon = _global.sinon; -var expect = _global.expect; +const _global = window; +const beforeEach = _global.beforeEach; +const afterEach = _global.afterEach; +const before = _global.before; +const describe = _global.describe; +const it = _global.it; +const sinon = _global.sinon; +const expect = _global.expect; -var angularMocks = { +const angularMocks = { module: _global.module, inject: _global.inject, }; -export { - beforeEach, - afterEach, - before, - describe, - it, - sinon, - expect, - angularMocks, -}; +export { beforeEach, afterEach, before, describe, it, sinon, expect, angularMocks };