Skip to content

Commit

Permalink
set the default index when deleting the default and when creating the…
Browse files Browse the repository at this point in the history
… first. Closes #98
  • Loading branch information
Spencer Alger authored and Rashid Khan committed May 31, 2014
1 parent 915c31e commit 225391a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/kibana/apps/settings/directives/indices/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define(function (require) {
});

require('modules').get('app/settings')
.controller('kbnSettingsIndicesCreate', function ($scope, $location, Notifier, Private, indexPatterns, es) {
.controller('kbnSettingsIndicesCreate', function ($scope, $location, Notifier, Private, indexPatterns, es, config) {
var notify = new Notifier();
var refreshKibanaIndex = Private(require('./_refresh_kibana_index'));
var MissingIndices = errors.IndexPatternMissingIndices;
Expand Down Expand Up @@ -140,6 +140,9 @@ define(function (require) {
return indexPattern.refreshFields()
.then(refreshKibanaIndex)
.then(function () {
if (!config.get('defaultIndex')) {
config.set('defaultIndex', indexPattern.id);
}
indexPatterns.cache.clear(indexPattern.id);
$location.url('/settings/indices/' + indexPattern.id);
});
Expand Down
11 changes: 9 additions & 2 deletions src/kibana/apps/settings/directives/indices/edit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
define(function (require) {
var _ = require('lodash');
var module = require('modules').get('app/settings');

require('routes')
.when('/settings/indices/:id', {
template: require('text!../../partials/indices/edit.html'),
Expand All @@ -10,12 +13,13 @@ define(function (require) {
}
});

require('modules').get('app/settings')
.controller('kbnSettingsIndicesEdit', function ($scope, $location, $route, config, courier, Notifier, Private) {
module.controller('kbnSettingsIndicesEdit', function ($scope, $location, $route, config, courier, Notifier, Private) {
var notify = new Notifier();
var refreshKibanaIndex = Private(require('./_refresh_kibana_index'));

$scope.indexPattern = $route.current.locals.indexPattern;
var otherIds = _.without($route.current.locals.indexPatternIds, $scope.indexPattern.id);

$scope.table = {
by: 'name',
reverse: false,
Expand All @@ -30,6 +34,9 @@ define(function (require) {
$scope.removePattern = function () {
if ($scope.indexPattern.id === config.get('defaultIndex')) {
config.delete('defaultIndex');
if (otherIds.length) {
config.set('defaultIndex', otherIds[0]);
}
}

courier.indexPatterns.delete($scope.indexPattern)
Expand Down

0 comments on commit 225391a

Please sign in to comment.