1
//var dashsocket = SocketService('dashboard.ws');
3
1
var Tab = $$({name:null,
6
4
{format: '<a class="item" data-bind="name" />'},
7
5
{'click &': function() {
8
this.model.set({active: true});
10
var newactive = this.model.get('name');
6
location.hash = this.model.get('name');
11
7
this.trigger('tab-activated', this);
13
var page = this.model.get('page');
17
10
'change:active': function(e) {
11
var page = this.model.get('page');
18
12
if (this.model.get('active') == true) {
19
13
this.view.$().addClass('active');
21
16
this.view.$().removeClass('active');
22
this.model.get('page')
31
25
$$({tabs: [], active: null},
32
26
{format: '<div class="ui tabular menu" />'},
33
27
{'create': function(){
34
var tabs = this.model.get('tabs');
35
this.model.set({active:tabs[0]});
36
tabs.forEach(function(t){
41
'child:tab-activated': function(e, obj){
42
this.model.get('active')
47
this.model.set({active: obj});
50
this.model.set({'active': null});
28
var tabs = this.model.get('tabs');
29
tabs.forEach(function(t){
33
this.tabByName = function(name) {
34
var result = this.model.get('tabs').filter(function(tab) {
35
return tab.model.get('name') == name;
41
'change:active': function(e) {
42
var active = this.model.get('active');
43
this.model.get('tabs').forEach(function(tab) {
44
tab.model.set({active: tab === active});
48
'child:tab-activated': function(e, active) {
49
this.model.set({active: active});
95
90
.append($$(StateCol, {label: "Current"}));
98
var Health = $$(Page, {title:'Health', content: null});
94
var HealthEntry = $$({service: null,
101
{'create': function() {
102
var dispositions = {pass: 'positive',
105
var service = this.model.get('service');
106
var unit = this.model.get('unit');
107
var rowspan = this.model.get('rowspan');
108
var health = this.model.get('health');
109
var disposition = dispositions[health]
110
var details = this.model.get('details');
112
details = health == 'pass' ? 'Ok' : 'Not ok';
118
'<th data-bind="service, rowspan=rowspan" class="three wide"/>'));
123
disposition: disposition + " three wide"},
124
'<td data-bind="unit, class=disposition"/>'));
128
disposition: disposition,
129
colspan: unit ? 1 : 2},
130
'<td data-bind="details, class=disposition, colspan=colspan"/></tr>'));
133
var Health = $$(Page,
134
{title:'Health', data: []},
135
{format: '<table class="ui column table segment"/>'},
136
{'change:data': function() {
137
var data = this.model.get('data');
139
data.forEach(function(service) {
140
if (!service.unhealthy_units.length) {
141
this.append($$(HealthEntry, {service: service.name,
142
health: service.health,
145
service.unhealthy_units.forEach(function(unit, i) {
146
var entry = {unit: unit.name,
148
details: unit.state};
150
entry.service = service.name;
151
entry.rowspan = service.unhealthy_units.length;
153
this.append($$(HealthEntry, entry));
99
160
var Waterfall = $$(Page, {title:'Waterfall', content: null});
100
161
var Logs = $$(Page, {title:'Logs', content: null});
164
var MessageHandler = function() {
167
health: function(data) {
168
Health.model.set({data: data});
172
$this.dispatch = function(message) {
173
var data = JSON.parse(message.data);
174
var handler = $this.handlers[data.message_type];
176
handler(data.message_data);
178
console.error('Unknown message type:', data.message_type)
103
185
$(document).ready(
105
187
var pagelist = [State, Health, Waterfall, Logs];
111
193
var tabcol = $$(TabCollection, {tabs: tabs});
112
194
$$.document.append(tabcol);
196
var tab_name = location.hash.replace('#', '');
197
tabcol.model.set({active: tabcol.tabByName(tab_name) || tabs[0]});
114
199
pagelist.forEach(function(page){
115
200
$$.document.append(page);
119
state.model.set({active: true});
122
var page = state.model.get('page');
123
page.view.$().show();
203
var protocol = location.protocol.replace('http', 'ws');
204
var ws = new WebSocket(protocol + '//' + location.host + '/dashboard.ws');
205
ws.onmessage = new MessageHandler().dispatch;
206
ws.onopen = function() {
207
ws.send(JSON.stringify({message_type: 'health'}));