Commit 0fa0066c by Torkel Ödegaard

tech(lodash): began migration work

parent 2146e69a
......@@ -14,6 +14,7 @@
],
"dependencies": {
"jquery": "3.1.0",
"lodash": "~4.15.0",
"angular": "1.5.3",
"angular-route": "1.5.3",
"angular-mocks": "1.5.3",
......
......@@ -40,7 +40,7 @@ function (_, $, coreModule) {
}
$scope.$apply(function() {
var selected = _.findWhere($scope.altSegments, { value: value });
var selected = _.find($scope.altSegments, {value: value});
if (selected) {
segment.value = selected.value;
segment.html = selected.html;
......@@ -174,7 +174,7 @@ function (_, $, coreModule) {
pre: function postLink($scope, elem, attrs) {
$scope.valueToSegment = function(value) {
var option = _.findWhere($scope.options, {value: value});
var option = _.find($scope.options, {value: value});
var segment = {
cssClass: attrs.cssClass,
custom: attrs.custom,
......@@ -196,7 +196,7 @@ function (_, $, coreModule) {
$scope.onSegmentChange = function() {
if ($scope.options) {
var option = _.findWhere($scope.options, {text: $scope.segment.value});
var option = _.find($scope.options, {text: $scope.segment.value});
if (option && option.value !== $scope.property) {
$scope.property = option.value;
} else if (attrs.custom !== 'false') {
......
......@@ -51,7 +51,7 @@ function (angular, _, coreModule) {
});
// convert values to text
var currentTexts = _.pluck(selectedAndNotInTag, 'text');
var currentTexts = _.map(selectedAndNotInTag, 'text');
// join texts
vm.linkText = currentTexts.join(' + ');
......@@ -167,7 +167,7 @@ function (angular, _, coreModule) {
_.each(vm.tags, function(tag) {
if (tag.selected) {
_.each(tag.values, function(value) {
if (!_.findWhere(vm.selectedValues, {value: value})) {
if (!_.find(vm.selectedValues, {value: value})) {
tag.selected = false;
}
});
......@@ -175,8 +175,8 @@ function (angular, _, coreModule) {
});
vm.selectedTags = _.filter(vm.tags, {selected: true});
vm.variable.current.value = _.pluck(vm.selectedValues, 'value');
vm.variable.current.text = _.pluck(vm.selectedValues, 'text').join(' + ');
vm.variable.current.value = _.map(vm.selectedValues, 'value');
vm.variable.current.text = _.map(vm.selectedValues, 'text').join(' + ');
vm.variable.current.tags = vm.selectedTags;
if (!vm.variable.multi) {
......
......@@ -93,7 +93,7 @@ export function parseDateMath(mathString, time, roundUp?) {
}
unit = mathString.charAt(i++);
if (!_.contains(units, unit)) {
if (!_.includes(units, unit)) {
return undefined;
} else {
if (type === 0) {
......
......@@ -81,20 +81,20 @@ function (angular, _) {
$scope.searchOrgs = function(queryStr, callback) {
if ($scope.orgsSearchCache.length > 0) {
callback(_.pluck($scope.orgsSearchCache, "name"));
callback(_.map($scope.orgsSearchCache, "name"));
return;
}
backendSrv.get('/api/orgs', {query: ''}).then(function(result) {
$scope.orgsSearchCache = result;
callback(_.pluck(result, "name"));
callback(_.map(result, "name"));
});
};
$scope.addOrgUser = function() {
if (!$scope.addOrgForm.$valid) { return; }
var orgInfo = _.findWhere($scope.orgsSearchCache, {name: $scope.newOrg.name});
var orgInfo = _.find($scope.orgsSearchCache, {name: $scope.newOrg.name});
if (!orgInfo) { return; }
$scope.newOrg.loginOrEmail = $scope.user.login;
......
......@@ -68,7 +68,7 @@ export class AlertTabCtrl {
this.notifications = res;
_.each(this.alert.notifications, item => {
var model = _.findWhere(this.notifications, {id: item.id});
var model = _.find(this.notifications, {id: item.id});
if (model) {
model.iconClass = this.getNotificationIcon(model.type);
this.alertNotifications.push(model);
......@@ -123,7 +123,7 @@ export class AlertTabCtrl {
}
notificationAdded() {
var model = _.findWhere(this.notifications, {name: this.addNotificationSegment.value});
var model = _.find(this.notifications, {name: this.addNotificationSegment.value});
if (!model) {
return;
}
......
......@@ -65,7 +65,7 @@ export class AnnotationsSrv {
return this.globalAnnotationsPromise;
}
var annotations = _.where(dashboard.annotations.list, {enable: true});
var annotations = _.filter(dashboard.annotations.list, {enable: true});
var range = this.timeSrv.timeRange();
this.globalAnnotationsPromise = this.$q.all(_.map(annotations, annotation => {
......
......@@ -298,7 +298,7 @@ function (angular, $, _, moment) {
if (oldVersion < 6) {
// move pulldowns to new schema
var annotations = _.findWhere(old.pulldowns, { type: 'annotations' });
var annotations = _.find(old.pulldowns, { type: 'annotations' });
if (annotations) {
this.annotations = {
......@@ -328,7 +328,7 @@ function (angular, $, _, moment) {
if (!target.refId) {
target.refId = this.getNextQueryLetter(panel);
}
}, this);
}.bind(this));
});
}
......
......@@ -106,7 +106,7 @@ export class DynamicDashboardSrv {
// returns a new row clone or reuses a clone from previous iteration
repeatRow(row, rowIndex) {
var variables = this.dashboard.templating.list;
var variable = _.findWhere(variables, {name: row.repeat});
var variable = _.find(variables, {name: row.repeat});
if (!variable) {
return;
}
......@@ -167,7 +167,7 @@ export class DynamicDashboardSrv {
repeatPanel(panel, row) {
var variables = this.dashboard.templating.list;
var variable = _.findWhere(variables, {name: panel.repeat});
var variable = _.find(variables, {name: panel.repeat});
if (!variable) { return; }
var selected;
......
......@@ -129,7 +129,7 @@ function (angular, _, config) {
});
scope.onAppEvent('panel-fullscreen-enter', function(evt, info) {
var hasPanel = _.findWhere(scope.row.panels, {id: info.panelId});
var hasPanel = _.find(scope.row.panels, {id: info.panelId});
if (!hasPanel) {
element.hide();
}
......
......@@ -102,7 +102,7 @@ describe('given dashboard with repeated panels', function() {
});
it('should add datasource to required', function() {
var require = _.findWhere(exported.__requires, {name: 'TestDB'});
var require = _.find(exported.__requires, {name: 'TestDB'});
expect(require.name).to.be("TestDB");
expect(require.id).to.be("testdb");
expect(require.type).to.be("datasource");
......@@ -110,28 +110,28 @@ describe('given dashboard with repeated panels', function() {
});
it('should add panel to required', function() {
var require = _.findWhere(exported.__requires, {name: 'Graph'});
var require = _.find(exported.__requires, {name: 'Graph'});
expect(require.name).to.be("Graph");
expect(require.id).to.be("graph");
expect(require.version).to.be("1.1.0");
});
it('should add grafana version', function() {
var require = _.findWhere(exported.__requires, {name: 'Grafana'});
var require = _.find(exported.__requires, {name: 'Grafana'});
expect(require.type).to.be("grafana");
expect(require.id).to.be("grafana");
expect(require.version).to.be("3.0.2");
});
it('should add constant template variables as inputs', function() {
var input = _.findWhere(exported.__inputs, {name: 'VAR_PREFIX'});
var input = _.find(exported.__inputs, {name: 'VAR_PREFIX'});
expect(input.type).to.be("constant");
expect(input.label).to.be("prefix");
expect(input.value).to.be("collectd");
});
it('should templatize constant variables', function() {
var variable = _.findWhere(exported.templating.list, {name: 'prefix'});
var variable = _.find(exported.templating.list, {name: 'prefix'});
expect(variable.query).to.be("${VAR_PREFIX}");
expect(variable.current.text).to.be("${VAR_PREFIX}");
expect(variable.current.value).to.be("${VAR_PREFIX}");
......
......@@ -111,8 +111,8 @@ function(angular, _) {
this.cleanDashboardFromIgnoredChanges(current);
this.cleanDashboardFromIgnoredChanges(original);
var currentTimepicker = _.findWhere(current.nav, { type: 'timepicker' });
var originalTimepicker = _.findWhere(original.nav, { type: 'timepicker' });
var currentTimepicker = _.find(current.nav, { type: 'timepicker' });
var originalTimepicker = _.find(original.nav, { type: 'timepicker' });
if (currentTimepicker && originalTimepicker) {
currentTimepicker.now = originalTimepicker.now;
......
......@@ -77,7 +77,7 @@ export class MetricsDsSelectorCtrl {
}
datasourceChanged() {
var ds = _.findWhere(this.datasources, {name: this.dsSegment.value});
var ds = _.find(this.datasources, {name: this.dsSegment.value});
if (ds) {
this.current = ds;
this.panelCtrl.setDatasource(ds);
......
......@@ -41,7 +41,7 @@ function (angular, _) {
$scope.dashboardChanged = function(link) {
backendSrv.search({query: link.dashboard}).then(function(hits) {
var dashboard = _.findWhere(hits, {title: link.dashboard});
var dashboard = _.find(hits, {title: link.dashboard});
if (dashboard) {
link.dashUri = dashboard.uri;
link.title = dashboard.title;
......
......@@ -36,13 +36,13 @@ export class PlaylistEditCtrl {
filterFoundPlaylistItems() {
this.filteredDashboards = _.reject(this.dashboardresult, (playlistItem) => {
return _.findWhere(this.playlistItems, (listPlaylistItem) => {
return _.find(this.playlistItems, (listPlaylistItem) => {
return parseInt(listPlaylistItem.value) === playlistItem.id;
});
});
this.filteredTags = _.reject(this.tagresult, (tag) => {
return _.findWhere(this.playlistItems, (listPlaylistItem) => {
return _.find(this.playlistItems, (listPlaylistItem) => {
return listPlaylistItem.value === tag.term;
});
});
......
......@@ -81,7 +81,7 @@ export class DataSourceEditCtrl {
this.hasDashboards = false;
return this.backendSrv.get('/api/plugins/' + this.current.type + '/settings').then(pluginInfo => {
this.datasourceMeta = pluginInfo;
this.hasDashboards = _.findWhere(pluginInfo.includes, {type: 'dashboard'});
this.hasDashboards = _.find(pluginInfo.includes, {type: 'dashboard'});
});
}
......
......@@ -51,7 +51,7 @@ export class PluginEditCtrl {
this.tabIndex = 1;
this.tabs.push('Config');
this.hasDashboards = _.findWhere(result.includes, {type: 'dashboard'});
this.hasDashboards = _.find(result.includes, {type: 'dashboard'});
if (this.hasDashboards) {
this.tabs.push('Dashboards');
}
......
......@@ -24,7 +24,7 @@ export class AppPageCtrl {
initPage(app) {
this.appModel = app;
this.page = _.findWhere(app.includes, {slug: this.$routeParams.slug});
this.page = _.find(app.includes, {slug: this.$routeParams.slug});
this.appLogoUrl = app.info.logos.small;
pluginInfoCache[this.pluginId] = app;
......
......@@ -102,7 +102,7 @@ function (angular, _) {
return false;
}
var sameName = _.findWhere($scope.variables, { name: $scope.current.name });
var sameName = _.find($scope.variables, { name: $scope.current.name });
if (sameName && sameName !== $scope.current) {
$scope.appEvent('alert-warning', ['Validation', 'Variable with the same name already exists']);
return false;
......
......@@ -19,7 +19,7 @@ function (angular, _, $, kbn) {
$rootScope.onAppEvent('refresh', function() {
// look for interval variables
var intervalVariable = _.findWhere(self.variables, { type: 'interval' });
var intervalVariable = _.find(self.variables, { type: 'interval' });
if (intervalVariable) {
self.updateAutoInterval(intervalVariable);
}
......@@ -290,7 +290,7 @@ function (angular, _, $, kbn) {
return self.setVariableValue(variable, selected, false);
} else {
var currentOption = _.findWhere(variable.options, {text: variable.current.text});
var currentOption = _.find(variable.options, {text: variable.current.text});
if (currentOption) {
return self.setVariableValue(variable, currentOption, false);
} else {
......@@ -372,8 +372,8 @@ function (angular, _, $, kbn) {
options.push({text: text, value: value});
}
options = _.uniq(options, 'value');
options = _.uniq(options, 'value');
return this.sortVariableValues(options, variable.sort);
};
......
......@@ -220,7 +220,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) {
return this.performEC2DescribeInstances(region, filters, null).then(function(result) {
var attributes = _.chain(result.Reservations)
.map(function(reservations) {
return _.pluck(reservations.Instances, targetAttributeName);
return _.map(reservations.Instances, targetAttributeName);
})
.flatten().uniq().sortBy().value();
return transformSuggestData(attributes);
......
......@@ -27,7 +27,7 @@ export class ElasticConfigCtrl {
];
indexPatternTypeChanged() {
var def = _.findWhere(this.indexPatternTypes, {value: this.current.jsonData.interval});
var def = _.find(this.indexPatternTypes, {value: this.current.jsonData.interval});
this.current.database = def.example || 'es-index-name';
}
}
......
......@@ -149,7 +149,7 @@ function (_, queryDef) {
var maxDepth = target.bucketAggs.length-1;
for (aggId in aggs) {
aggDef = _.findWhere(target.bucketAggs, {id: aggId});
aggDef = _.find(target.bucketAggs, {id: aggId});
esAgg = aggs[aggId];
if (!aggDef) {
......@@ -178,9 +178,9 @@ function (_, queryDef) {
};
ElasticResponse.prototype._getMetricName = function(metric) {
var metricDef = _.findWhere(queryDef.metricAggTypes, {value: metric});
var metricDef = _.find(queryDef.metricAggTypes, {value: metric});
if (!metricDef) {
metricDef = _.findWhere(queryDef.extendedStats, {value: metric});
metricDef = _.find(queryDef.extendedStats, {value: metric});
}
return metricDef ? metricDef.text : metric;
......@@ -205,7 +205,7 @@ function (_, queryDef) {
}
if (series.field && queryDef.isPipelineAgg(series.metric)) {
var appliedAgg = _.findWhere(target.metrics, { id: series.field });
var appliedAgg = _.find(target.metrics, { id: series.field });
if (appliedAgg) {
metricName += ' ' + queryDef.describeMetric(appliedAgg);
} else {
......@@ -233,8 +233,8 @@ function (_, queryDef) {
};
ElasticResponse.prototype.nameSeries = function(seriesList, target) {
var metricTypeCount = _.uniq(_.pluck(seriesList, 'metric')).length;
var fieldNameCount = _.uniq(_.pluck(seriesList, 'field')).length;
var metricTypeCount = _.uniq(_.map(seriesList, 'metric')).length;
var fieldNameCount = _.uniq(_.map(seriesList, 'field')).length;
for (var i = 0; i < seriesList.length; i++) {
var series = seriesList[i];
......@@ -270,7 +270,7 @@ function (_, queryDef) {
};
ElasticResponse.prototype.trimDatapoints = function(aggregations, target) {
var histogram = _.findWhere(target.bucketAggs, { type: 'date_histogram'});
var histogram = _.find(target.bucketAggs, { type: 'date_histogram'});
var shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.trimEdges;
if (shouldDropFirstAndLast) {
......
......@@ -50,7 +50,7 @@ function (angular, _, queryDef) {
$scope.isFirst = $scope.index === 0;
$scope.isSingle = metricAggs.length === 1;
$scope.settingsLinkText = '';
$scope.aggDef = _.findWhere($scope.metricAggTypes, {value: $scope.agg.type});
$scope.aggDef = _.find($scope.metricAggTypes, {value: $scope.agg.type});
if (queryDef.isPipelineAgg($scope.agg.type)) {
$scope.agg.pipelineAgg = $scope.agg.pipelineAgg || 'select metric';
......@@ -86,7 +86,7 @@ function (angular, _, queryDef) {
var stats = _.reduce($scope.agg.meta, function(memo, val, key) {
if (val) {
var def = _.findWhere($scope.extendedStats, {value: key});
var def = _.find($scope.extendedStats, {value: key});
memo.push(def.text);
}
return memo;
......
......@@ -53,7 +53,7 @@ export class ElasticQueryCtrl extends QueryCtrl {
text += 'Metrics: ';
_.each(metricAggs, (metric, index) => {
var aggDef = _.findWhere(metricAggTypes, {value: metric.type});
var aggDef = _.find(metricAggTypes, {value: metric.type});
text += aggDef.text + '(';
if (aggDef.requiresField) {
text += metric.field;
......@@ -66,7 +66,7 @@ export class ElasticQueryCtrl extends QueryCtrl {
text += ' Group by: ';
}
var aggDef = _.findWhere(bucketAggTypes, {value: bucketAgg.type});
var aggDef = _.find(bucketAggTypes, {value: bucketAgg.type});
text += aggDef.text + '(';
if (aggDef.requiresField) {
text += bucketAgg.field;
......
......@@ -131,21 +131,21 @@ function (_) {
},
describeOrder: function(order) {
var def = _.findWhere(this.orderOptions, {value: order});
var def = _.find(this.orderOptions, {value: order});
return def.text;
},
describeMetric: function(metric) {
var def = _.findWhere(this.metricAggTypes, {value: metric.type});
var def = _.find(this.metricAggTypes, {value: metric.type});
return def.text + ' ' + metric.field;
},
describeOrderBy: function(orderBy, target) {
var def = _.findWhere(this.orderByOptions, {value: orderBy});
var def = _.find(this.orderByOptions, {value: orderBy});
if (def) {
return def.text;
}
var metric = _.findWhere(target.metrics, {id: orderBy});
var metric = _.find(target.metrics, {id: orderBy});
if (metric) {
return this.describeMetric(metric);
} else {
......
......@@ -112,7 +112,7 @@ class DashListCtrl extends PanelCtrl {
return Promise.resolve();
}
var dashIds = _.first(impressions.getDashboardOpened(), this.panel.limit);
var dashIds = _.take(impressions.getDashboardOpened(), this.panel.limit);
return this.backendSrv.search({dashboardIds: dashIds, limit: this.panel.limit}).then(result => {
this.groups[1].list = dashIds.map(orderId => {
return _.find(result, dashboard => {
......
......@@ -351,7 +351,7 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholdManExports) {
options.yaxes.push(defaults);
if (_.findWhere(data, {yaxis: 2})) {
if (_.find(data, {yaxis: 2})) {
var secondY = _.clone(defaults);
secondY.index = 2,
secondY.show = panel.yaxes[1].show;
......
......@@ -291,7 +291,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}
toggleAxis(info) {
var override = _.findWhere(this.panel.seriesOverrides, {alias: info.alias});
var override = _.find(this.panel.seriesOverrides, {alias: info.alias});
if (!override) {
override = { alias: info.alias };
this.panel.seriesOverrides.push(override);
......
......@@ -71,7 +71,7 @@ export class TablePanelEditorCtrl {
addColumn() {
var columns = transformers[this.panel.transform].getColumns(this.panelCtrl.dataRaw);
var column = _.findWhere(columns, {text: this.addColumnSegment.value});
var column = _.find(columns, {text: this.addColumnSegment.value});
if (column) {
this.panel.columns.push(column);
......
......@@ -8,7 +8,7 @@ System.config({
'tether-drop': 'vendor/npm/tether-drop/dist/js/drop.js',
'moment': 'vendor/moment.js',
"jquery": "vendor/jquery/dist/jquery.js",
'lodash-src': 'vendor/lodash.js',
'lodash-src': 'vendor/lodash/dist/lodash.js',
"lodash": 'app/core/lodash_extended.js',
"angular": "vendor/angular/angular.js",
"bootstrap": "vendor/bootstrap/bootstrap.js",
......
......@@ -12,14 +12,6 @@ describe("rangeUtil", () => {
expect(_.keys(groups).length).to.be(4)
expect(groups[3][0].active).to.be(true)
});
// it('should add custom options to right section', () => {
// var groups = rangeUtil.getRelativeTimesList({
// time_options: ['12m', '15d']
// }, '');
// var value = _.findWhere(groups["3"], {display: 'Last 12 minutes'});
// expect(value).to.not.be(undefined)
// });
});
describe("Can get range text described", () => {
......
......@@ -155,7 +155,7 @@ define([
this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
this.data = {};
this.replace = function(text) {
return _.template(text, this.data, this.templateSettings);
return _.template(text, this.templateSettings)(this.data);
};
this.init = function() {};
this.fillVariableValuesForUrl = function() {};
......
......@@ -15,7 +15,7 @@
'tether-drop': 'vendor/npm/tether-drop/dist/js/drop.js',
'moment': 'vendor/moment.js',
"jquery": "vendor/jquery/dist/jquery.js",
'lodash-src': 'vendor/lodash.js',
'lodash-src': 'vendor/lodash/dist/lodash.js',
"lodash": 'app/core/lodash_extended.js',
"angular": 'vendor/angular/angular.js',
'angular-mocks': 'vendor/angular-mocks/angular-mocks.js',
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment