const api_url = "http://127.0.0.1:8000" var all_owned_games async function makeRequest(url) { try { const url_request = new Request(url) const response = await fetch(url_request); const result = await response.json(); return result } catch (error) { console.error("Error:", error); } } async function loadWishlistedGames() { var wishlist_priorities = [1,2,3,4] jQuery.each(wishlist_priorities, function(index, item){ var boardgame_datatable = new DataTable('#wishlist_table'+item, { ajax: { url: api_url + '/wishlist?priority='+item, dataSrc: '' }, columns: [ { data: 'wishlist_priority' }, { data: 'thumbnail_url', render: function (data,type){ return '' } }, { data: 'name' }, { data: 'min_players', render: function(data,type,row){ if (row.min_players != row.max_players){ return row.min_players + '-' + row.max_players }else{ return row.min_players } } }, { data: 'min_playing_time', render: function(data,type,row){ if (row.min_playing_time != row.max_playing_time){ return row.min_playing_time + '-' + row.max_playing_time }else{ return row.min_playing_time } } }, { data: 'weight' } ], columnDefs: [ { target: 0, visible: false }, { targets: 'no-sort', orderable: false } ], order: [[2, 'asc']] }); $('#wishlist_table'+item).on('click', 'tbody tr', function() { var boardgame_id = boardgame_datatable.row(this).data().id; window.location.href = "/boardgame?id=" + boardgame_id }) }); } async function loadOwnedGames() { var boardgame_datatable = new DataTable('.boardgame_table', { ajax: { url: api_url + '/owned', dataSrc: '' }, columns: [ { data: 'thumbnail_url', render: function (data,type){ return '' } }, { data: 'name' }, { data: 'min_players', render: function(data,type,row){ if (row.min_players != row.max_players){ return row.min_players + '-' + row.max_players }else{ return row.min_players } } }, { data: 'min_playing_time', render: function(data,type,row){ if (row.min_playing_time != row.max_playing_time){ return row.min_playing_time + '-' + row.max_playing_time }else{ return row.min_playing_time } } }, { data: 'weight' } ], columnDefs: [ { targets: 'no-sort', orderable: false } ], order: [[1, 'asc']] }); $('.boardgame_table').on('click', 'tbody tr', function() { var boardgame_id = boardgame_datatable.row(this).data().id; window.location.href = "/boardgame?id=" + boardgame_id }) } async function loadStatistics(){ const overtimechart = document.getElementById("overtimechart") games_over_time_statistic = await makeRequest(api_url + '/statistics/amount_of_games_over_time') console.log(games_over_time_statistic) console.log(Object.keys(games_over_time_statistic.result)) console.log(Object.values(games_over_time_statistic.result)) new Chart(overtimechart, { type: 'bar', data: { labels: Object.keys(games_over_time_statistic.result), datasets: [{ label: '# of Games', data: Object.values(games_over_time_statistic.result), borderWidth: 1 }] }, options: { scales: { y: { beginAtZero: true } } } }); $("#overtimechartname").text(games_over_time_statistic.name) } async function loadGame() { let params = new URLSearchParams(document.location.search); let boardgame_id = params.get("id"); var loadGameURL = api_url + '/boardgame?id=' + boardgame_id var requested_game = await makeRequest(loadGameURL) $('#boardgame_image').attr('src', requested_game.image_url) $('#boardgame_name').text(requested_game.name) $('#boardgame_weight').text(requested_game.weight) $('#boardgame_description').text(requested_game.description) $('#boardgame_link').attr('href', 'https://boardgamegeek.com/boardgame/' + boardgame_id) }