Skip to content

Commit

Permalink
fixes #18, fixes #19, fixes #11, fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
royrusso committed May 20, 2013
1 parent 6da1c84 commit 3d66c4f
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 45 deletions.
11 changes: 7 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@

<ul class="nav pull-right">
<li><a href="https://groups.google.com/d/forum/elastichq" target="_blank"><i
class="icon-comments-alt"></i> Get Help</a></li>
class="icon-comments-alt icon-large"></i> Get Help</a></li>
<li><a href="https://github.com/royrusso/elasticsearch-HQ" target="_blank"><i
class="icon-github icon-large"></i> Star us on GitHub</a></li>
<!-- <a class="btn btn-success" href="https://github.com/royrusso/elasticsearch-HQ"><i
class="icon-github icon-large"></i> Star us on GitHub</a>-->
</ul>
</div>
<!--/.nav-collapse -->
Expand Down Expand Up @@ -181,6 +179,8 @@ <h1>Getting Started...</h1>
<script src="js/lib/underscore/underscore.js"></script>
<script src="js/lib/backbone/backbone.js"></script>
<script src="js/lib/backbone-poller/backbone.poller.min.js"></script>
<script src="js/lib/backbone-validation/backbone-validation-min.js"></script>
<script src="js/lib/backbone-validation/backbone.validation.bootstrap.js"></script>

<!-- Notify -->
<script src="js/lib/pnotify/jquery.pnotify.min.js"></script>
Expand Down Expand Up @@ -219,7 +219,7 @@ <h1>Getting Started...</h1>
<script src="js/model/index/action/ClearCacheAllIndexModel.js"></script>
<script src="js/model/index/action/FlushAllIndexModel.js"></script>
<script src="js/model/index/action/OptimizeAllIndexModel.js"></script>
<script src="js/model/index/action/CreateIndexModel.js"></script>
<script src="js/model/index/action/IndexModel.js"></script>

<!-- View -->
<script src="js/view/ErrorMessageView.js"></script>
Expand All @@ -237,6 +237,9 @@ <h1>Getting Started...</h1>
<script src="js/view/index/action/ClearCacheAllIndexView.js"></script>
<script src="js/view/index/action/CreateIndexView.js"></script>

<!-- Routes -->
<script src="js/route/IndexRoute.js"></script>

<!-- Util -->
<script src="js/util/logger.js"></script>
<script src="js/util/tools.js"></script>
Expand Down
3 changes: 1 addition & 2 deletions js/model/cluster/ClusterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ var Cluster = Backbone.Model.extend({
var _this = this;
_this.get("clusterState").fetch({
success:function (model, res) {
_this.clusterState = model;
return;
_this.set({clusterState:model});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,43 @@
}'
* @type {*}
*/
var CreateIndexModel = Backbone.Model.extend({
var IndexModel = Backbone.Model.extend({
defaults:{
indexId:undefined
indexId:undefined,
cmd: undefined
},
initialize:function (args) {
console.log("Creating Index " + args.indexId);
this.nodeId = args.indexId;
this.indexId = args.indexId;
if (args.cmd != undefined) {
this.cmd = args.cmd;
}
},
url:function () {
return '/' + this.indexId;
}
if (this.cmd != undefined) {
return '/' + this.indexId + '/' + this.cmd;
}
else {
return '/' + this.indexId;
}

},
validation:{
indexId:{
required:true,
msg:'Please enter a valid Index ID'
},
shards:{
required:true,
min:1,
pattern:'number',
msg:'Please enter a # value.'
},
replicas:{
required:true,
min:0,
pattern:'number',
msg:'Please enter a # value.'
}
}
});
128 changes: 128 additions & 0 deletions js/route/IndexRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
Copyright 2013 Roy Russo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Latest Builds: https://github.com/royrusso/elasticsearch-HQ
*/

var indexRoute = {};


indexRoute.deleteIndex = function (indexId) {
var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});
indexModel.id = indexId;
indexModel.destroy({
success:function (model, response) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Deleted!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#defaultindexmodal').modal('show');
$('#defaultindexmodal').on('hidden', function () {
router.navigate("indices", true);
});
},
error:function (model, response, options) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Delete Failed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#defaultindexmodal').modal('show');
$('#defaultindexmodal').on('hidden', function () {
router.navigate("indices", true);
});
}
});

}

indexRoute.flushIndex = function (indexId) {
var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_flush'});
indexModel.fetch({
success:function (model, response) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Flushed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#defaultindexmodal').modal('show');
},
error:function (model, response, options) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Flush Failed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#deleteindexmodal').modal('show');
}
});
}

indexRoute.refreshIndex = function (indexId) {
var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_refresh'});
indexModel.fetch({
success:function (model, response) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Refreshed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#defaultindexmodal').modal('show');
},
error:function (model, response, options) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Refresh Failed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#deleteindexmodal').modal('show');
}
});
}

indexRoute.optimizeIndex = function (indexId) {
var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_optimize'});
indexModel.fetch({
success:function (model, response) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Optimized!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#defaultindexmodal').modal('show');
},
error:function (model, response, options) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Optimization Failed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#deleteindexmodal').modal('show');
}
});
}

