forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update designs and optimize tasks
- Loading branch information
Ali Salman
authored and
Ali Salman
committed
Nov 22, 2023
1 parent
f7de918
commit 3850f48
Showing
9 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Defines asynchronous celery task for updateing leaderboard entries | ||
""" | ||
import logging | ||
|
||
from django.db.models import F | ||
from celery import shared_task | ||
from celery_utils.logged_task import LoggedTask | ||
from edx_django_utils.monitoring import set_code_owner_attribute | ||
from lms.djangoapps.badges.models import BadgeAssertion, LeaderboardConfiguration, LeaderboardEntry | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task(base=LoggedTask) | ||
@set_code_owner_attribute | ||
def update_leaderboard_enties(course_badge_score, event_badge_score): | ||
""" | ||
Bulk Update scores for all entries in the LeaderboardEntry | ||
""" | ||
leaderboard_entries = LeaderboardEntry.objects.all() | ||
leaderboard_entries.update( | ||
score=F('course_badge_count') * course_badge_score + F('event_badge_count') * event_badge_score | ||
) | ||
log.info( | ||
f"Updated {leaderboard_entries.count()} enties in the LeaderboardEntry table" | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Function to fetch data from the API | ||
async function fetchData(url) { | ||
try { | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
return data; // Assuming the API response is in JSON format | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
} | ||
|
||
// Function to render a single user item | ||
function renderUserListItem(data) { | ||
const listItem = document.createElement('li'); | ||
listItem.className = 'user-item'; | ||
|
||
const avatarDiv = document.createElement('div'); | ||
avatarDiv.className = 'avatar'; | ||
const avatarImg = document.createElement('img'); | ||
avatarImg.src = data.user.profile_image_url; | ||
avatarImg.alt = 'User Avatar'; | ||
avatarDiv.appendChild(avatarImg); | ||
|
||
const userInfoDiv = document.createElement('div'); | ||
userInfoDiv.className = 'user-info'; | ||
const userNameDiv = document.createElement('div'); | ||
userNameDiv.className = 'user-name'; | ||
userNameDiv.textContent = data.user.name; | ||
userInfoDiv.appendChild(userNameDiv); | ||
|
||
const userScoreDiv = document.createElement('div'); | ||
userScoreDiv.className = 'user-score'; | ||
userScoreDiv.textContent = data.score; | ||
|
||
listItem.appendChild(avatarDiv); | ||
listItem.appendChild(userInfoDiv); | ||
listItem.appendChild(userScoreDiv); | ||
|
||
return listItem; | ||
} | ||
|
||
// Function to render user list | ||
async function renderUserList() { | ||
const userListElement = document.getElementById('userList'); | ||
let nextPageUrl = '/api/badges/v1/leaderboard/'; | ||
|
||
// Variable to track if data is currently being fetched to avoid multiple simultaneous requests | ||
let fetchingData = false; | ||
|
||
async function fetchAndRenderNextPage() { | ||
fetchingData = true; | ||
|
||
// Fetch the next set of data | ||
if (nextPageUrl){ | ||
const nextPageData = await fetchData(nextPageUrl); | ||
|
||
if (nextPageData.results && Array.isArray(nextPageData.results)) { | ||
nextPageData.results.forEach(user => { | ||
// Create and append list items for the next set of data | ||
const listItem = renderUserListItem(user); | ||
userListElement.appendChild(listItem); | ||
}); | ||
|
||
// Update the next page URL | ||
nextPageUrl = nextPageData.next; | ||
} | ||
|
||
fetchingData = false; | ||
} | ||
} | ||
|
||
// Initial rendering | ||
await fetchAndRenderNextPage(); | ||
|
||
// Add event listener to window scroll | ||
window.addEventListener('scroll', async () => { | ||
// Check if user has scrolled to the bottom | ||
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 1000 && !fetchingData) { | ||
await fetchAndRenderNextPage(); | ||
} | ||
}); | ||
} | ||
|
||
// Call the function to render the initial user list when the page loads | ||
document.addEventListener('DOMContentLoaded', renderUserList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
.leaderboard { | ||
margin: 20px; | ||
background-color: #fff; | ||
border-radius: 8px; | ||
padding: 10px; | ||
border: 1px solid #D9D9D9; | ||
|
||
|
||
.avatar { | ||
width: 40px; | ||
height: 40px; | ||
border-radius: 50%; | ||
overflow: hidden; | ||
} | ||
|
||
.avatar img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
.leaderboard-header { | ||
font-size: 1.1em; | ||
padding: 10px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
border-bottom: 1px solid #D9D9D9; | ||
|
||
.star-icon { | ||
width: 25%; | ||
} | ||
} | ||
|
||
.header { | ||
list-style: none; | ||
overflow-y: auto; | ||
padding: 0px 10px 0px 10px; | ||
margin: 0px; | ||
|
||
.header-item { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
color: #7C7C7C; | ||
|
||
.header-info { | ||
flex: 1; | ||
} | ||
} | ||
} | ||
|
||
.user-list { | ||
list-style: none; | ||
max-height: 300px; /* Set your desired maximum height */ | ||
overflow-y: auto; | ||
padding: 0px 10px 0px 10px; | ||
margin: 0px; | ||
|
||
.user-item { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-bottom: 10px; | ||
|
||
.user-info { | ||
flex: 1; | ||
margin-right: 10px; | ||
margin-left: 10px; | ||
} | ||
|
||
.user-name { | ||
font-weight: 600; | ||
color: #1C355E; | ||
} | ||
|
||
.user-score { | ||
color: #EA6852; | ||
font-size: 1em; /* Adjust font size if necessary */ | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters