tslint: tslint to const fixes part3 (#13036)
This commit is contained in:
+5
-5
@@ -53,7 +53,7 @@ export class GrafanaApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var app = angular.module('grafana', []);
|
const app = angular.module('grafana', []);
|
||||||
|
|
||||||
moment.locale(config.bootData.user.locale);
|
moment.locale(config.bootData.user.locale);
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ export class GrafanaApp {
|
|||||||
'$delegate',
|
'$delegate',
|
||||||
'$templateCache',
|
'$templateCache',
|
||||||
function($delegate, $templateCache) {
|
function($delegate, $templateCache) {
|
||||||
var get = $delegate.get;
|
const get = $delegate.get;
|
||||||
$delegate.get = function(url, config) {
|
$delegate.get = function(url, config) {
|
||||||
if (url.match(/\.html$/)) {
|
if (url.match(/\.html$/)) {
|
||||||
// some template's already exist in the cache
|
// some template's already exist in the cache
|
||||||
@@ -105,10 +105,10 @@ export class GrafanaApp {
|
|||||||
'react',
|
'react',
|
||||||
];
|
];
|
||||||
|
|
||||||
var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
|
const module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
|
||||||
|
|
||||||
_.each(module_types, type => {
|
_.each(module_types, type => {
|
||||||
var moduleName = 'grafana.' + type;
|
const moduleName = 'grafana.' + type;
|
||||||
this.useModule(angular.module(moduleName, []));
|
this.useModule(angular.module(moduleName, []));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ export class GrafanaApp {
|
|||||||
coreModule.config(setupAngularRoutes);
|
coreModule.config(setupAngularRoutes);
|
||||||
registerAngularDirectives();
|
registerAngularDirectives();
|
||||||
|
|
||||||
var preBootRequires = [System.import('app/features/all')];
|
const preBootRequires = [System.import('app/features/all')];
|
||||||
|
|
||||||
Promise.all(preBootRequires)
|
Promise.all(preBootRequires)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
@@ -346,19 +346,24 @@ export class Explore extends React.Component<any, ExploreState> {
|
|||||||
|
|
||||||
onQuerySuccess(datasourceId: string, queries: any[]): void {
|
onQuerySuccess(datasourceId: string, queries: any[]): void {
|
||||||
// save queries to history
|
// save queries to history
|
||||||
let { datasource, history } = this.state;
|
let { history } = this.state;
|
||||||
|
const { datasource } = this.state;
|
||||||
|
|
||||||
if (datasource.meta.id !== datasourceId) {
|
if (datasource.meta.id !== datasourceId) {
|
||||||
// Navigated away, queries did not matter
|
// Navigated away, queries did not matter
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ts = Date.now();
|
const ts = Date.now();
|
||||||
queries.forEach(q => {
|
queries.forEach(q => {
|
||||||
const { query } = q;
|
const { query } = q;
|
||||||
history = [{ query, ts }, ...history];
|
history = [{ query, ts }, ...history];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (history.length > MAX_HISTORY_ITEMS) {
|
if (history.length > MAX_HISTORY_ITEMS) {
|
||||||
history = history.slice(0, MAX_HISTORY_ITEMS);
|
history = history.slice(0, MAX_HISTORY_ITEMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine all queries of a datasource type into one history
|
// Combine all queries of a datasource type into one history
|
||||||
const historyKey = `grafana.explore.history.${datasourceId}`;
|
const historyKey = `grafana.explore.history.${datasourceId}`;
|
||||||
store.setObject(historyKey, history);
|
store.setObject(historyKey, history);
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import Legend from './Legend';
|
|||||||
// Copied from graph.ts
|
// Copied from graph.ts
|
||||||
function time_format(ticks, min, max) {
|
function time_format(ticks, min, max) {
|
||||||
if (min && max && ticks) {
|
if (min && max && ticks) {
|
||||||
var range = max - min;
|
const range = max - min;
|
||||||
var secPerTick = range / ticks / 1000;
|
const secPerTick = range / ticks / 1000;
|
||||||
var oneDay = 86400000;
|
const oneDay = 86400000;
|
||||||
var oneYear = 31536000000;
|
const oneYear = 31536000000;
|
||||||
|
|
||||||
if (secPerTick <= 45) {
|
if (secPerTick <= 45) {
|
||||||
return '%H:%M:%S';
|
return '%H:%M:%S';
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ const SelectNav = ({ main, customCss }: { main: NavModelItem; customCss: string
|
|||||||
});
|
});
|
||||||
|
|
||||||
const gotoUrl = evt => {
|
const gotoUrl = evt => {
|
||||||
var element = evt.target;
|
const element = evt.target;
|
||||||
var url = element.options[element.selectedIndex].value;
|
const url = element.options[element.selectedIndex].value;
|
||||||
appEvents.emit('location-change', { href: url });
|
appEvents.emit('location-change', { href: url });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export class FormDropdownCtrl {
|
|||||||
|
|
||||||
// modify typeahead lookup
|
// modify typeahead lookup
|
||||||
// this = typeahead
|
// this = typeahead
|
||||||
var typeahead = this.inputElement.data('typeahead');
|
const typeahead = this.inputElement.data('typeahead');
|
||||||
typeahead.lookup = function() {
|
typeahead.lookup = function() {
|
||||||
this.query = this.$element.val() || '';
|
this.query = this.$element.val() || '';
|
||||||
this.source(this.query, this.process.bind(this));
|
this.source(this.query, this.process.bind(this));
|
||||||
@@ -100,7 +100,7 @@ export class FormDropdownCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getOptionsInternal(query) {
|
getOptionsInternal(query) {
|
||||||
var result = this.getOptions({ $query: query });
|
const result = this.getOptions({ $query: query });
|
||||||
if (this.isPromiseLike(result)) {
|
if (this.isPromiseLike(result)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ export class FormDropdownCtrl {
|
|||||||
// if we have text use it
|
// if we have text use it
|
||||||
if (this.lookupText) {
|
if (this.lookupText) {
|
||||||
this.getOptionsInternal('').then(options => {
|
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);
|
this.updateDisplay(item ? item.text : this.model);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -186,7 +186,7 @@ export class FormDropdownCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.$scope.$apply(() => {
|
this.$scope.$apply(() => {
|
||||||
var option = _.find(this.optionCache, { text: text });
|
const option = _.find(this.optionCache, { text: text });
|
||||||
|
|
||||||
if (option) {
|
if (option) {
|
||||||
if (_.isObject(this.model)) {
|
if (_.isObject(this.model)) {
|
||||||
@@ -228,7 +228,7 @@ export class FormDropdownCtrl {
|
|||||||
this.linkElement.hide();
|
this.linkElement.hide();
|
||||||
this.linkMode = false;
|
this.linkMode = false;
|
||||||
|
|
||||||
var typeahead = this.inputElement.data('typeahead');
|
const typeahead = this.inputElement.data('typeahead');
|
||||||
if (typeahead) {
|
if (typeahead) {
|
||||||
this.inputElement.val('');
|
this.inputElement.val('');
|
||||||
typeahead.lookup();
|
typeahead.lookup();
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ export class ManageDashboardsCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTagFilterChange() {
|
onTagFilterChange() {
|
||||||
var res = this.filterByTag(this.selectedTagFilter.term);
|
const res = this.filterByTag(this.selectedTagFilter.term);
|
||||||
this.selectedTagFilter = this.tagFilterOptions[0];
|
this.selectedTagFilter = this.tagFilterOptions[0];
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import coreModule from '../core_module';
|
|||||||
export class InspectCtrl {
|
export class InspectCtrl {
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $sanitize) {
|
constructor($scope, $sanitize) {
|
||||||
var model = $scope.inspector;
|
const model = $scope.inspector;
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
$scope.editor = { index: 0 };
|
$scope.editor = { index: 0 };
|
||||||
@@ -53,10 +53,10 @@ export class InspectCtrl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
getParametersFromQueryString(queryString) {
|
getParametersFromQueryString(queryString) {
|
||||||
var result = [];
|
const result = [];
|
||||||
var parameters = queryString.split('&');
|
const parameters = queryString.split('&');
|
||||||
for (var i = 0; i < parameters.length; i++) {
|
for (let i = 0; i < parameters.length; i++) {
|
||||||
var keyValue = parameters[i].split('=');
|
const keyValue = parameters[i].split('=');
|
||||||
if (keyValue[1].length > 0) {
|
if (keyValue[1].length > 0) {
|
||||||
result.push({
|
result.push({
|
||||||
key: keyValue[0],
|
key: keyValue[0],
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class JsonEditorCtrl {
|
|||||||
$scope.canCopy = $scope.enableCopy;
|
$scope.canCopy = $scope.enableCopy;
|
||||||
|
|
||||||
$scope.update = function() {
|
$scope.update = function() {
|
||||||
var newObject = angular.fromJson($scope.json);
|
const newObject = angular.fromJson($scope.json);
|
||||||
$scope.updateHandler(newObject, $scope.object);
|
$scope.updateHandler(newObject, $scope.object);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export class LoginCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.toGrafana = function() {
|
$scope.toGrafana = function() {
|
||||||
var params = $location.search();
|
const params = $location.search();
|
||||||
|
|
||||||
if (params.redirect && params.redirect[0] === '/') {
|
if (params.redirect && params.redirect[0] === '/') {
|
||||||
window.location.href = config.appSubUrl + params.redirect;
|
window.location.href = config.appSubUrl + params.redirect;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export class ResetPasswordCtrl {
|
|||||||
$scope.formModel = {};
|
$scope.formModel = {};
|
||||||
$scope.mode = 'send';
|
$scope.mode = 'send';
|
||||||
|
|
||||||
var params = $location.search();
|
const params = $location.search();
|
||||||
if (params.code) {
|
if (params.code) {
|
||||||
$scope.mode = 'reset';
|
$scope.mode = 'reset';
|
||||||
$scope.formModel.code = params.code;
|
$scope.formModel.code = params.code;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class SignUpCtrl {
|
|||||||
|
|
||||||
$scope.formModel = {};
|
$scope.formModel = {};
|
||||||
|
|
||||||
var params = $location.search();
|
const params = $location.search();
|
||||||
|
|
||||||
// validate email is semi ok
|
// validate email is semi ok
|
||||||
if (params.email && !params.email.match(/^\S+@\S+$/)) {
|
if (params.email && !params.email.match(/^\S+@\S+$/)) {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ coreModule.filter('moment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
coreModule.filter('noXml', function() {
|
coreModule.filter('noXml', function() {
|
||||||
var noXml = function(text) {
|
const noXml = function(text) {
|
||||||
return _.isString(text)
|
return _.isString(text)
|
||||||
? text
|
? text
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
@@ -55,7 +55,7 @@ coreModule.filter('noXml', function() {
|
|||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function interpolateTemplateVars(templateSrv) {
|
function interpolateTemplateVars(templateSrv) {
|
||||||
var filterFunc: any = function(text, scope) {
|
const filterFunc: any = function(text, scope) {
|
||||||
var scopedVars;
|
var scopedVars;
|
||||||
if (scope.ctrl) {
|
if (scope.ctrl) {
|
||||||
scopedVars = (scope.ctrl.panel || scope.ctrl.row).scopedVars;
|
scopedVars = (scope.ctrl.panel || scope.ctrl.row).scopedVars;
|
||||||
|
|||||||
@@ -60,14 +60,14 @@ export class AlertSrv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newAlert = {
|
const newAlert = {
|
||||||
title: title || '',
|
title: title || '',
|
||||||
text: text || '',
|
text: text || '',
|
||||||
severity: severity || 'info',
|
severity: severity || 'info',
|
||||||
icon: this.getIconForSeverity(severity),
|
icon: this.getIconForSeverity(severity),
|
||||||
};
|
};
|
||||||
|
|
||||||
var newAlertJson = angular.toJson(newAlert);
|
const newAlertJson = angular.toJson(newAlert);
|
||||||
|
|
||||||
// remove same alert if it already exists
|
// remove same alert if it already exists
|
||||||
_.remove(this.list, function(value) {
|
_.remove(this.list, function(value) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class Analytics {
|
|||||||
dataType: 'script',
|
dataType: 'script',
|
||||||
cache: true,
|
cache: true,
|
||||||
});
|
});
|
||||||
var ga = ((<any>window).ga =
|
const ga = ((<any>window).ga =
|
||||||
(<any>window).ga ||
|
(<any>window).ga ||
|
||||||
function() {
|
function() {
|
||||||
(ga.q = ga.q || []).push(arguments);
|
(ga.q = ga.q || []).push(arguments);
|
||||||
@@ -25,8 +25,8 @@ export class Analytics {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.$rootScope.$on('$viewContentLoaded', () => {
|
this.$rootScope.$on('$viewContentLoaded', () => {
|
||||||
var track = { page: this.$location.url() };
|
const track = { page: this.$location.url() };
|
||||||
var ga = (<any>window).ga || this.gaInit();
|
const ga = (<any>window).ga || this.gaInit();
|
||||||
ga('set', track);
|
ga('set', track);
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class DynamicDirectiveSrv {
|
|||||||
constructor(private $compile, private $rootScope) {}
|
constructor(private $compile, private $rootScope) {}
|
||||||
|
|
||||||
addDirective(element, name, scope) {
|
addDirective(element, name, scope) {
|
||||||
var child = angular.element(document.createElement(name));
|
const child = angular.element(document.createElement(name));
|
||||||
this.$compile(child)(scope);
|
this.$compile(child)(scope);
|
||||||
|
|
||||||
element.empty();
|
element.empty();
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export class KeybindingSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit() {
|
exit() {
|
||||||
var popups = $('.popover.in');
|
const popups = $('.popover.in');
|
||||||
if (popups.length > 0) {
|
if (popups.length > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ export class KeybindingSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// close settings view
|
// close settings view
|
||||||
var search = this.$location.search();
|
const search = this.$location.search();
|
||||||
if (search.editview) {
|
if (search.editview) {
|
||||||
delete search.editview;
|
delete search.editview;
|
||||||
this.$location.search(search);
|
this.$location.search(search);
|
||||||
@@ -123,7 +123,7 @@ export class KeybindingSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showDashEditView() {
|
showDashEditView() {
|
||||||
var search = _.extend(this.$location.search(), { editview: 'settings' });
|
const search = _.extend(this.$location.search(), { editview: 'settings' });
|
||||||
this.$location.search(search);
|
this.$location.search(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,8 +218,8 @@ export class KeybindingSrv {
|
|||||||
// share panel
|
// share panel
|
||||||
this.bind('p s', () => {
|
this.bind('p s', () => {
|
||||||
if (dashboard.meta.focusPanelId) {
|
if (dashboard.meta.focusPanelId) {
|
||||||
var shareScope = scope.$new();
|
const shareScope = scope.$new();
|
||||||
var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId);
|
const panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId);
|
||||||
shareScope.panel = panelInfo.panel;
|
shareScope.panel = panelInfo.panel;
|
||||||
shareScope.dashboard = dashboard;
|
shareScope.dashboard = dashboard;
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ function popoverSrv($compile, $rootScope, $timeout) {
|
|||||||
openDrop = null;
|
openDrop = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scope = _.extend($rootScope.$new(true), options.model);
|
const scope = _.extend($rootScope.$new(true), options.model);
|
||||||
var drop;
|
let drop;
|
||||||
|
|
||||||
var cleanUp = () => {
|
const cleanUp = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scope.$destroy();
|
scope.$destroy();
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ function popoverSrv($compile, $rootScope, $timeout) {
|
|||||||
drop.close();
|
drop.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
var contentElement = document.createElement('div');
|
const contentElement = document.createElement('div');
|
||||||
contentElement.innerHTML = options.template;
|
contentElement.innerHTML = options.template;
|
||||||
|
|
||||||
$compile(contentElement)(scope);
|
$compile(contentElement)(scope);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class UtilSrv {
|
|||||||
this.modalScope = this.$rootScope.$new();
|
this.modalScope = this.$rootScope.$new();
|
||||||
}
|
}
|
||||||
|
|
||||||
var modal = this.$modal({
|
const modal = this.$modal({
|
||||||
modalClass: options.modalClass,
|
modalClass: options.modalClass,
|
||||||
template: options.src,
|
template: options.src,
|
||||||
templateHtml: options.templateHtml,
|
templateHtml: options.templateHtml,
|
||||||
@@ -50,7 +50,7 @@ export class UtilSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showConfirmModal(payload) {
|
showConfirmModal(payload) {
|
||||||
var scope = this.$rootScope.$new();
|
const scope = this.$rootScope.$new();
|
||||||
|
|
||||||
scope.onConfirm = function() {
|
scope.onConfirm = function() {
|
||||||
payload.onConfirm();
|
payload.onConfirm();
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import moment from 'moment';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
describe('DateMath', () => {
|
describe('DateMath', () => {
|
||||||
var spans = ['s', 'm', 'h', 'd', 'w', 'M', 'y'];
|
const spans = ['s', 'm', 'h', 'd', 'w', 'M', 'y'];
|
||||||
var anchor = '2014-01-01T06:06:06.666Z';
|
const anchor = '2014-01-01T06:06:06.666Z';
|
||||||
var unix = moment(anchor).valueOf();
|
const unix = moment(anchor).valueOf();
|
||||||
var format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
const format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
||||||
var clock;
|
let clock;
|
||||||
|
|
||||||
describe('errors', () => {
|
describe('errors', () => {
|
||||||
it('should return undefined if passed something falsy', () => {
|
it('should return undefined if passed something falsy', () => {
|
||||||
@@ -36,21 +36,21 @@ describe('DateMath', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('now/d should set to start of current day', () => {
|
it('now/d should set to start of current day', () => {
|
||||||
var expected = new Date();
|
const expected = new Date();
|
||||||
expected.setHours(0);
|
expected.setHours(0);
|
||||||
expected.setMinutes(0);
|
expected.setMinutes(0);
|
||||||
expected.setSeconds(0);
|
expected.setSeconds(0);
|
||||||
expected.setMilliseconds(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());
|
expect(startOfDay).toBe(expected.getTime());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('now/d on a utc dashboard should be start of the current day in UTC time', () => {
|
it('now/d on a utc dashboard should be start of the current day in UTC time', () => {
|
||||||
var today = new Date();
|
const today = new Date();
|
||||||
var expected = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), 0, 0, 0, 0));
|
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());
|
expect(startOfDay).toBe(expected.getTime());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,8 +65,8 @@ describe('DateMath', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_.each(spans, span => {
|
_.each(spans, span => {
|
||||||
var nowEx = 'now-5' + span;
|
const nowEx = 'now-5' + span;
|
||||||
var thenEx = anchor + '||-5' + span;
|
const thenEx = anchor + '||-5' + span;
|
||||||
|
|
||||||
it('should return 5' + span + ' ago', () => {
|
it('should return 5' + span + ' ago', () => {
|
||||||
expect(dateMath.parse(nowEx).format(format)).toEqual(now.subtract(5, span).format(format));
|
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() {
|
describe('relative time to date parsing', function() {
|
||||||
it('should handle negative time', 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());
|
expect(date.valueOf()).toEqual(moment([2014, 1, 3]).valueOf());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle multiple math expressions', function() {
|
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());
|
expect(date.valueOf()).toEqual(moment([2014, 1, 2, 18]).valueOf());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when invalid expression', function() {
|
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);
|
expect(date).toEqual(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { Emitter } from '../utils/emitter';
|
|||||||
describe('Emitter', () => {
|
describe('Emitter', () => {
|
||||||
describe('given 2 subscribers', () => {
|
describe('given 2 subscribers', () => {
|
||||||
it('should notfiy subscribers', () => {
|
it('should notfiy subscribers', () => {
|
||||||
var events = new Emitter();
|
const events = new Emitter();
|
||||||
var sub1Called = false;
|
let sub1Called = false;
|
||||||
var sub2Called = false;
|
let sub2Called = false;
|
||||||
|
|
||||||
events.on('test', () => {
|
events.on('test', () => {
|
||||||
sub1Called = true;
|
sub1Called = true;
|
||||||
@@ -21,8 +21,8 @@ describe('Emitter', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('when subscribing twice', () => {
|
it('when subscribing twice', () => {
|
||||||
var events = new Emitter();
|
const events = new Emitter();
|
||||||
var sub1Called = 0;
|
let sub1Called = 0;
|
||||||
|
|
||||||
function handler() {
|
function handler() {
|
||||||
sub1Called += 1;
|
sub1Called += 1;
|
||||||
@@ -37,9 +37,9 @@ describe('Emitter', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle errors', () => {
|
it('should handle errors', () => {
|
||||||
var events = new Emitter();
|
const events = new Emitter();
|
||||||
var sub1Called = 0;
|
let sub1Called = 0;
|
||||||
var sub2Called = 0;
|
let sub2Called = 0;
|
||||||
|
|
||||||
events.on('test', () => {
|
events.on('test', () => {
|
||||||
sub1Called++;
|
sub1Called++;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import flatten from 'app/core/utils/flatten';
|
|||||||
|
|
||||||
describe('flatten', () => {
|
describe('flatten', () => {
|
||||||
it('should return flatten object', () => {
|
it('should return flatten object', () => {
|
||||||
var flattened = flatten(
|
const flattened = flatten(
|
||||||
{
|
{
|
||||||
level1: 'level1-value',
|
level1: 'level1-value',
|
||||||
deeper: {
|
deeper: {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as dateMath from '../utils/datemath';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
describe('unit format menu', function() {
|
describe('unit format menu', function() {
|
||||||
var menu = kbn.getUnitFormats();
|
const menu = kbn.getUnitFormats();
|
||||||
menu.map(function(submenu) {
|
menu.map(function(submenu) {
|
||||||
describe('submenu ' + submenu.text, function() {
|
describe('submenu ' + submenu.text, function() {
|
||||||
it('should have a title', function() {
|
it('should have a title', function() {
|
||||||
@@ -34,8 +34,8 @@ describe('unit format menu', function() {
|
|||||||
function describeValueFormat(desc, value, tickSize, tickDecimals, result) {
|
function describeValueFormat(desc, value, tickSize, tickDecimals, result) {
|
||||||
describe('value format: ' + desc, function() {
|
describe('value format: ' + desc, function() {
|
||||||
it('should translate ' + value + ' as ' + result, function() {
|
it('should translate ' + value + ' as ' + result, function() {
|
||||||
var scaledDecimals = tickDecimals - Math.floor(Math.log(tickSize) / Math.LN10);
|
const scaledDecimals = tickDecimals - Math.floor(Math.log(tickSize) / Math.LN10);
|
||||||
var str = kbn.valueFormats[desc](value, tickDecimals, scaledDecimals);
|
const str = kbn.valueFormats[desc](value, tickDecimals, scaledDecimals);
|
||||||
expect(str).toBe(result);
|
expect(str).toBe(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -106,177 +106,177 @@ describe('date time formats', function() {
|
|||||||
const browserTime = moment(epoch);
|
const browserTime = moment(epoch);
|
||||||
|
|
||||||
it('should format as iso date', function() {
|
it('should format as iso date', function() {
|
||||||
var expected = browserTime.format('YYYY-MM-DD HH:mm:ss');
|
const expected = browserTime.format('YYYY-MM-DD HH:mm:ss');
|
||||||
var actual = kbn.valueFormats.dateTimeAsIso(epoch);
|
const actual = kbn.valueFormats.dateTimeAsIso(epoch);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as iso date (in UTC)', function() {
|
it('should format as iso date (in UTC)', function() {
|
||||||
var expected = utcTime.format('YYYY-MM-DD HH:mm:ss');
|
const expected = utcTime.format('YYYY-MM-DD HH:mm:ss');
|
||||||
var actual = kbn.valueFormats.dateTimeAsIso(epoch, true);
|
const actual = kbn.valueFormats.dateTimeAsIso(epoch, true);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as iso date and skip date when today', function() {
|
it('should format as iso date and skip date when today', function() {
|
||||||
var now = moment();
|
const now = moment();
|
||||||
var expected = now.format('HH:mm:ss');
|
const expected = now.format('HH:mm:ss');
|
||||||
var actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), false);
|
const actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), false);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as iso date (in UTC) and skip date when today', function() {
|
it('should format as iso date (in UTC) and skip date when today', function() {
|
||||||
var now = moment.utc();
|
const now = moment.utc();
|
||||||
var expected = now.format('HH:mm:ss');
|
const expected = now.format('HH:mm:ss');
|
||||||
var actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), true);
|
const actual = kbn.valueFormats.dateTimeAsIso(now.valueOf(), true);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as US date', function() {
|
it('should format as US date', function() {
|
||||||
var expected = browserTime.format('MM/DD/YYYY h:mm:ss a');
|
const expected = browserTime.format('MM/DD/YYYY h:mm:ss a');
|
||||||
var actual = kbn.valueFormats.dateTimeAsUS(epoch, false);
|
const actual = kbn.valueFormats.dateTimeAsUS(epoch, false);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as US date (in UTC)', function() {
|
it('should format as US date (in UTC)', function() {
|
||||||
var expected = utcTime.format('MM/DD/YYYY h:mm:ss a');
|
const expected = utcTime.format('MM/DD/YYYY h:mm:ss a');
|
||||||
var actual = kbn.valueFormats.dateTimeAsUS(epoch, true);
|
const actual = kbn.valueFormats.dateTimeAsUS(epoch, true);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as US date and skip date when today', function() {
|
it('should format as US date and skip date when today', function() {
|
||||||
var now = moment();
|
const now = moment();
|
||||||
var expected = now.format('h:mm:ss a');
|
const expected = now.format('h:mm:ss a');
|
||||||
var actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), false);
|
const actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), false);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as US date (in UTC) and skip date when today', function() {
|
it('should format as US date (in UTC) and skip date when today', function() {
|
||||||
var now = moment.utc();
|
const now = moment.utc();
|
||||||
var expected = now.format('h:mm:ss a');
|
const expected = now.format('h:mm:ss a');
|
||||||
var actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), true);
|
const actual = kbn.valueFormats.dateTimeAsUS(now.valueOf(), true);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as from now with days', function() {
|
it('should format as from now with days', function() {
|
||||||
var daysAgo = moment().add(-7, 'd');
|
const daysAgo = moment().add(-7, 'd');
|
||||||
var expected = '7 days ago';
|
const expected = '7 days ago';
|
||||||
var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false);
|
const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as from now with days (in UTC)', function() {
|
it('should format as from now with days (in UTC)', function() {
|
||||||
var daysAgo = moment.utc().add(-7, 'd');
|
const daysAgo = moment.utc().add(-7, 'd');
|
||||||
var expected = '7 days ago';
|
const expected = '7 days ago';
|
||||||
var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true);
|
const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as from now with minutes', function() {
|
it('should format as from now with minutes', function() {
|
||||||
var daysAgo = moment().add(-2, 'm');
|
const daysAgo = moment().add(-2, 'm');
|
||||||
var expected = '2 minutes ago';
|
const expected = '2 minutes ago';
|
||||||
var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false);
|
const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), false);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format as from now with minutes (in UTC)', function() {
|
it('should format as from now with minutes (in UTC)', function() {
|
||||||
var daysAgo = moment.utc().add(-2, 'm');
|
const daysAgo = moment.utc().add(-2, 'm');
|
||||||
var expected = '2 minutes ago';
|
const expected = '2 minutes ago';
|
||||||
var actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true);
|
const actual = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), true);
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('kbn.toFixed and negative decimals', function() {
|
describe('kbn.toFixed and negative decimals', function() {
|
||||||
it('should treat as zero 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');
|
expect(str).toBe('186');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('kbn ms format when scaled decimals is null do not use it', function() {
|
describe('kbn ms format when scaled decimals is null do not use it', function() {
|
||||||
it('should use specified decimals', 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');
|
expect(str).toBe('2.8 hour');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('kbn kbytes format when scaled decimals is null do not use it', function() {
|
describe('kbn kbytes format when scaled decimals is null do not use it', function() {
|
||||||
it('should use specified decimals', 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');
|
expect(str).toBe('9.537 GiB');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('kbn deckbytes format when scaled decimals is null do not use it', function() {
|
describe('kbn deckbytes format when scaled decimals is null do not use it', function() {
|
||||||
it('should use specified decimals', 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');
|
expect(str).toBe('10.000 GB');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('kbn roundValue', function() {
|
describe('kbn roundValue', function() {
|
||||||
it('should should handle null value', function() {
|
it('should should handle null value', function() {
|
||||||
var str = kbn.roundValue(null, 2);
|
const str = kbn.roundValue(null, 2);
|
||||||
expect(str).toBe(null);
|
expect(str).toBe(null);
|
||||||
});
|
});
|
||||||
it('should round value', function() {
|
it('should round value', function() {
|
||||||
var str = kbn.roundValue(200.877, 2);
|
const str = kbn.roundValue(200.877, 2);
|
||||||
expect(str).toBe(200.88);
|
expect(str).toBe(200.88);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('calculateInterval', function() {
|
describe('calculateInterval', function() {
|
||||||
it('1h 100 resultion', function() {
|
it('1h 100 resultion', function() {
|
||||||
var range = { from: dateMath.parse('now-1h'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-1h'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 100, null);
|
const res = kbn.calculateInterval(range, 100, null);
|
||||||
expect(res.interval).toBe('30s');
|
expect(res.interval).toBe('30s');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('10m 1600 resolution', function() {
|
it('10m 1600 resolution', function() {
|
||||||
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 1600, null);
|
const res = kbn.calculateInterval(range, 1600, null);
|
||||||
expect(res.interval).toBe('500ms');
|
expect(res.interval).toBe('500ms');
|
||||||
expect(res.intervalMs).toBe(500);
|
expect(res.intervalMs).toBe(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fixed user min interval', function() {
|
it('fixed user min interval', function() {
|
||||||
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 1600, '10s');
|
const res = kbn.calculateInterval(range, 1600, '10s');
|
||||||
expect(res.interval).toBe('10s');
|
expect(res.interval).toBe('10s');
|
||||||
expect(res.intervalMs).toBe(10000);
|
expect(res.intervalMs).toBe(10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('short time range and user low limit', function() {
|
it('short time range and user low limit', function() {
|
||||||
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 1600, '>10s');
|
const res = kbn.calculateInterval(range, 1600, '>10s');
|
||||||
expect(res.interval).toBe('10s');
|
expect(res.interval).toBe('10s');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('large time range and user low limit', function() {
|
it('large time range and user low limit', function() {
|
||||||
var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 1000, '>10s');
|
const res = kbn.calculateInterval(range, 1000, '>10s');
|
||||||
expect(res.interval).toBe('20m');
|
expect(res.interval).toBe('20m');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('10s 900 resolution and user low limit in ms', function() {
|
it('10s 900 resolution and user low limit in ms', function() {
|
||||||
var range = { from: dateMath.parse('now-10s'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-10s'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 900, '>15ms');
|
const res = kbn.calculateInterval(range, 900, '>15ms');
|
||||||
expect(res.interval).toBe('15ms');
|
expect(res.interval).toBe('15ms');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('1d 1 resolution', function() {
|
it('1d 1 resolution', function() {
|
||||||
var range = { from: dateMath.parse('now-1d'), to: dateMath.parse('now') };
|
const range = { from: dateMath.parse('now-1d'), to: dateMath.parse('now') };
|
||||||
var res = kbn.calculateInterval(range, 1, null);
|
const res = kbn.calculateInterval(range, 1, null);
|
||||||
expect(res.interval).toBe('1d');
|
expect(res.interval).toBe('1d');
|
||||||
expect(res.intervalMs).toBe(86400000);
|
expect(res.intervalMs).toBe(86400000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('86399s 1 resolution', function() {
|
it('86399s 1 resolution', function() {
|
||||||
var range = {
|
const range = {
|
||||||
from: dateMath.parse('now-86390s'),
|
from: dateMath.parse('now-86390s'),
|
||||||
to: dateMath.parse('now'),
|
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.interval).toBe('12h');
|
||||||
expect(res.intervalMs).toBe(43200000);
|
expect(res.intervalMs).toBe(43200000);
|
||||||
});
|
});
|
||||||
@@ -284,139 +284,139 @@ describe('calculateInterval', function() {
|
|||||||
|
|
||||||
describe('hex', function() {
|
describe('hex', function() {
|
||||||
it('positive integer', function() {
|
it('positive integer', function() {
|
||||||
var str = kbn.valueFormats.hex(100, 0);
|
const str = kbn.valueFormats.hex(100, 0);
|
||||||
expect(str).toBe('64');
|
expect(str).toBe('64');
|
||||||
});
|
});
|
||||||
it('negative integer', function() {
|
it('negative integer', function() {
|
||||||
var str = kbn.valueFormats.hex(-100, 0);
|
const str = kbn.valueFormats.hex(-100, 0);
|
||||||
expect(str).toBe('-64');
|
expect(str).toBe('-64');
|
||||||
});
|
});
|
||||||
it('null', function() {
|
it('null', function() {
|
||||||
var str = kbn.valueFormats.hex(null, 0);
|
const str = kbn.valueFormats.hex(null, 0);
|
||||||
expect(str).toBe('');
|
expect(str).toBe('');
|
||||||
});
|
});
|
||||||
it('positive float', function() {
|
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');
|
expect(str).toBe('32.8');
|
||||||
});
|
});
|
||||||
it('negative float', function() {
|
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');
|
expect(str).toBe('-32.547AE147AE14');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hex 0x', function() {
|
describe('hex 0x', function() {
|
||||||
it('positive integeter', function() {
|
it('positive integeter', function() {
|
||||||
var str = kbn.valueFormats.hex0x(7999, 0);
|
const str = kbn.valueFormats.hex0x(7999, 0);
|
||||||
expect(str).toBe('0x1F3F');
|
expect(str).toBe('0x1F3F');
|
||||||
});
|
});
|
||||||
it('negative integer', function() {
|
it('negative integer', function() {
|
||||||
var str = kbn.valueFormats.hex0x(-584, 0);
|
const str = kbn.valueFormats.hex0x(-584, 0);
|
||||||
expect(str).toBe('-0x248');
|
expect(str).toBe('-0x248');
|
||||||
});
|
});
|
||||||
it('null', function() {
|
it('null', function() {
|
||||||
var str = kbn.valueFormats.hex0x(null, 0);
|
const str = kbn.valueFormats.hex0x(null, 0);
|
||||||
expect(str).toBe('');
|
expect(str).toBe('');
|
||||||
});
|
});
|
||||||
it('positive float', function() {
|
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');
|
expect(str).toBe('0x4A.716872B020C4');
|
||||||
});
|
});
|
||||||
it('negative float', function() {
|
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');
|
expect(str).toBe('-0x41.8');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('duration', function() {
|
describe('duration', function() {
|
||||||
it('null', function() {
|
it('null', function() {
|
||||||
var str = kbn.toDuration(null, 0, 'millisecond');
|
const str = kbn.toDuration(null, 0, 'millisecond');
|
||||||
expect(str).toBe('');
|
expect(str).toBe('');
|
||||||
});
|
});
|
||||||
it('0 milliseconds', function() {
|
it('0 milliseconds', function() {
|
||||||
var str = kbn.toDuration(0, 0, 'millisecond');
|
const str = kbn.toDuration(0, 0, 'millisecond');
|
||||||
expect(str).toBe('0 milliseconds');
|
expect(str).toBe('0 milliseconds');
|
||||||
});
|
});
|
||||||
it('1 millisecond', function() {
|
it('1 millisecond', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'millisecond');
|
const str = kbn.toDuration(1, 0, 'millisecond');
|
||||||
expect(str).toBe('1 millisecond');
|
expect(str).toBe('1 millisecond');
|
||||||
});
|
});
|
||||||
it('-1 millisecond', function() {
|
it('-1 millisecond', function() {
|
||||||
var str = kbn.toDuration(-1, 0, 'millisecond');
|
const str = kbn.toDuration(-1, 0, 'millisecond');
|
||||||
expect(str).toBe('1 millisecond ago');
|
expect(str).toBe('1 millisecond ago');
|
||||||
});
|
});
|
||||||
it('seconds', function() {
|
it('seconds', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'second');
|
const str = kbn.toDuration(1, 0, 'second');
|
||||||
expect(str).toBe('1 second');
|
expect(str).toBe('1 second');
|
||||||
});
|
});
|
||||||
it('minutes', function() {
|
it('minutes', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'minute');
|
const str = kbn.toDuration(1, 0, 'minute');
|
||||||
expect(str).toBe('1 minute');
|
expect(str).toBe('1 minute');
|
||||||
});
|
});
|
||||||
it('hours', function() {
|
it('hours', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'hour');
|
const str = kbn.toDuration(1, 0, 'hour');
|
||||||
expect(str).toBe('1 hour');
|
expect(str).toBe('1 hour');
|
||||||
});
|
});
|
||||||
it('days', function() {
|
it('days', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'day');
|
const str = kbn.toDuration(1, 0, 'day');
|
||||||
expect(str).toBe('1 day');
|
expect(str).toBe('1 day');
|
||||||
});
|
});
|
||||||
it('weeks', function() {
|
it('weeks', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'week');
|
const str = kbn.toDuration(1, 0, 'week');
|
||||||
expect(str).toBe('1 week');
|
expect(str).toBe('1 week');
|
||||||
});
|
});
|
||||||
it('months', function() {
|
it('months', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'month');
|
const str = kbn.toDuration(1, 0, 'month');
|
||||||
expect(str).toBe('1 month');
|
expect(str).toBe('1 month');
|
||||||
});
|
});
|
||||||
it('years', function() {
|
it('years', function() {
|
||||||
var str = kbn.toDuration(1, 0, 'year');
|
const str = kbn.toDuration(1, 0, 'year');
|
||||||
expect(str).toBe('1 year');
|
expect(str).toBe('1 year');
|
||||||
});
|
});
|
||||||
it('decimal days', function() {
|
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');
|
expect(str).toBe('1 day, 12 hours, 0 minutes');
|
||||||
});
|
});
|
||||||
it('decimal months', function() {
|
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');
|
expect(str).toBe('1 month, 2 weeks, 1 day, 0 hours');
|
||||||
});
|
});
|
||||||
it('no decimals', function() {
|
it('no decimals', function() {
|
||||||
var str = kbn.toDuration(38898367008, 0, 'millisecond');
|
const str = kbn.toDuration(38898367008, 0, 'millisecond');
|
||||||
expect(str).toBe('1 year');
|
expect(str).toBe('1 year');
|
||||||
});
|
});
|
||||||
it('1 decimal', function() {
|
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');
|
expect(str).toBe('1 year, 2 months');
|
||||||
});
|
});
|
||||||
it('too many decimals', function() {
|
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');
|
expect(str).toBe('1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, 7 seconds, 8 milliseconds');
|
||||||
});
|
});
|
||||||
it('floating point error', function() {
|
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');
|
expect(str).toBe('1 year, 2 months, 0 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('volume', function() {
|
describe('volume', function() {
|
||||||
it('1000m3', 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³');
|
expect(str).toBe('1000.0 m³');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hh:mm:ss', function() {
|
describe('hh:mm:ss', function() {
|
||||||
it('00:04:06', 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');
|
expect(str).toBe('00:04:06');
|
||||||
});
|
});
|
||||||
it('24:00:00', function() {
|
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');
|
expect(str).toBe('24:00:00');
|
||||||
});
|
});
|
||||||
it('6824413:53:20', function() {
|
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');
|
expect(str).toBe('6824413:53:20');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import moment from 'moment';
|
|||||||
describe('rangeUtil', () => {
|
describe('rangeUtil', () => {
|
||||||
describe('Can get range grouped list of ranges', () => {
|
describe('Can get range grouped list of ranges', () => {
|
||||||
it('when custom settings should return default range list', () => {
|
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(_.keys(groups).length).toBe(4);
|
||||||
expect(groups[3][0].active).toBe(true);
|
expect(groups[3][0].active).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -13,62 +13,62 @@ describe('rangeUtil', () => {
|
|||||||
|
|
||||||
describe('Can get range text described', () => {
|
describe('Can get range text described', () => {
|
||||||
it('should handle simple old expression with only amount and unit', () => {
|
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');
|
expect(info.display).toBe('Last 5 minutes');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have singular when amount is 1', () => {
|
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');
|
expect(info.display).toBe('Last 1 hour');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle non default amount', () => {
|
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.display).toBe('Last 13 hours');
|
||||||
expect(info.from).toBe('now-13h');
|
expect(info.from).toBe('now-13h');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle non default future amount', () => {
|
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.display).toBe('Next 3 hours');
|
||||||
expect(info.from).toBe('now');
|
expect(info.from).toBe('now');
|
||||||
expect(info.to).toBe('now+3h');
|
expect(info.to).toBe('now+3h');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle now/d', () => {
|
it('should handle now/d', () => {
|
||||||
var info = rangeUtil.describeTextRange('now/d');
|
const info = rangeUtil.describeTextRange('now/d');
|
||||||
expect(info.display).toBe('Today so far');
|
expect(info.display).toBe('Today so far');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle now/w', () => {
|
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');
|
expect(info.display).toBe('This week so far');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle now/M', () => {
|
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');
|
expect(info.display).toBe('This month so far');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle now/y', () => {
|
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');
|
expect(info.display).toBe('This year so far');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Can get date range described', () => {
|
describe('Can get date range described', () => {
|
||||||
it('Date range with simple ranges', () => {
|
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');
|
expect(text).toBe('Last 1 hour');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with rounding ranges', () => {
|
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');
|
expect(text).toBe('now/d+6h to now');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with absolute 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]),
|
from: moment([2014, 10, 10, 2, 3, 4]),
|
||||||
to: 'now',
|
to: 'now',
|
||||||
});
|
});
|
||||||
@@ -76,7 +76,7 @@ describe('rangeUtil', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with absolute to relative', () => {
|
it('Date range with absolute to relative', () => {
|
||||||
var text = rangeUtil.describeTimeRange({
|
const text = rangeUtil.describeTimeRange({
|
||||||
from: moment([2014, 10, 10, 2, 3, 4]),
|
from: moment([2014, 10, 10, 2, 3, 4]),
|
||||||
to: 'now-1d',
|
to: 'now-1d',
|
||||||
});
|
});
|
||||||
@@ -84,7 +84,7 @@ describe('rangeUtil', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with relative to absolute', () => {
|
it('Date range with relative to absolute', () => {
|
||||||
var text = rangeUtil.describeTimeRange({
|
const text = rangeUtil.describeTimeRange({
|
||||||
from: 'now-7d',
|
from: 'now-7d',
|
||||||
to: moment([2014, 10, 10, 2, 3, 4]),
|
to: moment([2014, 10, 10, 2, 3, 4]),
|
||||||
});
|
});
|
||||||
@@ -92,17 +92,17 @@ describe('rangeUtil', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with non matching default ranges', () => {
|
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');
|
expect(text).toBe('Last 13 hours');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with from and to both are in now-* format', () => {
|
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');
|
expect(text).toBe('now-6h to now-3h');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with from and to both are either in now-* or now/* format', () => {
|
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',
|
from: 'now/d+6h',
|
||||||
to: 'now-3h',
|
to: 'now-3h',
|
||||||
});
|
});
|
||||||
@@ -110,7 +110,7 @@ describe('rangeUtil', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Date range with from and to both are either in now-* or now+* format', () => {
|
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');
|
expect(text).toBe('now-6h to now+1h');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import TableModel from 'app/core/table_model';
|
import TableModel from 'app/core/table_model';
|
||||||
|
|
||||||
describe('when sorting table desc', () => {
|
describe('when sorting table desc', () => {
|
||||||
var table;
|
let table;
|
||||||
var panel = {
|
const panel = {
|
||||||
sort: { col: 0, desc: true },
|
sort: { col: 0, desc: true },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ describe('when sorting table desc', () => {
|
|||||||
|
|
||||||
describe('when sorting table asc', () => {
|
describe('when sorting table asc', () => {
|
||||||
var table;
|
var table;
|
||||||
var panel = {
|
const panel = {
|
||||||
sort: { col: 1, desc: false },
|
sort: { col: 1, desc: false },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import TimeSeries from 'app/core/time_series2';
|
|||||||
import { updateLegendValues } from 'app/core/time_series2';
|
import { updateLegendValues } from 'app/core/time_series2';
|
||||||
|
|
||||||
describe('TimeSeries', function() {
|
describe('TimeSeries', function() {
|
||||||
var points, series;
|
let points, series;
|
||||||
var yAxisFormats = ['short', 'ms'];
|
const yAxisFormats = ['short', 'ms'];
|
||||||
var testData;
|
let testData;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
testData = {
|
testData = {
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
var waitSeconds = 100;
|
const waitSeconds = 100;
|
||||||
var head = document.getElementsByTagName('head')[0];
|
const head = document.getElementsByTagName('head')[0];
|
||||||
|
|
||||||
// get all link tags in the page
|
// get all link tags in the page
|
||||||
var links = document.getElementsByTagName('link');
|
const links = document.getElementsByTagName('link');
|
||||||
var linkHrefs = [];
|
const linkHrefs = [];
|
||||||
for (var i = 0; i < links.length; i++) {
|
for (let i = 0; i < links.length; i++) {
|
||||||
linkHrefs.push(links[i].href);
|
linkHrefs.push(links[i].href);
|
||||||
}
|
}
|
||||||
|
|
||||||
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
|
const isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
|
||||||
var webkitLoadCheck = function(link, callback) {
|
const webkitLoadCheck = function(link, callback) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||||
var sheet = document.styleSheets[i];
|
const sheet = document.styleSheets[i];
|
||||||
if (sheet.href === link.href) {
|
if (sheet.href === link.href) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
@@ -21,16 +21,16 @@ var webkitLoadCheck = function(link, callback) {
|
|||||||
}, 10);
|
}, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
var noop = function() {};
|
const noop = function() {};
|
||||||
|
|
||||||
var loadCSS = function(url) {
|
const loadCSS = function(url) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
var link = document.createElement('link');
|
const link = document.createElement('link');
|
||||||
var timeout = setTimeout(function() {
|
const timeout = setTimeout(function() {
|
||||||
reject('Unable to load CSS');
|
reject('Unable to load CSS');
|
||||||
}, waitSeconds * 1000);
|
}, waitSeconds * 1000);
|
||||||
|
|
||||||
var _callback = function(error) {
|
const _callback = function(error) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
link.onload = link.onerror = noop;
|
link.onload = link.onerror = noop;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|||||||
@@ -4,19 +4,19 @@
|
|||||||
export default function flatten(target, opts): any {
|
export default function flatten(target, opts): any {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
var delimiter = opts.delimiter || '.';
|
const delimiter = opts.delimiter || '.';
|
||||||
var maxDepth = opts.maxDepth || 3;
|
let maxDepth = opts.maxDepth || 3;
|
||||||
var currentDepth = 1;
|
let currentDepth = 1;
|
||||||
var output = {};
|
const output = {};
|
||||||
|
|
||||||
function step(object, prev) {
|
function step(object, prev) {
|
||||||
Object.keys(object).forEach(function(key) {
|
Object.keys(object).forEach(function(key) {
|
||||||
var value = object[key];
|
const value = object[key];
|
||||||
var isarray = opts.safe && Array.isArray(value);
|
const isarray = opts.safe && Array.isArray(value);
|
||||||
var type = Object.prototype.toString.call(value);
|
const type = Object.prototype.toString.call(value);
|
||||||
var isobject = type === '[object Object]';
|
const isobject = type === '[object Object]';
|
||||||
|
|
||||||
var newKey = prev ? prev + delimiter + key : key;
|
const newKey = prev ? prev + delimiter + key : key;
|
||||||
|
|
||||||
if (!opts.maxDepth) {
|
if (!opts.maxDepth) {
|
||||||
maxDepth = currentDepth + 1;
|
maxDepth = currentDepth + 1;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
var kbn: any = {};
|
const kbn: any = {};
|
||||||
|
|
||||||
kbn.valueFormats = {};
|
kbn.valueFormats = {};
|
||||||
|
|
||||||
@@ -103,27 +103,27 @@ kbn.round_interval = function(interval) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.secondsToHms = function(seconds) {
|
kbn.secondsToHms = function(seconds) {
|
||||||
var numyears = Math.floor(seconds / 31536000);
|
const numyears = Math.floor(seconds / 31536000);
|
||||||
if (numyears) {
|
if (numyears) {
|
||||||
return numyears + 'y';
|
return numyears + 'y';
|
||||||
}
|
}
|
||||||
var numdays = Math.floor((seconds % 31536000) / 86400);
|
const numdays = Math.floor((seconds % 31536000) / 86400);
|
||||||
if (numdays) {
|
if (numdays) {
|
||||||
return numdays + 'd';
|
return numdays + 'd';
|
||||||
}
|
}
|
||||||
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
|
const numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
|
||||||
if (numhours) {
|
if (numhours) {
|
||||||
return numhours + 'h';
|
return numhours + 'h';
|
||||||
}
|
}
|
||||||
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
|
const numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
|
||||||
if (numminutes) {
|
if (numminutes) {
|
||||||
return numminutes + 'm';
|
return numminutes + 'm';
|
||||||
}
|
}
|
||||||
var numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
|
const numseconds = Math.floor((((seconds % 31536000) % 86400) % 3600) % 60);
|
||||||
if (numseconds) {
|
if (numseconds) {
|
||||||
return numseconds + 's';
|
return numseconds + 's';
|
||||||
}
|
}
|
||||||
var nummilliseconds = Math.floor(seconds * 1000.0);
|
const nummilliseconds = Math.floor(seconds * 1000.0);
|
||||||
if (nummilliseconds) {
|
if (nummilliseconds) {
|
||||||
return nummilliseconds + 'ms';
|
return nummilliseconds + 'ms';
|
||||||
}
|
}
|
||||||
@@ -132,10 +132,10 @@ kbn.secondsToHms = function(seconds) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.secondsToHhmmss = function(seconds) {
|
kbn.secondsToHhmmss = function(seconds) {
|
||||||
var strings = [];
|
const strings = [];
|
||||||
var numhours = Math.floor(seconds / 3600);
|
const numhours = Math.floor(seconds / 3600);
|
||||||
var numminutes = Math.floor((seconds % 3600) / 60);
|
const numminutes = Math.floor((seconds % 3600) / 60);
|
||||||
var numseconds = Math.floor((seconds % 3600) % 60);
|
const numseconds = Math.floor((seconds % 3600) % 60);
|
||||||
numhours > 9 ? strings.push('' + numhours) : strings.push('0' + numhours);
|
numhours > 9 ? strings.push('' + numhours) : strings.push('0' + numhours);
|
||||||
numminutes > 9 ? strings.push('' + numminutes) : strings.push('0' + numminutes);
|
numminutes > 9 ? strings.push('' + numminutes) : strings.push('0' + numminutes);
|
||||||
numseconds > 9 ? strings.push('' + numseconds) : strings.push('0' + numseconds);
|
numseconds > 9 ? strings.push('' + numseconds) : strings.push('0' + numseconds);
|
||||||
@@ -191,7 +191,7 @@ kbn.calculateInterval = function(range, resolution, lowLimitInterval) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.describe_interval = function(str) {
|
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])) {
|
if (!matches || !_.has(kbn.intervals_in_seconds, matches[2])) {
|
||||||
throw new Error('Invalid interval string, expecting a number followed by one of "Mwdhmsy"');
|
throw new Error('Invalid interval string, expecting a number followed by one of "Mwdhmsy"');
|
||||||
} else {
|
} else {
|
||||||
@@ -204,12 +204,12 @@ kbn.describe_interval = function(str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.interval_to_ms = 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;
|
return info.sec * 1000 * info.count;
|
||||||
};
|
};
|
||||||
|
|
||||||
kbn.interval_to_seconds = function(str) {
|
kbn.interval_to_seconds = function(str) {
|
||||||
var info = kbn.describe_interval(str);
|
const info = kbn.describe_interval(str);
|
||||||
return info.sec * info.count;
|
return info.sec * info.count;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ kbn.stringToJsRegex = function(str) {
|
|||||||
return new RegExp('^' + 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]);
|
return new RegExp(match[1], match[2]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -242,8 +242,8 @@ kbn.toFixed = function(value, decimals) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
var factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
|
const factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
|
||||||
var formatted = String(Math.round(value * factor) / factor);
|
const formatted = String(Math.round(value * factor) / factor);
|
||||||
|
|
||||||
// if exponent return directly
|
// if exponent return directly
|
||||||
if (formatted.indexOf('e') !== -1 || value === 0) {
|
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
|
// If tickDecimals was specified, ensure that we have exactly that
|
||||||
// much precision; otherwise default to the value's own precision.
|
// much precision; otherwise default to the value's own precision.
|
||||||
if (decimals != null) {
|
if (decimals != null) {
|
||||||
var decimalPos = formatted.indexOf('.');
|
const decimalPos = formatted.indexOf('.');
|
||||||
var precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
|
const precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
|
||||||
if (precision < decimals) {
|
if (precision < decimals) {
|
||||||
return (precision ? formatted : formatted + '.') + String(factor).substr(1, decimals - precision);
|
return (precision ? formatted : formatted + '.') + String(factor).substr(1, decimals - precision);
|
||||||
}
|
}
|
||||||
@@ -275,8 +275,8 @@ kbn.roundValue = function(num, decimals) {
|
|||||||
if (num === null) {
|
if (num === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var n = Math.pow(10, decimals);
|
const n = Math.pow(10, decimals);
|
||||||
var formatted = (n * num).toFixed(decimals);
|
const formatted = (n * num).toFixed(decimals);
|
||||||
return Math.round(parseFloat(formatted)) / n;
|
return Math.round(parseFloat(formatted)) / n;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ kbn.formatBuilders.scaledUnits = function(factor, extArray) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var steps = 0;
|
var steps = 0;
|
||||||
var limit = extArray.length;
|
const limit = extArray.length;
|
||||||
|
|
||||||
while (Math.abs(size) >= factor) {
|
while (Math.abs(size) >= factor) {
|
||||||
steps++;
|
steps++;
|
||||||
@@ -330,7 +330,7 @@ kbn.formatBuilders.scaledUnits = function(factor, extArray) {
|
|||||||
kbn.formatBuilders.decimalSIPrefix = function(unit, offset) {
|
kbn.formatBuilders.decimalSIPrefix = function(unit, offset) {
|
||||||
var prefixes = ['n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
|
var prefixes = ['n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
|
||||||
prefixes = prefixes.slice(3 + (offset || 0));
|
prefixes = prefixes.slice(3 + (offset || 0));
|
||||||
var units = prefixes.map(function(p) {
|
const units = prefixes.map(function(p) {
|
||||||
return ' ' + p + unit;
|
return ' ' + p + unit;
|
||||||
});
|
});
|
||||||
return kbn.formatBuilders.scaledUnits(1000, units);
|
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 is given, it starts the units at the given prefix; otherwise, the
|
||||||
// offset defaults to zero and the initial unit is not prefixed.
|
// offset defaults to zero and the initial unit is not prefixed.
|
||||||
kbn.formatBuilders.binarySIPrefix = function(unit, offset) {
|
kbn.formatBuilders.binarySIPrefix = function(unit, offset) {
|
||||||
var prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset);
|
const prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'].slice(offset);
|
||||||
var units = prefixes.map(function(p) {
|
const units = prefixes.map(function(p) {
|
||||||
return ' ' + p + unit;
|
return ' ' + p + unit;
|
||||||
});
|
});
|
||||||
return kbn.formatBuilders.scaledUnits(1024, units);
|
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
|
// Currency formatter for prefixing a symbol onto a number. Supports scaling
|
||||||
// up to the trillions.
|
// up to the trillions.
|
||||||
kbn.formatBuilders.currency = function(symbol) {
|
kbn.formatBuilders.currency = function(symbol) {
|
||||||
var units = ['', 'K', 'M', 'B', 'T'];
|
const units = ['', 'K', 'M', 'B', 'T'];
|
||||||
var scaler = kbn.formatBuilders.scaledUnits(1000, units);
|
const scaler = kbn.formatBuilders.scaledUnits(1000, units);
|
||||||
return function(size, decimals, scaledDecimals) {
|
return function(size, decimals, scaledDecimals) {
|
||||||
if (size === null) {
|
if (size === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
var scaled = scaler(size, decimals, scaledDecimals);
|
const scaled = scaler(size, decimals, scaledDecimals);
|
||||||
return symbol + scaled;
|
return symbol + scaled;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
kbn.formatBuilders.simpleCountUnit = function(symbol) {
|
kbn.formatBuilders.simpleCountUnit = function(symbol) {
|
||||||
var units = ['', 'K', 'M', 'B', 'T'];
|
const units = ['', 'K', 'M', 'B', 'T'];
|
||||||
var scaler = kbn.formatBuilders.scaledUnits(1000, units);
|
const scaler = kbn.formatBuilders.scaledUnits(1000, units);
|
||||||
return function(size, decimals, scaledDecimals) {
|
return function(size, decimals, scaledDecimals) {
|
||||||
if (size === null) {
|
if (size === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
var scaled = scaler(size, decimals, scaledDecimals);
|
const scaled = scaler(size, decimals, scaledDecimals);
|
||||||
return scaled + ' ' + symbol;
|
return scaled + ' ' + symbol;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -420,7 +420,7 @@ kbn.valueFormats.hex0x = function(value, decimals) {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
var hexString = kbn.valueFormats.hex(value, decimals);
|
const hexString = kbn.valueFormats.hex(value, decimals);
|
||||||
if (hexString.substring(0, 1) === '-') {
|
if (hexString.substring(0, 1) === '-') {
|
||||||
return '-0x' + hexString.substring(1);
|
return '-0x' + hexString.substring(1);
|
||||||
}
|
}
|
||||||
@@ -769,7 +769,7 @@ kbn.toDuration = function(size, decimals, timeScale) {
|
|||||||
return kbn.toDuration(-size, decimals, timeScale) + ' ago';
|
return kbn.toDuration(-size, decimals, timeScale) + ' ago';
|
||||||
}
|
}
|
||||||
|
|
||||||
var units = [
|
const units = [
|
||||||
{ short: 'y', long: 'year' },
|
{ short: 'y', long: 'year' },
|
||||||
{ short: 'M', long: 'month' },
|
{ short: 'M', long: 'month' },
|
||||||
{ short: 'w', long: 'week' },
|
{ short: 'w', long: 'week' },
|
||||||
@@ -788,16 +788,16 @@ kbn.toDuration = function(size, decimals, timeScale) {
|
|||||||
}).short
|
}).short
|
||||||
] * 1000;
|
] * 1000;
|
||||||
|
|
||||||
var strings = [];
|
const strings = [];
|
||||||
// after first value >= 1 print only $decimals more
|
// after first value >= 1 print only $decimals more
|
||||||
var decrementDecimals = false;
|
var decrementDecimals = false;
|
||||||
for (var i = 0; i < units.length && decimals >= 0; i++) {
|
for (var i = 0; i < units.length && decimals >= 0; i++) {
|
||||||
var interval = kbn.intervals_in_seconds[units[i].short] * 1000;
|
const interval = kbn.intervals_in_seconds[units[i].short] * 1000;
|
||||||
var value = size / interval;
|
const value = size / interval;
|
||||||
if (value >= 1 || decrementDecimals) {
|
if (value >= 1 || decrementDecimals) {
|
||||||
decrementDecimals = true;
|
decrementDecimals = true;
|
||||||
var floor = Math.floor(value);
|
const floor = Math.floor(value);
|
||||||
var unit = units[i].long + (floor !== 1 ? 's' : '');
|
const unit = units[i].long + (floor !== 1 ? 's' : '');
|
||||||
strings.push(floor + ' ' + unit);
|
strings.push(floor + ' ' + unit);
|
||||||
size = size % interval;
|
size = size % interval;
|
||||||
decimals--;
|
decimals--;
|
||||||
@@ -824,7 +824,7 @@ kbn.valueFormats.timeticks = function(size, decimals, scaledDecimals) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) {
|
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')) {
|
if (moment().isSame(epoch, 'day')) {
|
||||||
return time.format('HH:mm:ss');
|
return time.format('HH:mm:ss');
|
||||||
@@ -833,7 +833,7 @@ kbn.valueFormats.dateTimeAsIso = function(epoch, isUtc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.valueFormats.dateTimeAsUS = 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')) {
|
if (moment().isSame(epoch, 'day')) {
|
||||||
return time.format('h:mm:ss a');
|
return time.format('h:mm:ss a');
|
||||||
@@ -842,7 +842,7 @@ kbn.valueFormats.dateTimeAsUS = function(epoch, isUtc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
kbn.valueFormats.dateTimeFromNow = 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();
|
return time.fromNow();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import _ from 'lodash';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import * as dateMath from './datemath';
|
import * as dateMath from './datemath';
|
||||||
|
|
||||||
var spans = {
|
const spans = {
|
||||||
s: { display: 'second' },
|
s: { display: 'second' },
|
||||||
m: { display: 'minute' },
|
m: { display: 'minute' },
|
||||||
h: { display: 'hour' },
|
h: { display: 'hour' },
|
||||||
@@ -12,7 +12,7 @@ var spans = {
|
|||||||
y: { display: 'year' },
|
y: { display: 'year' },
|
||||||
};
|
};
|
||||||
|
|
||||||
var rangeOptions = [
|
const rangeOptions = [
|
||||||
{ from: 'now/d', to: 'now/d', display: 'Today', section: 2 },
|
{ from: 'now/d', to: 'now/d', display: 'Today', section: 2 },
|
||||||
{ from: 'now/d', to: 'now', display: 'Today so far', section: 2 },
|
{ from: 'now/d', to: 'now', display: 'Today so far', section: 2 },
|
||||||
{ from: 'now/w', to: 'now/w', display: 'This week', 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 },
|
{ 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) {
|
_.each(rangeOptions, function(frame) {
|
||||||
rangeIndex[frame.from + ' to ' + frame.to] = frame;
|
rangeIndex[frame.from + ' to ' + frame.to] = frame;
|
||||||
});
|
});
|
||||||
|
|
||||||
export function getRelativeTimesList(timepickerSettings, currentDisplay) {
|
export function getRelativeTimesList(timepickerSettings, currentDisplay) {
|
||||||
var groups = _.groupBy(rangeOptions, (option: any) => {
|
const groups = _.groupBy(rangeOptions, (option: any) => {
|
||||||
option.active = option.display === currentDisplay;
|
option.active = option.display === currentDisplay;
|
||||||
return option.section;
|
return option.section;
|
||||||
});
|
});
|
||||||
@@ -130,7 +130,7 @@ export function describeTextRange(expr: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function describeTimeRange(range) {
|
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) {
|
if (option) {
|
||||||
return option.display;
|
return option.display;
|
||||||
}
|
}
|
||||||
@@ -140,17 +140,17 @@ export function describeTimeRange(range) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (moment.isMoment(range.from)) {
|
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();
|
return formatDate(range.from) + ' to ' + toMoment.fromNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moment.isMoment(range.to)) {
|
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);
|
return from.fromNow() + ' to ' + formatDate(range.to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range.to.toString() === 'now') {
|
if (range.to.toString() === 'now') {
|
||||||
var res = describeTextRange(range.from);
|
const res = describeTextRange(range.from);
|
||||||
return res.display;
|
return res.display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export class DashboardCtrl implements PanelContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showJsonEditor(evt, options) {
|
showJsonEditor(evt, options) {
|
||||||
var editScope = this.$rootScope.$new();
|
const editScope = this.$rootScope.$new();
|
||||||
editScope.object = options.object;
|
editScope.object = options.object;
|
||||||
editScope.updateHandler = options.updateHandler;
|
editScope.updateHandler = options.updateHandler;
|
||||||
this.$scope.appEvent('show-dash-editor', {
|
this.$scope.appEvent('show-dash-editor', {
|
||||||
@@ -137,7 +137,7 @@ export class DashboardCtrl implements PanelContainer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var panelInfo = this.dashboard.getPanelInfoById(options.panelId);
|
const panelInfo = this.dashboard.getPanelInfoById(options.panelId);
|
||||||
this.removePanel(panelInfo.panel, true);
|
this.removePanel(panelInfo.panel, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export class DashboardLoaderSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_loadScriptedDashboard(file) {
|
_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' })
|
return this.$http({ url: url, method: 'GET' })
|
||||||
.then(this._executeScript.bind(this))
|
.then(this._executeScript.bind(this))
|
||||||
@@ -99,14 +99,14 @@ export class DashboardLoaderSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_executeScript(result) {
|
_executeScript(result) {
|
||||||
var services = {
|
const services = {
|
||||||
dashboardSrv: this.dashboardSrv,
|
dashboardSrv: this.dashboardSrv,
|
||||||
datasourceSrv: this.datasourceSrv,
|
datasourceSrv: this.datasourceSrv,
|
||||||
$q: this.$q,
|
$q: this.$q,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*jshint -W054 */
|
/*jshint -W054 */
|
||||||
var script_func = new Function(
|
const script_func = new Function(
|
||||||
'ARGS',
|
'ARGS',
|
||||||
'kbn',
|
'kbn',
|
||||||
'dateMath',
|
'dateMath',
|
||||||
@@ -119,11 +119,11 @@ export class DashboardLoaderSrv {
|
|||||||
'services',
|
'services',
|
||||||
result.data
|
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
|
// Handle async dashboard scripts
|
||||||
if (_.isFunction(script_result)) {
|
if (_.isFunction(script_result)) {
|
||||||
var deferred = this.$q.defer();
|
const deferred = this.$q.defer();
|
||||||
script_result(dashboard => {
|
script_result(dashboard => {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
deferred.resolve({ data: dashboard });
|
deferred.resolve({ data: dashboard });
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ export class PanelLoader {
|
|||||||
constructor(private $compile, private $rootScope) {}
|
constructor(private $compile, private $rootScope) {}
|
||||||
|
|
||||||
load(elem, panel, dashboard): AttachedPanel {
|
load(elem, panel, dashboard): AttachedPanel {
|
||||||
var template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
|
const template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
|
||||||
var panelScope = this.$rootScope.$new();
|
const panelScope = this.$rootScope.$new();
|
||||||
panelScope.panel = panel;
|
panelScope.panel = panel;
|
||||||
panelScope.dashboard = dashboard;
|
panelScope.dashboard = dashboard;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class DashNavCtrl {
|
|||||||
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
|
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
|
||||||
|
|
||||||
if (this.dashboard.meta.isSnapshot) {
|
if (this.dashboard.meta.isSnapshot) {
|
||||||
var meta = this.dashboard.meta;
|
const meta = this.dashboard.meta;
|
||||||
this.titleTooltip = 'Created: ' + moment(meta.created).calendar();
|
this.titleTooltip = 'Created: ' + moment(meta.created).calendar();
|
||||||
if (meta.expires) {
|
if (meta.expires) {
|
||||||
this.titleTooltip += '<br>Expires: ' + moment(meta.expires).fromNow() + '<br>';
|
this.titleTooltip += '<br>Expires: ' + moment(meta.expires).fromNow() + '<br>';
|
||||||
@@ -49,7 +49,7 @@ export class DashNavCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shareDashboard(tabIndex) {
|
shareDashboard(tabIndex) {
|
||||||
var modalScope = this.$scope.$new();
|
const modalScope = this.$scope.$new();
|
||||||
modalScope.tabIndex = tabIndex;
|
modalScope.tabIndex = tabIndex;
|
||||||
modalScope.dashboard = this.dashboard;
|
modalScope.dashboard = this.dashboard;
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class SaveDashboardAsModalCtrl {
|
|||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private dashboardSrv) {
|
constructor(private dashboardSrv) {
|
||||||
var dashboard = this.dashboardSrv.getCurrent();
|
const dashboard = this.dashboardSrv.getCurrent();
|
||||||
this.clone = dashboard.getSaveModelClone();
|
this.clone = dashboard.getSaveModelClone();
|
||||||
this.clone.id = null;
|
this.clone.id = null;
|
||||||
this.clone.uid = '';
|
this.clone.uid = '';
|
||||||
|
|||||||
@@ -94,14 +94,14 @@ export class SaveDashboardModalCtrl {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
saveVariables: this.saveVariables,
|
saveVariables: this.saveVariables,
|
||||||
saveTimerange: this.saveTimerange,
|
saveTimerange: this.saveTimerange,
|
||||||
message: this.message,
|
message: this.message,
|
||||||
};
|
};
|
||||||
|
|
||||||
var dashboard = this.dashboardSrv.getCurrent();
|
const dashboard = this.dashboardSrv.getCurrent();
|
||||||
var saveModel = dashboard.getSaveModelClone(options);
|
const saveModel = dashboard.getSaveModelClone(options);
|
||||||
|
|
||||||
this.isSaving = true;
|
this.isSaving = true;
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class SaveProvisionedDashboardModalCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
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',
|
type: 'application/json;charset=utf-8',
|
||||||
});
|
});
|
||||||
saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
|
saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
|
||||||
|
|||||||
@@ -36,15 +36,15 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv,
|
|||||||
|
|
||||||
$scope.buildUrl = function() {
|
$scope.buildUrl = function() {
|
||||||
var baseUrl = $location.absUrl();
|
var baseUrl = $location.absUrl();
|
||||||
var queryStart = baseUrl.indexOf('?');
|
const queryStart = baseUrl.indexOf('?');
|
||||||
|
|
||||||
if (queryStart !== -1) {
|
if (queryStart !== -1) {
|
||||||
baseUrl = baseUrl.substring(0, queryStart);
|
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.from = range.from.valueOf();
|
||||||
params.to = range.to.valueOf();
|
params.to = range.to.valueOf();
|
||||||
params.orgId = config.bootData.user.orgId;
|
params.orgId = config.bootData.user.orgId;
|
||||||
|
|||||||
@@ -55,16 +55,16 @@ export class ShareSnapshotCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.saveSnapshot = function(external) {
|
$scope.saveSnapshot = function(external) {
|
||||||
var dash = $scope.dashboard.getSaveModelClone();
|
const dash = $scope.dashboard.getSaveModelClone();
|
||||||
$scope.scrubDashboard(dash);
|
$scope.scrubDashboard(dash);
|
||||||
|
|
||||||
var cmdData = {
|
const cmdData = {
|
||||||
dashboard: dash,
|
dashboard: dash,
|
||||||
name: dash.title,
|
name: dash.title,
|
||||||
expires: $scope.snapshot.expires,
|
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(
|
backendSrv.post(postUrl, cmdData).then(
|
||||||
function(results) {
|
function(results) {
|
||||||
@@ -75,8 +75,8 @@ export class ShareSnapshotCtrl {
|
|||||||
$scope.snapshotUrl = results.url;
|
$scope.snapshotUrl = results.url;
|
||||||
$scope.saveExternalSnapshotRef(cmdData, results);
|
$scope.saveExternalSnapshotRef(cmdData, results);
|
||||||
} else {
|
} else {
|
||||||
var url = $location.url();
|
const url = $location.url();
|
||||||
var baseUrl = $location.absUrl();
|
let baseUrl = $location.absUrl();
|
||||||
|
|
||||||
if (url !== '/') {
|
if (url !== '/') {
|
||||||
baseUrl = baseUrl.replace(url, '') + '/';
|
baseUrl = baseUrl.replace(url, '') + '/';
|
||||||
@@ -139,7 +139,7 @@ export class ShareSnapshotCtrl {
|
|||||||
|
|
||||||
// snapshot single panel
|
// snapshot single panel
|
||||||
if ($scope.modeSharePanel) {
|
if ($scope.modeSharePanel) {
|
||||||
var singlePanel = $scope.panel.getSaveModel();
|
const singlePanel = $scope.panel.getSaveModel();
|
||||||
singlePanel.gridPos.w = 24;
|
singlePanel.gridPos.w = 24;
|
||||||
singlePanel.gridPos.x = 0;
|
singlePanel.gridPos.x = 0;
|
||||||
singlePanel.gridPos.y = 0;
|
singlePanel.gridPos.y = 0;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class SubmenuCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openEditView(editview) {
|
openEditView(editview) {
|
||||||
var search = _.extend(this.$location.search(), { editview: editview });
|
const search = _.extend(this.$location.search(), { editview: editview });
|
||||||
this.$location.search(search);
|
this.$location.search(search);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ export class DashboardViewState {
|
|||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, private $location, private $timeout, private $rootScope) {
|
constructor($scope, private $location, private $timeout, private $rootScope) {
|
||||||
var self = this;
|
const self = this;
|
||||||
self.state = {};
|
self.state = {};
|
||||||
self.panelScopes = [];
|
self.panelScopes = [];
|
||||||
self.$scope = $scope;
|
self.$scope = $scope;
|
||||||
self.dashboard = $scope.dashboard;
|
self.dashboard = $scope.dashboard;
|
||||||
|
|
||||||
$scope.onAppEvent('$routeUpdate', function() {
|
$scope.onAppEvent('$routeUpdate', function() {
|
||||||
var urlState = self.getQueryStringState();
|
const urlState = self.getQueryStringState();
|
||||||
if (self.needsSync(urlState)) {
|
if (self.needsSync(urlState)) {
|
||||||
self.update(urlState, true);
|
self.update(urlState, true);
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ export class DashboardViewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getQueryStringState() {
|
getQueryStringState() {
|
||||||
var state = this.$location.search();
|
const state = this.$location.search();
|
||||||
state.panelId = parseInt(state.panelId) || null;
|
state.panelId = parseInt(state.panelId) || null;
|
||||||
state.fullscreen = state.fullscreen ? true : null;
|
state.fullscreen = state.fullscreen ? true : null;
|
||||||
state.edit = state.edit === 'true' || state.edit === true || null;
|
state.edit = state.edit === 'true' || state.edit === true || null;
|
||||||
@@ -58,7 +58,7 @@ export class DashboardViewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serializeToUrl() {
|
serializeToUrl() {
|
||||||
var urlState = _.clone(this.state);
|
const urlState = _.clone(this.state);
|
||||||
urlState.fullscreen = this.state.fullscreen ? true : null;
|
urlState.fullscreen = this.state.fullscreen ? true : null;
|
||||||
urlState.edit = this.state.edit ? true : null;
|
urlState.edit = this.state.edit ? true : null;
|
||||||
return urlState;
|
return urlState;
|
||||||
@@ -129,7 +129,7 @@ export class DashboardViewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.dashboard.meta.fullscreen) {
|
if (this.dashboard.meta.fullscreen) {
|
||||||
var panelScope = this.getPanelScope(this.state.panelId);
|
const panelScope = this.getPanelScope(this.state.panelId);
|
||||||
if (!panelScope) {
|
if (!panelScope) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -162,8 +162,8 @@ export class DashboardViewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
leaveFullscreen(render) {
|
leaveFullscreen(render) {
|
||||||
var self = this;
|
const self = this;
|
||||||
var ctrl = self.fullscreenPanel.ctrl;
|
const ctrl = self.fullscreenPanel.ctrl;
|
||||||
|
|
||||||
ctrl.editMode = false;
|
ctrl.editMode = false;
|
||||||
ctrl.fullscreen = false;
|
ctrl.fullscreen = false;
|
||||||
@@ -188,7 +188,7 @@ export class DashboardViewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enterFullscreen(panelScope) {
|
enterFullscreen(panelScope) {
|
||||||
var ctrl = panelScope.ctrl;
|
const ctrl = panelScope.ctrl;
|
||||||
|
|
||||||
ctrl.editMode = this.state.edit && this.dashboard.meta.canEdit;
|
ctrl.editMode = this.state.edit && this.dashboard.meta.canEdit;
|
||||||
ctrl.fullscreen = true;
|
ctrl.fullscreen = true;
|
||||||
@@ -203,7 +203,7 @@ export class DashboardViewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerPanel(panelScope) {
|
registerPanel(panelScope) {
|
||||||
var self = this;
|
const self = this;
|
||||||
self.panelScopes.push(panelScope);
|
self.panelScopes.push(panelScope);
|
||||||
|
|
||||||
if (!self.dashboard.meta.soloMode) {
|
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);
|
self.panelScopes = _.without(self.panelScopes, panelScope);
|
||||||
unbind();
|
unbind();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function dashLink($compile, $sanitize, linkSrv) {
|
|||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
link: function(scope, elem) {
|
link: function(scope, elem) {
|
||||||
var link = scope.link;
|
const link = scope.link;
|
||||||
var template =
|
var template =
|
||||||
'<div class="gf-form">' +
|
'<div class="gf-form">' +
|
||||||
'<a class="pointer gf-form-label" data-placement="bottom"' +
|
'<a class="pointer gf-form-label" data-placement="bottom"' +
|
||||||
@@ -42,7 +42,7 @@ function dashLink($compile, $sanitize, linkSrv) {
|
|||||||
$compile(elem.contents())(scope);
|
$compile(elem.contents())(scope);
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
var linkInfo = linkSrv.getAnchorInfo(link);
|
const linkInfo = linkSrv.getAnchorInfo(link);
|
||||||
|
|
||||||
const anchor = elem.find('a');
|
const anchor = elem.find('a');
|
||||||
const span = elem.find('span');
|
const span = elem.find('span');
|
||||||
@@ -84,7 +84,7 @@ function dashLink($compile, $sanitize, linkSrv) {
|
|||||||
export class DashLinksContainerCtrl {
|
export class DashLinksContainerCtrl {
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $rootScope, $q, backendSrv, dashboardSrv, linkSrv) {
|
constructor($scope, $rootScope, $q, backendSrv, dashboardSrv, linkSrv) {
|
||||||
var currentDashId = dashboardSrv.getCurrent().id;
|
const currentDashId = dashboardSrv.getCurrent().id;
|
||||||
|
|
||||||
function buildLinks(linkDef) {
|
function buildLinks(linkDef) {
|
||||||
if (linkDef.type === 'dashboards') {
|
if (linkDef.type === 'dashboards') {
|
||||||
@@ -128,7 +128,7 @@ export class DashLinksContainerCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateDashLinks() {
|
function updateDashLinks() {
|
||||||
var promises = _.map($scope.links, buildLinks);
|
const promises = _.map($scope.links, buildLinks);
|
||||||
|
|
||||||
$q.all(promises).then(function(results) {
|
$q.all(promises).then(function(results) {
|
||||||
$scope.generatedLinks = _.flatten(results);
|
$scope.generatedLinks = _.flatten(results);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class PanelLinksEditorCtrl {
|
|||||||
|
|
||||||
$scope.searchDashboards = function(queryStr, callback) {
|
$scope.searchDashboards = function(queryStr, callback) {
|
||||||
backendSrv.search({ query: queryStr }).then(function(hits) {
|
backendSrv.search({ query: queryStr }).then(function(hits) {
|
||||||
var dashboards = _.map(hits, function(dash) {
|
const dashboards = _.map(hits, function(dash) {
|
||||||
return dash.title;
|
return dash.title;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ export class PanelLinksEditorCtrl {
|
|||||||
|
|
||||||
$scope.dashboardChanged = function(link) {
|
$scope.dashboardChanged = function(link) {
|
||||||
backendSrv.search({ query: link.dashboard }).then(function(hits) {
|
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) {
|
||||||
if (dashboard.url) {
|
if (dashboard.url) {
|
||||||
link.url = dashboard.url;
|
link.url = dashboard.url;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { store } from 'app/stores/store';
|
|||||||
|
|
||||||
var datasourceTypes = [];
|
var datasourceTypes = [];
|
||||||
|
|
||||||
var defaults = {
|
const defaults = {
|
||||||
name: '',
|
name: '',
|
||||||
type: 'graphite',
|
type: 'graphite',
|
||||||
url: '',
|
url: '',
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export class DashImportListCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import(dash, overwrite) {
|
import(dash, overwrite) {
|
||||||
var installCmd = {
|
const installCmd = {
|
||||||
pluginId: this.plugin.id,
|
pluginId: this.plugin.id,
|
||||||
path: dash.path,
|
path: dash.path,
|
||||||
overwrite: overwrite,
|
overwrite: overwrite,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|||||||
if (component.template) {
|
if (component.template) {
|
||||||
return $q.when(component.template);
|
return $q.when(component.template);
|
||||||
}
|
}
|
||||||
var cached = $templateCache.get(component.templateUrl);
|
const cached = $templateCache.get(component.templateUrl);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
return $q.when(cached);
|
return $q.when(cached);
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadPanelComponentInfo(scope, attrs) {
|
function loadPanelComponentInfo(scope, attrs) {
|
||||||
var componentInfo: any = {
|
const componentInfo: any = {
|
||||||
name: 'panel-plugin-' + scope.panel.type,
|
name: 'panel-plugin-' + scope.panel.type,
|
||||||
bindings: { dashboard: '=', panel: '=', row: '=' },
|
bindings: { dashboard: '=', panel: '=', row: '=' },
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -143,7 +143,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|||||||
}
|
}
|
||||||
// Datasource ConfigCtrl
|
// Datasource ConfigCtrl
|
||||||
case 'datasource-config-ctrl': {
|
case 'datasource-config-ctrl': {
|
||||||
var dsMeta = scope.ctrl.datasourceMeta;
|
const dsMeta = scope.ctrl.datasourceMeta;
|
||||||
return importPluginModule(dsMeta.module).then(function(dsModule): any {
|
return importPluginModule(dsMeta.module).then(function(dsModule): any {
|
||||||
if (!dsModule.ConfigCtrl) {
|
if (!dsModule.ConfigCtrl) {
|
||||||
return { notFound: true };
|
return { notFound: true };
|
||||||
@@ -197,7 +197,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
function appendAndCompile(scope, elem, componentInfo) {
|
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) => {
|
_.each(componentInfo.attrs, (value, key) => {
|
||||||
child.attr(key, value);
|
child.attr(key, value);
|
||||||
});
|
});
|
||||||
@@ -228,8 +228,8 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!componentInfo.Component.registered) {
|
if (!componentInfo.Component.registered) {
|
||||||
var directiveName = attrs.$normalize(componentInfo.name);
|
const directiveName = attrs.$normalize(componentInfo.name);
|
||||||
var directiveFn = getPluginComponentDirective(componentInfo);
|
const directiveFn = getPluginComponentDirective(componentInfo);
|
||||||
coreModule.directive(directiveName, directiveFn);
|
coreModule.directive(directiveName, directiveFn);
|
||||||
componentInfo.Component.registered = true;
|
componentInfo.Component.registered = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export class PluginEditCtrl {
|
|||||||
|
|
||||||
initReadme() {
|
initReadme() {
|
||||||
return this.backendSrv.get(`/api/plugins/${this.pluginId}/markdown/readme`).then(res => {
|
return this.backendSrv.get(`/api/plugins/${this.pluginId}/markdown/readme`).then(res => {
|
||||||
var md = new Remarkable({
|
const md = new Remarkable({
|
||||||
linkify: true,
|
linkify: true,
|
||||||
});
|
});
|
||||||
this.readmeHtml = this.$sce.trustAsHtml(md.render(res));
|
this.readmeHtml = this.$sce.trustAsHtml(md.render(res));
|
||||||
@@ -124,7 +124,7 @@ export class PluginEditCtrl {
|
|||||||
update() {
|
update() {
|
||||||
this.preUpdateHook()
|
this.preUpdateHook()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var updateCmd = _.extend(
|
const updateCmd = _.extend(
|
||||||
{
|
{
|
||||||
enabled: this.model.enabled,
|
enabled: this.model.enabled,
|
||||||
pinned: this.model.pinned,
|
pinned: this.model.pinned,
|
||||||
@@ -154,7 +154,7 @@ export class PluginEditCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateAvailable() {
|
updateAvailable() {
|
||||||
var modalScope = this.$scope.$new(true);
|
const modalScope = this.$scope.$new(true);
|
||||||
modalScope.plugin = this.model;
|
modalScope.plugin = this.model;
|
||||||
|
|
||||||
this.$rootScope.appEvent('show-modal', {
|
this.$rootScope.appEvent('show-modal', {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
var pluginInfoCache = {};
|
const pluginInfoCache = {};
|
||||||
|
|
||||||
export class AppPageCtrl {
|
export class AppPageCtrl {
|
||||||
page: any;
|
page: any;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class AdhocVariable implements Variable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.filters = urlValue.map(item => {
|
this.filters = urlValue.map(item => {
|
||||||
var values = item.split('|').map(value => {
|
const values = item.split('|').map(value => {
|
||||||
return this.unescapeDelimiter(value);
|
return this.unescapeDelimiter(value);
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ export class DatasourceVariable implements Variable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateOptions() {
|
updateOptions() {
|
||||||
var options = [];
|
const options = [];
|
||||||
var sources = this.datasourceSrv.getMetricSources({ skipVariables: true });
|
const sources = this.datasourceSrv.getMetricSources({ skipVariables: true });
|
||||||
var regex;
|
var regex;
|
||||||
|
|
||||||
if (this.regex) {
|
if (this.regex) {
|
||||||
@@ -51,7 +51,7 @@ export class DatasourceVariable implements Variable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < sources.length; i++) {
|
for (var i = 0; i < sources.length; i++) {
|
||||||
var source = sources[i];
|
const source = sources[i];
|
||||||
// must match on type
|
// must match on type
|
||||||
if (source.meta.id !== this.query) {
|
if (source.meta.id !== this.query) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export class VariableEditorCtrl {
|
|||||||
return false;
|
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) {
|
if (sameName && sameName !== $scope.current) {
|
||||||
appEvents.emit('alert-warning', ['Validation', 'Variable with the same name already exists']);
|
appEvents.emit('alert-warning', ['Validation', 'Variable with the same name already exists']);
|
||||||
return false;
|
return false;
|
||||||
@@ -114,7 +114,7 @@ export class VariableEditorCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.duplicate = function(variable) {
|
$scope.duplicate = function(variable) {
|
||||||
var clone = _.cloneDeep(variable.getSaveModel());
|
const clone = _.cloneDeep(variable.getSaveModel());
|
||||||
$scope.current = variableSrv.createVariableFromModel(clone);
|
$scope.current = variableSrv.createVariableFromModel(clone);
|
||||||
$scope.current.name = 'copy_of_' + variable.name;
|
$scope.current.name = 'copy_of_' + variable.name;
|
||||||
variableSrv.addVariable($scope.current);
|
variableSrv.addVariable($scope.current);
|
||||||
@@ -148,7 +148,7 @@ export class VariableEditorCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.typeChanged = function() {
|
$scope.typeChanged = function() {
|
||||||
var old = $scope.current;
|
const old = $scope.current;
|
||||||
$scope.current = variableSrv.createVariableFromModel({
|
$scope.current = variableSrv.createVariableFromModel({
|
||||||
type: $scope.current.type,
|
type: $scope.current.type,
|
||||||
});
|
});
|
||||||
@@ -156,7 +156,7 @@ export class VariableEditorCtrl {
|
|||||||
$scope.current.hide = old.hide;
|
$scope.current.hide = old.hide;
|
||||||
$scope.current.label = old.label;
|
$scope.current.label = old.label;
|
||||||
|
|
||||||
var oldIndex = _.indexOf(this.variables, old);
|
const oldIndex = _.indexOf(this.variables, old);
|
||||||
if (oldIndex !== -1) {
|
if (oldIndex !== -1) {
|
||||||
this.variables[oldIndex] = $scope.current;
|
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);
|
this.templateSrv.setGrafanaVariable('$__auto_interval_' + this.name, res.interval);
|
||||||
// for backward compatibility, to be removed eventually
|
// for backward compatibility, to be removed eventually
|
||||||
this.templateSrv.setGrafanaVariable('$__auto_interval', res.interval);
|
this.templateSrv.setGrafanaVariable('$__auto_interval', res.interval);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export class QueryVariable implements Variable {
|
|||||||
|
|
||||||
getValuesForTag(tagKey) {
|
getValuesForTag(tagKey) {
|
||||||
return this.datasourceSrv.get(this.datasource).then(datasource => {
|
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 this.metricFindQuery(datasource, query).then(function(results) {
|
||||||
return _.map(results, function(value) {
|
return _.map(results, function(value) {
|
||||||
return value.text;
|
return value.text;
|
||||||
@@ -128,7 +128,7 @@ export class QueryVariable implements Variable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metricFindQuery(datasource, query) {
|
metricFindQuery(datasource, query) {
|
||||||
var options = { range: undefined, variable: this };
|
const options = { range: undefined, variable: this };
|
||||||
|
|
||||||
if (this.refresh === 2) {
|
if (this.refresh === 2) {
|
||||||
options.range = this.timeSrv.timeRange();
|
options.range = this.timeSrv.timeRange();
|
||||||
@@ -149,7 +149,7 @@ export class QueryVariable implements Variable {
|
|||||||
regex = kbn.stringToJsRegex(this.templateSrv.replace(this.regex, {}, 'regex'));
|
regex = kbn.stringToJsRegex(this.templateSrv.replace(this.regex, {}, 'regex'));
|
||||||
}
|
}
|
||||||
for (i = 0; i < metricNames.length; i++) {
|
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 text = item.text === undefined || item.text === null ? item.value : item.text;
|
||||||
|
|
||||||
var value = item.value === undefined || item.value === null ? item.text : item.value;
|
var value = item.value === undefined || item.value === null ? item.text : item.value;
|
||||||
@@ -185,14 +185,14 @@ export class QueryVariable implements Variable {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sortType = Math.ceil(sortOrder / 2);
|
const sortType = Math.ceil(sortOrder / 2);
|
||||||
var reverseSort = sortOrder % 2 === 0;
|
const reverseSort = sortOrder % 2 === 0;
|
||||||
|
|
||||||
if (sortType === 1) {
|
if (sortType === 1) {
|
||||||
options = _.sortBy(options, 'text');
|
options = _.sortBy(options, 'text');
|
||||||
} else if (sortType === 2) {
|
} else if (sortType === 2) {
|
||||||
options = _.sortBy(options, opt => {
|
options = _.sortBy(options, opt => {
|
||||||
var matches = opt.text.match(/.*?(\d+).*/);
|
const matches = opt.text.match(/.*?(\d+).*/);
|
||||||
if (!matches || matches.length < 2) {
|
if (!matches || matches.length < 2) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class TemplateSrv {
|
|||||||
this.index = {};
|
this.index = {};
|
||||||
|
|
||||||
for (var i = 0; i < this.variables.length; i++) {
|
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)) {
|
if (!variable.current || (!variable.current.isNone && !variable.current.value)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -51,7 +51,7 @@ export class TemplateSrv {
|
|||||||
var filters = [];
|
var filters = [];
|
||||||
|
|
||||||
for (var i = 0; i < this.variables.length; i++) {
|
for (var i = 0; i < this.variables.length; i++) {
|
||||||
var variable = this.variables[i];
|
const variable = this.variables[i];
|
||||||
if (variable.type !== 'adhoc') {
|
if (variable.type !== 'adhoc') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ export class TemplateSrv {
|
|||||||
if (value instanceof Array && value.length === 0) {
|
if (value instanceof Array && value.length === 0) {
|
||||||
return '__empty__';
|
return '__empty__';
|
||||||
}
|
}
|
||||||
var quotedValues = _.map(value, function(val) {
|
const quotedValues = _.map(value, function(val) {
|
||||||
return '"' + luceneEscape(val) + '"';
|
return '"' + luceneEscape(val) + '"';
|
||||||
});
|
});
|
||||||
return '(' + quotedValues.join(' OR ') + ')';
|
return '(' + quotedValues.join(' OR ') + ')';
|
||||||
@@ -97,7 +97,7 @@ export class TemplateSrv {
|
|||||||
return kbn.regexEscape(value);
|
return kbn.regexEscape(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var escapedValues = _.map(value, kbn.regexEscape);
|
const escapedValues = _.map(value, kbn.regexEscape);
|
||||||
if (escapedValues.length === 1) {
|
if (escapedValues.length === 1) {
|
||||||
return escapedValues[0];
|
return escapedValues[0];
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ export class TemplateSrv {
|
|||||||
|
|
||||||
getVariableName(expression) {
|
getVariableName(expression) {
|
||||||
this.regex.lastIndex = 0;
|
this.regex.lastIndex = 0;
|
||||||
var match = this.regex.exec(expression);
|
const match = this.regex.exec(expression);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ export class TemplateSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
variableExists(expression) {
|
variableExists(expression) {
|
||||||
var name = this.getVariableName(expression);
|
const name = this.getVariableName(expression);
|
||||||
return name && this.index[name] !== void 0;
|
return name && this.index[name] !== void 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ export class TemplateSrv {
|
|||||||
if (variable.allValue) {
|
if (variable.allValue) {
|
||||||
return variable.allValue;
|
return variable.allValue;
|
||||||
}
|
}
|
||||||
var values = [];
|
const values = [];
|
||||||
for (var i = 1; i < variable.options.length; i++) {
|
for (var i = 1; i < variable.options.length; i++) {
|
||||||
values.push(variable.options[i].value);
|
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;
|
return res;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ export class TemplateSrv {
|
|||||||
|
|
||||||
return target.replace(this.regex, (match, var1, var2, fmt2, var3) => {
|
return target.replace(this.regex, (match, var1, var2, fmt2, var3) => {
|
||||||
if (scopedVars) {
|
if (scopedVars) {
|
||||||
var option = scopedVars[var1 || var2 || var3];
|
const option = scopedVars[var1 || var2 || var3];
|
||||||
if (option) {
|
if (option) {
|
||||||
return option.text;
|
return option.text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class VariableSrv {
|
|||||||
variable.initLock = this.$q.defer();
|
variable.initLock = this.$q.defer();
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryParams = this.$location.search();
|
const queryParams = this.$location.search();
|
||||||
return this.$q
|
return this.$q
|
||||||
.all(
|
.all(
|
||||||
this.variables.map(variable => {
|
this.variables.map(variable => {
|
||||||
@@ -44,8 +44,8 @@ export class VariableSrv {
|
|||||||
return Promise.resolve({});
|
return Promise.resolve({});
|
||||||
}
|
}
|
||||||
|
|
||||||
var promises = this.variables.filter(variable => variable.refresh === 2).map(variable => {
|
const promises = this.variables.filter(variable => variable.refresh === 2).map(variable => {
|
||||||
var previousOptions = variable.options.slice();
|
const previousOptions = variable.options.slice();
|
||||||
|
|
||||||
return variable.updateOptions().then(() => {
|
return variable.updateOptions().then(() => {
|
||||||
if (angular.toJson(previousOptions) !== angular.toJson(variable.options)) {
|
if (angular.toJson(previousOptions) !== angular.toJson(variable.options)) {
|
||||||
@@ -58,7 +58,7 @@ export class VariableSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processVariable(variable, queryParams) {
|
processVariable(variable, queryParams) {
|
||||||
var dependencies = [];
|
const dependencies = [];
|
||||||
|
|
||||||
for (const otherVariable of this.variables) {
|
for (const otherVariable of this.variables) {
|
||||||
if (variable.dependsOn(otherVariable)) {
|
if (variable.dependsOn(otherVariable)) {
|
||||||
@@ -69,7 +69,7 @@ export class VariableSrv {
|
|||||||
return this.$q
|
return this.$q
|
||||||
.all(dependencies)
|
.all(dependencies)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var urlValue = queryParams['var-' + variable.name];
|
const urlValue = queryParams['var-' + variable.name];
|
||||||
if (urlValue !== void 0) {
|
if (urlValue !== void 0) {
|
||||||
return variable.setValueFromUrl(urlValue).then(variable.initLock.resolve);
|
return variable.setValueFromUrl(urlValue).then(variable.initLock.resolve);
|
||||||
}
|
}
|
||||||
@@ -87,14 +87,14 @@ export class VariableSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createVariableFromModel(model) {
|
createVariableFromModel(model) {
|
||||||
var ctor = variableTypes[model.type].ctor;
|
const ctor = variableTypes[model.type].ctor;
|
||||||
if (!ctor) {
|
if (!ctor) {
|
||||||
throw {
|
throw {
|
||||||
message: 'Unable to find variable constructor for ' + model.type,
|
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;
|
return variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ export class VariableSrv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeVariable(variable) {
|
removeVariable(variable) {
|
||||||
var index = _.indexOf(this.variables, variable);
|
const index = _.indexOf(this.variables, variable);
|
||||||
this.variables.splice(index, 1);
|
this.variables.splice(index, 1);
|
||||||
this.templateSrv.updateTemplateData();
|
this.templateSrv.updateTemplateData();
|
||||||
this.dashboard.updateSubmenuVisibility();
|
this.dashboard.updateSubmenuVisibility();
|
||||||
@@ -139,7 +139,7 @@ export class VariableSrv {
|
|||||||
|
|
||||||
selectOptionsForCurrentValue(variable) {
|
selectOptionsForCurrentValue(variable) {
|
||||||
var i, y, value, option;
|
var i, y, value, option;
|
||||||
var selected: any = [];
|
const selected: any = [];
|
||||||
|
|
||||||
for (i = 0; i < variable.options.length; i++) {
|
for (i = 0; i < variable.options.length; i++) {
|
||||||
option = variable.options[i];
|
option = variable.options[i];
|
||||||
@@ -185,7 +185,7 @@ export class VariableSrv {
|
|||||||
|
|
||||||
return variable.setValue(selected);
|
return variable.setValue(selected);
|
||||||
} else {
|
} else {
|
||||||
var currentOption = _.find(variable.options, {
|
const currentOption = _.find(variable.options, {
|
||||||
text: variable.current.text,
|
text: variable.current.text,
|
||||||
});
|
});
|
||||||
if (currentOption) {
|
if (currentOption) {
|
||||||
@@ -246,7 +246,7 @@ export class VariableSrv {
|
|||||||
|
|
||||||
updateUrlParamsWithCurrentVariables() {
|
updateUrlParamsWithCurrentVariables() {
|
||||||
// update url
|
// update url
|
||||||
var params = this.$location.search();
|
const params = this.$location.search();
|
||||||
|
|
||||||
// remove variable params
|
// remove variable params
|
||||||
_.each(params, function(value, key) {
|
_.each(params, function(value, key) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class LoadDashboardCtrl {
|
|||||||
if (homeDash.redirectUri) {
|
if (homeDash.redirectUri) {
|
||||||
$location.path(homeDash.redirectUri);
|
$location.path(homeDash.redirectUri);
|
||||||
} else {
|
} else {
|
||||||
var meta = homeDash.meta;
|
const meta = homeDash.meta;
|
||||||
meta.canSave = meta.canShare = meta.canStar = false;
|
meta.canSave = meta.canShare = meta.canStar = false;
|
||||||
$scope.initDashboard(homeDash, $scope);
|
$scope.initDashboard(homeDash, $scope);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-19
@@ -1,24 +1,15 @@
|
|||||||
var _global = <any>(window);
|
const _global = <any>window;
|
||||||
var beforeEach = _global.beforeEach;
|
const beforeEach = _global.beforeEach;
|
||||||
var afterEach = _global.afterEach;
|
const afterEach = _global.afterEach;
|
||||||
var before = _global.before;
|
const before = _global.before;
|
||||||
var describe = _global.describe;
|
const describe = _global.describe;
|
||||||
var it = _global.it;
|
const it = _global.it;
|
||||||
var sinon = _global.sinon;
|
const sinon = _global.sinon;
|
||||||
var expect = _global.expect;
|
const expect = _global.expect;
|
||||||
|
|
||||||
var angularMocks = {
|
const angularMocks = {
|
||||||
module: _global.module,
|
module: _global.module,
|
||||||
inject: _global.inject,
|
inject: _global.inject,
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export { beforeEach, afterEach, before, describe, it, sinon, expect, angularMocks };
|
||||||
beforeEach,
|
|
||||||
afterEach,
|
|
||||||
before,
|
|
||||||
describe,
|
|
||||||
it,
|
|
||||||
sinon,
|
|
||||||
expect,
|
|
||||||
angularMocks,
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user