mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactoring: moved app/controllers -> app/core/controllers
This commit is contained in:
@@ -71,7 +71,6 @@ function (angular, $, _, appLevelRequire) {
|
|||||||
var preBootRequires = [
|
var preBootRequires = [
|
||||||
'app/services/all',
|
'app/services/all',
|
||||||
'app/features/all',
|
'app/features/all',
|
||||||
'app/controllers/all',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
app.boot = function() {
|
app.boot = function() {
|
||||||
|
|||||||
@@ -1,186 +0,0 @@
|
|||||||
define([
|
|
||||||
'angular',
|
|
||||||
'lodash',
|
|
||||||
'app/core/config'
|
|
||||||
],
|
|
||||||
function (angular, _, config) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
|
||||||
|
|
||||||
module.controller('MetricKeysCtrl', function($scope, $http, $q) {
|
|
||||||
var elasticSearchUrlForMetricIndex = config.elasticsearch + '/' + config.grafana_metrics_index + '/';
|
|
||||||
var httpOptions = {};
|
|
||||||
if (config.elasticsearchBasicAuth) {
|
|
||||||
httpOptions.withCredentials = true;
|
|
||||||
httpOptions.headers = {
|
|
||||||
"Authorization": "Basic " + config.elasticsearchBasicAuth
|
|
||||||
};
|
|
||||||
}
|
|
||||||
$scope.init = function () {
|
|
||||||
$scope.metricPath = "prod.apps.api.boobarella.*";
|
|
||||||
$scope.metricCounter = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.createIndex = function () {
|
|
||||||
$scope.errorText = null;
|
|
||||||
$scope.infoText = null;
|
|
||||||
|
|
||||||
deleteIndex()
|
|
||||||
.then(createIndex)
|
|
||||||
.then(function () {
|
|
||||||
$scope.infoText = "Index created!";
|
|
||||||
})
|
|
||||||
.then(null, function (err) {
|
|
||||||
$scope.errorText = angular.toJson(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.loadMetricsFromPath = function() {
|
|
||||||
$scope.errorText = null;
|
|
||||||
$scope.infoText = null;
|
|
||||||
$scope.metricCounter = 0;
|
|
||||||
|
|
||||||
return loadMetricsRecursive($scope.metricPath)
|
|
||||||
.then(function() {
|
|
||||||
$scope.infoText = "Indexing completed!";
|
|
||||||
}, function(err) {
|
|
||||||
$scope.errorText = "Error: " + err;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.loadAll = function() {
|
|
||||||
$scope.infoText = "Fetching all metrics from graphite...";
|
|
||||||
|
|
||||||
getFromEachGraphite('/metrics/index.json', saveMetricsArray)
|
|
||||||
.then(function() {
|
|
||||||
$scope.infoText = "Indexing complete!";
|
|
||||||
}).then(null, function(err) {
|
|
||||||
$scope.errorText = err;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function getFromEachGraphite(request, data_callback, error_callback) {
|
|
||||||
return $q.all(_.map(config.datasources, function(datasource) {
|
|
||||||
if (datasource.type = 'graphite') {
|
|
||||||
return $http.get(datasource.url + request)
|
|
||||||
.then(data_callback, error_callback);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveMetricsArray(data, currentIndex) {
|
|
||||||
if (!data && !data.data && data.data.length === 0) {
|
|
||||||
return $q.reject('No metrics from graphite');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.data.length === currentIndex) {
|
|
||||||
return $q.when('done');
|
|
||||||
}
|
|
||||||
|
|
||||||
currentIndex = currentIndex || 0;
|
|
||||||
|
|
||||||
return saveMetricKey(data.data[currentIndex])
|
|
||||||
.then(function() {
|
|
||||||
return saveMetricsArray(data, currentIndex + 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteIndex()
|
|
||||||
{
|
|
||||||
var deferred = $q.defer();
|
|
||||||
$http.delete(elasticSearchUrlForMetricIndex, httpOptions)
|
|
||||||
.success(function() {
|
|
||||||
deferred.resolve('ok');
|
|
||||||
})
|
|
||||||
.error(function(data, status) {
|
|
||||||
if (status === 404) {
|
|
||||||
deferred.resolve('ok');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
deferred.reject('elastic search returned unexpected error');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createIndex()
|
|
||||||
{
|
|
||||||
return $http.put(elasticSearchUrlForMetricIndex, {
|
|
||||||
settings: {
|
|
||||||
analysis: {
|
|
||||||
analyzer: {
|
|
||||||
metric_path_ngram : { tokenizer : "my_ngram_tokenizer" }
|
|
||||||
},
|
|
||||||
tokenizer: {
|
|
||||||
my_ngram_tokenizer : {
|
|
||||||
type : "nGram",
|
|
||||||
min_gram : "3",
|
|
||||||
max_gram : "8",
|
|
||||||
token_chars: ["letter", "digit", "punctuation", "symbol"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mappings: {
|
|
||||||
metricKey: {
|
|
||||||
properties: {
|
|
||||||
metricPath: {
|
|
||||||
type: "multi_field",
|
|
||||||
fields: {
|
|
||||||
"metricPath": { type: "string", index: "analyzed", index_analyzer: "standard" },
|
|
||||||
"metricPath_ng": { type: "string", index: "analyzed", index_analyzer: "metric_path_ngram" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, httpOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
function receiveMetric(result) {
|
|
||||||
var data = result.data;
|
|
||||||
if (!data || data.length === 0) {
|
|
||||||
console.log('no data');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var funcs = _.map(data, function(metric) {
|
|
||||||
if (metric.expandable) {
|
|
||||||
return loadMetricsRecursive(metric.id + ".*");
|
|
||||||
}
|
|
||||||
if (metric.leaf) {
|
|
||||||
return saveMetricKey(metric.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $q.all(funcs);
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveMetricKey(metricId) {
|
|
||||||
|
|
||||||
// Create request with id as title. Rethink this.
|
|
||||||
var request = $scope.ejs.Document(config.grafana_metrics_index, 'metricKey', metricId).source({
|
|
||||||
metricPath: metricId
|
|
||||||
});
|
|
||||||
|
|
||||||
return request.doIndex(
|
|
||||||
function() {
|
|
||||||
$scope.infoText = "Indexing " + metricId;
|
|
||||||
$scope.metricCounter = $scope.metricCounter + 1;
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
$scope.errorText = "failed to save metric " + metricId;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadMetricsRecursive(metricPath)
|
|
||||||
{
|
|
||||||
return getFromEachGraphite('/metrics/find/?query=' + metricPath, receiveMetric);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash'
|
'../core_module',
|
||||||
],
|
],
|
||||||
function (angular) {
|
function (angular, coreModule) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('ErrorCtrl', function($scope, contextSrv) {
|
||||||
|
|
||||||
module.controller('ErrorCtrl', function($scope, contextSrv) {
|
|
||||||
|
|
||||||
var showSideMenu = contextSrv.sidemenu;
|
var showSideMenu = contextSrv.sidemenu;
|
||||||
contextSrv.sidemenu = false;
|
contextSrv.sidemenu = false;
|
||||||
@@ -2,15 +2,14 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'jquery',
|
'jquery',
|
||||||
|
'../core_module',
|
||||||
'app/core/config',
|
'app/core/config',
|
||||||
'app/core/store',
|
'app/core/store',
|
||||||
],
|
],
|
||||||
function (angular, _, $, config, store) {
|
function (angular, _, $, coreModule, config, store) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, $rootScope, $controller, contextSrv) {
|
||||||
|
|
||||||
module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, $rootScope, $controller, contextSrv) {
|
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
$scope.contextSrv = contextSrv;
|
$scope.contextSrv = contextSrv;
|
||||||
@@ -2,13 +2,12 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'jquery',
|
'jquery',
|
||||||
|
'../core_module',
|
||||||
],
|
],
|
||||||
function (angular, _, $) {
|
function (angular, _, $, coreModule) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('InspectCtrl', function($scope) {
|
||||||
|
|
||||||
module.controller('InspectCtrl', function($scope) {
|
|
||||||
var model = $scope.inspector;
|
var model = $scope.inspector;
|
||||||
|
|
||||||
function getParametersFromQueryString(queryString) {
|
function getParametersFromQueryString(queryString) {
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
|
'../core_module',
|
||||||
'app/core/config',
|
'app/core/config',
|
||||||
],
|
],
|
||||||
function (angular, config) {
|
function (angular, coreModule, config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('InvitedCtrl', function($scope, $routeParams, contextSrv, backendSrv) {
|
||||||
|
|
||||||
module.controller('InvitedCtrl', function($scope, $routeParams, contextSrv, backendSrv) {
|
|
||||||
|
|
||||||
contextSrv.sidemenu = false;
|
contextSrv.sidemenu = false;
|
||||||
|
|
||||||
$scope.formModel = {};
|
$scope.formModel = {};
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash'
|
'../core_module',
|
||||||
],
|
],
|
||||||
function (angular) {
|
function (angular, coreModule) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('JsonEditorCtrl', function($scope) {
|
||||||
|
|
||||||
module.controller('JsonEditorCtrl', function($scope) {
|
|
||||||
|
|
||||||
$scope.json = angular.toJson($scope.object, true);
|
$scope.json = angular.toJson($scope.object, true);
|
||||||
$scope.canUpdate = $scope.updateHandler !== void 0;
|
$scope.canUpdate = $scope.updateHandler !== void 0;
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
|
'../core_module',
|
||||||
'app/core/config',
|
'app/core/config',
|
||||||
],
|
],
|
||||||
function (angular, config) {
|
function (angular, coreModule, config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('LoginCtrl', function($scope, backendSrv, contextSrv, $location) {
|
||||||
|
|
||||||
module.controller('LoginCtrl', function($scope, backendSrv, contextSrv, $location) {
|
|
||||||
$scope.formModel = {
|
$scope.formModel = {
|
||||||
user: '',
|
user: '',
|
||||||
email: '',
|
email: '',
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
|
'../core_module',
|
||||||
],
|
],
|
||||||
function (angular) {
|
function (angular, coreModule) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('ResetPasswordCtrl', function($scope, contextSrv, backendSrv, $location) {
|
||||||
|
|
||||||
module.controller('ResetPasswordCtrl', function($scope, contextSrv, backendSrv, $location) {
|
|
||||||
|
|
||||||
contextSrv.sidemenu = false;
|
contextSrv.sidemenu = false;
|
||||||
$scope.formModel = {};
|
$scope.formModel = {};
|
||||||
$scope.mode = 'send';
|
$scope.mode = 'send';
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
|
'../core_module',
|
||||||
'app/core/config',
|
'app/core/config',
|
||||||
],
|
],
|
||||||
function (angular, _, config) {
|
function (angular, _, coreModule, config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('SearchCtrl', function($scope, $location, $timeout, backendSrv) {
|
||||||
|
|
||||||
module.controller('SearchCtrl', function($scope, $location, $timeout, backendSrv) {
|
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
$scope.giveSearchFocus = 0;
|
$scope.giveSearchFocus = 0;
|
||||||
@@ -2,14 +2,13 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'jquery',
|
'jquery',
|
||||||
|
'../core_module',
|
||||||
'app/core/config',
|
'app/core/config',
|
||||||
],
|
],
|
||||||
function (angular, _, $, config) {
|
function (angular, _, $, coreModule, config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
coreModule.controller('SideMenuCtrl', function($scope, $location, contextSrv, backendSrv) {
|
||||||
|
|
||||||
module.controller('SideMenuCtrl', function($scope, $location, contextSrv, backendSrv) {
|
|
||||||
|
|
||||||
$scope.getUrl = function(url) {
|
$scope.getUrl = function(url) {
|
||||||
return config.appSubUrl + url;
|
return config.appSubUrl + url;
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
///<reference path="../headers/common.d.ts" />
|
///<reference path="../../headers/common.d.ts" />
|
||||||
|
|
||||||
import angular = require('angular');
|
import angular = require('angular');
|
||||||
import config = require('app/core/config');
|
import config = require('app/core/config');
|
||||||
|
import coreModule = require('../core_module');
|
||||||
var module = angular.module('grafana.controllers');
|
|
||||||
|
|
||||||
export class SignUpCtrl {
|
export class SignUpCtrl {
|
||||||
|
|
||||||
@@ -48,5 +47,5 @@ export class SignUpCtrl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.controller('SignUpCtrl', SignUpCtrl);
|
coreModule.controller('SignUpCtrl', SignUpCtrl);
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
///<amd-dependency path="./directives/value_select_dropdown" />
|
///<amd-dependency path="./directives/value_select_dropdown" />
|
||||||
///<amd-dependency path="./routes/all" />
|
///<amd-dependency path="./routes/all" />
|
||||||
|
|
||||||
|
///<amd-dependency path="./controllers/all" />
|
||||||
///<amd-dependency path="./jquery_extended" />
|
///<amd-dependency path="./jquery_extended" />
|
||||||
///<amd-dependency path="./partials" />
|
///<amd-dependency path="./partials" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user