Index: lams_tool_doku/web/pages/learning/learning.jsp
===================================================================
diff -u -r8d372a4476d25a498b5af8c04e82576edc7b0976 -r0ebaba46f0ce87b5138e8e70cc1965887c1c7787
--- lams_tool_doku/web/pages/learning/learning.jsp (.../learning.jsp) (revision 8d372a4476d25a498b5af8c04e82576edc7b0976)
+++ lams_tool_doku/web/pages/learning/learning.jsp (.../learning.jsp) (revision 0ebaba46f0ce87b5138e8e70cc1965887c1c7787)
@@ -10,7 +10,6 @@
-
@@ -19,19 +18,20 @@
<%@ include file="/common/header.jsp"%>
@@ -69,22 +69,7 @@
,'userName':' '
});
- if (${secondsLeft > 0}) {
- displayCountdown()
- }
-
$('[data-toggle="tooltip"]').bootstrapTooltip();
-
- <%-- Connect to command websocket only if it is learner UI --%>
-
- // command websocket stuff for refreshing
- // trigger is an unique ID of page and action that command websocket code in Page.tag recognises
- commandWebsocketHookTrigger = 'doku-leader-change-refresh-${toolSessionID}';
- // if the trigger is recognised, the following action occurs
- commandWebsocketHook = function() {
- location.reload();
- };
-
});
if (${!hasEditRight && mode != "teacher" && !finishedLock}) {
@@ -115,48 +100,121 @@
function continueReflect(){
document.location.href='';
}
+
+
- function displayCountdown() {
+ // TIME LIMIT
+ var dokuWebsocketInitTime = Date.now(),
+ dokuWebsocket = new WebSocket(''.replace('http', 'ws')
+ + 'learningWebsocket?toolContentID=' + ${sessionMap.toolContentID}),
+ dokuWebsocketPingTimeout = null,
+ dokuWebsocketPingFunc = null;
+
+ dokuWebsocket.onclose = function(){
+ // react only on abnormal close
+ if (e.code === 1006 &&
+ Date.now() - dokuWebsocketInitTime > 1000) {
+ location.reload();
+ }
+ };
+
+ dokuWebsocketPingFunc = function(skipPing){
+ if (dokuWebsocket.readyState == dokuWebsocket.CLOSING
+ || dokuWebsocket.readyState == dokuWebsocket.CLOSED){
+ return;
+ }
+
+ // check and ping every 3 minutes
+ dokuWebsocketPingTimeout = setTimeout(dokuWebsocketPingFunc, 3*60*1000);
+ // initial set up does not send ping
+ if (!skipPing) {
+ dokuWebsocket.send("ping");
+ }
+ };
+
+ // set up timer for the first time
+ dokuWebsocketPingFunc(true);
+
+ var timeLimitExceeded = ${timeLimitExceeded};
+ // run when the server pushes new reports and vote statistics
+ dokuWebsocket.onmessage = function(e) {
+ // create JSON object
+ var input = JSON.parse(e.data);
+
+ if (input.clearTimer == true) {
+ // teacher stopped the timer, destroy it
+ $('#countdown').countdown('destroy').remove();
+ } else {
+ // teacher updated the timer
+ var secondsLeft = +input.secondsLeft,
+ counterInitialised = $('#countdown').length > 0;
+
+ if (counterInitialised) {
+ // just set the new time
+ $('#countdown').countdown('option', 'until', secondsLeft + 'S');
+ } else if (secondsLeft){
+ if (timeLimitExceeded) {
+ // teacher gave extra time, reload to writable Etherpad
+ location.reload();
+ return;
+ }
+ // initialise the timer
+ displayCountdown(secondsLeft);
+ }
+ }
+
+ // reset ping timer
+ clearTimeout(dokuWebsocketPingTimeout);
+ dokuWebsocketPingFunc(true);
+ };
+
+ function displayCountdown(secondsLeft){
+ $('#etherpad-panel').addClass('lower-to-fit-countdown');
+
+ var countdown = '';
+
$.blockUI({
- message: '',
+ message: countdown,
showOverlay: false,
focusInput: false,
css: {
- top: '10px',
+ top: '40px',
left: '',
- right: '1%',
- width: '150px',
- opacity: '.8',
+ right: '0%',
+ opacity: '1',
+ width: '150px',
cursor: 'default',
border: 'none'
}
});
$('#countdown').countdown({
- until: '+${secondsLeft}S',
+ until: '+' + secondsLeft +'S',
format: 'hMS',
compact: true,
- description: "
",
+ alwaysExpire : true,
onTick: function(periods) {
- //check for 30 seconds
- if ((periods[4] == 0) && (periods[5] == 0) && (periods[6] <= 30)) {
- $('#countdown').css('color', '#FF3333');
- }
+ // check for 30 seconds or less and display timer in red
+ var secondsLeft = $.countdown.periodsToSeconds(periods);
+ if (secondsLeft <= 30) {
+ $(this).addClass('countdown-timeout');
+ } else {
+ $(this).removeClass('countdown-timeout');
+ }
},
onExpiry: function(periods) {
$.blockUI({ message: '
' });
setTimeout(function() {
location.reload();
}, 4000);
- }
+ },
+ description: "
"
});
}
-
- <%@ include file="websocket.jsp"%>
-
+ <%@ include file="websocket.jsp"%>
@@ -180,8 +238,7 @@
-