[IMP] website_slides: improve the ui on a course (documentation)

Before, uncategorized slides  weren't display correctly on the slide_channel. It was impossible
to view all the slides if there were more than 4 slides uncategorized because the "View all" link wasn't
display.

Now, when there is no section/category on a course, it displays the last 4 slides with the "View all" link
which allows to be redirected to the uncategorized category (category_id=-1). This request displays all the
uncategorized slides with a pager if the limit of 12 slides per page is exceeded.
If there is at least one category created, all uncategorized slides are displayed under a section "Uncategorized".

Additionaly, there is a new button which allows to create a category directly on the course page to allow the user to
organize is course more effectively.

task-2161391
This commit is contained in:
Jérémy Hennecart
2020-02-12 12:55:35 +00:00
parent 67e49915b5
commit c9ace27135
2 changed files with 27 additions and 13 deletions
+14 -3
View File
@@ -348,9 +348,12 @@ class WebsiteSlides(WebsiteProfile):
'/slides/<model("slide.channel"):channel>/tag/<model("slide.tag"):tag>',
'/slides/<model("slide.channel"):channel>/tag/<model("slide.tag"):tag>/page/<int:page>',
'/slides/<model("slide.channel"):channel>/category/<model("slide.slide"):category>',
'/slides/<model("slide.channel"):channel>/category/<model("slide.slide"):category>/page/<int:page>'
'/slides/<model("slide.channel"):channel>/category/<model("slide.slide"):category>/page/<int:page>',
], type='http', auth="public", website=True, sitemap=sitemap_slide)
def channel(self, channel, category=None, tag=None, page=1, slide_type=None, uncategorized=False, sorting=None, search=None, **kw):
"""
Will return all necessary data to display the requested slide_channel along with a possible category.
"""
if not channel.can_access_from_current_website():
raise werkzeug.exceptions.NotFound()
@@ -376,7 +379,7 @@ class WebsiteSlides(WebsiteProfile):
pager_url += "/tag/%s" % tag.id
if uncategorized:
domain += [('category_id', '=', False)]
pager_url += "?uncategorized=1"
pager_args['uncategorized'] = 1
elif slide_type:
domain += [('slide_type', '=', slide_type)]
pager_url += "?slide_type=%s" % slide_type
@@ -463,10 +466,18 @@ class WebsiteSlides(WebsiteProfile):
# documentation mode may display less slides than content by category but overhead of
# computation is reasonable
values['slide_promoted'] = request.env['slide.slide'].sudo().search(domain, limit=1, order=order)
limit_category_data = False
if channel.channel_type == 'documentation':
if category or uncategorized:
limit_category_data = self._slides_per_page
else:
limit_category_data = self._slides_per_category
values['category_data'] = channel._get_categorized_slides(
domain, order,
force_void=not category,
limit=False if channel.channel_type != 'documentation' else self._slides_per_page if category else self._slides_per_category,
limit=limit_category_data,
offset=pager['offset'])
values['channel_progress'] = self._get_channel_progress(channel, include_quiz=True)
@@ -549,6 +549,12 @@
t-att-data-can-publish="channel.can_publish">
<i class="fa fa-cloud-upload mr-1"/>Upload new content
</a>
<a class="btn btn-secondary py-1 o_wslides_js_slide_section_add"
title="Add Section" role="button"
aria-label="Add Section" href="#"
t-att-channel_id="channel.id">
<i class="fa fa-folder-o mr-1"/>Add a section
</a>
</div>
<!-- Featured lesson -->
<div t-if="not search and not search_slide_type and slide_promoted" class="container py-1 mb-2">
@@ -592,11 +598,14 @@
<t t-foreach="category_data" t-as="category">
<div class="mb-2" t-if="(category['slides'] or channel.can_publish) and (search_category and search_category.id == category['id'] or not search_category)">
<div class="d-flex align-items-center justify-content-between border-bottom pb-2 mb-3" t-if="category['name'] != 'Uncategorized'">
<t t-set="is_empty_editable" t-value="not category['slides'] and channel.can_publish"/>
<t t-set="is_empty_editable" t-value="not category['slides'] and channel.can_publish"/>
<div class="d-flex align-items-center justify-content-between border-bottom pb-2 mb-3" t-if="category['id'] and query_string != '?search_uncategorized=1'">
<h5 t-attf-class="m-0 #{'text-muted' if is_empty_editable else ''}"><t t-esc="category['name']"/></h5>
<a t-if="category['id'] and not is_empty_editable" t-att-href="'/slides/%s/category/%s' % (slug(channel), category['slug_name'])">View all</a>
<a t-elif="not is_empty_editable" t-att-href="'/slides/%s?uncategorized=1' % (slug(channel))">View all</a>
</div>
<div class="d-flex align-items-center justify-content-between border-bottom pb-2 mb-3" t-if="not category['id'] and len(category['slides']) > 0">
<h5 t-if="len(category_data) > 1" t-attf-class="m-0 #{'text-muted' if is_empty_editable else ''}"><t t-esc="category['name']"/></h5>
<a t-att-href="'/slides/%s?uncategorized=1' % (slug(channel))">View all</a>
</div>
<div class="row mx-n2">
<t t-foreach="category['slides']" t-as="slide">
@@ -609,14 +618,8 @@
<div class="row">
<div class="col" t-field="channel.description_html"/>
</div>
<t t-if="search_category">
<div class="form-inline justify-content-center">
<t t-call="website_profile.pager_nobox"></t>
</div>
</t>
</div>
<t t-if="search_category">
<t t-if="search_category or search_uncategorized">
<div class="form-inline justify-content-center pb-5">
<t t-call="website_profile.pager_nobox"></t>
</div>