From: Emilie Date: Thu, 16 Mar 2017 18:35:08 +0000 (+0100) Subject: [Vertigo M&C] pin Europe/Paris timezone + improve X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=cd5b8f065277407f285c2e3edea633f7f73c128a;p=mezzo.git [Vertigo M&C] pin Europe/Paris timezone + improve --- diff --git a/app/organization/media/views.py b/app/organization/media/views.py index 2e893306..a12a1b1b 100644 --- a/app/organization/media/views.py +++ b/app/organization/media/views.py @@ -121,7 +121,7 @@ class MediaOverlayView(SlugMixin, DetailView): def get_template_names(self): templates = super(MediaOverlayView, self).get_template_names() templates.insert(0,'media/'+self.object.type.lower()+'/'+self.object.type.lower()+'_overlay.html') - return templates + return templatesc class PlaylistOverlayView(SlugMixin, DetailView): @@ -152,8 +152,7 @@ class LiveStreamingDetailView(SlugMixin, DetailView): context['slug'] = self.object.slug # event data - all_events = Event.objects.filter(location=self.object.event_location) - curr_event = Event.objects.filter(location=self.object.event_location).filter(end__gte=datetime.now()).order_by('start').first() + all_events = Event.objects.filter(location=self.object.event_location).filter(end__gte=datetime.now()).order_by('start') events_data = {} counter = 0 @@ -163,10 +162,7 @@ class LiveStreamingDetailView(SlugMixin, DetailView): events_data[counter]['title'] = event.title events_data[counter]['begin'] = event.start.isoformat() events_data[counter]['end'] = event.end.isoformat() - if curr_event: - if curr_event.id == event.id : - curr_event_index = counter counter += 1 - context['curr_event_index'] = curr_event_index + context['json_event'] = json.dumps(events_data) return context diff --git a/app/themes/base/static/src/js/modules/live-streaming-counter.js b/app/themes/base/static/src/js/modules/live-streaming-counter.js index e49ceab4..3b6f4c24 100644 --- a/app/themes/base/static/src/js/modules/live-streaming-counter.js +++ b/app/themes/base/static/src/js/modules/live-streaming-counter.js @@ -27,21 +27,20 @@ function failed(e) { } -function cleanCounter() { +function cleanCounter(timer) { + clearInterval(timer); $('#countdown-title').html('

'); $('#countdown').html('
'); + $('.countdown-overlay').show(); } -function CountDownTimer(json_event, curr_event_index, id, video_id/*, video_url*/) +function CountDownTimer(json_event, id, video_id) { - if (Object.keys(json_event).length <= curr_event_index) { - return ; - } var curr_event; var begin; var end; - + var curr_event_index = 0; var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; @@ -51,46 +50,49 @@ function CountDownTimer(json_event, curr_event_index, id, video_id/*, video_url* var distance_in = 1; function init() { - if (curr_event_index < Object.keys(json_event).length ) { + if (Object.keys(json_event).length > 0 ) { curr_event = json_event[curr_event_index]; begin = moment(new Date(curr_event.begin)); end = moment(new Date(curr_event.end)).add(30, 'm'); - clearInterval(timer); + timer = setInterval(start, 1000); + } else { + cleanCounter(timer); } } function showRemaining() { - var now = moment(new Date()); + var now = moment().tz("Europe/Paris").format(); var distance_out = begin.diff(now); + updateDisplay(distance_out); if (distance_out < 0) { //clearInterval(timer); // $('#countdown-title').html('

'); // $('#'+id).html('
'); // $('#live').html('- Live !'); //switchVideo(video_id, video_url); - $('.countdown-overlay').hide() - distance_in = 1; - hideRemaining() - //return; + $('.countdown-overlay').hide(); + hideRemaining(); } - updateDisplay(distance_out); } function hideRemaining() { - var now = moment(new Date()); + var now = moment().tz("Europe/Paris").format(); //moment(new Date()); var distance_in = end.diff(now); if (distance_in < 0) { nextEvent(); - distance_out = begin.diff(now); - updateDisplay(distance_out); - $('.countdown-overlay').show() + showRemaining(); + $('.countdown-overlay').show(); } } function nextEvent() { curr_event_index++; - init(); + if (curr_event_index >= Object.keys(json_event).length ) { + cleanCounter(timer); + } else { + init(); + } } function updateDisplay(time_remaining) { @@ -108,18 +110,21 @@ function CountDownTimer(json_event, curr_event_index, id, video_id/*, video_url* document.getElementById(id).innerHTML += seconds + 'secs'; } - // initialize - init(); + function start() { + // out of event + if (distance_out > 0) { + showRemaining(); + } - // out of event - if (distance_out > 0) { - timer = setInterval(showRemaining, 1000); - } + // meanwhile an event + if (distance_in > 0) { + hideRemaining(); + } - // meanwhile an event - if (distance_in > 0) { - timer = setInterval(hideRemaining, 1000); } + + // initialize + init(); } diff --git a/app/themes/base/templates/includes/footer_scripts.html b/app/themes/base/templates/includes/footer_scripts.html index 5645958f..09c588b9 100644 --- a/app/themes/base/templates/includes/footer_scripts.html +++ b/app/themes/base/templates/includes/footer_scripts.html @@ -15,6 +15,7 @@ + {% block extra_js %}{% endblock %} diff --git a/app/themes/base/templates/media/live_streaming/live_streaming_detail.html b/app/themes/base/templates/media/live_streaming/live_streaming_detail.html index fef8b508..95bc7305 100644 --- a/app/themes/base/templates/media/live_streaming/live_streaming_detail.html +++ b/app/themes/base/templates/media/live_streaming/live_streaming_detail.html @@ -49,6 +49,6 @@ {% endblock %} diff --git a/bower.json b/bower.json index 4627acc1..5aa235d8 100644 --- a/bower.json +++ b/bower.json @@ -30,6 +30,7 @@ "videojs-playlist": "^2.4.0", "jquery_lazyload": "jquery.lazyload#^1.9.7", "waypoints": "^4.0.1", - "moment": "*" + "moment": "^2.17.1", + "moment-timezone" : "^0.5.11" } }