From 152b484eb5e97a5f966c38cc36390f6a4c85b8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 30 Oct 2015 15:16:05 +0100 Subject: [PATCH] refactoring: moved app/controllers -> app/core/controllers --- public/app/app.js | 1 - public/app/controllers/metricKeys.js | 186 ------------------ public/app/{ => core}/controllers/all.js | 0 .../app/{ => core}/controllers/errorCtrl.js | 8 +- .../app/{ => core}/controllers/grafanaCtrl.js | 7 +- .../app/{ => core}/controllers/inspectCtrl.js | 7 +- .../app/{ => core}/controllers/invitedCtrl.js | 9 +- .../{ => core}/controllers/jsonEditorCtrl.js | 8 +- .../app/{ => core}/controllers/loginCtrl.js | 7 +- .../controllers/resetPasswordCtrl.js | 8 +- public/app/{ => core}/controllers/search.js | 7 +- .../{ => core}/controllers/sidemenuCtrl.js | 7 +- .../app/{ => core}/controllers/signupCtrl.ts | 7 +- public/app/core/core.ts | 1 + 14 files changed, 31 insertions(+), 232 deletions(-) delete mode 100644 public/app/controllers/metricKeys.js rename public/app/{ => core}/controllers/all.js (100%) rename public/app/{ => core}/controllers/errorCtrl.js (60%) rename public/app/{ => core}/controllers/grafanaCtrl.js (95%) rename public/app/{ => core}/controllers/inspectCtrl.js (92%) rename public/app/{ => core}/controllers/invitedCtrl.js (82%) rename public/app/{ => core}/controllers/jsonEditorCtrl.js (68%) rename public/app/{ => core}/controllers/loginCtrl.js (92%) rename public/app/{ => core}/controllers/resetPasswordCtrl.js (84%) rename public/app/{ => core}/controllers/search.js (95%) rename public/app/{ => core}/controllers/sidemenuCtrl.js (94%) rename public/app/{ => core}/controllers/signupCtrl.ts (89%) diff --git a/public/app/app.js b/public/app/app.js index b15bb43ddf5..6ffc95cb4f0 100644 --- a/public/app/app.js +++ b/public/app/app.js @@ -71,7 +71,6 @@ function (angular, $, _, appLevelRequire) { var preBootRequires = [ 'app/services/all', 'app/features/all', - 'app/controllers/all', ]; app.boot = function() { diff --git a/public/app/controllers/metricKeys.js b/public/app/controllers/metricKeys.js deleted file mode 100644 index ac8dffdcdf7..00000000000 --- a/public/app/controllers/metricKeys.js +++ /dev/null @@ -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); - } - - }); - -}); diff --git a/public/app/controllers/all.js b/public/app/core/controllers/all.js similarity index 100% rename from public/app/controllers/all.js rename to public/app/core/controllers/all.js diff --git a/public/app/controllers/errorCtrl.js b/public/app/core/controllers/errorCtrl.js similarity index 60% rename from public/app/controllers/errorCtrl.js rename to public/app/core/controllers/errorCtrl.js index 13b64584226..9816928fa6c 100644 --- a/public/app/controllers/errorCtrl.js +++ b/public/app/core/controllers/errorCtrl.js @@ -1,13 +1,11 @@ define([ 'angular', - 'lodash' + '../core_module', ], -function (angular) { +function (angular, coreModule) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('ErrorCtrl', function($scope, contextSrv) { + coreModule.controller('ErrorCtrl', function($scope, contextSrv) { var showSideMenu = contextSrv.sidemenu; contextSrv.sidemenu = false; diff --git a/public/app/controllers/grafanaCtrl.js b/public/app/core/controllers/grafanaCtrl.js similarity index 95% rename from public/app/controllers/grafanaCtrl.js rename to public/app/core/controllers/grafanaCtrl.js index 42a67064e29..baafd15938e 100644 --- a/public/app/controllers/grafanaCtrl.js +++ b/public/app/core/controllers/grafanaCtrl.js @@ -2,15 +2,14 @@ define([ 'angular', 'lodash', 'jquery', + '../core_module', 'app/core/config', 'app/core/store', ], -function (angular, _, $, config, store) { +function (angular, _, $, coreModule, config, store) { "use strict"; - var module = angular.module('grafana.controllers'); - - module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, $rootScope, $controller, contextSrv) { + coreModule.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, $rootScope, $controller, contextSrv) { $scope.init = function() { $scope.contextSrv = contextSrv; diff --git a/public/app/controllers/inspectCtrl.js b/public/app/core/controllers/inspectCtrl.js similarity index 92% rename from public/app/controllers/inspectCtrl.js rename to public/app/core/controllers/inspectCtrl.js index e70a88323e9..81cfaf64a85 100644 --- a/public/app/controllers/inspectCtrl.js +++ b/public/app/core/controllers/inspectCtrl.js @@ -2,13 +2,12 @@ define([ 'angular', 'lodash', 'jquery', + '../core_module', ], -function (angular, _, $) { +function (angular, _, $, coreModule) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('InspectCtrl', function($scope) { + coreModule.controller('InspectCtrl', function($scope) { var model = $scope.inspector; function getParametersFromQueryString(queryString) { diff --git a/public/app/controllers/invitedCtrl.js b/public/app/core/controllers/invitedCtrl.js similarity index 82% rename from public/app/controllers/invitedCtrl.js rename to public/app/core/controllers/invitedCtrl.js index 42443c4370f..540cb01ca1c 100644 --- a/public/app/controllers/invitedCtrl.js +++ b/public/app/core/controllers/invitedCtrl.js @@ -1,16 +1,13 @@ define([ 'angular', + '../core_module', 'app/core/config', ], -function (angular, config) { +function (angular, coreModule, config) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('InvitedCtrl', function($scope, $routeParams, contextSrv, backendSrv) { - + coreModule.controller('InvitedCtrl', function($scope, $routeParams, contextSrv, backendSrv) { contextSrv.sidemenu = false; - $scope.formModel = {}; $scope.init = function() { diff --git a/public/app/controllers/jsonEditorCtrl.js b/public/app/core/controllers/jsonEditorCtrl.js similarity index 68% rename from public/app/controllers/jsonEditorCtrl.js rename to public/app/core/controllers/jsonEditorCtrl.js index 60bda8514b7..0bfd5fcfb05 100644 --- a/public/app/controllers/jsonEditorCtrl.js +++ b/public/app/core/controllers/jsonEditorCtrl.js @@ -1,13 +1,11 @@ define([ 'angular', - 'lodash' + '../core_module', ], -function (angular) { +function (angular, coreModule) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('JsonEditorCtrl', function($scope) { + coreModule.controller('JsonEditorCtrl', function($scope) { $scope.json = angular.toJson($scope.object, true); $scope.canUpdate = $scope.updateHandler !== void 0; diff --git a/public/app/controllers/loginCtrl.js b/public/app/core/controllers/loginCtrl.js similarity index 92% rename from public/app/controllers/loginCtrl.js rename to public/app/core/controllers/loginCtrl.js index 7ec2c4353fd..22cb2c6f04b 100644 --- a/public/app/controllers/loginCtrl.js +++ b/public/app/core/controllers/loginCtrl.js @@ -1,13 +1,12 @@ define([ 'angular', + '../core_module', 'app/core/config', ], -function (angular, config) { +function (angular, coreModule, config) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('LoginCtrl', function($scope, backendSrv, contextSrv, $location) { + coreModule.controller('LoginCtrl', function($scope, backendSrv, contextSrv, $location) { $scope.formModel = { user: '', email: '', diff --git a/public/app/controllers/resetPasswordCtrl.js b/public/app/core/controllers/resetPasswordCtrl.js similarity index 84% rename from public/app/controllers/resetPasswordCtrl.js rename to public/app/core/controllers/resetPasswordCtrl.js index ed693f0d45a..d414b059458 100644 --- a/public/app/controllers/resetPasswordCtrl.js +++ b/public/app/core/controllers/resetPasswordCtrl.js @@ -1,13 +1,11 @@ define([ 'angular', + '../core_module', ], -function (angular) { +function (angular, coreModule) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('ResetPasswordCtrl', function($scope, contextSrv, backendSrv, $location) { - + coreModule.controller('ResetPasswordCtrl', function($scope, contextSrv, backendSrv, $location) { contextSrv.sidemenu = false; $scope.formModel = {}; $scope.mode = 'send'; diff --git a/public/app/controllers/search.js b/public/app/core/controllers/search.js similarity index 95% rename from public/app/controllers/search.js rename to public/app/core/controllers/search.js index cbae6366244..bbf869b9f38 100644 --- a/public/app/controllers/search.js +++ b/public/app/core/controllers/search.js @@ -1,14 +1,13 @@ define([ 'angular', 'lodash', + '../core_module', 'app/core/config', ], -function (angular, _, config) { +function (angular, _, coreModule, config) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('SearchCtrl', function($scope, $location, $timeout, backendSrv) { + coreModule.controller('SearchCtrl', function($scope, $location, $timeout, backendSrv) { $scope.init = function() { $scope.giveSearchFocus = 0; diff --git a/public/app/controllers/sidemenuCtrl.js b/public/app/core/controllers/sidemenuCtrl.js similarity index 94% rename from public/app/controllers/sidemenuCtrl.js rename to public/app/core/controllers/sidemenuCtrl.js index 7fe8a5036b4..c2ee868323f 100644 --- a/public/app/controllers/sidemenuCtrl.js +++ b/public/app/core/controllers/sidemenuCtrl.js @@ -2,14 +2,13 @@ define([ 'angular', 'lodash', 'jquery', + '../core_module', 'app/core/config', ], -function (angular, _, $, config) { +function (angular, _, $, coreModule, config) { 'use strict'; - var module = angular.module('grafana.controllers'); - - module.controller('SideMenuCtrl', function($scope, $location, contextSrv, backendSrv) { + coreModule.controller('SideMenuCtrl', function($scope, $location, contextSrv, backendSrv) { $scope.getUrl = function(url) { return config.appSubUrl + url; diff --git a/public/app/controllers/signupCtrl.ts b/public/app/core/controllers/signupCtrl.ts similarity index 89% rename from public/app/controllers/signupCtrl.ts rename to public/app/core/controllers/signupCtrl.ts index bda332f664d..9c18b121612 100644 --- a/public/app/controllers/signupCtrl.ts +++ b/public/app/core/controllers/signupCtrl.ts @@ -1,9 +1,8 @@ -/// +/// import angular = require('angular'); import config = require('app/core/config'); - -var module = angular.module('grafana.controllers'); +import coreModule = require('../core_module'); export class SignUpCtrl { @@ -48,5 +47,5 @@ export class SignUpCtrl { }; } -module.controller('SignUpCtrl', SignUpCtrl); +coreModule.controller('SignUpCtrl', SignUpCtrl); diff --git a/public/app/core/core.ts b/public/app/core/core.ts index 6c9d0cea958..1d4683b0ce7 100644 --- a/public/app/core/core.ts +++ b/public/app/core/core.ts @@ -16,6 +16,7 @@ /// /// +/// /// ///