From: Emilie Date: Wed, 15 Mar 2017 13:33:23 +0000 (+0100) Subject: [Vertigo M&C] : streaming event queue X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=539092602f5318c3d487a0d99556fc3437015ae9;p=mezzo.git [Vertigo M&C] : streaming event queue --- diff --git a/app/organization/core/templatetags/organization_tags.py b/app/organization/core/templatetags/organization_tags.py index 7b66bf79..a3db871a 100644 --- a/app/organization/core/templatetags/organization_tags.py +++ b/app/organization/core/templatetags/organization_tags.py @@ -238,7 +238,3 @@ def filter_content(dynamic_contents): else : dict["other"].append(dc) return dict - -@register.filter -def format_iso(date): - return date.isoformat() diff --git a/app/organization/media/views.py b/app/organization/media/views.py index 8b834d3b..2e893306 100644 --- a/app/organization/media/views.py +++ b/app/organization/media/views.py @@ -18,7 +18,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - +import json from django.shortcuts import render from collections import defaultdict from organization.media.models import * @@ -26,6 +26,7 @@ from organization.core.views import * from dal import autocomplete from django.core.exceptions import FieldDoesNotExist from datetime import datetime +from django.db.models import Q # temporarily excluse not ready models EXCLUDED_MODELS = ("organizationplaylist", "personplaylist") @@ -137,7 +138,8 @@ class LiveStreamingDetailView(SlugMixin, DetailView): def get_context_data(self, **kwargs): context = super(LiveStreamingDetailView, self).get_context_data(**kwargs) - print("LIVE_STREAMING_TYPE_CHOICES", LIVE_STREAMING_TYPE_CHOICES) + + # check type choices type_choices = [] for st in LIVE_STREAMING_TYPE_CHOICES: type_choices.append(st[0]) @@ -146,6 +148,25 @@ class LiveStreamingDetailView(SlugMixin, DetailView): else : context['type'] = self.kwargs['type'] - context['slug'] = self.object.slug - context['next_event'] = Event.objects.filter(location=self.object.event_location).filter(start__gt=datetime.now()).first() + # slug + 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() + + events_data = {} + counter = 0 + curr_event_index = len(all_events) + for event in all_events: + events_data[counter] = {} + 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 1dd05a3f..576897bb 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 @@ -32,10 +32,17 @@ function cleanCounter() { $('#countdown').html('
'); } -function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/) +function CountDownTimer(json_event, curr_event_index, id, video_id/*, video_url*/) { - var begin = new Date(dt_begin); - var end = new Date(dt_end); + //console.log("json_event.length", Object.keys(json_event).length); + //console.log("curr_event_index", curr_event_index); + if (Object.keys(json_event).length <= curr_event_index) { + return ; + } + + var curr_event = json_event[curr_event_index]; + var begin = new Date(curr_event.begin); + var end = new Date(curr_event.end); var _second = 1000; var _minute = _second * 60; @@ -43,12 +50,12 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/) var _day = _hour * 24; var timer; var distance_out = 1; - var distance_in = 0; + var distance_in = 1; function showRemaining() { var now = new Date(); var distance_out = begin - now; - // console.log("distance_out", distance_out) + //console.log("distance_out", distance_out) if (distance_out < 0) { //clearInterval(timer); @@ -58,11 +65,11 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/) //switchVideo(video_id, video_url); $('.countdown-overlay').hide() distance_in = 1; - nextEvent() - return; + hideRemaining() + //return; } - $('#countdown-title').html('Retransmission dans :'); + $('#countdown-title').html('Prochain évènement :

'+ curr_event.title +'

Retransmission dans :'); var days = Math.floor(distance_out / _day); var hours = Math.floor((distance_out % _day) / _hour); @@ -76,17 +83,37 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/) } - function nextEvent() { + function hideRemaining() { var now = new Date(); var distance_in = end - now; //console.log("distance_in", distance_in) if (distance_in < 0) { + nextEvent() + distance_in = end - now; $('.countdown-overlay').show() + } + } + + function nextEvent() { + curr_event_index++; + if (shouldStreamingStop()) { + curr_event = json_event[curr_event_index] + begin = new Date(curr_event.begin); + end = new Date(curr_event.end); + } + } + function shouldStreamingStop() { + var bool = true; + if (json_event.length - 1 < curr_event_index) { + clearInterval(timer); + bool = false; } + return bool; } + // calculer le diff avec le prochain évènement // réactiver le countdown @@ -96,7 +123,7 @@ function CountDownTimer(dt_begin, dt_end, id, video_id/*, video_url*/) //console.log("distance_in", distance_in) if (distance_in > 0) { - timer = setInterval(nextEvent, 1000); + timer = setInterval(hideRemaining, 1000); } } 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 486e9f66..9a1a67e7 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 @@ -52,8 +52,7 @@ {% endblock %}