Replace native map() and forEach() methods by lodash.

This commit is contained in:
Alexander Zobnin
2017-03-05 10:09:47 +03:00
parent 24b63f89aa
commit 5192e8648d
16 changed files with 36 additions and 19 deletions

View File

@@ -226,12 +226,12 @@ System.register(['lodash', './utils'], function (_export, _context) {
return nearestLeft;
}function timeShift(interval, range) {
var shift = utils.parseTimeShiftInterval(interval) / 1000;
return range.map(function (time) {
return _.map(range, function (time) {
return time - shift;
});
}function unShiftTimeSeries(interval, datapoints) {
var unshift = utils.parseTimeShiftInterval(interval);
return datapoints.map(function (dp) {
return _.map(datapoints, function (dp) {
return [dp[0], dp[1] + unshift];
});
}return {

File diff suppressed because one or more lines are too long

View File

@@ -311,6 +311,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
return getHistoryPromise.then(function (timeseries_data) {
return _this2.applyDataProcessingFunctions(timeseries_data, target);
});
}).catch(function (error) {
console.log(error);
return [];
});
}
}, {
@@ -558,7 +561,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
var _this7 = this;
var parts = ['group', 'host', 'application', 'item'];
parts.forEach(function (p) {
_.forEach(parts, function (p) {
if (target[p] && target[p].filter) {
target[p].filter = _this7.replaceTemplateVars(target[p].filter, options.scopedVars);
}
@@ -566,7 +569,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
_.forEach(target.functions, function (func) {
func.params = func.params.map(function (param) {
func.params = _.map(func.params, function (param) {
if (typeof param === 'number') {
return +_this7.templateSrv.replace(param.toString(), options.scopedVars);
} else {

File diff suppressed because one or more lines are too long

View File

@@ -169,7 +169,7 @@ System.register(['angular', 'lodash', './utils', './zabbixAPICore.service'], fun
return this.request('item.get', params).then(expandItems);
function expandItems(items) {
items.forEach(function (item) {
_.forEach(items, function (item) {
item.item = item.name;
item.name = utils.expandItemName(item.item, item.key_);
return item;

File diff suppressed because one or more lines are too long

View File

@@ -100,6 +100,8 @@ System.register(['angular'], function (_export, _context) {
// Success
return response.data.result;
}).catch(function () {
return Promise.reject(new ZabbixAPIError({ data: "Connection Error" }));
});
}
}, {

File diff suppressed because one or more lines are too long

View File

@@ -275,14 +275,14 @@ function findNearestLeft(series, point) {
function timeShift(interval, range) {
var shift = utils.parseTimeShiftInterval(interval) / 1000;
return range.map(function (time) {
return _lodash2.default.map(range, function (time) {
return time - shift;
});
}
function unShiftTimeSeries(interval, datapoints) {
var unshift = utils.parseTimeShiftInterval(interval);
return datapoints.map(function (dp) {
return _lodash2.default.map(datapoints, function (dp) {
return [dp[0], dp[1] + unshift];
});
}

View File

@@ -186,6 +186,9 @@ var ZabbixAPIDatasource = function () {
return getHistoryPromise.then(function (timeseries_data) {
return _this2.applyDataProcessingFunctions(timeseries_data, target);
});
}).catch(function (error) {
console.log(error);
return [];
});
}
}, {
@@ -460,7 +463,7 @@ var ZabbixAPIDatasource = function () {
var _this7 = this;
var parts = ['group', 'host', 'application', 'item'];
parts.forEach(function (p) {
_lodash2.default.forEach(parts, function (p) {
if (target[p] && target[p].filter) {
target[p].filter = _this7.replaceTemplateVars(target[p].filter, options.scopedVars);
}
@@ -468,7 +471,7 @@ var ZabbixAPIDatasource = function () {
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
_lodash2.default.forEach(target.functions, function (func) {
func.params = func.params.map(function (param) {
func.params = _lodash2.default.map(func.params, function (param) {
if (typeof param === 'number') {
return +_this7.templateSrv.replace(param.toString(), options.scopedVars);
} else {

View File

@@ -218,7 +218,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
return this.request('item.get', params).then(expandItems);
function expandItems(items) {
items.forEach(function (item) {
_lodash2.default.forEach(items, function (item) {
item.item = item.name;
item.name = utils.expandItemName(item.item, item.key_);
return item;

View File

@@ -83,6 +83,8 @@ var ZabbixAPICoreService = function () {
// Success
return response.data.result;
}).catch(function () {
return Promise.reject(new ZabbixAPIError({ data: "Connection Error" }));
});
}

View File

@@ -265,14 +265,14 @@ function findNearestLeft(series, point) {
function timeShift(interval, range) {
let shift = utils.parseTimeShiftInterval(interval) / 1000;
return range.map(time => {
return _.map(range, time => {
return time - shift;
});
}
function unShiftTimeSeries(interval, datapoints) {
let unshift = utils.parseTimeShiftInterval(interval);
return datapoints.map(dp => {
return _.map(datapoints, dp => {
return [
dp[0],
dp[1] + unshift

View File

@@ -137,6 +137,10 @@ class ZabbixAPIDatasource {
return getHistoryPromise.then(timeseries_data => {
return this.applyDataProcessingFunctions(timeseries_data, target);
});
})
.catch(error => {
console.log(error);
return [];
});
}
@@ -393,7 +397,7 @@ class ZabbixAPIDatasource {
// Replace template variables
replaceTargetVariables(target, options) {
let parts = ['group', 'host', 'application', 'item'];
parts.forEach(p => {
_.forEach(parts, p => {
if (target[p] && target[p].filter) {
target[p].filter = this.replaceTemplateVars(target[p].filter, options.scopedVars);
}
@@ -401,7 +405,7 @@ class ZabbixAPIDatasource {
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
_.forEach(target.functions, func => {
func.params = func.params.map(param => {
func.params = _.map(func.params, param => {
if (typeof param === 'number') {
return +this.templateSrv.replace(param.toString(), options.scopedVars);
} else {

View File

@@ -189,7 +189,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
.then(expandItems);
function expandItems(items) {
items.forEach(item => {
_.forEach(items, item => {
item.item = item.name;
item.name = utils.expandItemName(item.item, item.key_);
return item;

View File

@@ -64,6 +64,9 @@ class ZabbixAPICoreService {
// Success
return response.data.result;
})
.catch(() => {
return Promise.reject(new ZabbixAPIError({data: "Connection Error"}));
});
}