summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--myadmin/views.py4
-rw-r--r--templates/admin/changeMID.html48
-rw-r--r--templates/admin/testexp.html20
3 files changed, 66 insertions, 6 deletions
diff --git a/myadmin/views.py b/myadmin/views.py
index a3f6dda..97a23c3 100644
--- a/myadmin/views.py
+++ b/myadmin/views.py
@@ -4,7 +4,7 @@ from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.db.models import Count
from django.core.exceptions import ObjectDoesNotExist
-from sbhs_server.tables.models import Board, Booking, Slot, Experiment
+from sbhs_server.tables.models import Board, Booking, Slot, Experiment, Account
from sbhs_server import settings,sbhs
import subprocess,json,serial,os, datetime
# Create your views here.
@@ -133,7 +133,7 @@ def monitor_experiment(req):
@login_required(redirect_field_name=None)
def get_allocated_mids(req):
checkadmin(req)
- mid_count = Account.objects.select_related().filter('board__online'=1).values('board__mid', 'board_id').annotate(mcount=Count('board_id')).order_by('-mcount')
+ mid_count = Account.objects.select_related().filter(board__online=1).values('board__mid', 'board_id').annotate(mcount=Count('board_id')).order_by('mcount')
return render(req, 'admin/changeMID.html', {"mid_count" : mid_count})
def user_exists(username):
diff --git a/templates/admin/changeMID.html b/templates/admin/changeMID.html
index 784579d..5aff464 100644
--- a/templates/admin/changeMID.html
+++ b/templates/admin/changeMID.html
@@ -8,19 +8,61 @@
<div class="span12">
{% include "admin/sub_nav.html" %}
- Username: <input id="username" type="text">
+ Username: <br>
+
+ <input id="username" type="text" placeholder="Enter Username">
<br><br>
<select id="mid">
{% for mid in mid_count %}
- <option>
+ <option id = "{{ mid.board_id }}">
{{ mid.board__mid }}-{{mid.mcount}}
</option>
{% endfor %}
</select>
- <button class="btn btn-primary" onclick="updateMID()"> Update MID </button>
+ <br>
+ <button id="update-btn" class="btn btn-primary" onclick="updateMID()"> Update MID </button>
</div>
</div>
+
+ <script type="text/javascript">
+
+ function updateMID() {
+ $("#update-btn").prop('disabled',true);
+ var BASE_URL = window.location.origin;
+ var username = $("#username").val();
+ var board_id = $("#mid").children(":selected").attr("id");
+
+ if(username == "")
+ {
+ alert("Username field must not be empty");
+ return;
+ }
+
+ var request = $.ajax({
+ url:BASE_URL + "/admin/updatemid",
+ method : "POST",
+ data : {
+ "username" : username,
+ "board_id" : board_id
+ }
+ });
+
+ request.done(function(data){
+ if(data.status_code == 200) {
+ alert(data.message);
+ location.reload();
+ }
+ else {
+ alert(data.message);
+ $("#update-btn").prop('disabled',false);
+ }
+ });
+
+
+ }
+
+ </script>
</div>
{% endblock %} \ No newline at end of file
diff --git a/templates/admin/testexp.html b/templates/admin/testexp.html
index 052cfe9..f857902 100644
--- a/templates/admin/testexp.html
+++ b/templates/admin/testexp.html
@@ -96,6 +96,9 @@
return;
}
var selected_mid = selected_machine[0].getElementsByTagName('td')[0].innerHTML;
+
+ $(".btn").prop('disabled',true);
+
var request = $.ajax({
url : BASE_URL + '/admin/resetdevice',
method : 'POST',
@@ -113,10 +116,12 @@
else {
alert(data.message);
}
+ $(".btn").prop('disabled',false);
});
}
function setParams() {
+
var MAX_VALUE = 100;
var selected_machine = document.getElementsByClassName("highlight");
if (selected_machine.length == 0) {
@@ -127,11 +132,12 @@
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 <= MAX_VALUE && !isNaN(heater_value) && heater_value >=0 && heater_value <= MAX_VALUE;
+ var isInputOK = !isNaN(fan_value) && fan_value != "" && fan_value >=0 && fan_value <= MAX_VALUE && !isNaN(heater_value) && heater_value != "" && heater_value >=0 && heater_value <= MAX_VALUE;
if (!isInputOK) {
alert("Please enter a value between 0 and " + MAX_VALUE);
return;
}
+ $(".btn").prop('disabled',true);
var request = $.ajax({
url : BASE_URL + '/admin/setdevice',
@@ -150,6 +156,7 @@
else {
alert(data.message);
}
+ $(".btn").prop('disabled',false);
});
}
@@ -160,6 +167,9 @@
return;
}
var selected_mid = selected_machine[0].getElementsByTagName('td')[0].innerHTML;
+
+ $(".btn").prop('disabled',true);
+
var request = $.ajax({
url : BASE_URL + '/admin/gettemp',
method : 'POST',
@@ -175,6 +185,9 @@
else {
alert(data.message);
}
+
+ $(".btn").prop('disabled',false);
+
});
}
@@ -185,6 +198,9 @@
return;
}
var selected_mid = selected_machine[0].getElementsByTagName('td')[0].innerHTML;
+
+ $(".btn").prop('disabled',true);
+
var request = $.ajax({
url : BASE_URL + '/admin/monitor',
method : 'POST',
@@ -203,6 +219,8 @@
else {
alert(data.status_code);
}
+ $(".btn").prop('disabled',false);
+
});
}