Merge pull request #19 from LucasPatenaude/add-scoreboard-header

Add Live Scoreboard in Header to Main
This commit is contained in:
Lucas Patenaude
2024-04-09 20:36:56 -06:00
committed by GitHub
23 changed files with 659 additions and 565 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
node_modules
ProjectSourceCode/node_modules
.DS_Store

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,7 @@
"express": "^4.6.1",
"express-handlebars": "^7.1.2",
"express-session": "1.17.3",
"moment": "^2.30.1",
"nodemon": "2.0.20",
"pg-promise": "^10.11.1"
},

View File

@@ -12,6 +12,7 @@ const bodyParser = require('body-parser');
const session = require('express-session'); // To set the session object. To store or access session data, use the `req.session`, which is (generally) serialized as JSON by the store.
const bcrypt = require('bcryptjs'); // To hash passwords
const axios = require('axios'); // To make HTTP requests from our server. We'll learn more about it in Part C.
const moment = require('moment'); // To extract current time data
// *****************************************************
// <!-- Section 2 : Connect to DB -->
@@ -77,6 +78,17 @@ app.use(express.static(path.join(__dirname, 'resources')));
// <!-- Section 4 : API Routes -->
// *****************************************************
/************************
Header Scoreboard Routes
*************************/
const fetchMatchesData = require('./resources/js/navigation-bar/scoreboard-header/current-match-routes');
app.use(fetchMatchesData);
const convert_time = require('./resources/js/navigation-bar/scoreboard-header/convert-time');
app.use(convert_time);
/************************
Login Page Routes
*************************/
@@ -150,17 +162,15 @@ app.get('/', (req, res) => {
res.redirect('/register');
}
});
/************************
Discover Page Routes
Home Page Routes
*************************/
// Render registration page for /register route
app.get('/home', (req, res) => {
res.render('pages/home');
});
// *****************************************************
// <!-- Section 5 : Start Server-->
// *****************************************************

View File

@@ -0,0 +1,31 @@
#navigation-bar-container {
background-color: hsl(0, 98%, 40%);
box-shadow: 0px 3px 4px rgba(0, 0, 0, 0.4);
height: 50px;
display: flex;
}
.sticky {
position: fixed;
top: 0;
width: 100%;
z-index: 1000; /* Adjust as needed */
}
@font-face {
font-family: 'Scottsdale-Italic';
src: url('../fonts/Scottsdale-Italic.ttf') format('truetype');
}
#logo {
color: white;
text-decoration: none;
font-family: 'Scottsdale-Italic';
font-size: 25px;
margin-right: 10px;
}
#logo:hover {
font-size: 30px;
}

View File

@@ -0,0 +1,71 @@
#game-card {
display: inline-block; /* Display cards as inline-block to allow them to sit next to each other */
border: 1px solid #ccc;
border-radius: 4px;
padding: 6px;
margin: 6px 0px; /* Distance between cards and container */
margin-left: 5px;
min-width: 150px;
color: rgb(0, 0, 0);
background-color: rgb(255, 255, 255);
border: 1px solid rgb(160, 159, 159);
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
transition: transform 0.4s ease; /* Add transition for smooth effect */
}
#game-card:hover {
transform: scale(1.05); /* Scale up by 10% on hover */
}
/* Entire Card Information Body */
.score-card-body {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
}
/* Left Side of Container (Scores) */
.card-team-container {
flex: 70%;
flex-grow: 1; /* Both team containers will grow to occupy equal width */
flex-direction: column; /* Stacks each team over one another */
}
/* Right Side of Container (Time) */
.card-game-information-container {
flex: 30%;
display: flex;
align-items: center;
margin: 0px 15px;
}
/* Center the time in game */
#time {
margin: 0;
}
/* Container for each team in card's information */
.team {
display: flex; /* Keeps all items in a row */
align-items: center; /* Center items vertically */
padding: 5px;
}
.team p {
margin: 0; /* Remove default margin */
}
#team-name {
margin-right: 10px;
}
.team img {
max-width: 20px; /* Set the width of the image to 100% of its container */
max-height: 20px; /* Maintain the aspect ratio */
margin-right: 10px;
}

View File

