Skip to content

Commit

Permalink
issue Hexlet#180
Browse files Browse the repository at this point in the history
  • Loading branch information
sch0nik committed Nov 2, 2022
1 parent 00e70ec commit 3ff44fe
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'[::1]',
'.herokuapp.com',
'.hexlet.io',
'0.0.0.0',
]

INSTALLED_APPS = [
Expand Down
5 changes: 5 additions & 0 deletions contributors/views/contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ def get_context_data(self, **kwargs):
context['contributions_for_year'] = (
self.object.contribution_set.for_year()
)

context['current_contributor'] = self.object
if self.request.GET.get('compare') == 'yes':
context['my_contributions_for_year'] = self.request.user.contributor.contribution_set.for_year()

return context
Binary file modified locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ msgstr "Добавления и удаления"
msgid "Past year activity"
msgstr "Активность за год"

#: templates/contributor_details.html templates/home.html
msgid "Compare with yourself"
msgstr "Сравнить с собой"

#: templates/contributor_details.html
msgid "All-time contributions"
msgstr "Вклад за всё время"
Expand Down
58 changes: 58 additions & 0 deletions static/js/activity_chart/my_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function generateMonths() {
const months = [];
moment.locale(document.documentElement.lang);
for (let i = 1; i <= 12; i += 1) {
months.push(moment().add(i, 'months').format('MMM'));
}
return months;
}

const my_contributions = JSON.parse(document.getElementById('my_contributions_for_year').textContent);
const my_ctx = document.getElementById('my_yearActivityChart').getContext('2d');
const my_config = {
type: 'bar',
data: {
labels: generateMonths(),
datasets: [
{
label: gettext('Commits'),
data: my_contributions.commits,
backgroundColor: 'rgba(87, 173, 219, 0.7)',
},
{
label: gettext('Pull requests'),
data: my_contributions.pull_requests,
backgroundColor: 'rgba(82, 206, 97, 0.7)',
},
{
label: gettext('Issues'),
data: my_contributions.issues,
backgroundColor: 'rgba(226, 113, 90, 0.7)',
},
{
label: gettext('Comments'),
data: my_contributions.comments,
backgroundColor: 'rgba(242, 232, 96, 0.7)',
},
],
},
options: {
maintainAspectRatio: false,
tooltips: {
mode: 'index',
intersect: false,
},
animation: {
duration: 0,
},
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true,
}],
},
},
};
const my_yearActivityChart = new Chart(my_ctx, my_config);
5 changes: 5 additions & 0 deletions templates/components/activity_chart/chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

<div class="chart-container mb-5"><canvas id="yearActivityChart"></canvas></div>
<script src="{% static 'js/activity_chart/chart.js' %}"></script>

{% if my_contributions_for_year %}
<div class="chart-container mb-5"><canvas id="my_yearActivityChart"></canvas></div>
<script src="{% static 'js/activity_chart/my_chart.js' %}"></script>
{% endif %}
3 changes: 3 additions & 0 deletions templates/components/activity_chart/scripts.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
{{ contributions_for_year|json_script:'contributions_for_year' }}
{% if my_contributions_for_year %}
{{ my_contributions_for_year|json_script:'my_contributions_for_year' }}
{% endif %}
9 changes: 8 additions & 1 deletion templates/contributor_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,14 @@ <h2 class="h5 card-subtitle font-weight-light mt-3">
</div>
</div>
<div class="col">
<h2>{% trans "Past year activity" %}</h2>
<h2>{% translate "Past year activity" %}
{% if user.is_authenticated %}
<a class="btn btn-outline-primary"
href="{% url 'contributors:contributor_details' current_contributor %}?compare=yes">
{% translate "Compare with yourself" %}
</a>
{% endif %}
</h2>
{% include 'components/activity_chart/chart.html' %}
<h2 class="mr-5">{% trans "All-time contributions" %}</h2>
<input type="text" name="name" id="repo-search-field" class="form-control col-3"
Expand Down

0 comments on commit 3ff44fe

Please sign in to comment.