a6e1155ecdc17fcf7723d3bb5c20a007ecf77501
[ccsdk/features.git] /
1 (function( $, app, i18n ) {
2
3         var ui = app.ns("ui");
4
5         ui.Header = ui.AbstractWidget.extend({
6                 defaults: {
7                         cluster: null,
8                         clusterState: null
9                 },
10                 _baseCls: "uiHeader",
11                 init: function() {
12                         this._clusterConnect = new ui.ClusterConnect({
13                                 cluster: this.config.cluster
14                         });
15                         var quicks = [
16                                 { text: i18n.text("Nav.Info"), path: "" },
17                                 { text: i18n.text("Nav.Status"), path: "_stats" },
18                                 { text: i18n.text("Nav.NodeStats"), path: "_nodes/stats" },
19                                 { text: i18n.text("Nav.ClusterNodes"), path: "_nodes" },
20                                 { text: i18n.text("Nav.Plugins"), path: "_nodes/plugins" },
21                                 { text: i18n.text("Nav.ClusterState"), path: "_cluster/state" },
22                                 { text: i18n.text("Nav.ClusterHealth"), path: "_cluster/health" },
23                                 { text: i18n.text("Nav.Templates"), path: "_template" }
24                         ];
25                         var cluster = this.config.cluster;
26                         var quickPanels = {};
27                         var menuItems = quicks.map( function( item ) {
28                                 return { text: item.text, onclick: function() {
29                                         cluster.get( item.path, function( data ) {
30                                                 quickPanels[ item.path ] && quickPanels[ item.path ].el && quickPanels[ item.path ].remove();
31                                                 quickPanels[ item.path ] = new ui.JsonPanel({
32                                                         title: item.text,
33                                                         json: data
34                                                 });
35                                         } );
36                                 } };
37                         }, this );
38                         this._quickMenu = new ui.MenuButton({
39                                 label: i18n.text("NodeInfoMenu.Title"),
40                                 menu: new ui.MenuPanel({
41                                         items: menuItems
42                                 })
43                         });
44                         this.el = $.joey( this._main_template() );
45                         this.nameEl = this.el.find(".uiHeader-name");
46                         this.statEl = this.el.find(".uiHeader-status");
47                         this._clusterState = this.config.clusterState;
48                         this._clusterState.on("data", function( state ) {
49                                 var shards = state.status._shards;
50                                 var colour = state.clusterHealth.status;
51                                 var name = state.clusterState.cluster_name;
52                                 this.nameEl.text( name );
53                                 this.statEl
54                                         .text( i18n.text("Header.ClusterHealth", colour, shards.successful, shards.total ) )
55                                         .css( "background", colour );
56                         }.bind(this));
57                         this.statEl.text( i18n.text("Header.ClusterNotConnected") ).css("background", "grey");
58                         this._clusterState.refresh();
59                 },
60                 _main_template: function() { return (
61                         { tag: "DIV", cls: this._baseCls, children: [
62                                 this._clusterConnect,
63                                 { tag: "SPAN", cls: "uiHeader-name" },
64                                 { tag: "SPAN", cls: "uiHeader-status" },
65                                 { tag: "H1", text: i18n.text("General.Elasticsearch") },
66                                 { tag: "SPAN", cls: "pull-right", children: [
67                                         this._quickMenu
68                                 ] }
69                         ] }
70                 ); }
71         } );
72
73 })( this.jQuery, this.app, this.i18n );