591903bab62d83815cf22eec297cdc8814d13cef
[ccsdk/features.git] /
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 (function( $, app, i18n ) {
17
18         var ui = app.ns("ui");
19
20         ui.Header = ui.AbstractWidget.extend({
21                 defaults: {
22                         cluster: null,
23                         clusterState: null
24                 },
25                 _baseCls: "uiHeader",
26                 init: function() {
27                         this._clusterConnect = new ui.ClusterConnect({
28                                 cluster: this.config.cluster
29                         });
30                         var quicks = [
31                                 { text: i18n.text("Nav.Info"), path: "" },
32                                 { text: i18n.text("Nav.Status"), path: "_stats" },
33                                 { text: i18n.text("Nav.NodeStats"), path: "_nodes/stats" },
34                                 { text: i18n.text("Nav.ClusterNodes"), path: "_nodes" },
35                                 { text: i18n.text("Nav.Plugins"), path: "_nodes/plugins" },
36                                 { text: i18n.text("Nav.ClusterState"), path: "_cluster/state" },
37                                 { text: i18n.text("Nav.ClusterHealth"), path: "_cluster/health" },
38                                 { text: i18n.text("Nav.Templates"), path: "_template" }
39                         ];
40                         var cluster = this.config.cluster;
41                         var quickPanels = {};
42                         var menuItems = quicks.map( function( item ) {
43                                 return { text: item.text, onclick: function() {
44                                         cluster.get( item.path, function( data ) {
45                                                 quickPanels[ item.path ] && quickPanels[ item.path ].el && quickPanels[ item.path ].remove();
46                                                 quickPanels[ item.path ] = new ui.JsonPanel({
47                                                         title: item.text,
48                                                         json: data
49                                                 });
50                                         } );
51                                 } };
52                         }, this );
53                         this._quickMenu = new ui.MenuButton({
54                                 label: i18n.text("NodeInfoMenu.Title"),
55                                 menu: new ui.MenuPanel({
56                                         items: menuItems
57                                 })
58                         });
59                         this.el = $.joey( this._main_template() );
60                         this.nameEl = this.el.find(".uiHeader-name");
61                         this.statEl = this.el.find(".uiHeader-status");
62                         this._clusterState = this.config.clusterState;
63                         this._clusterState.on("data", function( state ) {
64                                 var shards = state.status._shards;
65                                 var colour = state.clusterHealth.status;
66                                 var name = state.clusterState.cluster_name;
67                                 this.nameEl.text( name );
68                                 this.statEl
69                                         .text( i18n.text("Header.ClusterHealth", colour, shards.successful, shards.total ) )
70                                         .css( "background", colour );
71                         }.bind(this));
72                         this.statEl.text( i18n.text("Header.ClusterNotConnected") ).css("background", "grey");
73                         this._clusterState.refresh();
74                 },
75                 _main_template: function() { return (
76                         { tag: "DIV", cls: this._baseCls, children: [
77                                 this._clusterConnect,
78                                 { tag: "SPAN", cls: "uiHeader-name" },
79                                 { tag: "SPAN", cls: "uiHeader-status" },
80                                 { tag: "H1", text: i18n.text("General.Elasticsearch") },
81                                 { tag: "SPAN", cls: "pull-right", children: [
82                                         this._quickMenu
83                                 ] }
84                         ] }
85                 ); }
86         } );
87
88 })( this.jQuery, this.app, this.i18n );