indexRoute.clearCacheIndex = function (indexId) {
var indexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId, cmd:'_cache/clear'});
indexModel.fetch({
success:function (model, response) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Index Cache Cleared!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#defaultindexmodal').modal('show');
},
error:function (model, response, options) {
var str = JSON.stringify(response, undefined, 2);
var template = _.template(indexActionTemplate.defaultModal, {title:'Clear Cache Failed!', res:str});
$('#infoModal-loc').html(template);
prettyPrint();
$('#deleteindexmodal').modal('show');
}
});
}
36 changes: 32 additions & 4 deletions js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ $(document).ready(
"flushall":"flushall",
"clearcacheall":"clearcacheall",
"createindex":"createIndex",
"deleteindex/:indexId":"deleteIndex",
"flushindex/:indexId":"flushIndex",
"clearcacheindex/:indexId":"clearCacheIndex",
"optimizeindex/:indexId":"optimizeIndex",
"refreshindex/:indexId":"refreshIndex",
"index/:indexId":"index",
"query":"query",
"admin":"admin",
Expand All @@ -59,6 +64,9 @@ $(document).ready(
clusterHealthPoller.on('success', function (healthModel) {
var clusterView = new ClusterHealthView({el:$("#clusterHealth-loc"), model:healthModel});
clusterView.render();

cluster.refreshClusterState();

$("#toolbar").css("visibility", "visible");

var nodeList = cluster.get("nodeList");
Expand Down Expand Up @@ -189,8 +197,12 @@ $(document).ready(
indexStatusModel.fetch(
{
success:function () {
var indexListView = new IndexStatusListView({model:indexStatusModel});
indexListView.render();
// need to have a refreshed clusterstate
cluster.get("clusterState").fetch({
success:function (model, res) {
var indexListView = new IndexStatusListView({model:indexStatusModel});
indexListView.render();
}});
},
error:function () {
// TODO
Expand Down Expand Up @@ -238,13 +250,29 @@ $(document).ready(
});
},
createIndex:function () {
var createIndexModel = new CreateIndexModel({connectionRootURL:cluster.get("connectionRootURL")});
var createIndexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL")});
var createIndexView = new CreateIndexView({model:createIndexModel});
createIndexView.render();
},
deleteIndex:function (indexId) {
indexRoute.deleteIndex(indexId);
},
clearCacheIndex:function (indexId) {
indexRoute.clearCacheIndex(indexId);
},
flushIndex:function (indexId) {
indexRoute.flushIndex(indexId);
},
refreshIndex:function (indexId) {
indexRoute.refreshIndex(indexId);
},
optimizeIndex:function (indexId) {
indexRoute.optimizeIndex(indexId);
},
index:function (indexId) {
stopNodePoller();
var indexView = new IndexView({});
var createIndexModel = new IndexModel({connectionRootURL:cluster.get("connectionRootURL"), indexId:indexId});
var indexView = new IndexView({model:createIndexModel});
indexView.render();
},
defaultRoute:function () {
Expand Down
42 changes: 32 additions & 10 deletions js/template/IndexActionTemplate.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
var indexActionTemplate = {};

indexActionTemplate.createIndex = [
'<div>',
'<div class="span8 center-table">',

'<form class="form-horizontal" id="createIndexForm">',
'<fieldset>',
'<div id="legend">',
'<legend class="">Login</legend>',
'<legend class="">Create an Index</legend>',
'</div>',
'<div class="control-group">',
'<!-- Username -->',
'<label class="control-label" for="username">Username</label>',
'<label class="control-label" for="indexId">Index ID</label>',
'<div class="controls">',
'<input type="text" id="username" name="username" placeholder="" class="input-xlarge">',
'<input type="text" id="indexId" name="indexId" placeholder="" class="input-xlarge" data-error-style="inline">',
'</div>',
'</div>',

'<div class="control-group">',
'<!-- Password-->',
'<label class="control-label" for="password">Password</label>',
'<label class="control-label" for="shards"># Shards</label>',
'<div class="controls">',
'<input type="password" id="password" name="password" placeholder="" class="input-xlarge">',
'<input type="text" id="shards" name="shards" placeholder="" class="input-mini" data-error-style="inline">',
'</div>',
'</div>',
'<div class="control-group">',
'<label class="control-label" for="replicas"># Replicas</label>',
'<div class="controls">',
'<input type="text" id="replicas" name="replicas" placeholder="" class="input-mini" data-error-style="inline">',
'</div>',
'</div>',

'<div class="control-group">',
'<!-- Button -->',
'<div class="controls">',
'<button type="submit" class="btn btn-success">Login</button>',
'<button type="submit" class="btn btn-success">Create</button>',
'<a href="#indices" class="btn">Cancel</a>',
'</div>',
'</div>',
'</fieldset>',
Expand All @@ -36,6 +40,24 @@ indexActionTemplate.createIndex = [
'</div>'
].join("\n");

indexActionTemplate.defaultModal = [
'<div class="modal hide fade" id="defaultindexmodal">',
'<div class="modal-header">',
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>',
'<h3><%- title %></h3>',
'</div>',
'<div class="modal-body">',
'<p>Response from Server is... </p>',
'<pre class="prettyprint linenums language-json">',
'<%- res %>',
'</pre>',
'</div>',
'<div class="modal-footer">',
'<a href="#" class="btn" data-dismiss="modal">Close</a>',
'</div>',
'</div>'
].join("\n");

indexActionTemplate.optimizeAll = [
'<div class="modal hide fade" id="optimizeallmodal">',
'<div class="modal-header">',
Expand Down
Loading

0 comments on commit 3d66c4f

Please sign in to comment.