committed files

This commit is contained in:
dominicjk
2024-04-11 08:36:52 -06:00
8260 changed files with 866980 additions and 243 deletions

View File

@@ -1,25 +0,0 @@
// create-league-routes.js
const express = require('express');
const exphbs = require('express-handlebars');
const app = express();
app.engine('hbs', exphbs({ extname: '.hbs' }));
app.set('view engine', 'hbs');
// Define the redirectToLeaguePage function
function redirectToLeaguePage(leagueName) {
window.location.href = '/views/pages/league-page/league-page.hbs?leagueName=' + encodeURIComponent(leagueName);
}
// Define a route to render the league-page.hbs template
app.get('/league-page/:leagueName', (req, res) => {
const leagueName = req.params.leagueName;
// Here you might fetch data related to the clicked league
// Pass the data to the template and render it
res.render('league-page/league-page', { leagueName });
});
// Export the app and redirectToLeaguePage function
module.exports = { app, redirectToLeaguePage };

View File

@@ -0,0 +1,7 @@
function redirectToLeaguePage(leagueName) {
// Append the league name to the URL
var url = "/league/" + leagueName.toLowerCase().replace(/\s+/g, '-');
// Redirect to the league page
window.location.href = url;
}

View File

@@ -1,66 +0,0 @@
const moment = require('moment');
const axios = require('axios');
// Middleware function to fetch matches data
const fetchMatchesData = async (req, res, next) => {
try {
const today = moment().format('YYYY-MM-DD'); // Get today's date in YYYY-MM-DD format
// Subtract one day to get yesterday's date
const yesterdayUnformatted = moment().subtract(3, 'days');
// Format yesterday's date as YYYY-MM-DD
const yesterday = yesterdayUnformatted.format('YYYY-MM-DD');
// Array of years to fetch matches data
const league_ids = [2021]; /* Readd , 2002, 2014, 2019, 2015, 2013 */
// Array to store all matches data
let allMatches = [];
// Loop through each year and fetch matches data
for (const league_id of league_ids) {
const response = await axios({
url: `http://api.football-data.org/v4/competitions/2021/matches`, /* Resinsert ${league_id} for 2021 */
method: 'GET',
params: {
dateFrom: yesterday, // Set dateFrom to yesterday's date
dateTo: today, // Set dateTo to today's date
},
headers: {
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3', // Add your API key here
},
});
// Extract relevant data from the API response
const matches = response.data.matches.map(match => ({
homeTeam: {
name: match.homeTeam.tla,
crest: match.homeTeam.crest,
},
awayTeam: {
name: match.awayTeam.tla,
crest: match.awayTeam.crest,
},
score: {
homeScore: match.score.fullTime.home,
awayScore: match.score.fullTime.away,
},
minute: match.status, // Set the minute of the game
}));
// Concatenate matches data to allMatches array
allMatches = allMatches.concat(matches);
}
// Attach all matches data to res.locals
res.locals.matches = allMatches;
next();
} catch (error) {
console.error('Error fetching matches data:', error);
res.locals.matches = []; // Set an empty array if there's an error
next(); // Call next middleware or route handler
}
};
module.exports = fetchMatchesData;

View File

@@ -1,8 +1,10 @@
$(document).ready(function() {
// When #user is clicked
$('#user').click(function() {
// Toggle the visibility of the login container
$('#login-container').toggle();
});
});
});

View File

@@ -0,0 +1,40 @@
document.addEventListener("DOMContentLoaded", function() {
const league_select = document.getElementById('league_dropdown');
const team_select = document.getElementById('team_dropdown');
league_select.addEventListener('change', updateTeamSelect);
function updateTeamSelect() {
var selectedLeague = league_select.value;
var teamSelect = team_select;
// Clear existing options
teamSelect.innerHTML = "";
// Add options based on the selected value from the first select element
if (selectedLeague === "La Liga") {
// Add options for La Liga
addOption(teamSelect, "Option 1 for LL", "option1A");
addOption(teamSelect, "Option 2 for LL", "option2A");
} else if (selectedLeague === "Serie A") {
// Add options for Serie A
addOption(teamSelect, "Team 1 in Serie A", "option1B");
addOption(teamSelect, "Team 2 in Serie A", "option2B");
} else {
// Add options for Bundesliga
addOption(teamSelect, "Option 1 for Bun", "option1C");
addOption(teamSelect, "Option 2 for Bun", "option2C");
}
}
function addOption(selectElement, text, value) {
var option = document.createElement("option");
option.text = text;
option.value = value;
selectElement.add(option);
}
});