Commit 5095641b authored by Stefan Kraus's avatar Stefan Kraus Committed by Tom Kunze
Browse files

server: show today's lectures

parent 9cba3a4f
......@@ -105,12 +105,15 @@ function toggleLectureMode() {
var cipButton = $(".cipButton").not(".current").parent('a');
var pane = $("#tutorRequestPane");
var modeButton = $("#lectureModeButton");
var lecturePane = $("#lecture-overview");
if (lectureMode) {
cipButton.show();
lecturePane.show();
pane.hide();
modeButton.removeClass("current");
} else {
cipButton.hide();
lecturePane.hide();
pane.show();
modeButton.addClass("current");
}
......@@ -546,6 +549,58 @@ function populateMap() {
error: newErrorHandler("populateMap"),
});
}
$.ajax(server+"/lectures", {
success: showLectures,
beforeSend: showSpinner,
complete:hideSpinner,
timeout: 4000,
error: newErrorHandler("showLectures"),
});
}
function showLectures(response) {
var lecturePane = $("#lecture-overview");
lecturePane.empty();
var lectures = response["lectures"];
var today = new Date();
//extracts hh:mm from complete string with timezone, ignore rest.
var timenow = today.toTimeString().substr(0, 5)
$.each(lectures, function(index, lec){
var name = lec["name"];
var start = lec["start"].substr(0, 5); //only hours and minutes
var end = lec["end"].substr(0, 5);
var weekday = lec["weekday"];
var room = lec["room"];
// If not today or not in this room, ignore it
// getDay 0 is a sunday, but for us monday is 0,
// so we have to correct it here...
if((weekday != (today.getDay() + 6) % 7) ||
(currentRoom() != room)){
return;
}
//Already sorted in database, so no need to sort again!
var div = document.createElement("div")
if(start <= timenow && timenow < end){
$(div).css({'font-weight': 'bold'});
}
//build lecture entrys
$(div).css({'margin': '5px 0px 5px 0px'});
div.append(document.createTextNode(start.substr(0, 2) + ":00 Uhr: "));
div.append(document.createElement("br"));
div.append(document.createTextNode(name));
lecturePane.append(div);
});
}
//Calculates a human readable time and displays it in all .ageTimer elements
......
......@@ -80,6 +80,9 @@
</label>
</div>
</div>
{% block lecture-overview %}{% endblock %}
</div>
{% block main %}{% endblock %}
......
......@@ -5,6 +5,10 @@
<body onload="cipInit();">
{% endblock %}
{% block lecture-overview %}
<div id="lecture-overview">
</div>
{% endblock %}
{% block nav-lecturemode %}
<div id="tutorRequestPane" style="display:none">
......
......@@ -17,6 +17,7 @@ urlpatterns = [
# User api
url(r'^api/hosts$', cache_page(0)(views.hosts)),
url(r'^api/hostname$', cache_page(0)(views.hostname)), # no caching!
url(r'^api/lectures$', cache_page(60*10)(views.lectures)), # cache 10 min
url(r'^api/opt$', cache_page(0)(views.api_optin)), # no caching!
url(r'^api/request$', views.request),
url(r'^api/requests$', cache_page(10)(views.requests)),
......
......@@ -229,6 +229,16 @@ def _requests(request, send_hostname=None):
data['hostname'] = send_hostname
return JsonResponse(data)
def lectures(request):
# Get all lectures we know of to display them in main view
if request.method != "GET":
raise SuspiciousOperation('invalid method')
lecs = Exercise.objects.all().values('name', 'start', 'end', 'weekday', 'room')
return JsonResponse({"lectures": list(lecs)})
def api_optin(request):
if 'REMOTE_USER' not in request.META:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment