1 (function( app, i18n, joey ) {
6 ui.NodesView = ui.AbstractWidget.extend({
16 this.interactive = this.config.interactive;
17 this.cluster = this.config.cluster;
18 this._aliasRenderFunction = {
19 "none": this._aliasRender_template_none,
20 "list": this._aliasRender_template_list,
21 "full": this._aliasRender_template_full
22 }[ this.config.aliasRenderer ];
23 this._styleSheetEl = joey({ tag: "STYLE", text: ".uiNodesView-nullReplica, .uiNodesView-replica { zoom: " + this.config.scaleReplicas + " }" });
24 this.el = $( this._main_template( this.config.data.cluster, this.config.data.indices ) );
27 _newAliasAction_handler: function( index ) {
28 var fields = new app.ux.FieldCollection({
30 new ui.TextField({ label: i18n.text("AliasForm.AliasName"), name: "alias", require: true })
33 var dialog = new ui.DialogPanel({
34 title: i18n.text("AliasForm.NewAliasForIndexName", index.name),
35 body: new ui.PanelForm({ fields: fields }),
36 onCommit: function(panel, args) {
37 if(fields.validate()) {
38 var data = fields.getData();
41 { "add" : { "index" : index.name, "alias" : data["alias"] } }
44 this.config.cluster.post('_aliases', JSON.stringify(command), function(d) {
46 alert(JSON.stringify(d));
53 _postIndexAction_handler: function(action, index, redraw) {
54 this.cluster.post(encodeURIComponent( index.name ) + "/" + encodeURIComponent( action ), null, function(r) {
55 alert(JSON.stringify(r));
56 redraw && this.fire("redraw");
59 _optimizeIndex_handler: function(index) {
60 var fields = new app.ux.FieldCollection({
62 new ui.TextField({ label: i18n.text("OptimizeForm.MaxSegments"), name: "max_num_segments", value: "1", require: true }),
63 new ui.CheckField({ label: i18n.text("OptimizeForm.ExpungeDeletes"), name: "only_expunge_deletes", value: false }),
64 new ui.CheckField({ label: i18n.text("OptimizeForm.FlushAfter"), name: "flush", value: true }),
65 new ui.CheckField({ label: i18n.text("OptimizeForm.WaitForMerge"), name: "wait_for_merge", value: false })
68 var dialog = new ui.DialogPanel({
69 title: i18n.text("OptimizeForm.OptimizeIndex", index.name),
70 body: new ui.PanelForm({ fields: fields }),
71 onCommit: function( panel, args ) {
72 if(fields.validate()) {
73 this.cluster.post(encodeURIComponent( index.name ) + "/_optimize", fields.getData(), function(r) {
74 alert(JSON.stringify(r));
81 _testAnalyser_handler: function(index) {
82 this.cluster.get(encodeURIComponent( index.name ) + "/_analyze?text=" + encodeURIComponent( prompt( i18n.text("IndexCommand.TextToAnalyze") ) ), function(r) {
83 alert(JSON.stringify(r, true, " "));
86 _deleteIndexAction_handler: function(index) {
87 if( prompt( i18n.text("AliasForm.DeleteAliasMessage", i18n.text("Command.DELETE"), index.name ) ) === i18n.text("Command.DELETE") ) {
88 this.cluster["delete"](encodeURIComponent( index.name ), null, function(r) {
89 alert(JSON.stringify(r));
94 _shutdownNode_handler: function(node) {
95 if(prompt( i18n.text("IndexCommand.ShutdownMessage", i18n.text("Command.SHUTDOWN"), node.cluster.name ) ) === i18n.text("Command.SHUTDOWN") ) {
96 this.cluster.post( "_cluster/nodes/" + encodeURIComponent( node.name ) + "/_shutdown", null, function(r) {
97 alert(JSON.stringify(r));
102 _deleteAliasAction_handler: function( index, alias ) {
103 if( confirm( i18n.text("Command.DeleteAliasMessage" ) ) ) {
106 { "remove" : { "index" : index.name, "alias" : alias.name } }
109 this.config.cluster.post('_aliases', JSON.stringify(command), function(d) {
110 alert(JSON.stringify(d));
116 _replica_template: function(replica) {
117 var r = replica.replica;
119 cls: "uiNodesView-replica" + (r.primary ? " primary" : "") + ( " state-" + r.state ),
120 text: r.shard.toString(),
121 onclick: function() { new ui.JsonPanel({
122 json: replica.status || r,
123 title: r.index + "/" + r.node + " [" + r.shard + "]" });
127 _routing_template: function(routing) {
128 var cell = { tag: "TD", cls: "uiNodesView-routing" + (routing.open ? "" : " close"), children: [] };
129 for(var i = 0; i < routing.replicas.length; i++) {
130 if(i % routing.max_number_of_shards === 0 && i > 0) {
131 cell.children.push({ tag: "BR" });
133 if( routing.replicas[i] ) {
134 cell.children.push(this._replica_template(routing.replicas[i]));
136 cell.children.push( { tag: "DIV", cls: "uiNodesView-nullReplica" } );
141 _nodeControls_template: function( node ) { return (
142 { tag: "DIV", cls: "uiNodesView-controls", children: [
144 label: i18n.text("NodeInfoMenu.Title"),
145 menu: new ui.MenuPanel({
147 { text: i18n.text("NodeInfoMenu.ClusterNodeInfo"), onclick: function() { new ui.JsonPanel({ json: node.cluster, title: node.name });} },
148 { text: i18n.text("NodeInfoMenu.NodeStats"), onclick: function() { new ui.JsonPanel({ json: node.stats, title: node.name });} }
153 label: i18n.text("NodeActionsMenu.Title"),
154 menu: new ui.MenuPanel({
156 { text: i18n.text("NodeActionsMenu.Shutdown"), onclick: function() { this._shutdownNode_handler(node); }.bind(this) }
162 _nodeIcon_template: function( node ) {
164 if( node.name === "Unassigned" ) {
165 icon = "fa-exclamation-triangle";
166 alt = i18n.text( "NodeType.Unassigned" );
167 } else if( node.cluster.settings && "tribe" in node.cluster.settings) {
169 alt = i18n.text("NodeType.Tribe" );
171 icon = "fa-" + (node.master_node ? "star" : "circle") + (node.data_node ? "" : "-o" );
172 alt = i18n.text( node.master_node ? ( node.data_node ? "NodeType.Master" : "NodeType.Coord" ) : ( node.data_node ? "NodeType.Worker" : "NodeType.Client" ) );
174 return { tag: "TD", title: alt, cls: "uiNodesView-icon", children: [
175 { tag: "SPAN", cls: "fa fa-2x " + icon }
178 _node_template: function(node) {
179 return { tag: "TR", cls: "uiNodesView-node" + (node.master_node ? " master": ""), children: [
180 this._nodeIcon_template( node ),
181 { tag: "TH", children: node.name === "Unassigned" ? [
182 { tag: "H3", text: node.name }
184 { tag: "H3", text: node.cluster.name },
185 { tag: "DIV", text: node.cluster.hostname },
186 this.interactive ? this._nodeControls_template( node ) : null
188 ].concat(node.routings.map(this._routing_template, this))};
190 _indexHeaderControls_template: function( index ) { return (
191 { tag: "DIV", cls: "uiNodesView-controls", children: [
193 label: i18n.text("IndexInfoMenu.Title"),
194 menu: new ui.MenuPanel({
196 { text: i18n.text("IndexInfoMenu.Status"), onclick: function() { new ui.JsonPanel({ json: index.status, title: index.name }); } },
197 { text: i18n.text("IndexInfoMenu.Metadata"), onclick: function() { new ui.JsonPanel({ json: index.metadata, title: index.name }); } }
202 label: i18n.text("IndexActionsMenu.Title"),
203 menu: new ui.MenuPanel({
205 { text: i18n.text("IndexActionsMenu.NewAlias"), onclick: function() { this._newAliasAction_handler(index); }.bind(this) },
206 { text: i18n.text("IndexActionsMenu.Refresh"), onclick: function() { this._postIndexAction_handler("_refresh", index, false); }.bind(this) },
207 { text: i18n.text("IndexActionsMenu.Flush"), onclick: function() { this._postIndexAction_handler("_flush", index, false); }.bind(this) },
208 { text: i18n.text("IndexActionsMenu.Optimize"), onclick: function () { this._optimizeIndex_handler(index); }.bind(this) },
209 { text: i18n.text("IndexActionsMenu.Snapshot"), disabled: closed, onclick: function() { this._postIndexAction_handler("_gateway/snapshot", index, false); }.bind(this) },
210 { text: i18n.text("IndexActionsMenu.Analyser"), onclick: function() { this._testAnalyser_handler(index); }.bind(this) },
211 { text: (index.state === "close") ? i18n.text("IndexActionsMenu.Open") : i18n.text("IndexActionsMenu.Close"), onclick: function() { this._postIndexAction_handler((index.state === "close") ? "_open" : "_close", index, true); }.bind(this) },
212 { text: i18n.text("IndexActionsMenu.Delete"), onclick: function() { this._deleteIndexAction_handler(index); }.bind(this) }
218 _indexHeader_template: function( index ) {
219 var closed = index.state === "close";
220 var line1 = closed ? "index: close" : ( "size: " + (index.status && index.status.primaries && index.status.total ? ut.byteSize_template( index.status.primaries.store.size_in_bytes ) + " (" + ut.byteSize_template( index.status.total.store.size_in_bytes ) + ")" : "unknown" ) );
221 var line2 = closed ? "\u00A0" : ( "docs: " + (index.status && index.status.primaries && index.status.primaries.docs && index.status.total && index.status.total.docs ? index.status.primaries.docs.count.toLocaleString() + " (" + (index.status.total.docs.count + index.status.total.docs.deleted).toLocaleString() + ")" : "unknown" ) );
222 return index.name ? { tag: "TH", cls: (closed ? "close" : ""), children: [
223 { tag: "H3", text: index.name },
224 { tag: "DIV", text: line1 },
225 { tag: "DIV", text: line2 },
226 this.interactive ? this._indexHeaderControls_template( index ) : null
227 ] } : [ { tag: "TD" }, { tag: "TH" } ];
229 _aliasRender_template_none: function( cluster, indices ) {
232 _aliasRender_template_list: function( cluster, indices ) {
233 return cluster.aliases.length && { tag: "TBODY", children: [
234 { tag: "TR", children: [
236 ].concat( indices.map( function( index ) {
237 return { tag: "TD", children: index.metadata && index.metadata.aliases.map( function( alias ) {
238 return { tag: "LI", text: alias };
243 _aliasRender_template_full: function( cluster, indices ) {
244 return cluster.aliases.length && { tag: "TBODY", children: cluster.aliases.map( function(alias, row) {
245 return { tag: "TR", children: [ { tag: "TD" },{ tag: "TD" } ].concat(alias.indices.map(function(index, i) {
249 css: { background: "#" + "9ce9c7fc9".substr((row+6)%7,3) },
250 cls: "uiNodesView-hasAlias" + ( alias.min === i ? " min" : "" ) + ( alias.max === i ? " max" : "" ),
252 children: this.interactive ? [
254 text: i18n.text("General.CloseGlyph"),
255 cls: 'uiNodesView-hasAlias-remove',
256 onclick: this._deleteAliasAction_handler.bind( this, index, alias )
261 return { tag: "TD" };
266 _main_template: function(cluster, indices) {
267 return { tag: "TABLE", cls: "table uiNodesView", children: [
269 { tag: "THEAD", children: [ { tag: "TR", children: indices.map(this._indexHeader_template, this) } ] },
270 this._aliasRenderFunction( cluster, indices ),
271 { tag: "TBODY", children: cluster.nodes.map(this._node_template, this) }
277 })( this.app, this.i18n, this.joey );