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
|
{% extends "layout.html" %}
{% load staticfiles %}
{% block style_block %}
<style>
.default {
background-color: #999;
}
.default[href]:hover,
.default[href]:focus {
background-color: #808080;
}
.primary {
background-color: #428bca;
}
.primary[href]:hover,
.primary[href]:focus {
background-color: #3071a9;
}
.success {
background-color: #5cb85c;
}
.success[href]:hover,
.success[href]:focus {
background-color: #449d44;
}
.info {
background-color: #5bc0de;
}
.info[href]:hover,
.info[href]:focus {
background-color: #31b0d5;
}
.warning {
background-color: #f0ad4e;
}
.warning[href]:hover,
.warning[href]:focus {
background-color: #ec971f;
}
.danger {
background-color: #d9534f;
}
.danger[href]:hover,
.danger[href]:focus {
background-color: #c9302c;
}
</style>
{% endblock %}
{% block content %}
<div class="container">
<div class="row">
{% include "account/sub_nav.html" %}
<div class="span12">
{% include "admin/sub_nav.html" %}
<h4>MID allotment mode is {{ allotment_mode }}. <small>Change to <a href="{% url 'admin_toggle_allotment_mode' %}">{% if allotment_mode == 'Random' %}Workshop mode{% else %}Random mode{% endif %}</a></small></h4>
<h1>Board status</h1>
<table class="table table-bordered">
<thead>
<tr>
<th>Board MID</th>
<th>Status</th>
<th>Power Status</th>
<th>Webcam</th>
<th>Temperature Profile</th>
<th>Download Logs</th>
</tr>
</thead>
<tbody>
{% for b in boards %}
<tr>
<td class = "board_id">{{ b.mid }}</td>
<td><span style="cursor: pointer;" class="label label-{% if not b.online %}important{% elif b.temp_offline %}warning{% else %}success{% endif %}">{% if not b.online %}Offline{% elif b.temp_offline %}Temp Offline{% else %}Online{% endif %}</span></td>
<td><span style = "cursor: pointer;" class = "label {% if not b.power_status %}danger{% else %}success{% endif %}">{% if not b.power_status %}OFF{% else %}ON{% endif %}</span></td>
<td><a href="{% url 'webcam_show_video_to_admin' b.mid %}" target="_blank">View image</a></td>
<td><a href="{% url 'admin_profile' b.mid %}">View</a></td>
<td><a href="{% url 'admin_logs' b.mid %}">Download</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(".label-success").click(toggleState);
$(".label-warning").click(toggleState);
$(".success").click(togglePowerState);
$(".danger").click(togglePowerState);
function toggleState() {
console.log('inside toggleState')
var BASE_URL = window.location.origin + "";
if (window.confirm("Are you sure you want to toggle the state?")) {
var element = $(this);
console.log('element '+element)
var board_class = element.attr("class");
console.log('board_class '+board_class);
var selected_mid = element.parent().prev().html();
console.log('selected_mid '+selected_mid)
var request = $.ajax({
url : BASE_URL + '/sbhs/admin/toggledevice',
method : 'POST',
data : {
'mid' : selected_mid
}
});
request.done(function(data){
if (data.status_code == 200) {
if (board_class.indexOf("label-success") > -1) {
element.removeClass("label-success");
element.addClass("label-warning");
element.html("Temp Offline");
}
else {
element.removeClass("label-warning");
element.addClass("label-success");
element.html("Online");
}
}
else {
alert("Sorry! The state could not be toggled. "+data.message);
}
});
}
}
function togglePowerState(){
console.log('togglePowerState!');
var BASE_URL = window.location.origin + "";
if (window.confirm("Are you sure you want to toggle the state?")) {
var element = $(this);
console.log('element '+element)
var board_class = element.attr("class");
console.log('board_class '+board_class);
// var selected_mid = element.parent().prev().html();
var selected_mid = element.parent().siblings('td.board_id').html()
console.log('selected_mid '+selected_mid)
var request = $.ajax({
url : BASE_URL + '/sbhs/admin/togglePowerState',
method : 'POST',
data : {
'mid' : selected_mid
}
});
request.done(function(data){
if (data.status_code == 200) {
if (board_class.indexOf("success") > -1) {
element.removeClass("success");
element.addClass("danger");
element.html("OFF");
}
else {
element.removeClass("danger");
element.addClass("success");
element.html("ON");
}
}
else {
alert("Sorry! The state could not be toggled. "+data.message);
}
});
}
}
// $(window).bind("beforeunload",function(event){
// return "Please don't refresh. This will change the state of off devices to disconnected."
// });
// This function does not allow to refresh the admin page. Refreshing admin Page will change the state of device
function disableF5(e){
if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e. preventDefault();
};
$(document).ready(function(){
$(document).on("keydown",disableF5);
});
</script>
{% endblock %}
|