Skip to content
Permalink
Browse files

[IMP] website_profile: add badge breadcrumb and profile rank

This commit add a breadcrumb in the badge frontend view to redirect
to the last page the user was.
It highlights the user profile line in ranking view (profile/users).
It add this line at the top of every pages except for the one where
it already was.

Part of #46634

task-2201708
  • Loading branch information
Esperax committed Mar 19, 2020
1 parent c682899 commit 50c9c73c7769aedeff85ede2ff14d45818605717
@@ -149,7 +149,8 @@
<a t-attf-href="/forum/#{ slug(forum) }/tag" t-attf-class="nav-link #{searches.get('tags') and 'active'}">Tags</a>
</li>
<li class="nav-item">
<a t-attf-href="/profile/ranks_badges?badge_category=forum" t-attf-class="nav-link #{searches.get('badges') and 'active'}">Badges</a>
<a t-attf-href="/profile/ranks_badges?badge_category=forum&amp;url_origin=#{request.httprequest.path}&amp;name_origin=#{forum.name}"
t-attf-class="nav-link #{searches.get('badges') and 'active'}">Badges</a>
</li>
<li class="nav-item">
<a t-attf-href="/forum/#{ slug(forum) }/faq" t-attf-class="nav-link #{header.get('is_guidelines') and 'active'}">About</a>
@@ -175,7 +176,7 @@
<a t-if="searches or my or question" t-attf-href="/forum/#{ slug(forum) }" class="dropdown-item">All Topics</a>
<a t-if="not searches.get('users')" t-attf-href="/profile/users?forum_origin=#{request.httprequest.path}" class="dropdown-item">People</a>
<a t-if="not searches.get('tags')" t-attf-href="/forum/#{slug(forum)}/tag" class="dropdown-item">Tags</a>
<a t-if="not searches.get('badges')" t-attf-href="/profile/ranks_badges?badge_category=forum" class="dropdown-item">Badges</a>
<a t-if="not searches.get('badges')" t-attf-href="/profile/ranks_badges?badge_category=forum&amp;url_origin=#{request.httprequest.path}&amp;name_origin=#{forum.name}" class="dropdown-item">Badges</a>
<a t-if="not header.get('is_guidelines')" t-attf-href="/forum/#{ slug(forum) }/faq" class="dropdown-item">About</a>
<t t-if="uid">
<div class="dropdown-divider"/>
@@ -227,6 +227,8 @@ def view_all_users_page(self, page=1, **kwargs):
dom = expression.AND([['|', ('name', 'ilike', search_term), ('company_id.name', 'ilike', search_term)], dom])

user_count = User.sudo().search_count(dom)
uid = request.env.user.id
current_user_values = []
if user_count:
page_count = math.ceil(user_count / self._users_per_page)
pager = request.website.pager(url="/profile/users", total=user_count, page=page, step=self._users_per_page,
@@ -235,6 +237,10 @@ def view_all_users_page(self, page=1, **kwargs):
users = User.sudo().search(dom, limit=self._users_per_page, offset=pager['offset'], order='karma DESC')
user_values = self._prepare_all_users_values(users)

current_user = User.sudo().search(expression.AND([[('id', '=', uid)], dom]))
if (current_user not in users):
current_user_values = self._prepare_all_users_values(current_user)

# Get karma position for users (only website_published)
position_domain = [('karma', '>', 1), ('website_published', '=', True)]
if group_by:
@@ -250,14 +256,28 @@ def view_all_users_page(self, page=1, **kwargs):
user['karma_gain'] = user_data.get('karma_gain_total', 0)
user_values.sort(key=itemgetter('position'))

# OSU TODO : Same code twice
if (current_user_values):
if group_by:
position_map = self._get_user_tracking_karma_gain_position(position_domain, current_user.id, group_by)
else:
position_results = current_user._get_karma_position(position_domain)
position_map = dict((user_data['user_id'], dict(user_data)) for user_data in position_results)

user_data = position_map.get(current_user_values[0]['id'], dict())

current_user_values[0]['position'] = user_data.get('karma_position', 0)
current_user_values[0]['karma_gain'] = user_data.get('karma_gain_total', 0)

else:
user_values = []
pager = {'page_count': 0}

render_values.update({
'top3_users': user_values[:3] if not search_term and page == 1 else [],
'users': user_values,
'pager': pager})
'pager': pager,
'current_user': current_user_values,
'uid': uid})
return request.render("website_profile.users_page_main", render_values)

def _get_user_tracking_karma_gain_position(self, domain, user_ids, group_by):
@@ -249,3 +249,8 @@ $owprofile-color-bg: mix($body-bg, #efeff4);
.o_wprofile_pointer {
cursor: pointer;
}

// Own profile border
.border_profile_focus {
border-left: 4px solid $secondary
}
@@ -250,7 +250,7 @@
<div t-if="user.rank_id" class="d-flex align-items-center">
<small class="font-weight-bold mr-2">Current rank:</small>
<img t-att-src="website.image_url(user.rank_id, 'image_128')" width="16" height="16" alt="" class="o_object_fit_cover mr-1"/>
<a href="/profile/ranks_badges" t-field="user.rank_id"/>
<a t-attf-href="/profile/ranks_badges?url_origin=#{request.httprequest.path}&amp;name_origin=#{user.name}" t-field="user.rank_id"/>
</div>
<button class="btn btn-sm d-md-none bg-white border" type="button" data-toggle="collapse" data-target="#o_wprofile_sidebar_collapse" aria-expanded="false" aria-controls="o_wprofile_sidebar_collapse">More info</button>
</div>
@@ -380,15 +380,25 @@
<p class="text-muted">No badges yet!</p>
</div>
<div class="text-right d-inline-block pull-right">
<a t-if="not user.badge_ids and badge_category" t-attf-href="/profile/ranks_badges?badge_category=#{badge_category}" class="btn btn-link btn-sm"><i class="fa fa-arrow-right"/> All Badges</a>
<a t-else="" href="/profile/ranks_badges" class="btn btn-link btn-sm"><i class="fa fa-arrow-right mr-1"/>All Badges</a>
<a t-if="not user.badge_ids and badge_category" t-attf-href="/profile/ranks_badges?badge_category=#{badge_category}&amp;url_origin=#{request.httprequest.path}&amp;name_origin=#{user.name}"
class="btn btn-link btn-sm"><i class="fa fa-arrow-right"/> All Badges</a>
<a t-else="" t-attf-href="/profile/ranks_badges?url_origin=#{request.httprequest.path}&amp;name_origin=#{user.name}"
class="btn btn-link btn-sm"><i class="fa fa-arrow-right mr-1"/>All Badges</a>
</div>
</template>

<!-- About Ranks and badges Page -->
<template id="rank_badge_main" name="Ranks Page">
<t t-call="website.layout">
<div class="container mb32 mt48">
<nav t-if="request.params.get('url_origin') and request.params.get('name_origin')" aria-label="breadcrumb">
<ol class="breadcrumb p-0 bg-white">
<li class="breadcrumb-item">
<a t-att-href="request.website._get_http_domain() + request.params.get('url_origin')" t-esc="request.params.get('name_origin')"/>
</li>
<li class="breadcrumb-item">Badges</li>
</ol>
</nav>
<div class="row justify-content-between" t-if="ranks">
<div class="col-12 col-md-6 col-lg-5">
<h1>Ranks</h1>
@@ -511,8 +521,13 @@
<t t-call="website_profile.top3_user_card"></t>
</div>
</div>
<table class="table table-sm" t-if='current_user'>
<tr t-foreach="current_user" t-as="user" t-attf-onclick="location.href='/profile/user/#{user['id']}';" class="o_wprofile_pointer bg-white border_profile_focus">
<t t-call="website_profile.all_user_card"/>
</tr>
</table>
<table class="table table-sm" t-if='users'>
<tr t-foreach="users" t-as="user" t-attf-onclick="location.href='/profile/user/#{user['id']}';" class="o_wprofile_pointer bg-white">
<tr t-foreach="users" t-as="user" t-attf-onclick="location.href='/profile/user/#{user['id']}';" t-attf-class="o_wprofile_pointer bg-white #{user['id'] == uid and 'border_profile_focus'}">
<t t-call="website_profile.all_user_card"/>
</tr>
</table>

0 comments on commit 50c9c73

Please sign in to comment.
You can’t perform that action at this time.