From ef687ad23cf67f6eb61b19b3652afefbc79c4b03 Mon Sep 17 00:00:00 2001 From: Dominik Breu Date: Tue, 22 Oct 2013 00:15:45 +0200 Subject: [PATCH 1/2] Fix for wrong format of clock and countdown on projector --- AUTHORS | 1 + .../projector/static/javascript/clock.js | 9 ++++++ .../projector/static/javascript/countdown.js | 30 +++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 866c452df..52d204a63 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,3 +13,4 @@ Authors of OpenSlides in chronological order of first contribution: Pavel Fric (Czech translation) Max Brauer Marco A.G.Pinto (Portuguese translation) + Dominik Breu diff --git a/openslides/projector/static/javascript/clock.js b/openslides/projector/static/javascript/clock.js index 6b3de95c4..6fcd167dd 100644 --- a/openslides/projector/static/javascript/clock.js +++ b/openslides/projector/static/javascript/clock.js @@ -2,7 +2,16 @@ function update_clock() { var currentTime = new Date(); var currentHours = currentTime.getHours(); var currentMinutes = currentTime.getMinutes(); + currentHours = normalise(currentHours); + currentMinutes = normalise(currentMinutes); $('#currentTime').html(currentHours + ':' + currentMinutes); setTimeout('update_clock()', 200); } + update_clock(); +function normalise(i) { + if(i < 10) { + i = "0" + i; + } + return i; +} diff --git a/openslides/projector/static/javascript/countdown.js b/openslides/projector/static/javascript/countdown.js index fb428c948..3a5aff9e6 100644 --- a/openslides/projector/static/javascript/countdown.js +++ b/openslides/projector/static/javascript/countdown.js @@ -1,11 +1,13 @@ function update_countdown() { var time = new Date().getTime() / 1000; var seconds; + var minutes_digit; + var seconds_digit; + var hours_digit; var start = projector.projector_countdown_start; var duration = projector.projector_countdown_duration; var pause = projector.projector_countdown_pause; - - switch (projector.projector_countdown_state) { + switch(projector.projector_countdown_state) { case 'active': seconds = start + duration - time; break; @@ -16,10 +18,32 @@ function update_countdown() { seconds = duration; break; } - if (seconds !== undefined) { + if(seconds > 60) { + hours_digit = Math.floor(seconds / 3600); + minutes_digit = Math.floor((seconds - (hours_digit * 3600)) / 60); + seconds_digit = Math.floor(seconds - (hours_digit * 3600) - (minutes_digit * 60)); + minutes_digit = normalise(minutes_digit); + seconds_digit = normalise(seconds_digit); + if(hours_digit > 0) { + hours_digit = normalise(hours_digit); + seconds = hours_digit + ":" + minutes_digit + ":" + seconds_digit; + } else { + seconds = minutes_digit + ":" + seconds_digit; + } + } else { seconds = Math.max(0, Math.floor(seconds)); + } + if(seconds !== undefined) { $('#overlay_countdown_inner').html(seconds); } setTimeout('update_countdown()', 200); } update_countdown(); + +function normalise(i) { + if(i < 10) { + i = "0" + i; + } + return i; +} + From ffe612359f975e28503b6418998dbb9438574b09 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 26 Oct 2013 12:59:39 +0200 Subject: [PATCH 2/2] use the server_time for countdown and clock --- openslides/projector/signals.py | 5 ++++- openslides/projector/static/javascript/clock.js | 5 +++-- openslides/projector/static/javascript/countdown.js | 11 +++++++---- openslides/projector/static/javascript/projector.js | 11 ++++++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/openslides/projector/signals.py b/openslides/projector/signals.py index 4ddda365b..e6b2634a2 100644 --- a/openslides/projector/signals.py +++ b/openslides/projector/signals.py @@ -9,6 +9,8 @@ :copyright: 2011–2013 by OpenSlides team, see AUTHORS. :license: GNU GPL, see LICENSE for more details. """ +from time import time + from django.contrib.staticfiles.templatetags.staticfiles import static from django.core.context_processors import csrf from django.dispatch import receiver, Signal @@ -167,7 +169,8 @@ def projector_clock(sender, **kwargs): """ Returns JavaScript for the projector """ - return {'load_file': static('javascript/clock.js')} + return {'load_file': static('javascript/clock.js'), + 'server_time': int(time())} return Overlay(name, None, get_projector_html, get_projector_js, allways_active=True) diff --git a/openslides/projector/static/javascript/clock.js b/openslides/projector/static/javascript/clock.js index 6fcd167dd..35bfe0833 100644 --- a/openslides/projector/static/javascript/clock.js +++ b/openslides/projector/static/javascript/clock.js @@ -1,5 +1,5 @@ function update_clock() { - var currentTime = new Date(); + var currentTime = projector.get_server_time() var currentHours = currentTime.getHours(); var currentMinutes = currentTime.getMinutes(); currentHours = normalise(currentHours); @@ -9,8 +9,9 @@ function update_clock() { } update_clock(); + function normalise(i) { - if(i < 10) { + if (i < 10) { i = "0" + i; } return i; diff --git a/openslides/projector/static/javascript/countdown.js b/openslides/projector/static/javascript/countdown.js index 3a5aff9e6..2b248b63e 100644 --- a/openslides/projector/static/javascript/countdown.js +++ b/openslides/projector/static/javascript/countdown.js @@ -1,5 +1,5 @@ function update_countdown() { - var time = new Date().getTime() / 1000; + var time = projector.get_server_time().getTime() / 1000; var seconds; var minutes_digit; var seconds_digit; @@ -7,7 +7,8 @@ function update_countdown() { var start = projector.projector_countdown_start; var duration = projector.projector_countdown_duration; var pause = projector.projector_countdown_pause; - switch(projector.projector_countdown_state) { + + switch (projector.projector_countdown_state) { case 'active': seconds = start + duration - time; break; @@ -18,13 +19,13 @@ function update_countdown() { seconds = duration; break; } - if(seconds > 60) { + if (seconds > 60) { hours_digit = Math.floor(seconds / 3600); minutes_digit = Math.floor((seconds - (hours_digit * 3600)) / 60); seconds_digit = Math.floor(seconds - (hours_digit * 3600) - (minutes_digit * 60)); minutes_digit = normalise(minutes_digit); seconds_digit = normalise(seconds_digit); - if(hours_digit > 0) { + if (hours_digit > 0) { hours_digit = normalise(hours_digit); seconds = hours_digit + ":" + minutes_digit + ":" + seconds_digit; } else { @@ -33,11 +34,13 @@ function update_countdown() { } else { seconds = Math.max(0, Math.floor(seconds)); } + if(seconds !== undefined) { $('#overlay_countdown_inner').html(seconds); } setTimeout('update_countdown()', 200); } + update_countdown(); function normalise(i) { diff --git a/openslides/projector/static/javascript/projector.js b/openslides/projector/static/javascript/projector.js index 113f08b57..7fc989c88 100644 --- a/openslides/projector/static/javascript/projector.js +++ b/openslides/projector/static/javascript/projector.js @@ -31,11 +31,20 @@ var projector = { $('#content').css('font-size', 100 + 20 * value + '%'); }, + get_server_time: function () { + var date = new Date(); + date.setTime(date.getTime() + projector.server_time_offset); + return date; + }, + update_data: function(data) { $.each(data, function (key, value) { if (key === 'load_file') projector.load_file(value); - else + else if (key === 'server_time') { + var local_time = Date.parse(new Date().toUTCString()); + projector.server_time_offset = local_time - value * 1000; + } else projector[key] = value; }); }