Skip to content

Commit

Permalink
feat(account): show logged user xp progress on profile avatar border
Browse files Browse the repository at this point in the history
  • Loading branch information
Hojagulyyev committed Nov 11, 2023
1 parent 87ac440 commit 0ca8049
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 54 deletions.
3 changes: 3 additions & 0 deletions apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __str__(self):
def get_full_name(self):
return f"{self.user.first_name} {self.user.last_name}"

def get_xp_in_percentage(self):
return float(self.xp / self.get_required_xp_for_next_level())

def get_required_xp_for_next_level(self):
return self.level * ADDITIONAL_GROWING_XP_PER_LEVEL

Expand Down
2 changes: 0 additions & 2 deletions apps/diaries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def __str__(self):
return f"{self.account} - {self.created_date}"

def get_earned_xp(self):
print("Hello")
xp_amount_list = self.xps.values_list("amount", flat=True)
print(xp_amount_list)
return sum(xp_amount_list)


Expand Down
30 changes: 15 additions & 15 deletions static/js/global/global.hexagons.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ app.plugins.createHexagon({
lineColor: '#1d2333'
});

app.plugins.createHexagon({
container: '.hexagon-progress-100-110',
width: 100,
height: 110,
lineWidth: 6,
roundedCorners: true,
gradient: {
colors: ['#d9ff65', '#40d04f']
},
scale: {
start: 0,
end: 1,
stop: .8
}
});
//app.plugins.createHexagon({
// container: '.hexagon-progress-100-110',
// width: 100,
// height: 110,
// lineWidth: 6,
// roundedCorners: true,
// gradient: {
// colors: ['#d9ff65', '#40d04f']
// },
// scale: {
// start: 0,
// end: 1,
// stop: .8
// }
//});

app.plugins.createHexagon({
container: '.hexagon-border-100-110',
Expand Down
72 changes: 54 additions & 18 deletions templates/base/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,63 @@
<!-- onMounted Lifecycle Hook -->
<script>
window.onload = function () {
{% block onMounted %}
{% endblock onMounted %}
calculateLoggedAccountXPForNextLevel()
{% block onMounted %}
{% endblock onMounted %}
calculateLoggedAccountXPForNextLevel();
calculateLoggedAccountXPInHexagonProgress();
}

function calculateLoggedAccountXPForNextLevel() {
app.plugins.createProgressBar({
container: '#logged-user-level',
height: 4,
gradient: {
colors: ['#40d04f', '#d9ff65']
},
scale: {
start: 0,
end: {{ user.account.get_required_xp_for_next_level }},
stop: {{ user.account.xp }}
},
linkText: true,
linkUnits: 'xp',
invertedProgress: true
});
app.plugins.createProgressBar({
container: '#logged-user-level',
height: 4,
gradient: {
colors: ['#40d04f', '#d9ff65']
},
scale: {
start: 0,
end: {{ user.account.get_required_xp_for_next_level }},
stop: {{ user.account.xp }}
},
linkText: true,
linkUnits: 'xp',
invertedProgress: true
});
}

function calculateLoggedAccountXPInHexagonProgress() {
app.plugins.createHexagon({
container: '.logged-account-hexagon-progress-40-44',
width: 40,
height: 44,
lineWidth: 3,
roundedCorners: true,
roundedCornerRadius: 1,
gradient: {
colors: ['#d9ff65', '#40d04f']
},
scale: {
start: 0,
end: 1,
stop: {{ user.account.get_xp_in_percentage }}
}
});

app.plugins.createHexagon({
container: '.logged-account-hexagon-progress-100-110',
width: 100,
height: 110,
lineWidth: 6,
roundedCorners: true,
gradient: {
colors: ['#d9ff65', '#40d04f']
},
scale: {
start: 0,
end: 1,
stop: {{ user.account.get_xp_in_percentage }}
}
});
}
</script>

Expand Down
14 changes: 9 additions & 5 deletions templates/includes/account-avatar-small.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{% load static %}

<!-- USER AVATAR -->
<!-- add 'online' class below if user online -->
<div class="user-avatar small no-outline">
<!-- USER AVATAR CONTENT -->
<div class="user-avatar-content">
<!-- HEXAGON -->
<div class="hexagon-image-30-32"
{% if account == user.account %}
data-src="{% static 'img/avatar/17.jpg' %}"
data-src="{% static 'img/avatar/17.jpg' %}"
{% else %}
data-src="{% static 'img/avatar/08.jpg' %}"
data-src="{% static 'img/avatar/08.jpg' %}"
{% endif %}
>
</div>
Expand All @@ -19,9 +20,12 @@

<!-- USER AVATAR PROGRESS -->
<div class="user-avatar-progress">
<!-- HEXAGON -->
<div class="hexagon-progress-40-44"></div>
<!-- /HEXAGON -->
<!-- HEXAGON -->
<div class="hexagon-progress-40-44
{% if account == user.account %}
logged-account-hexagon-progress-40-44
{% endif %}"></div>
<!-- /HEXAGON -->
</div>
<!-- /USER AVATAR PROGRESS -->

Expand Down
8 changes: 7 additions & 1 deletion templates/partials/expanded-left-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
</div>
<!-- /USER AVATAR CONTENT -->

<!-- USER AVATAR PROGRESS --><!-- /USER AVATAR PROGRESS -->
<!-- USER AVATAR PROGRESS -->
<div class="user-avatar-progress">
<!-- HEXAGON -->
<div class="hexagon-progress-100-110 logged-account-hexagon-progress-100-110"></div>
<!-- /HEXAGON -->
</div>
<!-- /USER AVATAR PROGRESS -->

<!-- USER AVATAR PROGRESS BORDER -->
<div class="user-avatar-progress-border">
Expand Down
2 changes: 1 addition & 1 deletion templates/partials/mobile-left-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<!-- USER AVATAR PROGRESS BORDER -->
<div class="user-avatar-progress-border">
<!-- HEXAGON -->
<div class="hexagon-border-40-44"></div>
<div class="hexagon-border-40-44 logged-account-hexagon-progress-40-44"></div>
<!-- /HEXAGON -->
</div>
<!-- /USER AVATAR PROGRESS BORDER -->
Expand Down
13 changes: 1 addition & 12 deletions templates/partials/shrunk-left-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@

<nav id="navigation-widget-small" class="navigation-widget navigation-widget-desktop closed sidebar left delayed">
<!-- USER AVATAR -->
<!-- add 'online' class below if user online -->
<a class="user-avatar small no-outline" href="#">
<!-- USER AVATAR CONTENT -->
<div class="user-avatar-content">
<!-- HEXAGON -->
<div class="hexagon-image-30-32" data-src="{% static 'img/avatar/17.jpg' %}"></div>
<!-- /HEXAGON -->
</div>
<!-- /USER AVATAR CONTENT -->
<!-- USER AVATAR PROGRESS --><!-- /USER AVATAR PROGRESS -->
<!-- USER AVATAR BADGE --><!-- /USER AVATAR BADGE -->
</a>
{% include "includes/account-avatar-small.html" with account=user.account %}
<!-- /USER AVATAR -->

<!-- MENU -->
Expand Down

0 comments on commit 0ca8049

Please sign in to comment.