Skip to content

Commit 3c9d46d

Browse files
committed
make news page and set as start page. update navbar.
1 parent 9f8d717 commit 3c9d46d

14 files changed

+138
-150
lines changed

games.html

+15-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<li id="listings-li" class="dropdown">
2929
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Listings <span class="caret"></span></a>
3030
<ul class="dropdown-menu">
31-
<li><a href="index.html">Leaderboard</a></li>
31+
<li><a href="leaderboard.html">Leaderboard</a></li>
3232
<li><a href="games.html">Games</a></li>
3333
</ul>
3434
</li>
@@ -66,20 +66,22 @@
6666

6767

6868

69+
<div class="col-sm-8 col-sm-offset-2">
70+
<table class="table table-striped table-dark" id="game-table">
71+
<thead class="thead-dark">
72+
<tr>
73+
<th scope="col">Winners</th>
74+
<th scope="col">Losers</th>
75+
<th scope="col">Points</th>
76+
<th scope="col">Date</th>
77+
</tr>
78+
</thead>
79+
<tbody id="tableBody">
6980

70-
<table class="table table-striped table-dark" id="game-table">
71-
<thead class="thead-dark">
72-
<tr>
73-
<th scope="col">Winners</th>
74-
<th scope="col">Losers</th>
75-
<th scope="col">Points</th>
76-
<th scope="col">Date</th>
77-
</tr>
78-
</thead>
79-
<tbody id="tableBody">
81+
</tbody>
82+
</table>
83+
</div>
8084

81-
</tbody>
82-
</table>
8385

8486

8587
<!-- The core Firebase JS SDK is always required and must be listed first -->