@@ -0,0 +1,18 @@
.scoreboard-container {
overflow-x: auto; /* Enable horizontal scrolling */
white-space: nowrap; /* Prevent cards from wrapping to the next line */
border: 1px solid rgb(202, 2, 2);
background-color: rgb(255, 255, 255);
/* Inner box shadow */
box-shadow: inset 0px 0px 15px rgba(77, 76, 76, 0.3);
}
/* Hide scrollbar in scoreboard for webkit browsers */
.scoreboard-container::-webkit-scrollbar {
display: none;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@@ -0,0 +1,37 @@
// navbar-sticky.js
// Function to add sticky behavior to the navbar
function makeNavbarSticky() {
// Get the navigation bar element
var navbar = document.getElementById("navigation-bar-container");
// Get the initial offset of the navbar from the top of the page
var navbarOffset = navbar.offsetTop;
// Function to add sticky behavior when scrolling
function stickyNavbar() {
// Check if the current scroll position is greater than or equal to the initial offset of the navbar
if (window.pageYOffset >= navbarOffset) {
// Add the 'fixed-top' class to make the navbar sticky
navbar.classList.add("fixed-top");
// Add padding to the body to prevent content from jumping when the navbar becomes sticky
document.body.style.paddingTop = navbar.offsetHeight + "px";
} else {
// Remove the 'fixed-top' class to make the navbar non-sticky
navbar.classList.remove("fixed-top");
// Reset the padding of the body
document.body.style.paddingTop = 0;
}
}
// Call the stickyNavbar function when the page is scrolled
window.onscroll = function() {
stickyNavbar();
};
}
// Call the makeNavbarSticky function when the page loads
window.onload = function() {
makeNavbarSticky();
};

View File

@@ -0,0 +1,30 @@
// Convert finished matches to "FT"
const convert_time = (req, res, next) => {
try {
// Access matches data from res.locals
const matches = res.locals.matches;
// Loop through matches and convert "FINISHED" to "FT" for minute
const convertedMatches = matches.map(match => {
if (match.minute === "FINISHED") {
match.minute = "FT";
}
else if (match.minute === "TIMED") {
match.minute = "TM";
}
return match;
});
// Update res.locals with converted matches
res.locals.matches = convertedMatches;
// Proceed to the next middleware/route handler
next();
} catch (error) {
// If an error occurs, log it and proceed to the next middleware/route handler
console.error('Error converting finished matches:', error);
next();
}
};
module.exports = convert_time;

View File

@@ -0,0 +1,66 @@
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(1, '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,18 +1,20 @@
<!DOCTYPE html>
<html lang="en" class="h-100">
<!-- TODO: Add the head.hbs partial here -->
<head>
<!-- Add your head content here -->
{{> head}}
</head>
<body>
<!-- Render the scoreboard header on every page -->
{{> navigation-bar/scoreboard-header/scoreboard-header}}
<!-- Add your navigation -->
{{> navigation-bar/nav}}
<!-- TODO: Add the nav.hbs partial here -->
{{> nav}}
<!-- Render the main content of each page -->
{{{body}}}
<!-- TODO: Add the footer.hbs partial here -->
<!-- Add your footer -->
{{> footer}}
</body>
</html>

View File

@@ -1,4 +1,3 @@
<body>
<div class="container mt-5">
<h1 class="mb-4 underlined-header">Leagues</h1>
<div class="card-container">
@@ -34,5 +33,5 @@
</div>
</div>
</div>
</body>

View File

@@ -1,4 +1,3 @@
<body class="container">
<!-- Linking forms.css -->
<div class="login-page">
<div class="form-container">
@@ -28,4 +27,3 @@
<p class="mt-3">Don't have an account? <a href="/register">Register</a></p>
</div>
</div>
</body>

View File

@@ -1,4 +1,3 @@
<body class="container">
<div class="register-page">
<div class="form-container">
<h1 class="mt-5 mb-4">Register</h1>
@@ -47,4 +46,4 @@
<p class="mt-3">Already have an account? <a href="/login">Login</a></p>
</div>
</div>
</body>

View File

@@ -1,8 +1,14 @@
<footer class="text-center text-muted w-100 mt-auto fixed-bottom">
<p>
&copy; 2024 - CSCI 3308 Group 6
</p>
<footer class="text-center text-muted w-100 mt-auto fixed-bottom">
<p>
&copy; 2024 - CSCI 3308 Group 6
</p>
<!-- TODO: Add the <script><script /> tag to include bootstrap javascript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</footer>
<!-- In your HTML file -->
<script src="js/navigation-bar/navigation-bar-follow.js"></script>
<!-- Include Bootstrap JavaScript -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</footer>

View File

@@ -1,4 +1,3 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta name="description" content="" />
@@ -6,15 +5,15 @@
<!-- Linking forms.css -->
<link rel="stylesheet" type="text/css" href="css/login_and_registration.css">
<link rel="stylesheet" type="text/css" href="css/home-screen.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Golos+Text:wght@400..900&display=swap" rel="stylesheet">
<!-- Navigation Bar Stylesheets -->
<link rel="stylesheet" type="text/css" href="css/navigation-bar/navigation-bar.css">
<!-- Scoreboard Header Stylesheets -->
<link rel="stylesheet" type="text/css" href="css/navigation-bar/scoreboard-header/scoreboard.css">
<link rel="stylesheet" type="text/css" href="css/navigation-bar/scoreboard-header/game-card.css">
<title>Group 6 Final Project</title>
<!-- Include Bootstrap CSS -->
<body class="h-100 d-flex flex-column"></body>
</head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">

View File

@@ -1,27 +0,0 @@
<nav class="navbar navbar-expand-sm border-bottom">
<div class="container">
<button
class="navbar-toggler ms-auto"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbar-collapse"
aria-controls="navbar"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<!-- TODO: For Discover, add a <a> tag with an attribute href to call the '/discover' API -->
<a class="nav-link" href="/home">Home</a>
</li>
</ul>
<div class="nav-item me-1">
<!-- TODO: For Logout, add a <a> tag with an attribute href to call the '/logout API -->
<a class="nav-link" href="/logout">Logout</a>
</div>
</div>
</div>
</nav>

View File

@@ -0,0 +1,56 @@
<nav class="navbar navbar-expand-lg navbar-dark" id="navigation-bar-container">
<div class="container-fluid d-flex justify-content-between align-items-center"> <!-- Added container-fluid for full-width -->
<div> <!-- Wrapped navbar brand and toggler in a div -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation" style="margin-right: 20px;">
<span class="navbar-toggler-icon"></span>
</button>
<a class="logo" id="logo" href="#">ScoreSpot</a>
</div>
<div class="collapse navbar-collapse" id="navbarToggler">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">Premier League</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Bundesliga</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">La Liga</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Serie A</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Ligue 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Brasileirao</a>
</li>
</ul>
</div>
<!-- Right-aligned image outside collapsing area -->
<div id="user" class="d-sm-flex">
<img src="img/navigation-bar/user.png" alt="Your Image" class="img-fluid" style="width: 30px;">
</div>
<style>
/* CSS to hide the user icon when navbar toggler is expanded */
.navbar-toggler:(.collapsed) + .collapse #user {
display: none;
}
</style>
</div>
</nav>

View File

@@ -0,0 +1,31 @@
<div class="card" id="game-card">
<div class="score-card-body">
<!-- Left side (70%) -->
<div class="card-team-container">
<!-- Team 1 Name with Score -->
<div class="team">
<img src="{{ homeTeam.crest }}" alt="{{ homeTeam.name }} Crest">
<p id="team-name">{{ homeTeam.name }}</p> <!-- {{team1.name}} -->
<p id="team-score">{{ score.homeScore }}</p>
</div>
<!-- Team 2 Name with Score -->
<div class="team">
<img src="{{ awayTeam.crest }}" alt="{{ awayTeam.name }} Crest">
<p id="team-name">{{ awayTeam.name }}</p> <!-- {{team1.name}} -->
<p id="team-score">{{ score.awayScore }}</p>
</div>
</div>
<!-- Right side (30%) -->
<div class="card-game-information-container">
<!-- Time -->
<div class="game-info">
<p id="time">{{ minute }}</p>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,10 @@
<div class="scoreboard-container" id="scoreboard">
<div class="scoreboard-league-container">
<!-- Iterate over matches and insert a game card for each -->
{{#each matches}}
{{> navigation-bar/scoreboard-header/game-card}}
{{/each}}
</div>
</div>