Commit e1beaaa0 by Torkel Ödegaard Committed by GitHub

tslint: tslint to const fixes part3 (#13036)

parent 35c00891
......@@ -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(() => {
......
......@@ -346,19 +346,24 @@ export class Explore extends React.Component<any, ExploreState> {
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);
......
......@@ -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';
......
......@@ -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 });
};
......
......@@ -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();
......
......@@ -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;
}
......
......@@ -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],
......
......@@ -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);
};
......
......@@ -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;
......
......@@ -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;
......
......@@ -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+$/)) {
......
......@@ -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, '&amp;')
......@@ -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;
......
......@@ -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) {
......
......@@ -12,7 +12,7 @@ export class Analytics {
dataType: 'script',
cache: true,
});
var ga = ((<any>window).ga =
const ga = ((<any>window).ga =
(<any>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 = (<any>window).ga || this.gaInit();
const track = { page: this.$location.url() };
const ga = (<any>window).ga || this.gaInit();
ga('set', track);
ga('send', 'pageview');
});
......
......@@ -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();
......
......@@ -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;
......
......@@ -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);
......
......@@ -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();
......
......@@ -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);
});
});
......
......@@ -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++;
......
......@@ -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: {
......
......@@ -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');
});
});
......
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 },
};
......
......@@ -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 = {
......
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() {
......
......@@ -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;
......
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();
};
......
......@@ -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;
}
......
......@@ -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);
}
......
......@@ -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 });
......
......@@ -10,8 +10,8 @@ export class PanelLoader {
constructor(private $compile, private $rootScope) {}
load(elem, panel, dashboard): AttachedPanel {
var template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
var panelScope = this.$rootScope.$new();
const template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
const panelScope = this.$rootScope.$new();
panelScope.panel = panel;
panelScope.dashboard = dashboard;
......
......@@ -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: &nbsp;' + moment(meta.created).calendar();
if (meta.expires) {
this.titleTooltip += '<br>Expires: &nbsp;' + moment(meta.expires).fromNow() + '<br>';
......@@ -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;
......
......@@ -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 = '';
......
......@@ -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;
......
......@@ -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');
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
}
......
......@@ -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();
});
......
......@@ -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 =
'<div class="gf-form">' +
'<a class="pointer gf-form-label" data-placement="bottom"' +
......@@ -42,7 +42,7 @@ function dashLink($compile, $sanitize, linkSrv) {
$compile(elem.contents())(scope);
function update() {
var linkInfo = linkSrv.getAnchorInfo(link);
const linkInfo = linkSrv.getAnchorInfo(link);
const anchor = elem.find('a');
const span = elem.find('span');
......@@ -84,7 +84,7 @@ function dashLink($compile, $sanitize, linkSrv) {
export class DashLinksContainerCtrl {
/** @ngInject */
constructor($scope, $rootScope, $q, backendSrv, dashboardSrv, linkSrv) {
var currentDashId = dashboardSrv.getCurrent().id;
const currentDashId = dashboardSrv.getCurrent().id;
function buildLinks(linkDef) {
if (linkDef.type === 'dashboards') {
......@@ -128,7 +128,7 @@ export class DashLinksContainerCtrl {
}
function updateDashLinks() {
var promises = _.map($scope.links, buildLinks);
const promises = _.map($scope.links, buildLinks);
$q.all(promises).then(function(results) {
$scope.generatedLinks = _.flatten(results);
......
......@@ -27,7 +27,7 @@ export class PanelLinksEditorCtrl {
$scope.searchDashboards = function(queryStr, callback) {
backendSrv.search({ query: queryStr }).then(function(hits) {
var dashboards = _.map(hits, function(dash) {
const dashboards = _.map(hits, function(dash) {
return dash.title;
});
......@@ -37,7 +37,7 @@ export class PanelLinksEditorCtrl {
$scope.dashboardChanged = function(link) {
backendSrv.search({ query: link.dashboard }).then(function(hits) {
var dashboard = _.find(hits, { title: link.dashboard });
const dashboard = _.find(hits, { title: link.dashboard });
if (dashboard) {
if (dashboard.url) {
link.url = dashboard.url;
......
......@@ -6,7 +6,7 @@ import { store } from 'app/stores/store';
var datasourceTypes = [];
var defaults = {
const defaults = {
name: '',
type: 'graphite',
url: '',
......
......@@ -45,7 +45,7 @@ export class DashImportListCtrl {
}
import(dash, overwrite) {
var installCmd = {
const installCmd = {
pluginId: this.plugin.id,
path: dash.path,
overwrite: overwrite,
......
......@@ -13,7 +13,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
if (component.template) {
return $q.when(component.template);
}
var cached = $templateCache.get(component.templateUrl);
const cached = $templateCache.get(component.templateUrl);
if (cached) {
return $q.when(cached);
}
......@@ -58,7 +58,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
}
function loadPanelComponentInfo(scope, attrs) {
var componentInfo: any = {
const componentInfo: any = {
name: 'panel-plugin-' + scope.panel.type,
bindings: { dashboard: '=', panel: '=', row: '=' },
attrs: {
......@@ -143,7 +143,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
}
// Datasource ConfigCtrl
case 'datasource-config-ctrl': {
var dsMeta = scope.ctrl.datasourceMeta;
const dsMeta = scope.ctrl.datasourceMeta;
return importPluginModule(dsMeta.module).then(function(dsModule): any {
if (!dsModule.ConfigCtrl) {
return { notFound: true };
......@@ -197,7 +197,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
}
function appendAndCompile(scope, elem, componentInfo) {
var child = angular.element(document.createElement(componentInfo.name));
const child = angular.element(document.createElement(componentInfo.name));
_.each(componentInfo.attrs, (value, key) => {
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;
}
......
......@@ -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', {
......
import angular from 'angular';
import _ from 'lodash';
var pluginInfoCache = {};
const pluginInfoCache = {};
export class AppPageCtrl {
page: any;
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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) {
......
......@@ -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);
}
......
var _global = <any>(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 = <any>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 };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment