]> git.parisson.com Git - mezzo.git/commitdiff
[Vertigo M&C] pin Europe/Paris timezone + improve
authorEmilie <zawadzki@ircam.fr>
Thu, 16 Mar 2017 18:35:08 +0000 (19:35 +0100)
committerEmilie <zawadzki@ircam.fr>
Thu, 16 Mar 2017 18:35:08 +0000 (19:35 +0100)
app/organization/media/views.py
app/themes/base/static/src/js/modules/live-streaming-counter.js
app/themes/base/templates/includes/footer_scripts.html
app/themes/base/templates/media/live_streaming/live_streaming_detail.html
bower.json

index 2e893306e5f3a48855a8bdc84701e8e9ad2ec81f..a12a1b1bfa32ef1b18eb3d4b29285c7910aa5369 100644 (file)
@@ -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
index e49ceab4504585eef78d120c26279e175800e5c1..3b6f4c24608ebc9247f6a8fdeeeec7d31b471956 100644 (file)
@@ -27,21 +27,20 @@ function failed(e) {
 }
 
 
-function cleanCounter() {
+function cleanCounter(timer) {
+    clearInterval(timer);
     $('#countdown-title').html('<br /><br />');
     $('#countdown').html('<br />');
+    $('.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('<br /><br />');
                 // $('#'+id).html('<br />');
                 // $('#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();
     }
 
 
index 5645958f7de3dd58c1006785d5bcc4a2c772e30c..09c588b9c429f8dd132709fbbfe164dad4f100b5 100644 (file)
@@ -15,6 +15,7 @@
     <script src="{% static "vendors/jquery_lazyload/jquery.lazyload.js" %}"></script>
     <script src="{% static "vendors/waypoints/lib/jquery.waypoints.js" %}"></script>
     <script src="{% static "vendors/moment/moment.js" %}"></script>
+    <script src="{% static "vendors/moment-timezone/builds/moment-timezone-with-data.js" %}"></script>
     <script src="{% static "js/water.js" %}"></script>
     <script src="{% static "js/index.min.js" %}"></script>
 {% block extra_js %}{% endblock %}
index fef8b508f0259dd9982b3b6f85f1b480875cbf00..95bc7305462c94073a8808b8c06855c3e14ca66f 100644 (file)
@@ -49,6 +49,6 @@
 
     <script type="text/javascript">
         var json_event = {{ json_event|safe }}
-        CountDownTimer(json_event, {{ curr_event_index }}, 'countdown', 'live-streaming');
+        CountDownTimer(json_event, 'countdown', 'live-streaming');
     </script>
 {% endblock %}
index 4627acc1465ea549f198a776be813d027937b01c..5aa235d8bfc9bd695a12c042d953a6da3cd92955 100644 (file)
@@ -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"
   }
 }