diff --git a/index.html b/index.html index ce5e3137..3ab678ea 100644 --- a/index.html +++ b/index.html @@ -63,11 +63,9 @@ @@ -181,6 +179,8 @@

Getting Started...

+ + @@ -219,7 +219,7 @@

Getting Started...

- + @@ -237,6 +237,9 @@

Getting Started...

+ + + diff --git a/js/model/cluster/ClusterModel.js b/js/model/cluster/ClusterModel.js index bd988580..a0c2de58 100644 --- a/js/model/cluster/ClusterModel.js +++ b/js/model/cluster/ClusterModel.js @@ -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}); } }); } diff --git a/js/model/index/action/CreateIndexModel.js b/js/model/index/action/IndexModel.js similarity index 54% rename from js/model/index/action/CreateIndexModel.js rename to js/model/index/action/IndexModel.js index 9784ea3f..34f37b5f 100644 --- a/js/model/index/action/CreateIndexModel.js +++ b/js/model/index/action/IndexModel.js @@ -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.' + } + } }); \ No newline at end of file diff --git a/js/route/IndexRoute.js b/js/route/IndexRoute.js new file mode 100644 index 00000000..ec03a29a --- /dev/null +++ b/js/route/IndexRoute.js @@ -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'); + } + }); +} \ No newline at end of file diff --git a/js/router.js b/js/router.js index 45377fbc..37ec27e1 100644 --- a/js/router.js +++ b/js/router.js @@ -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", @@ -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"); @@ -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 @@ -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 () { diff --git a/js/template/IndexActionTemplate.js b/js/template/IndexActionTemplate.js index 2fc44a61..73a026ea 100644 --- a/js/template/IndexActionTemplate.js +++ b/js/template/IndexActionTemplate.js @@ -1,33 +1,37 @@ var indexActionTemplate = {}; indexActionTemplate.createIndex = [ - '
', + '
', '
', '
', '
', - 'Login', + 'Create an Index', '
', '
', - '', - '', + '', '
', - '', + '', '
', '
', '
', - '', - '', + '', '
', - '', + '', + '
', + '
', + '
', + '', + '
', + '', '
', '
', '
', - '', '
', - '', + '', + 'Cancel', '
', '
', '
', @@ -36,6 +40,24 @@ indexActionTemplate.createIndex = [ '
' ].join("\n"); +indexActionTemplate.defaultModal = [ + '' +].join("\n"); + indexActionTemplate.optimizeAll = [ '