Browse Source

refactoring: moved app/controllers -> app/core/controllers

Torkel Ödegaard 10 years ago
parent
commit
152b484eb5

+ 0 - 1
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() {

+ 0 - 186
public/app/controllers/metricKeys.js

@@ -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);
-    }
-
-  });
-
-});

+ 0 - 0
public/app/controllers/all.js → public/app/core/controllers/all.js


+ 3 - 5
public/app/controllers/errorCtrl.js → 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;

+ 3 - 4
public/app/controllers/grafanaCtrl.js → 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;

+ 3 - 4
public/app/controllers/inspectCtrl.js → 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) {

+ 3 - 6
public/app/controllers/invitedCtrl.js → 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() {

+ 3 - 5
public/app/controllers/jsonEditorCtrl.js → 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;

+ 3 - 4
public/app/controllers/loginCtrl.js → 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: '',

+ 3 - 5
public/app/controllers/resetPasswordCtrl.js → 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';

+ 3 - 4
public/app/controllers/search.js → 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;

+ 3 - 4
public/app/controllers/sidemenuCtrl.js → 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;

+ 3 - 4
public/app/controllers/signupCtrl.ts → public/app/core/controllers/signupCtrl.ts

@@ -1,9 +1,8 @@
-///<reference path="../headers/common.d.ts" />
+///<reference path="../../headers/common.d.ts" />
 
 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);
 

+ 1 - 0
public/app/core/core.ts

@@ -16,6 +16,7 @@
 ///<amd-dependency path="./directives/value_select_dropdown" />
 ///<amd-dependency path="./routes/all" />
 
+///<amd-dependency path="./controllers/all" />
 ///<amd-dependency path="./jquery_extended" />
 ///<amd-dependency path="./partials" />