]> git.sesse.net Git - ultimatescore/commitdiff
Show the entire schedule, even if it spans multiple days.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 26 Oct 2017 17:53:35 +0000 (19:53 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 26 Oct 2017 17:53:35 +0000 (19:53 +0200)
carousel.js

index 0d5ec25783f9a6a392ec8743d448c16f4244192e..e6a45d2385aa4c463341846c9f9a49c0fd69b9da 100644 (file)
@@ -401,16 +401,15 @@ var clear_carousel = function(table)
 };
 
 // Stream schedule
+var max_list_len = 8;
+
 var display_stream_schedule = function(response, group_name) {
        var teams = parse_teams_from_spreadsheet(response);
        var games = parse_games_from_spreadsheet(response, group_name, true);
-       display_stream_schedule_parsed(teams, games);
+       display_stream_schedule_parsed(teams, games, 0);
 };
 
-var display_stream_schedule_parsed = function(teams, games) {
-       document.getElementById('entire-bug').style.display = 'none';
-
-       var teams_to_idx = make_teams_to_idx(teams);
+var sort_game_list = function(games) {
        games = games.filter(function(game) { return game.streamtime !== undefined && game.streamtime.match(/[0-9]+:[0-9]+/) != null; });
        games.sort(function(a, b) {
                if (a.streamday !== b.streamday) {
@@ -421,10 +420,12 @@ var display_stream_schedule_parsed = function(teams, games) {
                var m2 = b.streamtime.match(/([0-9]+):([0-9]+)/);
                return (m1[1] * 60 + m1[2]) - (m2[1] * 60 + m2[2]);
        });
+       return games;
+}
 
+var find_game_start_idx = function(games) {
        // Pick out a reasonable place to start the list. We'll show the last
        // completed match and start from there.
-       var max_list_len = 8;
        var start_idx = games.length - 1;
        for (var i = 0; i < games.length; ++i) {
                if (isNaN(games[i].score1) || isNaN(games[i].score2) &&
@@ -437,17 +438,45 @@ var display_stream_schedule_parsed = function(teams, games) {
        if (games.length >= max_list_len) {
                start_idx = Math.min(start_idx, games.length - max_list_len);
        }
+       return start_idx;
+}
+
+var find_num_pages = function(games) {
+       games = sort_game_list(games);
+       var start_idx = find_game_start_idx(games);
+       return Math.ceil((games.length - start_idx) / max_list_len);
+}
+
+var display_stream_schedule_parsed = function(teams, games, page) {
+       document.getElementById('entire-bug').style.display = 'none';
+
+       games = sort_game_list(games);
+       var start_idx = find_game_start_idx(games);
+
+       start_idx += page * max_list_len;
+       if (start_idx >= games.length) {
+               // Error.
+               return;
+       }
 
        var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
        var shortdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
        var today = days[(new Date).getDay()];
-       var short_today = shortdays[(new Date).getDay()];
+
+       var covered_days = [];
+       var row_num = 0;
+       for (var i = start_idx; i < games.length && row_num++ < max_list_len; ++i) {
+               if (i == start_idx || games[i].streamday != games[i - 1].streamday) {
+                       covered_days.push(days[games[i].streamday]);
+               }
+       }
        
        var carousel = document.getElementById('carousel');
        clear_carousel(carousel);
-       addheading(carousel, 3, "Stream schedule, Trøndisk 2017<br />" + today);
+       addheading(carousel, 3, "Stream schedule, Trøndisk 2017<br />" + covered_days.join('/'));
 
-       var row_num = 0;
+       var teams_to_idx = make_teams_to_idx(teams);
+       row_num = 0;
        for (i = start_idx; i < games.length && row_num < max_list_len; ++i) {
                var tr = document.createElement("tr");
 
@@ -505,7 +534,7 @@ var hidetable = function()
        fade_out_rows(document.getElementById('carousel'));
 };
 
-var showschedule = function()
+var showschedule = function(page)
 {
        var teams = [];
        var games = [];
@@ -515,7 +544,7 @@ var showschedule = function()
                teams = teams.concat(parse_teams_from_spreadsheet(response));
                games = games.concat(parse_games_from_spreadsheet(response, group_name, true));
                if (--num_left == 0) {
-                       display_stream_schedule_parsed(teams, games);
+                       display_stream_schedule_parsed(teams, games, page);
                }
        };
 
@@ -554,14 +583,20 @@ var showcarousel = function()
                combined_teams = combined_teams.concat(teams);
                combined_games = combined_games.concat(games);
                if (--num_left == 0) {
-                       do_series([
+                       var series = [
                                [ 13000, function() { display_group_parsed(teams_per_group['Group A'], games_per_group['Group A'], 'Group A'); } ],
                                [ 2000, function() { hidetable(); } ],
                                [ 13000, function() { display_group_parsed(teams_per_group['Group B'], games_per_group['Group B'], 'Group B'); } ],
-                               [ 2000, function() { hidetable(); } ],
-                               [ 13000, function() { display_stream_schedule_parsed(combined_teams, combined_games); } ],
                                [ 2000, function() { hidetable(); } ]
-                       ]);
+                       ];
+                       series = [];
+                       var num_pages = find_num_pages(combined_games);
+                       for (let page = 0; page < num_pages; ++page) {
+                               series.push([ 13000, function() { display_stream_schedule_parsed(combined_teams, combined_games, page); } ]);
+                               series.push([ 2000, function() { hidetable(); } ]);
+                       }
+
+                       do_series(series);
                }
        };