Commit a4c77054 by Brian Jacobel

Add resume indicator to course outline

parent 4c8dc904
......@@ -392,7 +392,7 @@ def course_info(request, course_id):
# Get the URL of the user's last position in order to display the 'where you were last' message
context['last_accessed_courseware_url'] = None
if SelfPacedConfiguration.current().enable_course_home_improvements:
context['last_accessed_courseware_url'] = get_last_accessed_courseware(course, request, user)
context['last_accessed_courseware_url'], _ = get_last_accessed_courseware(course, request, user)
now = datetime.now(UTC())
effective_start = _adjust_start_date_for_beta_testers(user, course, course_key)
......@@ -427,8 +427,8 @@ def course_info(request, course_id):
def get_last_accessed_courseware(course, request, user):
"""
Return the courseware module URL that the user last accessed,
or None if it cannot be found.
Returns a tuple containing the courseware module (URL, id) that the user last accessed,
or (None, None) if it cannot be found.
"""
field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
course.id, request.user, course, depth=2
......@@ -445,8 +445,8 @@ def get_last_accessed_courseware(course, request, user):
'chapter': chapter_module.url_name,
'section': section_module.url_name
})
return url
return None
return (url, section_module.url_name)
return (None, None)
class StaticCourseTabView(FragmentView):
......
......@@ -43,6 +43,14 @@
text-decoration: none;
}
}
&.current {
border: 1px solid $lms-active-color;
.resume-right {
float: right;
}
}
}
}
}
......
......@@ -27,13 +27,25 @@ from django.utils.translation import ugettext as _
</div>
<ol class="outline-item focusable" role="group" tabindex="0">
% for subsection in section.get('children') or []:
<li class="subsection" role="treeitem" tabindex="-1" aria-expanded="true">
<li
class="subsection ${ 'current' if subsection['current'] else '' }"
role="treeitem"
tabindex="-1"
aria-expanded="true"
>
<a
class="outline-item focusable"
href="${ subsection['lms_web_url'] }"
id="${ subsection['id'] }"
>
${ subsection['display_name'] }
<span>${ subsection['display_name'] }</span>
<span class="sr-only">This is your last visited course section.</span>
% if subsection['current']:
<span class="resume-right">
<b>Resume Course</b>
<span class="icon fa fa-arrow-circle-right" aria-hidden="true"></span>
</span>
%endif
</a>
</li>
% endfor
......
......@@ -6,6 +6,7 @@ from django.core.context_processors import csrf
from django.template.loader import render_to_string
from courseware.courses import get_course_with_access
from lms.djangoapps.courseware.views.views import get_last_accessed_courseware
from lms.djangoapps.course_api.blocks.api import get_blocks
from opaque_keys.edx.keys import CourseKey
from web_fragments.fragment import Fragment
......@@ -18,7 +19,7 @@ class CourseOutlineFragmentView(FragmentView):
Course outline fragment to be shown in the unified course view.
"""
def populate_children(self, block, all_blocks):
def populate_children(self, block, all_blocks, course_position):
"""
For a passed block, replace each id in its children array with the full representation of that child,
which will be looked up by id in the passed all_blocks dict.
......@@ -28,8 +29,9 @@ class CourseOutlineFragmentView(FragmentView):
for i in range(len(children)):
child_id = block['children'][i]
child_detail = self.populate_children(all_blocks[child_id], all_blocks)
child_detail = self.populate_children(all_blocks[child_id], all_blocks, course_position)
block['children'][i] = child_detail
block['children'][i]['current'] = course_position == child_detail['block_id']
return block
......@@ -39,6 +41,7 @@ class CourseOutlineFragmentView(FragmentView):
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
_, course_position = get_last_accessed_courseware(course, request, request.user)
course_usage_key = modulestore().make_course_usage_key(course_key)
all_blocks = get_blocks(
request,
......@@ -55,7 +58,7 @@ class CourseOutlineFragmentView(FragmentView):
'csrf': csrf(request)['csrf_token'],
'course': course,
# Recurse through the block tree, fleshing out each child object
'blocks': self.populate_children(course_block_tree, all_blocks['blocks'])
'blocks': self.populate_children(course_block_tree, all_blocks['blocks'], course_position)
}
html = render_to_string('course_experience/course-outline-fragment.html', context)
return Fragment(html)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment