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

{% block content %}
<div class="container">
    <div class="row">
        {% include "account/sub_nav.html" %}
        <div style="margin-left: 30px">
            {% include "admin/sub_nav.html" %}
            <h1>Board status</h1>
        </div>
        <div class="span7">
            <table class="table table-bordered" id="tableId">
                <thead>
                    <tr>
                        <th>Board MID</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    {% for b in boards %}
                    <tr>
                        <td>{{ b.mid }}</td>
                        <td><span class="label label-{% if b.online %}success{% else %}important{% endif %}">{% if b.online %}Online{% else %}Offline{% endif %}</span></td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        <div class="span5">    
            <div>
                <input type="text" id="temp"><br/>
                <button class="btn btn-primary" onclick="getTemp()">Get Temperature</button>
            </div>
            <br><br>

            <div>
                Heater Input: <input type="number" size="3" min="0" max="250" id="heater_val"><br/>
                Fan Input:<input type="number" size="3" min="0" max="250" id="fan_val" style="margin-left: 20px"><br/>
                <button class="btn btn-primary" onclick="setParams()">Set Parameters</button>
                <br><br>
            </div>
            <br><br>

            <div>
                <button class="btn btn-primary" onclick="resetParams()">Reset Parameters</button>
            </div>           

        </div>

    </div>
</div>
<style type="text/css">
    .highlight {
        background-color: lightblue;
    }
</style>
<script>
    var BASE_URL = window.location.origin;
    $("#tableId").on("click", "tr", function(e) {
        $("#tableId").find("tr.highlight").removeClass("highlight");
        $(this).addClass("highlight");
    });
    
    function resetParams() {
        var selected_machine = document.getElementsByClassName("highlight");
        if (selected_machine.length == 0) {
            alert("Please select a machine first");
            return;
        }
        var selected_mid = selected_machine[0].getElementsByTagName('td')[0].innerHTML;
        var request = $.ajax({
            url : BASE_URL + '/admin/resetdevice',
            method : 'POST',
            data : {
                'mid' : selected_mid
            }
        });

        request.done(function(data){
            if (data.status_code == 200) {
                document.getElementById("temp").value = data.message;
            }
            else {
                alert("Some error occured. Please try again!!");
            }
        });
    }

    function setParams() {
        var selected_machine = document.getElementsByClassName("highlight");
        if (selected_machine.length == 0) {
            alert("Please select a machine first");
            return;
        }
        var selected_mid = selected_machine[0].getElementsByTagName('td')[0].innerHTML;
        var fan_value = document.getElementById("fan_val").value;
        var heater_value = document.getElementById("heater_val").value;

        var isInputOK = !isNaN(fan_value) && fan_value >=0 && fan_value <= 250 && !isNaN(heater_value) && heater_value >=0 && heater_value;
        if (!isInputOK) {
            alert("Please enter a value between 0 and 250");
        }

        var request = $.ajax({
            url : BASE_URL + '/admin/setdevice',
            method : 'POST',
            data : {
                'mid' : selected_mid,
                'fan' : fan_value,
                'heat' : heater_value
            }
        });

        request.done(function(data){
            if (data.status_code == 200) {
                document.getElementById("temp").value = data.message;
            }
            else {
                alert("Some error occured. Please try again!!");
            }
        });
    }

    function getTemp() {
        var selected_machine = document.getElementsByClassName("highlight");
        if (selected_machine.length == 0) {
            alert("Please select a machine first");
            return;
        }
        var selected_mid = selected_machine[0].getElementsByTagName('td')[0].innerHTML;
        var request = $.ajax({
            url : BASE_URL + '/admin/gettemp',
            method : 'POST',
            data : {
                'mid' : selected_mid
            }
        });

        request.done(function(data){
            if (data.status_code == 200) {
                document.getElementById("temp").value = data.message;
            }
            else {
                alert("Some error occured. Please try again!!");
            }
        });
    }
</script>

{% endblock %}