Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
fixes create index action
Browse files Browse the repository at this point in the history
information wasn't being correctly sent. now also, when loading settings from another index, the settings will be properly formatted
  • Loading branch information
Leonardo Menezes committed Sep 5, 2013
1 parent fa4010f commit 1ddc2ed
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
44 changes: 41 additions & 3 deletions js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function CreateIndexCtrl($scope, $location, $timeout) {
$scope.mapping = '';
$scope.settings = '';
$scope.shards = '';
$scope.replicas = '';
$scope.name = '';
Expand All @@ -12,13 +12,13 @@ function CreateIndexCtrl($scope, $location, $timeout) {
var settings = {};
if ($scope.mapping.trim().length > 0) {
try {
settings = JSON.parse($scope.mapping, null);
settings = JSON.parse($scope.settings);
} catch (error) {
throw "Invalid JSON: " + error;
}
}
if (!isDefined(settings['settings'])) {
settings['settings'] = {};
settings = {"settings":settings};
}
if (!isDefined(settings['settings']['index'])) {
settings['settings']['index'] = {};
Expand All @@ -38,6 +38,13 @@ function CreateIndexCtrl($scope, $location, $timeout) {
$scope.modal.alert = new Alert(false, "Error while creating index", error);
}
}

$scope.prepareCreateIndex=function() {
$scope.settings = '';
$scope.shards = '';
$scope.name = '';
$scope.replicas = '';
}
}

function ClusterOverviewCtrl($scope, $location, $timeout) {
Expand Down Expand Up @@ -903,4 +910,35 @@ function NodeSwapCheck() {
function Diagnostic(critical, message) {
this.critical = critical;
this.message = message;
}

function hierachyJson(json) {
var jsonObject = JSON.parse(json);
var resultObject = {};
Object.keys(jsonObject).forEach(function(key) {
var parts = key.split(".");
var property = null;
var reference = resultObject;
var previous = null;
for (var i = 0; i<parts.length; i++) {
if (i == parts.length - 1) {
if (isNaN(parts[i])) {
reference[parts[i]] = jsonObject[key];
} else {
if (!(previous[property] instanceof Array)) {
previous[property] = [];
}
previous[property].push(jsonObject[key]);
}
} else {
property = parts[i];
if (!isDefined(reference[property])) {
reference[property] = {};
}
previous = reference;
reference = reference[property];
}
}
});
return JSON.stringify(resultObject,undefined,4);
}
4 changes: 2 additions & 2 deletions js/elastic_client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function createIndex(host, name, settings) {
var response = syncRequest('PUT', host + "/" + name, settings);
var response = syncRequest('POST', host + "/" + name, settings);
if (!response.success) {
throw response.response;
}
Expand Down Expand Up @@ -376,7 +376,7 @@ function Index(index_name,index_info, index_metadata, index_status) {
this.size = has_status ? index_status['index']['primary_size_in_bytes'] : 0;
this.total_size = has_status ? index_status['index']['size_in_bytes'] : 0;
this.settingsAsString=function() {
return JSON.stringify(this.settings, undefined, " ");
return hierachyJson(JSON.stringify(this.settings, undefined, ""));
}
}

Expand Down
10 changes: 5 additions & 5 deletions modals/create_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ <h4 class="modal-title">Create new index</h4>
<input type="text" ng-model="replicas" class="form-control input-sm" placeholder="# of replicas" type="number">
</div>
<div class="col-lg-6">
<select ng-model="mapping" ng-options="i.settingsAsString() as i.name for i in pagination.results" class="form-control input-sm">
<option value="">Load settings from an existing index<option>
<select ng-model="settings" ng-options="i.settingsAsString() as i.name for i in pagination.results" class="form-control input-sm">
<option value="">load settings from an existing index<option>
</select>
</div>
</div>
</div>

<h6 class="">Index settings</h6>
<div class="form-group">
<textarea class="form-control settings-area" ng-model="mapping" rows="20">
{{mapping}}
<textarea class="form-control settings-area" ng-model="settings" rows="20">
{{settings}}
</textarea>
</div>
</fieldset>
Expand All @@ -40,7 +40,7 @@ <h6 class="">Index settings</h6>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click='closeModal()' >Back</button>
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click='closeModal()'>Back</button>
<button type="button" class="btn btn-primary" ng-click='createIndex()'>Create</button>
</div>
</div><!-- /.modal-content -->
Expand Down
2 changes: 1 addition & 1 deletion partials/shard_map_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<th class="cluster-map-header-cluster-actions" rowspan="2">
<div class="row">
<div class="col-lg-4">
<a data-toggle="modal" href="#create_index" class="cluster-map-header-cluster-action" data-backdrop="static" data-keyboard="false">
<a data-toggle="modal" href="#create_index" class="cluster-map-header-cluster-action" data-backdrop="static" data-keyboard="false" ng-click="prepareCreateIndex()">
<i class="icon-file-alt" title="create new index"></i>
</a>
</div>
Expand Down

0 comments on commit 1ddc2ed

Please sign in to comment.