1 (function( $, app, i18n ) {
6 ui.IndexOverview = ui.Page.extend({
12 this.cluster = this.config.cluster;
13 this._clusterState = this.config.clusterState;
14 this._clusterState.on("data", this._refresh_handler );
15 this.el = $(this._main_template());
16 this._refresh_handler();
19 this._clusterState.removeObserver( "data", this._refresh_handler );
21 _refresh_handler: function() {
22 var state = this._clusterState;
24 indices: acx.eachMap( state.status.indices, function( name, index ) {
29 }).sort( function( a, b ) {
30 return a.name < b.name ? -1 : 1;
33 this._indexViewEl && this._indexViewEl.remove();
34 this._indexViewEl = $( this._indexTable_template( view ) );
35 this.el.find(".uiIndexOverview-table").append( this._indexViewEl );
37 _newIndex_handler: function() {
38 var fields = new app.ux.FieldCollection({
40 new ui.TextField({ label: i18n.text("ClusterOverView.IndexName"), name: "_name", require: true }),
42 label: i18n.text("ClusterOverview.NumShards"),
43 name: "number_of_shards",
45 require: function( val ) { return parseInt( val, 10 ) >= 1; }
48 label: i18n.text("ClusterOverview.NumReplicas"),
49 name: "number_of_replicas",
51 require: function( val ) { return parseInt( val, 10 ) >= 0; }
55 var dialog = new ui.DialogPanel({
56 title: i18n.text("ClusterOverview.NewIndex"),
57 body: new ui.PanelForm({ fields: fields }),
58 onCommit: function(panel, args) {
59 if(fields.validate()) {
60 var data = fields.getData();
61 var name = data["_name"];
63 this.config.cluster.put( encodeURIComponent( name ), JSON.stringify({ settings: { index: data } }), function(d) {
65 alert(JSON.stringify(d));
66 this._clusterState.refresh();
72 _indexTable_template: function( view ) { return (
73 { tag: "TABLE", cls: "table", children: [
74 { tag: "THEAD", children: [
75 { tag: "TR", children: [
77 { tag: "TH", children: [
78 { tag: "H3", text: "Size" }
80 { tag: "TH", children: [
81 { tag: "H3", text: "Docs" }
85 { tag: "TBODY", cls: "striped", children: view.indices.map( this._index_template, this ) }
89 _index_template: function( index ) { return (
90 { tag: "TR", children: [
91 { tag: "TD", children: [
92 { tag: "H3", text: index.name }
94 { tag: "TD", text: ut.byteSize_template( index.state.primaries.store.size_in_bytes ) + "/" + ut.byteSize_template( index.state.total.store.size_in_bytes ) },
95 { tag: "TD", text: ut.count_template( index.state.primaries.docs.count ) }
98 _main_template: function() {
99 return { tag: "DIV", id: this.id(), cls: "uiIndexOverview", children: [
101 label: i18n.text("IndexOverview.PageTitle"),
104 label: i18n.text("ClusterOverview.NewIndex"),
105 onclick: this._newIndex_handler
109 { tag: "DIV", cls: "uiIndexOverview-table", children: this._indexViewEl }
115 })( this.jQuery, this.app, this.i18n );