Skip to content

Commit

Permalink
Delete news and progressional fill of data
Browse files Browse the repository at this point in the history
Click wheel winner bug fixed
  • Loading branch information
aunefyren committed Oct 31, 2023
1 parent ffbebed commit e616ffb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
1 change: 0 additions & 1 deletion web/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,6 @@ input[type=checkbox]
height: auto;
max-height: 58em;
overflow-y: auto;
margin-bottom: 1em;
}

.leaderboard-week {
Expand Down
28 changes: 13 additions & 15 deletions web/js/frontpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ function load_page(result) {
<h3 id="current-week-title">Current week</h3>
<div id="current-week-users" class="current-week-users">
...
</div>
Expand All @@ -300,6 +301,7 @@ function load_page(result) {
<h3 style="margin: 0.5em;">Past weeks</h3>
<div id="leaderboard-weeks" class="leaderboard-weeks">
...
</div>
</div>
Expand Down Expand Up @@ -738,15 +740,19 @@ function get_leaderboard(fireworks){

function place_leaderboard(weeks_array) {

var leaderboardWeeks = document.getElementById("leaderboard-weeks")
var html = ``;

if(weeks_array.length == 0) {
html = `
<div id="" class="leaderboard-weeks">
<p id="" style="margin: 0.5em; text-align: center;">No past weeks.</p>
</div>
`;
leaderboardWeeks.innerHTML = html
} else {
leaderboardWeeks.innerHTML = ""

for(var i = 0; i < weeks_array.length; i++) {
var week_html = `
<div class="leaderboard-week" id="">
Expand Down Expand Up @@ -791,16 +797,12 @@ function place_leaderboard(weeks_array) {

week_html += results_html + `</div></div>`;

html += week_html

leaderboardWeeks.innerHTML += week_html
}

}

document.getElementById("leaderboard-weeks").innerHTML = html

return

}

function GetProfileImageForUserOnLeaderboard(userID) {
Expand Down Expand Up @@ -871,10 +873,13 @@ function place_season_details(goal, sickleave, seasonStart, SeasonEnd) {
}

function place_current_week(week_array) {
var currentWeekUsers = document.getElementById("current-week-users")

// Sort users
week_array.users = week_array.users.sort((a,b) => b.week_completion - a.week_completion);

var html = ``;
// Remove intial data
currentWeekUsers.innerHTML = ""

for(var i = 0; i < week_array.users.length; i++) {

Expand Down Expand Up @@ -936,18 +941,11 @@ function place_current_week(week_array) {
</div>
`;

html += week_html

}

document.getElementById("current-week-users").innerHTML = html

for(var i = 0; i < week_array.users.length; i++) {
currentWeekUsers.innerHTML += week_html
GetProfileImagesForCurrentWeek(week_array.users[i].user.ID, i)
}

return

}

function GetProfileImagesForCurrentWeek(userID, index) {
Expand Down
45 changes: 44 additions & 1 deletion web/js/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ function place_news(news_array) {
}

html += '<div class="news-post">'

if(admin) {
html += `<div id="news-delete" class="text-date clickable">`;
html += `<img src="assets/trash-2.svg" style="height: 1.5em; width: 1.5em;" onclick="deleteNews(${news_array[i].ID})" class="btn_logo clickable">`
html += '</div>';
}

html += '<div id="news-title" class="title">';
html += news_array[i].title
Expand All @@ -152,7 +158,7 @@ function place_news(news_array) {
html += news_array[i].body
html += '</div>';

html += '<div id="news-body" class="text-date">';
html += '<div id="news-date" class="text-date">';
html += date_string
html += '</div>';

Expand Down Expand Up @@ -226,4 +232,41 @@ function create_news() {
xhttp.send(form_data);
return false;

}

function deleteNews(newsID) {
if(!confirm("Are you sure you want to delete this post?")) {
return;
}

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {

try {
result = JSON.parse(this.responseText);
} catch(e) {
console.log(e +' - Response: ' + this.responseText);
error("Could not reach API.");
return;
}

if(result.error) {
error(result.error);
} else {
success(result.message);
news = result.news;
place_news(news);
}

} else {
info("Deleting news...");
}
};
xhttp.withCredentials = true;
xhttp.open("post", api_url + "admin/news/" + newsID + "/delete");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", jwt);
xhttp.send();
return;
}
2 changes: 1 addition & 1 deletion web/js/wheel.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function drawTriangle()
function spinFinished() {

GetProfileImage(winner.ID);
document.getElementById('spinner-winner-image').onclick = function(){location.href=`/users/${winner.ID}`};
document.getElementById('spinner-winner-image-div').onclick = function(){location.href=`/users/${winner.ID}`};
document.getElementById('spinner-winner-image-wrapper').style.animation = "slide 0.25s ease 0.5s forwards";
setTimeout(function () {
document.getElementById('spinner-winner-image-wrapper').style.animation = "slide 0.25s ease 0.5s forwards, smooth-appear 0.5s ease forwards";
Expand Down

0 comments on commit e616ffb

Please sign in to comment.