Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmit Goswami authored and Harmit Goswami committed Nov 29, 2024
1 parent 4970971 commit bbd2a50
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 36 deletions.
10 changes: 5 additions & 5 deletions pontoon/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user")
super().__init__(*args, **kwargs)
# Track if user reached new level for Community Builder Badge
self.community_builder_level = 0
self.community_builder_level_reached = 0

def assign_users_to_groups(self, group_name, users):
"""
Expand Down Expand Up @@ -142,7 +142,7 @@ def save(self, *args, **kwargs):
after_count > before_count
and after_count in settings.BADGES_PROMOTION_THRESHOLDS
):
self.community_builder_level = (
self.community_builder_level_reached = (
settings.BADGES_PROMOTION_THRESHOLDS.index(after_count) + 1
)
desc = """
Expand All @@ -152,7 +152,7 @@ def save(self, *args, **kwargs):
<br>
You can view this badge on your <a href={profile_href}> profile page </a>.
""".format(
level=self.community_builder_level,
level=self.community_builder_level_reached,
profile_href=reverse(
"pontoon.contributors.contributor.username",
kwargs={
Expand All @@ -163,11 +163,11 @@ def save(self, *args, **kwargs):
notify.send(
sender=self.user,
recipient=self.user,
verb="", # Triggers render of description only
verb="ignore", # Triggers render of description only
description=desc,
)

return self.community_builder_level
return self.community_builder_level_reached


class ProjectLocalePermsForm(UserPermissionLogFormMixin, forms.ModelForm):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
</span>

<span class="verb">
{% if notification.verb != 'ignore' %}
{{ notification.verb.replace("has added a comment in", "has added a comment") }}
{% endif %}
</span>

{% if target %}
Expand Down
28 changes: 12 additions & 16 deletions pontoon/teams/static/js/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ $(function () {
});
});

const $tooltip = $('#badge-tooltip-container');

$.ajax({
url: $('#permissions-form').prop('action'),
type: $('#permissions-form').prop('method'),
Expand All @@ -56,23 +58,12 @@ $(function () {

// Check for new badge notification
if (badgeLevel > 0) {
const $tooltip = $('#badge-tooltip-container');

if ($tooltip.length) {
$tooltip.show();
$tooltip.show();

// Force a re-render of the text with the proper badge level
$tooltip
.find('p:nth-of-type(2)')
.text(
`Community Builder Badge level gained: Level ${badgeLevel}`,
);

$tooltip.find('button').one('click', function (e) {
e.preventDefault();
$tooltip.hide();
});
}
// Force a re-render of the text with the proper badge level
$tooltip
.find('.badge-tooltip-info')
.text(`Community Builder Badge level gained: Level ${badgeLevel}`);

const duration = 2000;
const animationEnd = Date.now() + duration;
Expand Down Expand Up @@ -113,6 +104,11 @@ $(function () {
Pontoon.endLoader('Oops, something went wrong.', 'error');
},
});

$tooltip.find('button').one('click', function (e) {
e.preventDefault();
$tooltip.hide();
});
});

// Switch available users
Expand Down
9 changes: 4 additions & 5 deletions pontoon/teams/templates/teams/includes/permissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
<form id="permissions-form" method="POST" action="{{ url('pontoon.teams.ajax.permissions', locale.code) }}">
<input type="hidden" value="{{ csrf_token }}" name="csrfmiddlewaretoken">

<input type="hidden" id="community-builder-level" value="{{ community_builder_badge }}">
<div id="badge-tooltip-container" class="badge-tooltip" >
<p >New badge level gained!</p>
<p >
</p>
<input type="hidden" id="community-builder-level" value="{{ community_builder_level_reached }}">
<div id="badge-tooltip-container" class="badge-tooltip">
<p>New badge level gained!</p>
<p class="badge-tooltip-info"></p>
<img class="badge" src="{{ static('badges/community_builder_badge.svg') }}" title="Community Builder Badge" />
<p>You can view your new badge on your <a href="{{ url('pontoon.contributors.contributor.username', request.user) }}">profile page</a>.</p>
<button>Dismiss</button>
Expand Down
6 changes: 3 additions & 3 deletions pontoon/teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def ajax_permissions(request, locale):
locale = get_object_or_404(Locale, code=locale)
project_locales = locale.project_locale.visible().visible_for(request.user)

community_builder_level = 0
community_builder_level_reached = 0
if request.method == "POST":
locale_form = forms.LocalePermsForm(
request.POST, instance=locale, prefix="general", user=request.user
Expand All @@ -181,7 +181,7 @@ def ajax_permissions(request, locale):
)

if locale_form.is_valid() and project_locale_form.is_valid():
community_builder_level = locale_form.save()
community_builder_level_reached = locale_form.save()
project_locale_form.save()

else:
Expand Down Expand Up @@ -250,7 +250,7 @@ def ajax_permissions(request, locale):
"project_locale_form": project_locale_form,
"project_locales": project_locales,
"hide_project_selector": hide_project_selector,
"community_builder_badge": community_builder_level,
"community_builder_level_reached": community_builder_level_reached,
},
)

Expand Down
6 changes: 3 additions & 3 deletions pontoon/translations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def create_translation(request):
notify.send(
sender=user,
recipient=user,
verb="", # Triggers render of description only
verb="ignore", # Triggers render of description only
description=desc,
)

Expand Down Expand Up @@ -370,7 +370,7 @@ def approve_translation(request):
notify.send(
sender=user,
recipient=user,
verb="", # Triggers render of description only
verb="ignore", # Triggers render of description only
description=desc,
)

Expand Down Expand Up @@ -529,7 +529,7 @@ def reject_translation(request):
notify.send(
sender=request.user,
recipient=request.user,
verb="", # Triggers render of description only
verb="ignore", # Triggers render of description only
description=desc,
)

Expand Down
2 changes: 0 additions & 2 deletions translate/public/translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<link rel="icon" href="/favicon.ico" sizes="32x32">
<link rel="icon" href="/static/img/logo.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/static/img/apple-touch-icon.png">
<link rel="review-master-badge" href=" {{ static('badges/review_master_badge.svg') }}" type="image/svg+xml">
<link rel="translation-champion-badge" href="{{ static('badges/translation_champion_badge.svg') }}" type="image/svg+xml">

<title>Pontoon</title>

Expand Down
5 changes: 3 additions & 2 deletions translate/src/modules/user/components/UserNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Comment = ({
<span className='actor'>{actor.anchor}</span>

<span className='verb'>
<a href={target.url}>{verb}</a>
{verb !== 'ignore' && <a href={target.url}>{verb}</a>}
</span>

<span className='target'>{target.anchor}</span>
Expand Down Expand Up @@ -79,7 +79,8 @@ const Other = ({
</span>

<span className='verb'>
{verb.replace('has added a comment in', 'has added a comment')}
{verb !== 'ignore' &&
verb.replace('has added a comment in', 'has added a comment')}
</span>

{!target ? null : (
Expand Down

0 comments on commit bbd2a50

Please sign in to comment.