summaryrefslogtreecommitdiff
path: root/templates/admin/index.html
blob: dba8419506a0b46d08e5a3b17b25b0a7053ba18c (plain)
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
{% extends "layout.html" %}
{% load staticfiles %}

{% 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>Webcam</th>
                        <th>Temperature Profile</th>
                        <th>Download Logs</th>
                    </tr>
                </thead>
                <tbody>
                    {% for b in boards %}
                    <tr>
                        <td>{{ 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><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);

    function toggleState() {
        var BASE_URL = window.location.origin + "/sbhs";
        if (window.confirm("Are you sure you want to toggle the state?")) {
            var element = $(this);
            var board_class = element.attr("class");
            var selected_mid = element.parent().prev().html();

            var request = $.ajax({
                url : BASE_URL + '/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.");
                }
            });
        }
    }
</script>
{% endblock %}