Changed functions to arrow functions for only-arrow-functions rule. (#13131)

This commit is contained in:
Patrick O'Carroll
2018-09-05 07:47:30 +02:00
committed by Torkel Ödegaard
parent 7c88436a9b
commit 72ab24f300
50 changed files with 367 additions and 367 deletions

View File

@@ -128,7 +128,7 @@ export class ChangeTracker {
});
// ignore template variable values
_.each(dash.templating.list, function(value) {
_.each(dash.templating.list, value => {
value.current = null;
value.options = null;
value.filters = null;

View File

@@ -59,7 +59,7 @@ export class DashboardLoaderSrv {
});
}
promise.then(function(result) {
promise.then(result => {
if (result.meta.dashboardNotFound !== true) {
impressionSrv.addDashboardImpression(result.dashboard.id);
}

View File

@@ -15,7 +15,7 @@ function dashRepeatOptionDirective(variableSrv) {
scope: {
panel: '=',
},
link: function(scope, element) {
link: (scope, element) => {
element.css({ display: 'block', width: '100%' });
scope.variables = variableSrv.variables.map(item => {
@@ -36,7 +36,7 @@ function dashRepeatOptionDirective(variableSrv) {
scope.panel.repeatDirection = 'h';
}
scope.optionChanged = function() {
scope.optionChanged = () => {
if (scope.panel.repeat) {
scope.panel.repeatDirection = 'h';
}

View File

@@ -11,7 +11,7 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv,
};
$scope.editor = { index: $scope.tabIndex || 0 };
$scope.init = function() {
$scope.init = () => {
$scope.modeSharePanel = $scope.panel ? true : false;
$scope.tabs = [{ title: 'Link', src: 'shareLink.html' }];
@@ -34,7 +34,7 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv,
$scope.buildUrl();
};
$scope.buildUrl = function() {
$scope.buildUrl = () => {
let baseUrl = $location.absUrl();
const queryStart = baseUrl.indexOf('?');
@@ -90,7 +90,7 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv,
// This function will try to return the proper full name of the local timezone
// Chrome does not handle the timezone offset (but phantomjs does)
$scope.getLocalTimeZone = function() {
$scope.getLocalTimeZone = () => {
const utcOffset = '&tz=UTC' + encodeURIComponent(moment().format('Z'));
// Older browser does not the internationalization API
@@ -111,7 +111,7 @@ export function ShareModalCtrl($scope, $rootScope, $location, $timeout, timeSrv,
return '&tz=' + encodeURIComponent(options.timeZone);
};
$scope.getShareUrl = function() {
$scope.getShareUrl = () => {
return $scope.shareUrl;
};
}

View File

@@ -25,8 +25,8 @@ export class ShareSnapshotCtrl {
{ text: 'Public on the web', value: 3 },
];
$scope.init = function() {
backendSrv.get('/api/snapshot/shared-options').then(function(options) {
$scope.init = () => {
backendSrv.get('/api/snapshot/shared-options').then(options => {
$scope.externalUrl = options['externalSnapshotURL'];
$scope.sharingButtonText = options['externalSnapshotName'];
$scope.externalEnabled = options['externalEnabled'];
@@ -35,7 +35,7 @@ export class ShareSnapshotCtrl {
$scope.apiUrl = '/api/snapshots';
$scope.createSnapshot = function(external) {
$scope.createSnapshot = external => {
$scope.dashboard.snapshot = {
timestamp: new Date(),
};
@@ -49,12 +49,12 @@ export class ShareSnapshotCtrl {
$rootScope.$broadcast('refresh');
$timeout(function() {
$timeout(() => {
$scope.saveSnapshot(external);
}, $scope.snapshot.timeoutSeconds * 1000);
};
$scope.saveSnapshot = function(external) {
$scope.saveSnapshot = external => {
const dash = $scope.dashboard.getSaveModelClone();
$scope.scrubDashboard(dash);
@@ -67,7 +67,7 @@ export class ShareSnapshotCtrl {
const postUrl = external ? $scope.externalUrl + $scope.apiUrl : $scope.apiUrl;
backendSrv.post(postUrl, cmdData).then(
function(results) {
results => {
$scope.loading = false;
if (external) {
@@ -88,17 +88,17 @@ export class ShareSnapshotCtrl {
$scope.step = 2;
},
function() {
() => {
$scope.loading = false;
}
);
};
$scope.getSnapshotUrl = function() {
$scope.getSnapshotUrl = () => {
return $scope.snapshotUrl;
};
$scope.scrubDashboard = function(dash) {
$scope.scrubDashboard = dash => {
// change title
dash.title = $scope.snapshot.name;
@@ -106,7 +106,7 @@ export class ShareSnapshotCtrl {
dash.time = timeSrv.timeRange();
// remove panel queries & links
_.each(dash.panels, function(panel) {
_.each(dash.panels, panel => {
panel.targets = [];
panel.links = [];
panel.datasource = null;
@@ -114,10 +114,10 @@ export class ShareSnapshotCtrl {
// remove annotation queries
dash.annotations.list = _.chain(dash.annotations.list)
.filter(function(annotation) {
.filter(annotation => {
return annotation.enable;
})
.map(function(annotation) {
.map(annotation => {
return {
name: annotation.name,
enable: annotation.enable,
@@ -131,7 +131,7 @@ export class ShareSnapshotCtrl {
.value();
// remove template queries
_.each(dash.templating.list, function(variable) {
_.each(dash.templating.list, variable => {
variable.query = '';
variable.options = variable.current;
variable.refresh = false;
@@ -149,21 +149,21 @@ export class ShareSnapshotCtrl {
// cleanup snapshotData
delete $scope.dashboard.snapshot;
$scope.dashboard.forEachPanel(function(panel) {
$scope.dashboard.forEachPanel(panel => {
delete panel.snapshotData;
});
_.each($scope.dashboard.annotations.list, function(annotation) {
_.each($scope.dashboard.annotations.list, annotation => {
delete annotation.snapshotData;
});
};
$scope.deleteSnapshot = function() {
backendSrv.get($scope.deleteUrl).then(function() {
$scope.deleteSnapshot = () => {
backendSrv.get($scope.deleteUrl).then(() => {
$scope.step = 3;
});
};
$scope.saveExternalSnapshotRef = function(cmdData, results) {
$scope.saveExternalSnapshotRef = (cmdData, results) => {
// save external in local instance as well
cmdData.external = true;
cmdData.key = results.key;

View File

@@ -5,10 +5,10 @@ export function inputDateDirective() {
return {
restrict: 'A',
require: 'ngModel',
link: function($scope, $elem, attrs, ngModel) {
link: ($scope, $elem, attrs, ngModel) => {
const format = 'YYYY-MM-DD HH:mm:ss';
const fromUser = function(text) {
const fromUser = text => {
if (text.indexOf('now') !== -1) {
if (!dateMath.isValid(text)) {
ngModel.$setValidity('error', false);
@@ -34,7 +34,7 @@ export function inputDateDirective() {
return parsed;
};
const toUser = function(currentValue) {
const toUser = currentValue => {
if (moment.isMoment(currentValue)) {
return currentValue.format(format);
} else {

View File

@@ -16,11 +16,11 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
scope: {
onUpload: '&',
},
link: function(scope) {
link: scope => {
function file_selected(evt) {
const files = evt.target.files; // FileList object
const readerOnload = function() {
return function(e) {
const readerOnload = () => {
return e => {
let dash;
try {
dash = JSON.parse(e.target.result);
@@ -30,7 +30,7 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
return;
}
scope.$apply(function() {
scope.$apply(() => {
scope.onUpload({ dash: dash });
});
};

View File

@@ -22,18 +22,18 @@ export class DashboardViewState {
self.$scope = $scope;
self.dashboard = $scope.dashboard;
$scope.onAppEvent('$routeUpdate', function() {
$scope.onAppEvent('$routeUpdate', () => {
const urlState = self.getQueryStringState();
if (self.needsSync(urlState)) {
self.update(urlState, true);
}
});
$scope.onAppEvent('panel-change-view', function(evt, payload) {
$scope.onAppEvent('panel-change-view', (evt, payload) => {
self.update(payload);
});
$scope.onAppEvent('panel-initialized', function(evt, payload) {
$scope.onAppEvent('panel-initialized', (evt, payload) => {
self.registerPanel(payload.scope);
});
@@ -156,7 +156,7 @@ export class DashboardViewState {
}
getPanelScope(id) {
return _.find(this.panelScopes, function(panelScope) {
return _.find(this.panelScopes, panelScope => {
return panelScope.ctrl.panel.id === id;
});
}
@@ -176,7 +176,7 @@ export class DashboardViewState {
return false;
}
this.$timeout(function() {
this.$timeout(() => {
if (self.oldTimeRange !== ctrl.range) {
self.$rootScope.$broadcast('refresh');
} else {
@@ -216,7 +216,7 @@ export class DashboardViewState {
}
}
const unbind = panelScope.$on('$destroy', function() {
const unbind = panelScope.$on('$destroy', () => {
self.panelScopes = _.without(self.panelScopes, panelScope);
unbind();
});
@@ -226,7 +226,7 @@ export class DashboardViewState {
/** @ngInject */
export function dashboardViewStateSrv($location, $timeout, $rootScope) {
return {
create: function($scope) {
create: $scope => {
return new DashboardViewState($scope, $location, $timeout, $rootScope);
},
};

View File

@@ -10,7 +10,7 @@ function dashLinksContainer() {
restrict: 'E',
controller: 'DashLinksContainerCtrl',
template: '<dash-link ng-repeat="link in generatedLinks" link="link"></dash-link>',
link: function() {},
link: () => {},
};
}
@@ -18,7 +18,7 @@ function dashLinksContainer() {
function dashLink($compile, $sanitize, linkSrv) {
return {
restrict: 'E',
link: function(scope, elem) {
link: (scope, elem) => {
const link = scope.link;
let template =
'<div class="gf-form">' +
@@ -130,16 +130,16 @@ export class DashLinksContainerCtrl {
function updateDashLinks() {
const promises = _.map($scope.links, buildLinks);
$q.all(promises).then(function(results) {
$q.all(promises).then(results => {
$scope.generatedLinks = _.flatten(results);
});
}
$scope.searchDashboards = function(link, limit) {
return backendSrv.search({ tag: link.tags, limit: limit }).then(function(results) {
$scope.searchDashboards = (link, limit) => {
return backendSrv.search({ tag: link.tags, limit: limit }).then(results => {
return _.reduce(
results,
function(memo, dash) {
(memo, dash) => {
// do not add current dashboard
if (dash.id !== currentDashId) {
memo.push({
@@ -158,9 +158,9 @@ export class DashLinksContainerCtrl {
});
};
$scope.fillDropdown = function(link) {
$scope.searchDashboards(link, 100).then(function(results) {
_.each(results, function(hit) {
$scope.fillDropdown = link => {
$scope.searchDashboards(link, 100).then(results => {
_.each(results, hit => {
hit.url = linkSrv.getLinkUrl(hit);
});
link.searchHits = results;

View File

@@ -9,7 +9,7 @@ export class ChangePasswordCtrl {
$scope.ldapEnabled = config.ldapEnabled;
$scope.navModel = navModelSrv.getNav('profile', 'change-password', 0);
$scope.changePassword = function() {
$scope.changePassword = () => {
if (!$scope.userForm.$valid) {
return;
}
@@ -19,7 +19,7 @@ export class ChangePasswordCtrl {
return;
}
backendSrv.put('/api/user/password', $scope.command).then(function() {
backendSrv.put('/api/user/password', $scope.command).then(() => {
$location.path('profile');
});
};

View File

@@ -7,9 +7,9 @@ export class NewOrgCtrl {
$scope.navModel = navModelSrv.getNav('cfg', 'admin', 'global-orgs', 1);
$scope.newOrg = { name: '' };
$scope.createOrg = function() {
backendSrv.post('/api/orgs/', $scope.newOrg).then(function(result) {
backendSrv.post('/api/user/using/' + result.orgId).then(function() {
$scope.createOrg = () => {
backendSrv.post('/api/orgs/', $scope.newOrg).then(result => {
backendSrv.post('/api/user/using/' + result.orgId).then(() => {
window.location.href = config.appSubUrl + '/org';
});
});

View File

@@ -8,22 +8,22 @@ export class OrgApiKeysCtrl {
$scope.roleTypes = ['Viewer', 'Editor', 'Admin'];
$scope.token = { role: 'Viewer' };
$scope.init = function() {
$scope.init = () => {
$scope.getTokens();
};
$scope.getTokens = function() {
backendSrv.get('/api/auth/keys').then(function(tokens) {
$scope.getTokens = () => {
backendSrv.get('/api/auth/keys').then(tokens => {
$scope.tokens = tokens;
});
};
$scope.removeToken = function(id) {
$scope.removeToken = id => {
backendSrv.delete('/api/auth/keys/' + id).then($scope.getTokens);
};
$scope.addToken = function() {
backendSrv.post('/api/auth/keys', $scope.token).then(function(result) {
$scope.addToken = () => {
backendSrv.post('/api/auth/keys', $scope.token).then(result => {
const modalScope = $scope.$new(true);
modalScope.key = result.key;
modalScope.rootPath = window.location.origin + $scope.$root.appSubUrl;

View File

@@ -14,18 +14,18 @@ export class SelectOrgCtrl {
},
};
$scope.init = function() {
$scope.init = () => {
$scope.getUserOrgs();
};
$scope.getUserOrgs = function() {
backendSrv.get('/api/user/orgs').then(function(orgs) {
$scope.getUserOrgs = () => {
backendSrv.get('/api/user/orgs').then(orgs => {
$scope.orgs = orgs;
});
};
$scope.setUsingOrg = function(org) {
backendSrv.post('/api/user/using/' + org.orgId).then(function() {
$scope.setUsingOrg = org => {
backendSrv.post('/api/user/using/' + org.orgId).then(() => {
window.location.href = config.appSubUrl + '/';
});
};

View File

@@ -54,13 +54,13 @@ const panelTemplate = `
</div>
`;
module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
module.directive('grafanaPanel', ($rootScope, $document, $timeout) => {
return {
restrict: 'E',
template: panelTemplate,
transclude: true,
scope: { ctrl: '=' },
link: function(scope, elem) {
link: (scope, elem) => {
const panelContainer = elem.find('.panel-container');
const panelContent = elem.find('.panel-content');
const cornerInfoElem = elem.find('.panel-info-corner');
@@ -184,7 +184,7 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
infoDrop = new Drop({
target: cornerInfoElem[0],
content: function() {
content: () => {
return ctrl.getInfoContent({ mode: 'tooltip' });
},
classes: ctrl.error ? 'drop-error' : 'drop-help',
@@ -208,7 +208,7 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
scope.$watchGroup(['ctrl.error', 'ctrl.panel.description'], updatePanelCornerInfo);
scope.$watchCollection('ctrl.panel.links', updatePanelCornerInfo);
cornerInfoElem.on('click', function() {
cornerInfoElem.on('click', () => {
infoDrop.close();
scope.$apply(ctrl.openInspector.bind(ctrl));
});
@@ -216,7 +216,7 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
elem.on('mouseenter', mouseEnter);
elem.on('mouseleave', mouseLeave);
scope.$on('$destroy', function() {
scope.$on('$destroy', () => {
elem.off();
cornerInfoElem.off();
@@ -232,7 +232,7 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) {
};
});
module.directive('panelHelpCorner', function($rootScope) {
module.directive('panelHelpCorner', $rootScope => {
return {
restrict: 'E',
template: `
@@ -242,6 +242,6 @@ module.directive('panelHelpCorner', function($rootScope) {
</span>
</span>
`,
link: function(scope, elem) {},
link: (scope, elem) => {},
};
});

View File

@@ -85,12 +85,12 @@ function panelHeader($compile) {
return {
restrict: 'E',
template: template,
link: function(scope, elem, attrs) {
link: (scope, elem, attrs) => {
const menuElem = elem.find('.panel-menu');
let menuScope;
let isDragged;
elem.click(function(evt) {
elem.click(evt => {
const targetClass = evt.target.className;
// remove existing scope

View File

@@ -170,8 +170,8 @@ export function queryTroubleshooter() {
panelCtrl: '=',
isOpen: '=',
},
link: function(scope, elem, attrs, ctrl) {
ctrl.renderJsonExplorer = function(data) {
link: (scope, elem, attrs, ctrl) => {
ctrl.renderJsonExplorer = data => {
const jsonElem = elem.find('.query-troubleshooter-json');
ctrl.jsonExplorer = new JsonExplorer(data, 3, {

View File

@@ -7,7 +7,7 @@ export class SoloPanelCtrl {
constructor($scope, $routeParams, $location, dashboardLoaderSrv, contextSrv, backendSrv) {
let panelId;
$scope.init = function() {
$scope.init = () => {
contextSrv.sidemenu = false;
appEvents.emit('toggle-sidemenu-hidden');
@@ -27,13 +27,13 @@ export class SoloPanelCtrl {
return;
}
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then(function(result) {
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then(result => {
result.meta.soloMode = true;
$scope.initDashboard(result, $scope);
});
};
$scope.initPanelScope = function() {
$scope.initPanelScope = () => {
const panelInfo = $scope.dashboard.getPanelInfoById(panelId);
// fake row ctrl scope

View File

@@ -10,7 +10,7 @@ function panelLinksEditor() {
restrict: 'E',
controller: 'PanelLinksEditorCtrl',
templateUrl: 'public/app/features/panellinks/module.html',
link: function() {},
link: () => {},
};
}
@@ -19,15 +19,15 @@ export class PanelLinksEditorCtrl {
constructor($scope, backendSrv) {
$scope.panel.links = $scope.panel.links || [];
$scope.addLink = function() {
$scope.addLink = () => {
$scope.panel.links.push({
type: 'dashboard',
});
};
$scope.searchDashboards = function(queryStr, callback) {
backendSrv.search({ query: queryStr }).then(function(hits) {
const dashboards = _.map(hits, function(dash) {
$scope.searchDashboards = (queryStr, callback) => {
backendSrv.search({ query: queryStr }).then(hits => {
const dashboards = _.map(hits, dash => {
return dash.title;
});
@@ -35,8 +35,8 @@ export class PanelLinksEditorCtrl {
});
};
$scope.dashboardChanged = function(link) {
backendSrv.search({ query: link.dashboard }).then(function(hits) {
$scope.dashboardChanged = link => {
backendSrv.search({ query: link.dashboard }).then(hits => {
const dashboard = _.find(hits, { title: link.dashboard });
if (dashboard) {
if (dashboard.url) {
@@ -50,7 +50,7 @@ export class PanelLinksEditorCtrl {
});
};
$scope.deleteLink = function(link) {
$scope.deleteLink = link => {
$scope.panel.links = _.without($scope.panel.links, link);
};
}

View File

@@ -21,7 +21,7 @@ function grafanaRoutes($routeProvider) {
.when('/playlists/play/:id', {
template: '',
resolve: {
init: function(playlistSrv, $route) {
init: (playlistSrv, $route) => {
const playlistId = $route.current.params.id;
playlistSrv.start(playlistId);
},

View File

@@ -200,7 +200,7 @@ export class DataSourceEditCtrl {
coreModule.controller('DataSourceEditCtrl', DataSourceEditCtrl);
coreModule.directive('datasourceHttpSettings', function() {
coreModule.directive('datasourceHttpSettings', () => {
return {
scope: {
current: '=',
@@ -209,15 +209,15 @@ coreModule.directive('datasourceHttpSettings', function() {
},
templateUrl: 'public/app/features/plugins/partials/ds_http_settings.html',
link: {
pre: function($scope, elem, attrs) {
pre: ($scope, elem, attrs) => {
// do not show access option if direct access is disabled
$scope.showAccessOption = $scope.noDirectAccess !== 'true';
$scope.showAccessHelp = false;
$scope.toggleAccessHelp = function() {
$scope.toggleAccessHelp = () => {
$scope.showAccessHelp = !$scope.showAccessHelp;
};
$scope.getSuggestUrls = function() {
$scope.getSuggestUrls = () => {
return [$scope.suggestUrl];
};
},

View File

@@ -36,7 +36,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
// handle relative template urls for plugin templates
options.Component.templateUrl = relativeTemplateUrlToAbs(options.Component.templateUrl, options.baseUrl);
return function() {
return () => {
return {
templateUrl: options.Component.templateUrl,
template: options.Component.template,
@@ -71,12 +71,12 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
const panelInfo = config.panels[scope.panel.type];
let panelCtrlPromise = Promise.resolve(UnknownPanelCtrl);
if (panelInfo) {
panelCtrlPromise = importPluginModule(panelInfo.module).then(function(panelModule) {
panelCtrlPromise = importPluginModule(panelInfo.module).then(panelModule => {
return panelModule.PanelCtrl;
});
}
return panelCtrlPromise.then(function(PanelCtrl: any) {
return panelCtrlPromise.then((PanelCtrl: any) => {
componentInfo.Component = PanelCtrl;
if (!PanelCtrl || PanelCtrl.registered) {
@@ -128,7 +128,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
}
// Annotations
case 'annotations-query-ctrl': {
return importPluginModule(scope.ctrl.currentDatasource.meta.module).then(function(dsModule) {
return importPluginModule(scope.ctrl.currentDatasource.meta.module).then(dsModule => {
return {
baseUrl: scope.ctrl.currentDatasource.meta.baseUrl,
name: 'annotations-query-ctrl-' + scope.ctrl.currentDatasource.meta.id,
@@ -144,7 +144,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
// Datasource ConfigCtrl
case 'datasource-config-ctrl': {
const dsMeta = scope.ctrl.datasourceMeta;
return importPluginModule(dsMeta.module).then(function(dsModule): any {
return importPluginModule(dsMeta.module).then((dsModule): any => {
if (!dsModule.ConfigCtrl) {
return { notFound: true };
}
@@ -161,7 +161,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
// AppConfigCtrl
case 'app-config-ctrl': {
const model = scope.ctrl.model;
return importPluginModule(model.module).then(function(appModule) {
return importPluginModule(model.module).then(appModule => {
return {
baseUrl: model.baseUrl,
name: 'app-config-' + model.id,
@@ -174,7 +174,7 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
// App Page
case 'app-page': {
const appModel = scope.ctrl.appModel;
return importPluginModule(appModel.module).then(function(appModule) {
return importPluginModule(appModel.module).then(appModule => {
return {
baseUrl: appModel.baseUrl,
name: 'app-page-' + appModel.id + '-' + scope.ctrl.page.slug,
@@ -206,9 +206,9 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
elem.empty();
// let a binding digest cycle complete before adding to dom
setTimeout(function() {
setTimeout(() => {
elem.append(child);
scope.$applyAsync(function() {
scope.$applyAsync(() => {
scope.$broadcast('component-did-mount');
scope.$broadcast('refresh');
});
@@ -239,9 +239,9 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
return {
restrict: 'E',
link: function(scope, elem, attrs) {
link: (scope, elem, attrs) => {
getModule(scope, attrs)
.then(function(componentInfo) {
.then(componentInfo => {
registerPluginComponent(scope, elem, attrs, componentInfo);
})
.catch(err => {

View File

@@ -10,7 +10,7 @@ import { CustomVariable } from './custom_variable';
import { ConstantVariable } from './constant_variable';
import { AdhocVariable } from './adhoc_variable';
coreModule.factory('templateSrv', function() {
coreModule.factory('templateSrv', () => {
return templateSrv;
});

View File

@@ -39,7 +39,7 @@ export class CustomVariable implements Variable {
updateOptions() {
// extract options in comma separated string
this.options = _.map(this.query.split(/[,]+/), function(text) {
this.options = _.map(this.query.split(/[,]+/), text => {
return { text: text.trim(), value: text.trim() };
});

View File

@@ -30,31 +30,31 @@ export class VariableEditorCtrl {
$scope.hideOptions = [{ value: 0, text: '' }, { value: 1, text: 'Label' }, { value: 2, text: 'Variable' }];
$scope.init = function() {
$scope.init = () => {
$scope.mode = 'list';
$scope.variables = variableSrv.variables;
$scope.reset();
$scope.$watch('mode', function(val) {
$scope.$watch('mode', val => {
if (val === 'new') {
$scope.reset();
}
});
};
$scope.setMode = function(mode) {
$scope.setMode = mode => {
$scope.mode = mode;
};
$scope.add = function() {
$scope.add = () => {
if ($scope.isValid()) {
variableSrv.addVariable($scope.current);
$scope.update();
}
};
$scope.isValid = function() {
$scope.isValid = () => {
if (!$scope.ctrl.form.$valid) {
return false;
}
@@ -84,7 +84,7 @@ export class VariableEditorCtrl {
return true;
};
$scope.validate = function() {
$scope.validate = () => {
$scope.infoText = '';
if ($scope.current.type === 'adhoc' && $scope.current.datasource !== null) {
$scope.infoText = 'Adhoc filters are applied automatically to all queries that target this datasource';
@@ -96,7 +96,7 @@ export class VariableEditorCtrl {
}
};
$scope.runQuery = function() {
$scope.runQuery = () => {
$scope.optionsLimit = 20;
return variableSrv.updateOptions($scope.current).catch(err => {
if (err.data && err.data.message) {
@@ -106,23 +106,23 @@ export class VariableEditorCtrl {
});
};
$scope.edit = function(variable) {
$scope.edit = variable => {
$scope.current = variable;
$scope.currentIsNew = false;
$scope.mode = 'edit';
$scope.validate();
};
$scope.duplicate = function(variable) {
$scope.duplicate = variable => {
const clone = _.cloneDeep(variable.getSaveModel());
$scope.current = variableSrv.createVariableFromModel(clone);
$scope.current.name = 'copy_of_' + variable.name;
variableSrv.addVariable($scope.current);
};
$scope.update = function() {
$scope.update = () => {
if ($scope.isValid()) {
$scope.runQuery().then(function() {
$scope.runQuery().then(() => {
$scope.reset();
$scope.mode = 'list';
templateSrv.updateTemplateData();
@@ -130,18 +130,18 @@ export class VariableEditorCtrl {
}
};
$scope.reset = function() {
$scope.reset = () => {
$scope.currentIsNew = true;
$scope.current = variableSrv.createVariableFromModel({ type: 'query' });
// this is done here in case a new data source type variable was added
$scope.datasources = _.filter(datasourceSrv.getMetricSources(), function(ds) {
$scope.datasources = _.filter(datasourceSrv.getMetricSources(), ds => {
return !ds.meta.mixed && ds.value !== null;
});
$scope.datasourceTypes = _($scope.datasources)
.uniqBy('meta.id')
.map(function(ds) {
.map(ds => {
return { text: ds.meta.name, value: ds.meta.id };
})
.value();
@@ -164,11 +164,11 @@ export class VariableEditorCtrl {
$scope.validate();
};
$scope.removeVariable = function(variable) {
$scope.removeVariable = variable => {
variableSrv.removeVariable(variable);
};
$scope.showMoreOptions = function() {
$scope.showMoreOptions = () => {
$scope.optionsLimit += 20;
};
}

View File

@@ -65,7 +65,7 @@ export class IntervalVariable implements Variable {
updateOptions() {
// extract options between quotes and/or comma
this.options = _.map(this.query.match(/(["'])(.*?)\1|\w+/g), function(text) {
this.options = _.map(this.query.match(/(["'])(.*?)\1|\w+/g), text => {
text = text.replace(/["']+/g, '');
return { text: text.trim(), value: text.trim() };
});

View File

@@ -106,8 +106,8 @@ export class QueryVariable implements Variable {
getValuesForTag(tagKey) {
return this.datasourceSrv.get(this.datasource).then(datasource => {
const query = this.tagValuesQuery.replace('$tag', tagKey);
return this.metricFindQuery(datasource, query).then(function(results) {
return _.map(results, function(value) {
return this.metricFindQuery(datasource, query).then(results => {
return _.map(results, value => {
return value.text;
});
});

View File

@@ -77,7 +77,7 @@ export class TemplateSrv {
if (value instanceof Array && value.length === 0) {
return '__empty__';
}
const quotedValues = _.map(value, function(val) {
const quotedValues = _.map(value, val => {
return '"' + luceneEscape(val) + '"';
});
return '(' + quotedValues.join(' OR ') + ')';
@@ -248,7 +248,7 @@ export class TemplateSrv {
}
fillVariableValuesForUrl(params, scopedVars) {
_.each(this.variables, function(variable) {
_.each(this.variables, variable => {
if (scopedVars && scopedVars[variable.name] !== void 0) {
if (scopedVars[variable.name].skipUrlSync) {
return;
@@ -264,7 +264,7 @@ export class TemplateSrv {
}
distributeVariable(value, variable) {
value = _.map(value, function(val, index) {
value = _.map(value, (val, index) => {
if (index !== 0) {
return variable + '=' + val;
} else {

View File

@@ -175,10 +175,10 @@ export class VariableSrv {
selected = variable.options[0];
} else {
selected = {
value: _.map(selected, function(val) {
value: _.map(selected, val => {
return val.value;
}),
text: _.map(selected, function(val) {
text: _.map(selected, val => {
return val.text;
}).join(' + '),
};
@@ -250,7 +250,7 @@ export class VariableSrv {
const params = this.$location.search();
// remove variable params
_.each(params, function(value, key) {
_.each(params, (value, key) => {
if (key.indexOf('var-') === 0) {
delete params[key];
}