Commit 64074d96 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

Merge branch 'develop'

parents c0a690c7 327fab02
Loading
Loading
Loading
Loading

CONTRIBUTING.md

0 → 100644
+49 −0
Original line number Diff line number Diff line
Contributing to cerebro
=============================

You can contribute to cerebro through code, documentation or bug reports.

## Bug reports

For bug reports, make sure you:
- give enough details regarding your cerebro setup
- include versions for elasticsearch and cerebro
- describe steps to reproduce the error, the error itself and expected behaviour

## Pull requests

Before getting started on a pull request(be it a new feature or a bug fix), please open an issue explaning what you would like to achieve and how you would go about this.
Even though I'm open to feature requests, I might not always agree on the value a feature might bring. And I would hate to waste someone else's time.

Once working on a pull request, please:
- include the generated css/js files(grunt build)
- add tests that validate your changes
- squash your development commits to keep only important commits(fix typo, wrong indent should not be part of git history)
- rebase it against development before submiting
- make sure all tests pass(sbt test / grunt test)

## Development

You can run cerebro for development through sbt:

```sh
$ sbt
[info] Loading project definition from /Users/leo/dev/cerebro/project
[info] Set current project to cerebro (in build file:/Users/leo/dev/cerebro/)
[cerebro] $ run

--- (Running the application, auto-reloading is enabled) ---

[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)
```

Make sure you also run Grunt in order to build the js/css artifcats as you change the code.

```sh
$ grunt watch
Running "watch" task
Waiting...(node:20784) DeprecationWarning: process.EventEmitter is deprecated. 
Use require('events') instead.
```
+55 −1
Original line number Diff line number Diff line
@@ -858,8 +858,9 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http',

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

    $scope.editor = undefined;
    $scope.response = undefined;
@@ -904,6 +905,30 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http',
        $scope.options = autocomplete.getAlternatives(text);
      }
    };

    $scope.copyAsCURLCommand = function() {
      var method = $scope.method;
      var host = DataService.getHost();
      var path = encodeURI($scope.path);
      if (path.substring(0, 1) !== '/') {
        path = '/' + path;
      }
      var body = JSON.stringify($scope.editor.getValue(), undefined, 1);
      var curl = 'curl -X' + method + ' \'' + host + path + '\'';
      if (['POST', 'PUT'].indexOf(method) >= 0) {
        curl += ' -d \'' + body + '\'';
      }
      ClipboardService.copy(
        curl,
        function() {
          AlertService.info('cURL request successfully copied to clipboard');
        },
        function() {
          AlertService.error('Error while copying request to clipboard');
        }
      );
    };

  }]
);

@@ -1750,6 +1775,35 @@ angular.module('cerebro').factory('AlertService', function() {
  return this;
});

angular.module('cerebro').factory('ClipboardService', ['AlertService',
  '$document', '$window',
  function(AlertService, $document, $window) {
    var textarea = angular.element($document[0].createElement('textarea'));
    textarea.css({
      position: 'absolute',
      left: '-9999px',
      top: (
          $window.pageYOffset || $document[0].documentElement.scrollTop
      ) + 'px'
    });
    textarea.attr({readonly: ''});
    angular.element($document[0].body).append(textarea);

    this.copy = function(value, success, failure) {
      try {
        textarea.val(value);
        textarea.select();
        $document[0].execCommand('copy');
        success();
      } catch (error) {
        failure();
      }
    };

    return this;
  }
]);

angular.module('cerebro').factory('ClusterChangesService', [
  '$rootScope', 'AlertService', 'RefreshService', 'DataService',
  function($rootScope, AlertService, RefreshService, DataService) {
+5 −0
Original line number Diff line number Diff line
@@ -47,6 +47,11 @@
    </div>
    <div class="form-group row">
      <div class="col-lg-12 text-right">
        <div class="btn-group">
          <button type="submit" class="btn btn-default" ng-click="copyAsCURLCommand()">
            <i class="fa fa-clipboard"></i> cURL
          </button>
        </div>
        <div class="btn-group">
          <button type="submit" class="btn btn-default" ng-click="editor.format()">
            <i class="fa fa-align-left"></i> format
+26 −1
Original line number Diff line number Diff line
angular.module('cerebro').controller('RestController', ['$scope', '$http',
  '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService',
  'ClipboardService',
  function($scope, $http, $sce, DataService, AlertService, ModalService,
           AceEditorService) {
           AceEditorService, ClipboardService) {

    $scope.editor = undefined;
    $scope.response = undefined;
@@ -46,5 +47,29 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http',
        $scope.options = autocomplete.getAlternatives(text);
      }
    };

    $scope.copyAsCURLCommand = function() {
      var method = $scope.method;
      var host = DataService.getHost();
      var path = encodeURI($scope.path);
      if (path.substring(0, 1) !== '/') {
        path = '/' + path;
      }
      var body = JSON.stringify($scope.editor.getValue(), undefined, 1);
      var curl = 'curl -X' + method + ' \'' + host + path + '\'';
      if (['POST', 'PUT'].indexOf(method) >= 0) {
        curl += ' -d \'' + body + '\'';
      }
      ClipboardService.copy(
        curl,
        function() {
          AlertService.info('cURL request successfully copied to clipboard');
        },
        function() {
          AlertService.error('Error while copying request to clipboard');
        }
      );
    };

  }]
);
+28 −0
Original line number Diff line number Diff line
angular.module('cerebro').factory('ClipboardService', ['AlertService',
  '$document', '$window',
  function(AlertService, $document, $window) {
    var textarea = angular.element($document[0].createElement('textarea'));
    textarea.css({
      position: 'absolute',
      left: '-9999px',
      top: (
          $window.pageYOffset || $document[0].documentElement.scrollTop
      ) + 'px'
    });
    textarea.attr({readonly: ''});
    angular.element($document[0].body).append(textarea);

    this.copy = function(value, success, failure) {
      try {
        textarea.val(value);
        textarea.select();
        $document[0].execCommand('copy');
        success();
      } catch (error) {
        failure();
      }
    };

    return this;
  }
]);
Loading