From 4e3a238d940b387fb1444032b75b233e569d208d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 26 Oct 2017 19:53:35 +0200 Subject: [PATCH] Show the entire schedule, even if it spans multiple days. --- carousel.js | 65 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/carousel.js b/carousel.js index 0d5ec25..e6a45d2 100644 --- a/carousel.js +++ b/carousel.js @@ -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
" + today); + addheading(carousel, 3, "Stream schedule, Trøndisk 2017
" + 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); } }; -- 2.39.2