diff --git a/public/app/core/components/grafana_app.ts b/public/app/core/components/grafana_app.ts index 1f55bc332ac..b715a20e28f 100644 --- a/public/app/core/components/grafana_app.ts +++ b/public/app/core/components/grafana_app.ts @@ -49,7 +49,7 @@ export class GrafanaCtrl { }; $rootScope.onAppEvent = function(name, callback, localScope) { - var unbind = $rootScope.$on(name, callback); + const unbind = $rootScope.$on(name, callback); var callerScope = this; if (callerScope.$id === 1 && !localScope) { console.log('warning rootScope onAppEvent called without localscope'); @@ -76,7 +76,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop controller: GrafanaCtrl, link: (scope, elem) => { var sidemenuOpen; - var body = $('body'); + const body = $('body'); // see https://github.com/zenorocha/clipboard.js/issues/155 $.fn.modal.Constructor.prototype.enforceFocus = function() {}; @@ -153,7 +153,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop // handle in active view state class var lastActivity = new Date().getTime(); var activeUser = true; - var inActiveTimeLimit = 60 * 1000; + const inActiveTimeLimit = 60 * 1000; var sidemenuHidden = false; function checkForInActiveUser() { @@ -215,16 +215,16 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop // handle document clicks that should hide things body.click(function(evt) { - var target = $(evt.target); + const target = $(evt.target); if (target.parents().length === 0) { return; } // for stuff that animates, slides out etc, clicking it needs to // hide it right away - var clickAutoHide = target.closest('[data-click-hide]'); + const clickAutoHide = target.closest('[data-click-hide]'); if (clickAutoHide.length) { - var clickAutoHideParent = clickAutoHide.parent(); + const clickAutoHideParent = clickAutoHide.parent(); clickAutoHide.detach(); setTimeout(function() { clickAutoHideParent.append(clickAutoHide); @@ -245,7 +245,7 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop } // hide popovers - var popover = elem.find('.popover'); + const popover = elem.find('.popover'); if (popover.length > 0 && target.parents('.graph-legend').length === 0) { popover.hide(); } diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 4dd8a123378..99f8358fdfc 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -74,8 +74,8 @@ export class BackendSrv { request(options) { options.retry = options.retry || 0; - var requestIsLocal = !options.url.match(/^http/); - var firstAttempt = options.retry === 0; + const requestIsLocal = !options.url.match(/^http/); + const firstAttempt = options.retry === 0; if (requestIsLocal) { if (this.contextSrv.user && this.contextSrv.user.orgId) { @@ -123,30 +123,31 @@ export class BackendSrv { } resolveCancelerIfExists(requestId) { - var cancelers = this.inFlightRequests[requestId]; + const cancelers = this.inFlightRequests[requestId]; if (!_.isUndefined(cancelers) && cancelers.length) { cancelers[0].resolve(); } } datasourceRequest(options) { + let canceler = null; options.retry = options.retry || 0; // A requestID is provided by the datasource as a unique identifier for a // particular query. If the requestID exists, the promise it is keyed to // is canceled, canceling the previous datasource request if it is still // in-flight. - var requestId = options.requestId; + const requestId = options.requestId; if (requestId) { this.resolveCancelerIfExists(requestId); // create new canceler - var canceler = this.$q.defer(); + canceler = this.$q.defer(); options.timeout = canceler.promise; this.addCanceler(requestId, canceler); } - var requestIsLocal = !options.url.match(/^http/); - var firstAttempt = options.retry === 0; + const requestIsLocal = !options.url.match(/^http/); + const firstAttempt = options.retry === 0; if (requestIsLocal) { if (this.contextSrv.user && this.contextSrv.user.orgId) { diff --git a/public/app/core/time_series2.ts b/public/app/core/time_series2.ts index c29242c9aca..f8c27cfc67d 100644 --- a/public/app/core/time_series2.ts +++ b/public/app/core/time_series2.ts @@ -8,7 +8,7 @@ function matchSeriesOverride(aliasOrRegex, seriesAlias) { } if (aliasOrRegex[0] === '/') { - var regex = kbn.stringToJsRegex(aliasOrRegex); + const regex = kbn.stringToJsRegex(aliasOrRegex); return seriesAlias.match(regex) != null; } @@ -43,9 +43,9 @@ export function updateLegendValues(data: TimeSeries[], panel, height) { // legend and tooltip gets one more decimal precision // than graph legend ticks const { datamin, datamax } = getDataMinMax(data); - let { tickDecimals, scaledDecimals } = getFlotTickDecimals(datamin, datamax, axis, height); - tickDecimals = (tickDecimals || -1) + 1; - series.updateLegendValues(formater, tickDecimals, scaledDecimals + 2); + const { tickDecimals, scaledDecimals } = getFlotTickDecimals(datamin, datamax, axis, height); + const tickDecimalsPlusOne = (tickDecimals || -1) + 1; + series.updateLegendValues(formater, tickDecimalsPlusOne, scaledDecimals + 2); } } } @@ -125,7 +125,7 @@ export default class TimeSeries { delete this.bars.show; for (var i = 0; i < overrides.length; i++) { - var override = overrides[i]; + const override = overrides[i]; if (!matchSeriesOverride(override.alias, this.alias)) { continue; } @@ -193,7 +193,7 @@ export default class TimeSeries { } getFlotPairs(fillStyle) { - var result = []; + const result = []; this.stats.total = 0; this.stats.max = -Number.MAX_VALUE; @@ -209,8 +209,8 @@ export default class TimeSeries { this.allIsNull = true; this.allIsZero = true; - var ignoreNulls = fillStyle === 'connected'; - var nullAsZero = fillStyle === 'null as zero'; + const ignoreNulls = fillStyle === 'connected'; + const nullAsZero = fillStyle === 'null as zero'; var currentTime; var currentValue; var nonNulls = 0; @@ -330,7 +330,7 @@ export default class TimeSeries { isMsResolutionNeeded() { for (var i = 0; i < this.datapoints.length; i++) { if (this.datapoints[i][1] !== null) { - var timestamp = this.datapoints[i][1].toString(); + const timestamp = this.datapoints[i][1].toString(); if (timestamp.length === 13 && timestamp % 1000 !== 0) { return true; } diff --git a/public/app/features/annotations/annotation_tooltip.ts b/public/app/features/annotations/annotation_tooltip.ts index ed2d797b7bf..cadbac1bd89 100644 --- a/public/app/features/annotations/annotation_tooltip.ts +++ b/public/app/features/annotations/annotation_tooltip.ts @@ -21,16 +21,16 @@ export function annotationTooltipDirective($sanitize, dashboardSrv, contextSrv, onEdit: '&', }, link: function(scope, element) { - var event = scope.event; + const event = scope.event; var title = event.title; var text = event.text; - var dashboard = dashboardSrv.getCurrent(); + const dashboard = dashboardSrv.getCurrent(); var tooltip = '
diff --git a/public/app/plugins/panel/heatmap/color_legend.ts b/public/app/plugins/panel/heatmap/color_legend.ts index 84ecd2389b6..005d1e3ca8c 100644 --- a/public/app/plugins/panel/heatmap/color_legend.ts +++ b/public/app/plugins/panel/heatmap/color_legend.ts @@ -200,7 +200,7 @@ function drawSimpleColorLegend(elem, colorScale) { const valuesRange = d3.range(0, legendWidth, rangeStep); const legend = d3.select(legendElem.get(0)); - var legendRects = legend.selectAll('.heatmap-color-legend-rect').data(valuesRange); + const legendRects = legend.selectAll('.heatmap-color-legend-rect').data(valuesRange); legendRects .enter() @@ -239,7 +239,7 @@ function drawSimpleOpacityLegend(elem, options) { const rangeStep = 10; const valuesRange = d3.range(0, legendWidth, rangeStep); - var legendRects = legend.selectAll('.heatmap-opacity-legend-rect').data(valuesRange); + const legendRects = legend.selectAll('.heatmap-opacity-legend-rect').data(valuesRange); legendRects .enter() diff --git a/public/app/plugins/panel/pluginlist/module.ts b/public/app/plugins/panel/pluginlist/module.ts index 93bf258f50d..eeac352f799 100644 --- a/public/app/plugins/panel/pluginlist/module.ts +++ b/public/app/plugins/panel/pluginlist/module.ts @@ -44,7 +44,7 @@ class PluginListCtrl extends PanelCtrl { $event.stopPropagation(); $event.preventDefault(); - var modalScope = this.$scope.$new(true); + const modalScope = this.$scope.$new(true); modalScope.plugin = plugin; this.publishAppEvent('show-modal', { diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index b858f77556f..ba2f81c1541 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -122,7 +122,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { } seriesHandler(seriesData) { - var series = new TimeSeries({ + const series = new TimeSeries({ datapoints: seriesData.datapoints || [], alias: seriesData.target, }); @@ -214,7 +214,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { } invertColorOrder() { - var tmp = this.panel.colors[0]; + const tmp = this.panel.colors[0]; this.panel.colors[0] = this.panel.colors[2]; this.panel.colors[2] = tmp; this.render(); @@ -242,12 +242,12 @@ class SingleStatCtrl extends MetricsPanelCtrl { return { decimals: this.panel.decimals, scaledDecimals: null }; } - var delta = value / 2; + const delta = value / 2; var dec = -Math.floor(Math.log(delta) / Math.LN10); - var magn = Math.pow(10, -dec), - norm = delta / magn, // norm is between 1.0 and 10.0 - size; + const magn = Math.pow(10, -dec); + const norm = delta / magn; // norm is between 1.0 and 10.0 + let size; if (norm < 1.5) { size = 1; @@ -271,7 +271,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { dec = 0; } - var result: any = {}; + const result: any = {}; result.decimals = Math.max(0, dec); result.scaledDecimals = result.decimals - Math.floor(Math.log(size) / Math.LN10) + 2; @@ -282,7 +282,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { data.flotpairs = []; if (this.series.length > 1) { - var error: any = new Error(); + const error: any = new Error(); error.message = 'Multiple Series Error'; error.data = 'Metric query returns ' + @@ -341,7 +341,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { } // value/number to text mapping - var value = parseFloat(map.value); + const value = parseFloat(map.value); if (value === data.valueRounded) { data.valueFormatted = map.text; return; @@ -360,8 +360,8 @@ class SingleStatCtrl extends MetricsPanelCtrl { } // value/number to range mapping - var from = parseFloat(map.from); - var to = parseFloat(map.to); + const from = parseFloat(map.from); + const to = parseFloat(map.to); if (to >= data.valueRounded && from <= data.valueRounded) { data.valueFormatted = map.text; return; @@ -375,7 +375,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { } removeValueMap(map) { - var index = _.indexOf(this.panel.valueMaps, map); + const index = _.indexOf(this.panel.valueMaps, map); this.panel.valueMaps.splice(index, 1); this.render(); } @@ -385,7 +385,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { } removeRangeMap(rangeMap) { - var index = _.indexOf(this.panel.rangeMaps, rangeMap); + const index = _.indexOf(this.panel.rangeMaps, rangeMap); this.panel.rangeMaps.splice(index, 1); this.render(); } @@ -395,17 +395,17 @@ class SingleStatCtrl extends MetricsPanelCtrl { } link(scope, elem, attrs, ctrl) { - var $location = this.$location; - var linkSrv = this.linkSrv; - var $timeout = this.$timeout; - var panel = ctrl.panel; - var templateSrv = this.templateSrv; + const $location = this.$location; + const linkSrv = this.linkSrv; + const $timeout = this.$timeout; + const panel = ctrl.panel; + const templateSrv = this.templateSrv; var data, linkInfo; - var $panelContainer = elem.find('.panel-container'); + const $panelContainer = elem.find('.panel-container'); elem = elem.find('.singlestat-panel'); function applyColoringThresholds(value, valueString) { - var color = getColorForValue(data, value); + const color = getColorForValue(data, value); if (color) { return '' + valueString + ''; } @@ -457,10 +457,10 @@ class SingleStatCtrl extends MetricsPanelCtrl { } function addGauge() { - var width = elem.width(); - var height = elem.height(); + const width = elem.width(); + const height = elem.height(); // Allow to use a bit more space for wide gauges - var dimension = Math.min(width, height * 1.3); + const dimension = Math.min(width, height * 1.3); ctrl.invalidGaugeRange = false; if (panel.gauge.minValue > panel.gauge.maxValue) { @@ -468,8 +468,8 @@ class SingleStatCtrl extends MetricsPanelCtrl { return; } - var plotCanvas = $('
'); - var plotCss = { + const plotCanvas = $(''); + const plotCss = { top: '10px', margin: 'auto', position: 'relative', @@ -479,7 +479,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { plotCanvas.css(plotCss); - var thresholds = []; + const thresholds = []; for (var i = 0; i < data.thresholds.length; i++) { thresholds.push({ value: data.thresholds[i], @@ -491,17 +491,17 @@ class SingleStatCtrl extends MetricsPanelCtrl { color: data.colorMap[data.colorMap.length - 1], }); - var bgColor = config.bootData.user.lightTheme ? 'rgb(230,230,230)' : 'rgb(38,38,38)'; + const bgColor = config.bootData.user.lightTheme ? 'rgb(230,230,230)' : 'rgb(38,38,38)'; - var fontScale = parseInt(panel.valueFontSize) / 100; - var fontSize = Math.min(dimension / 5, 100) * fontScale; + const fontScale = parseInt(panel.valueFontSize) / 100; + const fontSize = Math.min(dimension / 5, 100) * fontScale; // Reduce gauge width if threshold labels enabled - var gaugeWidthReduceRatio = panel.gauge.thresholdLabels ? 1.5 : 1; - var gaugeWidth = Math.min(dimension / 6, 60) / gaugeWidthReduceRatio; - var thresholdMarkersWidth = gaugeWidth / 5; - var thresholdLabelFontSize = fontSize / 2.5; + const gaugeWidthReduceRatio = panel.gauge.thresholdLabels ? 1.5 : 1; + const gaugeWidth = Math.min(dimension / 6, 60) / gaugeWidthReduceRatio; + const thresholdMarkersWidth = gaugeWidth / 5; + const thresholdLabelFontSize = fontSize / 2.5; - var options = { + const options = { series: { gauges: { gauge: { @@ -543,7 +543,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { elem.append(plotCanvas); - var plotSeries = { + const plotSeries = { data: [[0, data.valueRounded]], }; @@ -551,7 +551,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { } function addSparkline() { - var width = elem.width() + 20; + const width = elem.width() + 20; if (width < 30) { // element has not gotten it's width yet // delay sparkline render @@ -559,16 +559,16 @@ class SingleStatCtrl extends MetricsPanelCtrl { return; } - var height = ctrl.height; - var plotCanvas = $(''); - var plotCss: any = {}; + const height = ctrl.height; + const plotCanvas = $(''); + const plotCss: any = {}; plotCss.position = 'absolute'; if (panel.sparkline.full) { plotCss.bottom = '5px'; plotCss.left = '-5px'; plotCss.width = width - 10 + 'px'; - var dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5; + const dynamicHeightMargin = height <= 100 ? 5 : Math.round(height / 100) * 15 + 5; plotCss.height = height - dynamicHeightMargin + 'px'; } else { plotCss.bottom = '0px'; @@ -579,7 +579,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { plotCanvas.css(plotCss); - var options = { + const options = { legend: { show: false }, series: { lines: { @@ -602,7 +602,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { elem.append(plotCanvas); - var plotSeries = { + const plotSeries = { data: data.flotpairs, color: panel.sparkline.lineColor, }; @@ -622,10 +622,10 @@ class SingleStatCtrl extends MetricsPanelCtrl { }); data.colorMap = panel.colors; - var body = panel.gauge.show ? '' : getBigValueHtml(); + const body = panel.gauge.show ? '' : getBigValueHtml(); if (panel.colorBackground) { - var color = getColorForValue(data, data.value); + const color = getColorForValue(data, data.value); if (color) { $panelContainer.css('background-color', color); if (scope.fullscreen) { @@ -660,7 +660,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { function hookupDrilldownLinkTooltip() { // drilldown link tooltip - var drilldownTooltip = $('