mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tslint: tslint to const fixes part3 (#13036)
This commit is contained in:
@@ -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, '&')
|
||||
@@ -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: {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 },
|
||||
};
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user