This repository has been archived by the owner on May 14, 2021. It is now read-only.
/
dashboard.js
194 lines (172 loc) · 4.33 KB
/
dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
$(function() {
Highcharts.setOptions({
global : {
useUTC : false
}
});
$(".multiselect").multiselect().multiselect('disable');
var companySuccessHandler = function(data){
var output = [];
for(company in data){
output.push('<option value="'+ data[company].id +'">'+ data[company].name +'</option>');
}
$('#select_companies').html(output.join('')).multiselect('refresh').multiselect('enable');
};
$.ajax({
url: "companies",
dataType:"json",
context: document.body,
success: companySuccessHandler
});
var facilitiesSuccessHandler = function(data){
var output = [];
for(facility in data){
var facilityOption = new Option(data[facility].name, data[facility].id);
$('#select_facilities').append(facilityOption).multiselect('refresh').multiselect('enable');
}
};
$("#select_companies").bind("multiselectclick", function(event, ui){
if (ui.checked){
$.ajax({
url: "companies/" + ui.value + "/facilities.json",
dataType:"json",
context: document.body,
success: facilitiesSuccessHandler
});
}
}
);
var buildingSuccessHandler = function(data){
var output = [];
for(building in data){
var buildingOption = new Option(data[building].name, data[building].id);
$('#select_buildings').append(buildingOption).multiselect('refresh').multiselect('enable');
}
};
$("#select_facilities").bind("multiselectclick", function(event, ui){
if (ui.checked){
$.ajax({
url: "facilities/" + ui.value + "/buildings.json",
dataType:"json",
context: document.body,
success: buildingSuccessHandler
});
}
}
);
var systemSuccessHandler = function(data){
var output = [];
for(system in data){
var systemOption = new Option(data[system].name, data[system].id);
$('#select_systems').append(systemOption).multiselect('refresh').multiselect('enable');
}
};
$("#select_buildings").bind("multiselectclick", function(event, ui){
if (ui.checked){
$.ajax({
url: "buildings/" + ui.value + "/systems.json",
dataType:"json",
context: document.body,
success: systemSuccessHandler
});
}
}
);
var sensorSuccessHandler = function(data){
var output = [];
for(sensor in data){
var sensorOption = new Option(data[sensor].name, data[sensor].id);
$('#select_sensors').append(sensorOption).multiselect('refresh').multiselect('enable');
}
};
$("#select_systems").bind("multiselectclick", function(event, ui){
if (ui.checked){
$.ajax({
url: "systems/" + ui.value + "/sensors.json",
dataType:"json",
context: document.body,
success: sensorSuccessHandler
});
}
}
);
var sensorSelectSuccessHandler = function(data){
var output = [];
for(sensor in data){
var sensorOption = new Option(data[sensor].name, data[sensor].id);
$('#select_sensors').append(sensorOption).multiselect('refresh').multiselect('enable');
}
};
$("#select_sensors").bind("multiselectclick", function(event, ui){
if (ui.checked){
var values = $.map(ui.inputs, function(checkbox){
return checkbox.value;
});
$.ajax({
url: "sensors/inputs.json",
dataType:"json",
data:{"ids":values},
context: document.body,
success: sensorSelectSuccessHandler
});
}
}
);
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'chart',
events : {
load : function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100);
series.addPoint([x, y], true, true);
}, 3000);
}
}
},
rangeSelector: {
buttons: [{
count: 1,
type: 'day',
text: '1D'
}, {
count: 1,
type: 'week',
text: '1W'
}, {
count: 1,
type: 'month',
text: '1M'
}, {
count: 6,
type: 'month',
text: '6M'
}, {
type: 'all',
text: 'All'
}],
inputEnabled: false,
selected: 0
},
exporting: {
enabled: true
},
series : [{
name : 'Random data',
data : (function() {
// generate an array of random data
var data = [], time = (new Date()).getTime(), i;
for( i = -999; i <= 0; i++) {
data.push({
x : time + i * 1000,
y : Math.round(Math.random() * 100)
});
}
return data;
})()
}]
});
});