Refactoring - reformat code.

This commit is contained in:
Alexander Zobnin
2015-07-25 18:48:08 +03:00
parent f53ebaa9fc
commit 9855c05f64

View File

@@ -2,16 +2,16 @@ define([
'angular', 'angular',
'lodash', 'lodash',
'./helperFunctions' './helperFunctions'
], ],
function (angular, _) { function (angular, _) {
'use strict'; 'use strict';
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');
var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
module.controller('ZabbixAPIQueryCtrl', function($scope, $sce, templateSrv, zabbixHelperSrv) { module.controller('ZabbixAPIQueryCtrl', function ($scope, $sce, templateSrv, zabbixHelperSrv) {
$scope.init = function() { $scope.init = function () {
$scope.targetLetters = targetLetters; $scope.targetLetters = targetLetters;
if ($scope.target.ITService) { if ($scope.target.ITService) {
$scope.slaPropertyList = [ $scope.slaPropertyList = [
@@ -42,7 +42,7 @@ function (angular, _) {
$scope.target.errors = validateTarget($scope.target); $scope.target.errors = validateTarget($scope.target);
}; };
$scope.switchEditorMode = function() { $scope.switchEditorMode = function () {
$scope.target.ITService = !$scope.target.ITService; $scope.target.ITService = !$scope.target.ITService;
$scope.init(); $scope.init();
}; };
@@ -56,7 +56,7 @@ function (angular, _) {
} }
} }
$scope.targetBlur = function() { $scope.targetBlur = function () {
setItemAlias(); setItemAlias();
$scope.target.errors = validateTarget($scope.target); $scope.target.errors = validateTarget($scope.target);
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) { if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
@@ -68,7 +68,7 @@ function (angular, _) {
/** /**
* Call when IT service is selected. * Call when IT service is selected.
*/ */
$scope.selectITService = function() { $scope.selectITService = function () {
$scope.target.errors = validateTarget($scope.target); $scope.target.errors = validateTarget($scope.target);
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) { if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
$scope.oldTarget = angular.copy($scope.target); $scope.oldTarget = angular.copy($scope.target);
@@ -79,7 +79,7 @@ function (angular, _) {
/** /**
* Call when host group selected * Call when host group selected
*/ */
$scope.selectHostGroup = function() { $scope.selectHostGroup = function () {
$scope.updateHostList(); $scope.updateHostList();
$scope.updateAppList(); $scope.updateAppList();
$scope.updateItemList(); $scope.updateItemList();
@@ -94,7 +94,7 @@ function (angular, _) {
/** /**
* Call when host selected * Call when host selected
*/ */
$scope.selectHost = function() { $scope.selectHost = function () {
$scope.updateAppList(); $scope.updateAppList();
$scope.updateItemList(); $scope.updateItemList();
@@ -108,7 +108,7 @@ function (angular, _) {
/** /**
* Call when application selected * Call when application selected
*/ */
$scope.selectApplication = function() { $scope.selectApplication = function () {
$scope.updateItemList(); $scope.updateItemList();
$scope.target.errors = validateTarget($scope.target); $scope.target.errors = validateTarget($scope.target);
@@ -121,7 +121,7 @@ function (angular, _) {
/** /**
* Call when item selected * Call when item selected
*/ */
$scope.selectItem = function() { $scope.selectItem = function () {
setItemAlias(); setItemAlias();
$scope.target.errors = validateTarget($scope.target); $scope.target.errors = validateTarget($scope.target);
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) { if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
@@ -130,12 +130,12 @@ function (angular, _) {
} }
}; };
$scope.duplicate = function() { $scope.duplicate = function () {
var clone = angular.copy($scope.target); var clone = angular.copy($scope.target);
$scope.panel.targets.push(clone); $scope.panel.targets.push(clone);
}; };
$scope.moveMetricQuery = function(fromIndex, toIndex) { $scope.moveMetricQuery = function (fromIndex, toIndex) {
_.move($scope.panel.targets, fromIndex, toIndex); _.move($scope.panel.targets, fromIndex, toIndex);
}; };
@@ -143,11 +143,10 @@ function (angular, _) {
// SUGGESTION QUERIES // SUGGESTION QUERIES
////////////////////////////// //////////////////////////////
/** /**
* Update list of IT services * Update list of IT services
*/ */
$scope.updateITServiceList = function() { $scope.updateITServiceList = function () {
$scope.datasource.zabbixAPI.getITService().then(function (iteservices) { $scope.datasource.zabbixAPI.getITService().then(function (iteservices) {
$scope.itserviceList = []; $scope.itserviceList = [];
$scope.itserviceList = $scope.itserviceList.concat(iteservices); $scope.itserviceList = $scope.itserviceList.concat(iteservices);
@@ -157,7 +156,7 @@ function (angular, _) {
/** /**
* Update list of host groups * Update list of host groups
*/ */
$scope.updateGroupList = function() { $scope.updateGroupList = function () {
$scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) { $scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
$scope.metric.groupList = [{name: '*', visible_name: 'All'}]; $scope.metric.groupList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.groupList); addTemplatedVariables($scope.metric.groupList);
@@ -168,7 +167,7 @@ function (angular, _) {
/** /**
* Update list of hosts * Update list of hosts
*/ */
$scope.updateHostList = function() { $scope.updateHostList = function () {
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
if (groups) { if (groups) {
$scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) { $scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) {
@@ -182,7 +181,7 @@ function (angular, _) {
/** /**
* Update list of host applications * Update list of host applications
*/ */
$scope.updateAppList = function() { $scope.updateAppList = function () {
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined; var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
if (groups && hosts) { if (groups && hosts) {
@@ -200,7 +199,7 @@ function (angular, _) {
/** /**
* Update list of items * Update list of items
*/ */
$scope.updateItemList = function() { $scope.updateItemList = function () {
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined; var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
var apps = $scope.target.application ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined; var apps = $scope.target.application ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
@@ -225,7 +224,7 @@ function (angular, _) {
* @param {Array} metricList List of metrics which variables add to * @param {Array} metricList List of metrics which variables add to
*/ */
function addTemplatedVariables(metricList) { function addTemplatedVariables(metricList) {
_.each(templateSrv.variables, function(variable) { _.each(templateSrv.variables, function (variable) {
metricList.push({ metricList.push({
name: '$' + variable.name, name: '$' + variable.name,
templated: true templated: true
@@ -247,4 +246,4 @@ function (angular, _) {
}); });
}); });