diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 1c4755f7092541521b939a4e00831a0058ba59d0..de04744ffb9402f31cf9dc35298bef8ca7e9c841 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -161,7 +161,7 @@ t-attf-class="nav-link #{searches.get('tags') and 'active' or ''}">Tags</a> </li> <li class="nav-item"> - <a t-attf-href="/profile/badge?category=forum" + <a t-attf-href="/profile/ranks_badges?badge_category=forum" t-attf-class="nav-link #{searches.get('badges') and 'active' or ''}">Badges</a> </li> <li class="nav-item" t-if="user.karma >= forum.karma_moderate"> diff --git a/addons/website_profile/controllers/main.py b/addons/website_profile/controllers/main.py index de56318e7c6e9452a333bccb58305111eb9f147c..9c6d31c2efc34c5c78b628497d28a0d8f8781866 100644 --- a/addons/website_profile/controllers/main.py +++ b/addons/website_profile/controllers/main.py @@ -163,40 +163,36 @@ class WebsiteProfile(http.Controller): return werkzeug.utils.redirect("/profile/user/%d?%s" % (user.id, kwargs['url_param'])) else: return werkzeug.utils.redirect("/profile/user/%d" % user.id) - # Ranks - # --------------------------------------------------- - @http.route('/profile/ranks', type='http', auth="public", website=True) - def ranks(self, **kwargs): - Rank = request.env['gamification.karma.rank'] - ranks = Rank.sudo().search([]) - ranks = ranks.sorted(key=lambda b: b.karma_min) - values = { - 'ranks': ranks, - 'user': request.env.user, - } - return request.render("website_profile.rank_main", values) - # Badges + # Ranks and Badges # --------------------------------------------------- def _prepare_badges_domain(self, **kwargs): """ Hook for other modules to restrict the badges showed on profile page, depending of the context """ domain = [('website_published', '=', True)] - if 'category' in kwargs: - domain = expression.AND([[('challenge_ids.category', '=', kwargs.get('category'))], domain]) + if 'badge_category' in kwargs: + domain = expression.AND([[('challenge_ids.category', '=', kwargs.get('badge_category'))], domain]) return domain - @http.route('/profile/badge', type='http', auth="public", website=True) - def badges(self, **kwargs): + @http.route('/profile/ranks_badges', type='http', auth="public", website=True) + def view_ranks_badges(self, **kwargs): + ranks = [] + if 'badge_category' not in kwargs: + Rank = request.env['gamification.karma.rank'] + ranks = Rank.sudo().search([], order='karma_min DESC') + Badge = request.env['gamification.badge'] badges = Badge.sudo().search(self._prepare_badges_domain(**kwargs)) badges = sorted(badges, key=lambda b: b.stat_count_distinct, reverse=True) values = self._prepare_user_values(searches={'badges': True}) + values.update({ + 'ranks': ranks, 'badges': badges, + 'user': request.env.user, }) - return request.render("website_profile.badge_main", values) + return request.render("website_profile.rank_badge_main", values) # All Users Page # --------------------------------------------------- diff --git a/addons/website_profile/views/website_profile.xml b/addons/website_profile/views/website_profile.xml index b115d553e8af22dc5c44b2723a4e355f4a26c845..c92f12e1e19f15eecb9b9cbc326726802b278353 100644 --- a/addons/website_profile/views/website_profile.xml +++ b/addons/website_profile/views/website_profile.xml @@ -179,7 +179,7 @@ <div t-if="user.rank_id" class="d-flex align-items-center"> <small class="font-weight-bold mr-2">Rank:</small> <img t-attf-src="/web/image/gamification.karma.rank/#{user.rank_id.id}/image_small" height="16" alt="" class="mr-1"/> - <a href="/profile/ranks" t-field="user.rank_id"/> + <a href="/profile/ranks_badges" 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> @@ -288,18 +288,18 @@ <p class="text-muted">No badge yet</p> </div> <div class="text-right"> - <a t-if="not user.badge_ids and badge_category" t-attf-href="/profile/badge?category=#{badge_category}"><i class="fa fa-arrow-right"/> Check available badges</a> - <a t-else="" href="/profile/badge" class="btn btn-link btn-sm"><i class="fa fa-arrow-right mr-1"/>Check all available badges</a> + <a t-if="not user.badge_ids and badge_category" t-attf-href="/profile/ranks_badges?badge_category=#{badge_category}"><i class="fa fa-arrow-right"/> Check available badges</a> + <a t-else="" href="/profile/ranks_badges" class="btn btn-link btn-sm"><i class="fa fa-arrow-right mr-1"/>Check all available badges</a> </div> </template> - <!-- About Rank Page --> - <template id="rank_main" name="Ranks Page"> + <!-- About Ranks and badges Page --> + <template id="rank_badge_main" name="Ranks Page"> <t t-call="website.layout"> <div class="container mb32 mt48"> - <div class="row justify-content-between"> - <div class="col-12 col-md-6"> - <h1>Ranks & Badges</h1> + <div class="row justify-content-between" t-if="ranks"> + <div class="col-12 col-md-6 col-lg-5"> + <h1>Ranks</h1> <p class="lead mb-4">Keep learning with <t t-esc="user.company_id.name"/>. Collect points on the forum or on the eLearning platform. Those points will make you reach new ranks.</p> <h5>How do I earn badges?</h5> <p>When you finish a course or reach milestones, you're awarded badges.</p> @@ -307,64 +307,55 @@ <p>You can score more points by answering quizzes at the end of each course content. Points can also be earned on the forum. Follow this link to the guidelines of the forum.</p> </div> <div class="col-12 col-md-5 col-lg-4"> - <t t-call="website_profile.rank_content"/> - </div> - </div> - </div> - </t> - </template> - - <template id="rank_content" name="Rank Page content"> - <h5 class="text-muted my-2">Ranks</h5> - <div class="row flex-column"> - <t t-foreach="ranks" t-as="rank"> - <t t-set="order_inverse" t-value="6 - rank.id"/> - - <div t-attf-class="col order-#{order_inverse}"> - <div class="media align-items-center py-2 border-top"> - <img height="50" t-attf-src="/web/image/gamification.karma.rank/#{rank.id}/image" class="mr-2" alt="Rank badge"/> - <div class="media-body"> - <h5 class="mt-0 mb-0" t-field="rank.name"/> - <span class="badge badge-success"><span t-field="rank.karma_min"/></span> point<span t-if="rank.karma_min">s</span> + <div class="card"> + <div class="card-header border-bottom-0">Ranks</div> + <ul class="list-group list-group-flush"> + <t t-foreach="ranks" t-as="rank"> + <li t-attf-class="list-group-item"> + <div class="media align-items-center"> + <img height="40" t-attf-src="/web/image/gamification.karma.rank/#{rank.id}/image" class="mr-2" alt="Rank badge"/> + <div class="media-body"> + <h5 class="mt-0 mb-0" t-field="rank.name"/> + <span class="badge badge-success"><span t-field="rank.karma_min"/></span> point<span t-if="rank.karma_min">s</span> + </div> + </div> + </li> + </t> + </ul> </div> </div> </div> - </t> - </div> - </template> - - <!-- About Badge Page --> - <template id="badge_main" name="Badges Page"> - <t t-call="website.layout"> - <div class="container mb32 mt48"> - <t t-call="website_profile.badge_content"> - </t> + <t t-call="website_profile.badge_content"/> </div> </t> </template> <template id="badge_content" name="Badges Page content"> - <h1>Badges</h1> - <p class="lead"> - Besides gaining reputation with your questions and answers, - you receive badges for being especially helpful.<br/>Badges - appear on your profile page, and your posts. - </p> - <table class="table table-sm mt32 mb64"> - <tr t-foreach="badges" t-as="badge"> - <td class="align-middle"> - <img t-attf-src="/website_profile/static/src/img/badge_#{badge.level}.svg" class="my-1" style="height:2.5em" alt=""/> - <h6 t-field="badge.name" class="d-inline my-0"/> - </td> - <td class="align-middle d-none d-md-table-cell"> - <b t-esc="badge.stat_count_distinct"/> - <i class="text-muted"> awarded users</i> - </td> - <td class="align-middle"> - <span t-field="badge.description"/> - </td> - </tr> - </table> + <div class="row"> + <div class="col-12"> + <h1 class="mt-4 mt-lg-2">Badges</h1> + <p class="lead"> + Besides gaining reputation with your questions and answers, + you receive badges for being especially helpful.<br class="d-none d-lg-inline-block"/>Badges + appear on your profile page, and your posts. + </p> + </div> + </div> + <table class="table table-sm mb64"> + <tr t-foreach="badges" t-as="badge"> + <td class="align-middle"> + <img t-attf-src="/website_profile/static/src/img/badge_#{badge.level}.svg" class="my-1" style="height:2.5em" t-att-alt="badge.level"/> + <h6 t-field="badge.name" class="d-inline my-0"/> + </td> + <td class="align-middle d-none d-md-table-cell"> + <b t-esc="badge.stat_count_distinct"/> + <i class="text-muted"> awarded users</i> + </td> + <td class="align-middle"> + <span t-field="badge.description"/> + </td> + </tr> + </table> </template> <!--Private profile--> diff --git a/addons/website_slides/views/website_slides_templates_homepage.xml b/addons/website_slides/views/website_slides_templates_homepage.xml index 59668760e8ae875a57cfa9b345dac9461cfd08fa..d5ebcd6ed9645ef5894a45e211ffe4152866d6bf 100644 --- a/addons/website_slides/views/website_slides_templates_homepage.xml +++ b/addons/website_slides/views/website_slides_templates_homepage.xml @@ -360,7 +360,7 @@ <div t-if="user.rank_id" class="d-flex align-items-center"> <span class="font-weight-bold text-muted mr-2">Current rank:</span> <img t-attf-src="/web/image/gamification.karma.rank/#{user.rank_id.id}/image_small" height="16" alt="" class="mr-1"/> - <a href="/profile/ranks" t-field="user.rank_id"/> + <a href="/profile/ranks_badges" t-field="user.rank_id"/> </div> <t t-if="user.next_rank_id"> <div class="font-weight-bold text-muted mt-1">Next rank:</div>