Commit d0141a8b authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

snapshot: fix showSpecialIndices toggle

closes #89
parent 556dee76
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -4,8 +4,7 @@ import javax.inject.Inject

import controllers.auth.AuthenticationModule
import elastic.{ElasticClient, Error, Success}
import models.commons.Indices
import models.snapshot.{Repositories, Snapshots}
import models.snapshot.{Repositories, Snapshots, Indices}
import models.{CerebroResponse, Hosts}
import play.api.libs.json.Json

+16 −0
Original line number Diff line number Diff line
package models.snapshot

import play.api.libs.json.{JsArray, JsString, JsValue, Json}

object Indices {

  def apply(data: JsValue) = JsArray(data.as[JsArray].value.collect {
    case index =>
      val name = (index \ "index").as[String]
      Json.obj(
        "name" -> JsString(name),
        "special" -> name.startsWith(".")
      )
  })

}
+19 −1
Original line number Diff line number Diff line
@@ -1313,9 +1313,12 @@ angular.module('cerebro').controller('SnapshotController', ['$scope',
'SnapshotsDataService', 'AlertService', 'ModalService',
  function($scope, SnapshotsDataService, AlertService, ModalService) {

    $scope._indices = [];
    $scope.indices = [];
    $scope.repositories = [];

    $scope.showSpecialIndices = false;

    $scope.repository = undefined;
    $scope.snapshots = [];
    $scope.form = {
@@ -1333,6 +1336,10 @@ angular.module('cerebro').controller('SnapshotController', ['$scope',
      true
    );

    $scope.$watch('showSpecialIndices', function(current, previous) {
      $scope.refreshIndices();
    });

    $scope.loadSnapshots = function(repository) {
      if (repository) {
        SnapshotsDataService.loadSnapshots(
@@ -1403,10 +1410,21 @@ angular.module('cerebro').controller('SnapshotController', ['$scope',
      );
    };

    $scope.refreshIndices = function() {
      if (!$scope.showSpecialIndices) {
        $scope.indices = $scope._indices.filter(function(i) {
          return !i.special;
        });
      } else {
        $scope.indices = $scope._indices;
      }
    };

    $scope.setup = function() {
      SnapshotsDataService.load(
        function(data) {
          $scope.indices = data.indices;
          $scope._indices = data.indices;
          $scope.refreshIndices();
          $scope.repositories = data.repositories;
        },
        function(error) {
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@
              <input type="checkbox" ng-model="showSpecialIndices" ng-true-value="true"> show special indices
            </label>
          </label>
          <select multiple ng-model="form.indices" ng-options="index for index in indices | orderBy:'index'"
          <select multiple ng-model="form.indices" ng-options="index.name for index in indices | orderBy:'name'"
                  class="form-control" size="13">
          </select>
        </div>
+19 −1
Original line number Diff line number Diff line
@@ -2,9 +2,12 @@ angular.module('cerebro').controller('SnapshotController', ['$scope',
'SnapshotsDataService', 'AlertService', 'ModalService',
  function($scope, SnapshotsDataService, AlertService, ModalService) {

    $scope._indices = [];
    $scope.indices = [];
    $scope.repositories = [];

    $scope.showSpecialIndices = false;

    $scope.repository = undefined;
    $scope.snapshots = [];
    $scope.form = {
@@ -22,6 +25,10 @@ angular.module('cerebro').controller('SnapshotController', ['$scope',
      true
    );

    $scope.$watch('showSpecialIndices', function(current, previous) {
      $scope.refreshIndices();
    });

    $scope.loadSnapshots = function(repository) {
      if (repository) {
        SnapshotsDataService.loadSnapshots(
@@ -92,10 +99,21 @@ angular.module('cerebro').controller('SnapshotController', ['$scope',
      );
    };

    $scope.refreshIndices = function() {
      if (!$scope.showSpecialIndices) {
        $scope.indices = $scope._indices.filter(function(i) {
          return !i.special;
        });
      } else {
        $scope.indices = $scope._indices;
      }
    };

    $scope.setup = function() {
      SnapshotsDataService.load(
        function(data) {
          $scope.indices = data.indices;
          $scope._indices = data.indices;
          $scope.refreshIndices();
          $scope.repositories = data.repositories;
        },
        function(error) {
Loading