2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 (function( $, app, i18n ) {
18 var ui = app.ns("ui");
19 var ut = app.ns("ut");
21 ui.IndexOverview = ui.Page.extend({
27 this.cluster = this.config.cluster;
28 this._clusterState = this.config.clusterState;
29 this._clusterState.on("data", this._refresh_handler );
30 this.el = $(this._main_template());
31 this._refresh_handler();
34 this._clusterState.removeObserver( "data", this._refresh_handler );
36 _refresh_handler: function() {
37 var state = this._clusterState;
39 indices: acx.eachMap( state.status.indices, function( name, index ) {
44 }).sort( function( a, b ) {
45 return a.name < b.name ? -1 : 1;
48 this._indexViewEl && this._indexViewEl.remove();
49 this._indexViewEl = $( this._indexTable_template( view ) );
50 this.el.find(".uiIndexOverview-table").append( this._indexViewEl );
52 _newIndex_handler: function() {
53 var fields = new app.ux.FieldCollection({
55 new ui.TextField({ label: i18n.text("ClusterOverView.IndexName"), name: "_name", require: true }),
57 label: i18n.text("ClusterOverview.NumShards"),
58 name: "number_of_shards",
60 require: function( val ) { return parseInt( val, 10 ) >= 1; }
63 label: i18n.text("ClusterOverview.NumReplicas"),
64 name: "number_of_replicas",
66 require: function( val ) { return parseInt( val, 10 ) >= 0; }
70 var dialog = new ui.DialogPanel({
71 title: i18n.text("ClusterOverview.NewIndex"),
72 body: new ui.PanelForm({ fields: fields }),
73 onCommit: function(panel, args) {
74 if(fields.validate()) {
75 var data = fields.getData();
76 var name = data["_name"];
78 this.config.cluster.put( encodeURIComponent( name ), JSON.stringify({ settings: { index: data } }), function(d) {
80 alert(JSON.stringify(d));
81 this._clusterState.refresh();
87 _indexTable_template: function( view ) { return (
88 { tag: "TABLE", cls: "table", children: [
89 { tag: "THEAD", children: [
90 { tag: "TR", children: [
92 { tag: "TH", children: [
93 { tag: "H3", text: "Size" }
95 { tag: "TH", children: [
96 { tag: "H3", text: "Docs" }
100 { tag: "TBODY", cls: "striped", children: view.indices.map( this._index_template, this ) }
104 _index_template: function( index ) { return (
105 { tag: "TR", children: [
106 { tag: "TD", children: [
107 { tag: "H3", text: index.name }
109 { tag: "TD", text: ut.byteSize_template( index.state.primaries.store.size_in_bytes ) + "/" + ut.byteSize_template( index.state.total.store.size_in_bytes ) },
110 { tag: "TD", text: ut.count_template( index.state.primaries.docs.count ) }
113 _main_template: function() {
114 return { tag: "DIV", id: this.id(), cls: "uiIndexOverview", children: [
116 label: i18n.text("IndexOverview.PageTitle"),
119 label: i18n.text("ClusterOverview.NewIndex"),
120 onclick: this._newIndex_handler
124 { tag: "DIV", cls: "uiIndexOverview-table", children: this._indexViewEl }
130 })( this.jQuery, this.app, this.i18n );