Commit 9e2f76fa authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

added js linter

parent eb81642c
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -51,7 +51,12 @@ module.exports = function(grunt) {
    jshint: {
      cerebro: {
        src: [

          'src/common/*.js',
          'src/controllers/*.js',
          'src/directives/*.js',
          'src/filters/*.js',
          'src/services/*.js',
          'src/stats/*.js',
        ]
      }
    },
@@ -60,6 +65,20 @@ module.exports = function(grunt) {
    },
    karma: {
      unit: {configFile: 'tests/karma.config.js', keepalive: true}
    },
    jscs: {
      src: [
        'src/common/*.js',
        'src/controllers/*.js',
        'src/directives/*.js',
        'src/filters/*.js',
        'src/services/*.js',
        'src/stats/*.js',
      ],
      options: {
        preset: 'google',
        requireCamelCaseOrUpperCaseIdentifiers: "ignoreProperties"
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-clean');
@@ -73,6 +92,6 @@ module.exports = function(grunt) {
  grunt.loadNpmTasks("grunt-jscs");
  grunt.registerTask('dev', ['watch'])
  grunt.registerTask('build',
      ['clean', 'copy', 'concat', 'qunit' ]);
      ['clean', 'jshint', 'jscs', 'concat', 'copy', 'qunit' ]);
  grunt.registerTask('test', ['karma'])
};
+692 −648
Original line number Diff line number Diff line
@@ -399,7 +399,8 @@ function URLAutocomplete(mappings) {
              valid = Object.keys(mappings).indexOf(pathTokens[index]) >= 0;
              break;
            case '{type}':
                            valid = mappings[pathTokens[index - 1]]["types"].indexOf(pathTokens[index]) >= 0;
              var types = mappings[pathTokens[index - 1]].types;
              valid = types.indexOf(pathTokens[index]) >= 0;
              break;
            default:
              valid = pathTokens[index] === token;
@@ -434,7 +435,7 @@ function URLAutocomplete(mappings) {
            break;
          case '{type}':
            var pathIndex = pathTokens[suggestedTokenIndex - 1];
                        mappings[pathIndex]["types"].forEach(function(type) {
            mappings[pathIndex].types.forEach(function(type) {
              addIfNotPresent(alternatives, format(pathTokens, type));
            });
            break;
@@ -453,8 +454,8 @@ function URLAutocomplete(mappings) {

}

angular.module('cerebro').controller('AlertsController', ['$scope', 'AlertService',
  function($scope, AlertService) {
angular.module('cerebro').controller('AlertsController', ['$scope',
  'AlertService', function($scope, AlertService) {

    $scope.alerts = [];

@@ -485,6 +486,12 @@ angular.module('cerebro').controller('ConnectController', [

    $scope.host = undefined;

    $scope.username = undefined;

    $scope.password = undefined;

    $scope.showAuth = false;

    DataService.getHosts(
      function(hosts) {
        $scope.hosts = hosts;
@@ -499,13 +506,15 @@ angular.module('cerebro').controller('ConnectController', [
        $scope.connecting = true;
        DataService.setHost(
          host,
          $scope.username,
          $scope.password,
          function(response) {
              $location.path("/overview");
            $location.path('/overview');
            $scope.host = DataService.getHost();
          },
          function(response) {
            $scope.connecting = false;
              AlertService.error("Error connecting to " + host, response);
            AlertService.error('Error connecting to ' + host, response);
          }
        );
      }
@@ -513,8 +522,8 @@ angular.module('cerebro').controller('ConnectController', [

  }]);

angular.module('cerebro').controller('ModalController', ['$scope', 'ModalService',
  function($scope, ModalService) {
angular.module('cerebro').controller('ModalController', ['$scope',
  'ModalService', function($scope, ModalService) {

    $scope.service = ModalService;

@@ -529,7 +538,8 @@ angular.module('cerebro').controller('ModalController', ['$scope', 'ModalService
  }
]);

angular.module('cerebro').controller('NavbarController', ['$scope', '$http', 'PageService', 'DataService',
angular.module('cerebro').controller('NavbarController', ['$scope', '$http',
  'PageService', 'DataService',
  function($scope, $http, PageService, DataService) {

    $scope.status = undefined;
@@ -553,9 +563,11 @@ angular.module('cerebro').controller('NavbarController', ['$scope', '$http', 'Pa
      }
    );

  }]);
  }]
);

angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '$window', 'DataService', 'AlertService', 'ModalService',
angular.module('cerebro').controller('OverviewController', ['$scope', '$http',
  '$window', 'DataService', 'AlertService', 'ModalService',
  function($scope, $http, $window, DataService, AlertService, ModalService) {

    $scope.indices = undefined;
@@ -573,7 +585,12 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      return Math.max(Math.round($window.innerWidth / 280), 1);
    };

    $scope.paginator = new Paginator(1, $scope.getPageSize(), [], $scope.indices_filter);
    $scope.paginator = new Paginator(
      1,
      $scope.getPageSize(),
      [],
      $scope.indices_filter)
    ;

    $scope.page = $scope.paginator.getPage();

@@ -706,7 +723,7 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      ModalService.promptConfirmation(
        'Close all ' + indices.length + ' selected indices?',
        function() {
            DataService.closeIndex(indices.join(","), success, error);
          DataService.closeIndex(indices.join(','), success, error);
        }
      );
    };
@@ -718,7 +735,7 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      ModalService.promptConfirmation(
        'Open all ' + indices.length + ' selected indices?',
        function() {
            DataService.openIndex(indices.join(","), success, error);
          DataService.openIndex(indices.join(','), success, error);
        }
      );
    };
@@ -730,7 +747,7 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      ModalService.promptConfirmation(
        'Optimize all ' + indices.length + ' selected indices?',
        function() {
            DataService.optimizeIndex(indices.join(","), success, error);
          DataService.optimizeIndex(indices.join(','), success, error);
        }
      );
    };
@@ -742,7 +759,7 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      ModalService.promptConfirmation(
        'Refresh all ' + indices.length + ' selected indices?',
        function() {
            DataService.refreshIndex(indices.join(","), success, error);
          DataService.refreshIndex(indices.join(','), success, error);
        }
      );
    };
@@ -754,7 +771,7 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      ModalService.promptConfirmation(
        'Clear all ' + indices.length + ' selected indices cache?',
        function() {
            DataService.clearIndexCache(indices.join(","), success, error);
          DataService.clearIndexCache(indices.join(','), success, error);
        }
      );
    };
@@ -766,7 +783,7 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '
      ModalService.promptConfirmation(
        'Delete all ' + indices.length + ' selected indices?',
        function() {
            DataService.deleteIndex(indices.join(","), success, error);
          DataService.deleteIndex(indices.join(','), success, error);
        }
      );
    };
@@ -797,17 +814,18 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', '

  }]);

angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService',
    'ModalService', 'AceEditorService',
    function ($scope, $http, $sce, DataService, AlertService, ModalService, AceEditorService) {
angular.module('cerebro').controller('RestController', ['$scope', '$http',
  '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService',
  function($scope, $http, $sce, DataService, AlertService, ModalService,
           AceEditorService) {

    $scope.editor = undefined;
    $scope.response = undefined;

    $scope.mappings = undefined;

        $scope.method = "POST";
        $scope.path = "";
    $scope.method = 'POST';
    $scope.path = '';
    $scope.options = [];

    var success = function(response) {
@@ -824,9 +842,9 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce
      DataService.execute($scope.method, $scope.path, data, success, failure);
    };

        $scope.initializeController = function() {
    $scope.setup = function() {
      $scope.editor = AceEditorService.init('rest-client-editor');
            $scope.editor.setValue("{}");
      $scope.editor.setValue('{}');
      DataService.getClusterMapping(
        function(response) {
          $scope.mappings = response;
@@ -840,12 +858,15 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce

    $scope.updateOptions = function(text) {
      if ($scope.mappings) {
                $scope.options = new URLAutocomplete($scope.mappings).getAlternatives(text);
        var autocomplete = new URLAutocomplete($scope.mappings);
        $scope.options = autocomplete.getAlternatives(text);
      }
    };
    }]);
  }]
);

angular.module('cerebro').directive('ngPagination', ['$document', function($document) {
angular.module('cerebro').directive('ngPagination', ['$document',
  function($document) {

    return {
      scope: {
@@ -880,7 +901,8 @@ angular.module('cerebro').directive('ngPagination', ['$document', function($docu
        });
      }
    };
}]);
  }]
);

angular.module('cerebro').directive('ngProgress',
  function() {
@@ -897,7 +919,7 @@ angular.module('cerebro').directive('ngProgress',
          '<div class="progress-bar-info" style="width: {{value}}%"' +
          'ng-class="{\'progress-bar-danger\': {{(value / max) > 0.75}}}">' +
          '{{value}}%' +
              '</div></div>'
          '</div></div>';
      }
    };
  }
@@ -924,22 +946,17 @@ angular.module('cerebro').filter('bytes', function() {

angular.module('cerebro').filter('startsWith', function() {

    console.log("created!");

  function strStartsWith(str, prefix) {
    return (str + '').indexOf(prefix) === 0;
  }

  return function(elements, prefix) {
        console.log("filtering...");
    var filtered = [];
    angular.forEach(elements, function(element) {
      if (strStartsWith(element, prefix)) {
        filtered.push(element);
      }
    });
        console.log("filtered!!");
        console.log(filtered);
    return filtered;
  };
});
@@ -1037,13 +1054,25 @@ angular.module('cerebro').factory('AlertService', function() {
  return this;
});

angular.module('cerebro').factory('DataService', function ($rootScope, $timeout, $http, $location) {
angular.module('cerebro').factory('DataService',
  function($rootScope, $timeout, $http, $location) {

    var data; // current data

    var host;

  var data = undefined; // current data
    var username;

  var host = undefined;
    var password;

  var baseUrl = $location.protocol() + '://' + $location.host() + ':' + $location.port();
    var buildBaseUrl = function() {
      var protocol = $location.protocol();
      var host = $location.host();
      var port = $location.port();
      return protocol + '://' + host + ':' + port;
    };

    var baseUrl = buildBaseUrl();

    var successfulRefresh = function(success) {
      return function(response) {
@@ -1051,7 +1080,7 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
        if (success) {
          success(response);
        }
    }
      };
    };

    var failedRefresh = function(error) {
@@ -1060,14 +1089,19 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
        if (error) {
          error(response);
        }
    }
      };
    };

    var refresh = function(success, error) {
      if (host) {
      request('/apis/overview', {}, successfulRefresh(success), failedRefresh(error));
        request(
          '/apis/overview',
          {},
          successfulRefresh(success),
          failedRefresh(error)
        );
      } else {
      $location.path("/connect");
        $location.path('/connect');
      }
    };

@@ -1088,14 +1122,14 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
      return host;
    };

  this.setHost = function(newHost, success, error) {
    this.setHost = function(newHost, newUsername, newPassword, success, error) {
      data = undefined;
      host = newHost;
      username = newUsername;
      password = newPassword;
      refresh(success, error);
    };

  autoRefresh();

    this.closeIndex = function(index, success, error) {
      request('/apis/close_indices', {indices: index}, success, error);
    };
@@ -1155,10 +1189,15 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
    };

    var request = function(path, data, success, error) {
      var defaultData = {
        host: host,
        username: username,
        password: password
      };
      var config = {
        method: 'POST',
        url: baseUrl + path,
      data: angular.merge(data, {host: host}) // adds host to data
        data: angular.merge(data, defaultData) // adds host to data
      };
      $http(config).success(success).error(error);
    };
@@ -1171,23 +1210,28 @@ angular.module('cerebro').factory('DataService', function ($rootScope, $timeout,
      $http(config).success(success).error(error);
    };

    if ($location.search().location) {
      this.setHost($location.search().location);
    }

    autoRefresh();

    return this;

  });

angular.module('cerebro').factory('ModalService', ['$sce', function($sce) {

  this.text = undefined;
  this.info = undefined;

  var confirmCallback = undefined;
  var confirmCallback;

  this.promptConfirmation = function(body, callback) {
    this.text = body;
    this.info = undefined;
    confirmCallback = callback;
  };

  this.showInfo = function(info) {
    this.text = undefined;
    this.info = $sce.trustAsHtml(JSONTree.create(info));
  };

@@ -1215,12 +1259,12 @@ angular.module('cerebro').factory('ModalService', ['$sce', function ($sce) {
  return this;
}]);

angular.module('cerebro').factory('PageService', ['DataService', '$rootScope', '$document',
  function (DataService, $rootScope, $document) {
angular.module('cerebro').factory('PageService', ['DataService', '$rootScope',
  '$document', function(DataService, $rootScope, $document) {

    var link = $document[0].querySelector('link[rel~=\'icon\']');
    var clusterName = undefined;
    var clusterStatus = undefined;
    var clusterName;
    var clusterStatus;

    if (link) {
      var faviconUrl = link.href;
@@ -1253,7 +1297,7 @@ angular.module('cerebro').factory('PageService', ['DataService', '$rootScope', '
    };

    var setFavIconColor = function(newClusterStatus) {
      if (link && clusterStatus !== newClusterStatus) {
      if (link) {
        clusterStatus = newClusterStatus;
        try {
          var colors = {green: '#1AC98E', yellow: '#E4D836', red: '#E64759'};
@@ -1279,8 +1323,8 @@ angular.module('cerebro').factory('PageService', ['DataService', '$rootScope', '

  }]);

angular.module('cerebro').controller('StatsController', ['$scope', '$http', 'DataService',
  function ($scope, $http, DataService) {
angular.module('cerebro').controller('StatsController', ['$scope', '$http',
  'DataService', function($scope, $http, DataService) {

    $scope.number_of_nodes = undefined;

+118 −117
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ function URLAutocomplete(mappings) {
              valid = Object.keys(mappings).indexOf(pathTokens[index]) >= 0;
              break;
            case '{type}':
                            valid = mappings[pathTokens[index - 1]]["types"].indexOf(pathTokens[index]) >= 0;
              var types = mappings[pathTokens[index - 1]].types;
              valid = types.indexOf(pathTokens[index]) >= 0;
              break;
            default:
              valid = pathTokens[index] === token;
@@ -111,7 +112,7 @@ function URLAutocomplete(mappings) {
            break;
          case '{type}':
            var pathIndex = pathTokens[suggestedTokenIndex - 1];
                        mappings[pathIndex]["types"].forEach(function(type) {
            mappings[pathIndex].types.forEach(function(type) {
              addIfNotPresent(alternatives, format(pathTokens, type));
            });
            break;
+8 −8
Original line number Diff line number Diff line
angular.module('cerebro').controller('AlertsController', ['$scope', 'AlertService',
  function($scope, AlertService) {
angular.module('cerebro').controller('AlertsController', ['$scope',
  'AlertService', function($scope, AlertService) {

    $scope.alerts = [];

+22 −14
Original line number Diff line number Diff line
@@ -8,6 +8,12 @@ angular.module('cerebro').controller('ConnectController', [

    $scope.host = undefined;

    $scope.username = undefined;

    $scope.password = undefined;

    $scope.showAuth = false;

    DataService.getHosts(
      function(hosts) {
        $scope.hosts = hosts;
@@ -22,13 +28,15 @@ angular.module('cerebro').controller('ConnectController', [
        $scope.connecting = true;
        DataService.setHost(
          host,
          $scope.username,
          $scope.password,
          function(response) {
              $location.path("/overview");
            $location.path('/overview');
            $scope.host = DataService.getHost();
          },
          function(response) {
            $scope.connecting = false;
              AlertService.error("Error connecting to " + host, response);
            AlertService.error('Error connecting to ' + host, response);
          }
        );
      }
Loading