games.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function fillTable(data) {
4040
const tableBody = document.getElementById('tableBody');
4141
let dataHtml = '';
4242
gamesArray.forEach(function(child) {
43-
dataHtml += `<tr><td><a href="#">${child.winners.join(", ")}</a></td><td><a href="#">${child.losers.join(", ")}</a></td><td><a href="#">${child.rating}</a></td><td><a href="#">${formatDate(new Date(child.timestamp))}</a></td></tr>`
43+
dataHtml += `<tr><td><a href="profile.html?id=${child.winners[0]}">${child.winners.join(", ")}</a></td><td><a href="profile.html?id=${child.losers[0]}">${child.losers.join(", ")}</a></td><td><a href="#">${child.rating}</a></td><td><a href="#">${formatDate(new Date(child.timestamp))}</a></td></tr>`
4444
});
4545

4646
tableBody.innerHTML = dataHtml;

index.html

+21-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<li id="listings-li" class="dropdown">
2929
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Listings <span class="caret"></span></a>
3030
<ul class="dropdown-menu">
31-
<li><a href="index.html">Leaderboard</a></li>
31+
<li><a href="leaderboard.html">Leaderboard</a></li>
3232
<li><a href="games.html">Games</a></li>
3333
</ul>
3434
</li>
@@ -63,29 +63,35 @@
6363
</div>
6464
</nav>
6565

66+
<!--div class="welcome">
67+
<div class="col-sm-6 col-sm-offset-3">
68+
<div class="welcome-message-container">
69+
<h2>Welcome</h2>
70+
<h4>This is a web application for keeping track of your beer pong.</h4>
71+
</div>
72+
</div>
73+
</div-->
74+
75+
<div class="col-sm-6 col-sm-offset-3">
76+
<div class="welcome-message">
77+
<h2>Welcome</h2>
78+
<h5>This is a web application for keeping track of your beer pong games. Here are the latest news and updates.<br>For help, feedback or bug-reports, please contact <a href="mailto:[email protected]">[email protected]</a>.</h5>
79+
</div>
80+
<div id="newsfeed">
81+
</div>
82+
</div>
6683

6784

6885

6986

70-
<table class="table table-striped table-dark" id="playertable">
71-
<thead class="thead-dark">
72-
<tr>
73-
<th scope="col">Rank</th>
74-
<th scope="col">Name</th>
75-
<th scope="col">Points</th>
76-
</tr>
77-
</thead>
78-
<tbody id="tableBody">
7987

80-
</tbody>
81-
</table>
8288

8389

8490
<!-- The core Firebase JS SDK is always required and must be listed first -->
8591
<script src="https://www.gstatic.com/firebasejs/7.2.3/firebase-app.js"></script>
8692

8793
<!-- TODO: Add SDKs for Firebase products that you want to use
88-
https://firebase.google.com/docs/web/setup#available-libraries -->
94+
https://firebase.google.com/docs/web/setup#available-libraries -->
8995

9096
<script>
9197
// Your web app's Firebase configuration
@@ -106,5 +112,7 @@
106112

107113
<script src="main.js"></script>
108114
<script src="index.js"></script>
115+
116+
109117
</body>
110118
</html>

index.js

+35-25
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1-
function config() {
2-
document.getElementById('listings-li').classList.add("active");
3-
var playersRef = firebase.database().ref('players')
4-
playersRef.on('value',gotData, gotErr)
5-
}
6-
config();
71

8-
function gotData(data) {
9-
fillTable(data);
10-
}
2+
firebase.database().ref('/news/').once('value').then(function(snapshot) {
3+
data=snapshot.val();
4+
if (data!=null) {
5+
console.log("no news");
116

12-
function gotErr(err) {
13-
console.log('Error!')
14-
console.log(err);
7+
fillNews(data)
8+
}
9+
});
10+
11+
function formatDate(date) {
12+
var d = new Date(date),
13+
month = '' + (d.getMonth() + 1),
14+
day = '' + d.getDate(),
15+
year = d.getFullYear(),
16+
hours = '' + d.getHours(),
17+
minutes = '' + d.getMinutes();
18+
19+
if (month.length < 2)
20+
month = '0' + month;
21+
if (day.length < 2)
22+
day = '0' + day;
23+
if (hours.length < 2)
24+
hours = '0' + hours;
25+
if (minutes.length < 2)
26+
minutes = '0' + minutes;
27+
return [year, month, day].join('-')+" "+hours + ":" + minutes;
1528
}
1629

17-
function fillTable(data) {
1830

19-
var playerArray = []
20-
data.forEach(function(child) {
21-
playerArray.push([child.val().name,child.val().rating]);
22-
});
31+
function fillNews(data) {
32+
var newsArray = Object.values(data);
2333

24-
playerArray.sort(function(a ,b) {
25-
return b[1] - a[1];
34+
newsArray = newsArray.sort(function(a ,b) {
35+
return b.timestamp-a.timestamp;
2636
})
2737

28-
console.log(playerArray);
38+
console.log(newsArray);
2939

30-
const tableBody = document.getElementById('tableBody');
40+
const tableBody = document.getElementById('newsfeed');
3141
let dataHtml = '';
32-
for (let i = 0; i < playerArray.length; i++) {
33-
var href = "profile.html?id=" + playerArray[i][0];
34-
dataHtml += `<tr><td><a href="${href}">${i+1}</a></td><td><a href="${href}">${playerArray[i][0]}</a></td><td><a href="${href}">${playerArray[i][1]}</a></td></tr>`
35-
}
42+
newsArray.forEach(function(child) {
43+
dataHtml += `<div class="news-post"><h3>${child.title}</h3><h5>${child.text}</h5><h6 class="news-timestamp">${formatDate(child.timestamp)}</h6></div>`;
44+
45+
});
3646

3747
tableBody.innerHTML = dataHtml;
3848

news.html leaderboard.html

+17-36
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
<span class="icon-bar"></span>
2121
<span class="icon-bar"></span>
2222
</button>
23-
<a id="logo" class="navbar-brand" href="index.html">D-Pong</a>
23+
<a class="navbar-brand" href="index.html">D-Pong</a>
2424
</div>
2525

2626
<div class="collapse navbar-collapse" id="myNavbar">
2727
<ul class="nav navbar-nav">
2828
<li id="listings-li" class="dropdown">
2929
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Listings <span class="caret"></span></a>
3030
<ul class="dropdown-menu">
31-
<li><a href="index.html">Leaderboard</a></li>
31+
<li><a href="leaderboard.html">Leaderboard</a></li>
3232
<li><a href="games.html">Games</a></li>
3333
</ul>
3434
</li>
@@ -63,46 +63,29 @@
6363
</div>
6464
</nav>
6565

66-
<!--div class="welcome">
67-
<div class="col-sm-6 col-sm-offset-3">
68-
<div class="welcome-message-container">
69-
<h2>Welcome</h2>
70-
<h4>This is a web application for keeping track of your beer pong.</h4>
71-
</div>
72-
</div>
73-
</div-->
74-
75-
<div class="col-sm-6 col-sm-offset-3">
76-
<div class="welcome-message">
77-
<h2>Welcome</h2>
78-
<h4>This is a web application for keeping track of your beer pong games. Here are the latest news and updates.</h4>
79-
</div>
80-
<div id="newsfeed">
81-
<div class="news-post">
82-
<h2>This weeks updates</h2>
83-
<h4></h4>
84-
<h4>2019-12-01</h4>
85-
</div>
86-
87-
<div class="news-post">
88-
<h2>Some other updates</h2>
89-
<h4>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </h4>
90-
<h4>2019-11-01</h4>
91-
</div>
92-
</div>
66+
<div class="col-sm-8 col-sm-offset-2">
67+
<table class="table table-striped table-dark" id="playertable">
68+
<thead class="thead-dark">
69+
<tr>
70+
<th scope="col">Rank</th>
71+
<th scope="col">Name</th>
72+
<th scope="col">Points</th>
73+
</tr>
74+
</thead>
75+
<tbody id="tableBody">
76+
77+
</tbody>
78+
</table>
9379
</div>
9480

9581

9682

9783

98-
99-
100-
10184
<!-- The core Firebase JS SDK is always required and must be listed first -->
10285
<script src="https://www.gstatic.com/firebasejs/7.2.3/firebase-app.js"></script>
10386

10487
<!-- TODO: Add SDKs for Firebase products that you want to use
105-
https://firebase.google.com/docs/web/setup#available-libraries -->
88+
https://firebase.google.com/docs/web/setup#available-libraries -->
10689

10790
<script>
10891
// Your web app's Firebase configuration
@@ -122,8 +105,6 @@ <h4>2019-11-01</h4>
122105
<script src="https://www.gstatic.com/firebasejs/7.2.2/firebase-auth.js"></script>
123106

124107
<script src="main.js"></script>
125-
<script src="news.js"></script>
126-
127-
108+
<script src="leaderboard.js"></script>
128109
</body>
129110
</html>

leaderboard.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function config() {
2+
document.getElementById('listings-li').classList.add("active");
3+
var playersRef = firebase.database().ref('players')
4+
playersRef.on('value',gotData, gotErr)
5+
}
6+
config();
7+
8+
function gotData(data) {
9+
fillTable(data);
10+
}
11+
12+
function gotErr(err) {
13+
console.log('Error!')
14+
console.log(err);
15+
}
16+
17+
function fillTable(data) {
18+
19+
var playerArray = []
20+
data.forEach(function(child) {
21+
playerArray.push([child.val().name,child.val().rating]);
22+
});
23+
24+
playerArray.sort(function(a ,b) {
25+
return b[1] - a[1];
26+
})
27+
28+
console.log(playerArray);
29+
30+
const tableBody = document.getElementById('tableBody');
31+
let dataHtml = '';
32+
for (let i = 0; i < playerArray.length; i++) {
33+
var href = "profile.html?id=" + playerArray[i][0];
34+
dataHtml += `<tr><td><a href="${href}">${i+1}</a></td><td><a href="${href}">${playerArray[i][0]}</a></td><td><a href="${href}">${playerArray[i][1]}</a></td></tr>`
35+
}
36+
37+
tableBody.innerHTML = dataHtml;
38+
39+
}

login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<li id="listings-li" class="dropdown">
2929
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Listings <span class="caret"></span></a>
3030
<ul class="dropdown-menu">
31-
<li><a href="index.html">Leaderboard</a></li>
31+
<li><a href="leaderboard.html">Leaderboard</a></li>
3232
<li><a href="games.html">Games</a></li>
3333
</ul>
3434
</li>

news.js

-53
This file was deleted.

0 commit comments

Comments
 (0)