From 54a48a3227291d16c50be96ee1387d0d04025ac1 Mon Sep 17 00:00:00 2001 From: Ari Rizzitano Date: Thu, 29 Dec 2016 18:42:30 -0500 Subject: [PATCH] [courseware] generate sequence-specific titles server-side (AC-695) [courseware] generate sequence-specific titles server-side (AC-695) [courseware] generate sequence-specific titles server-side (AC-695) case for empty subsections [AC-695] move title logic into courseware context method [AC-695] pep8 coffeescript -> js js mistake jslint refactor sequence title generation slightly missed a line line too long python is not javascript ugh js ugh js part 2 --- .../lib/xmodule/xmodule/js/src/sequence/display.js | 11 ++++++++--- lms/djangoapps/courseware/tests/test_views.py | 1 + lms/djangoapps/courseware/views/index.py | 7 +++++++ lms/templates/courseware/courseware.html | 12 +++++------- .../core/djangoapps/site_configuration/helpers.py | 1 + 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/sequence/display.js b/common/lib/xmodule/xmodule/js/src/sequence/display.js index b240b487c5..380eebcd9e 100644 --- a/common/lib/xmodule/xmodule/js/src/sequence/display.js +++ b/common/lib/xmodule/xmodule/js/src/sequence/display.js @@ -57,8 +57,8 @@ this.ajaxUrl = this.el.data('ajax-url'); this.nextUrl = this.el.data('next-url'); this.prevUrl = this.el.data('prev-url'); - this.base_page_title = ' | ' + document.title; this.keydownHandler($(element).find('#sequence-list .tab')); + this.base_page_title = ($('title').data('base-title') || '').trim(); this.bind(); this.render(parseInt(this.el.data('position'), 10)); } @@ -136,10 +136,15 @@ Sequence.prototype.updatePageTitle = function() { // update the page title to include the current section - var positionLink = this.link_for(this.position); + var currentSectionTitle, + positionLink = this.link_for(this.position); if (positionLink && positionLink.data('page-title')) { - document.title = positionLink.data('page-title') + this.base_page_title; + currentSectionTitle = positionLink.data('page-title') + ' | ' + this.base_page_title; + + if (currentSectionTitle !== document.title) { + document.title = currentSectionTitle; + } } }; diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 43d3f7e400..e6c3b228cc 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -1824,6 +1824,7 @@ class ViewCheckerBlock(XBlock): """ has_children = True state = String(scope=Scope.user_state) + position = 0 def student_view(self, context): # pylint: disable=unused-argument """ diff --git a/lms/djangoapps/courseware/views/index.py b/lms/djangoapps/courseware/views/index.py index 5b740aac86..2744cb8433 100644 --- a/lms/djangoapps/courseware/views/index.py +++ b/lms/djangoapps/courseware/views/index.py @@ -388,6 +388,8 @@ class CoursewareIndex(View): 'bookmarks_api_url': reverse('bookmarks'), 'language_preference': self._get_language_preference(), 'disable_optimizely': True, + 'section_title': None, + 'sequence_title': None } table_of_contents = toc_for_course( self.effective_user, @@ -437,6 +439,11 @@ class CoursewareIndex(View): table_of_contents['next_of_active_section'], ) courseware_context['fragment'] = self.section.render(STUDENT_VIEW, section_context) + if self.section.position and self.section.has_children: + display_items = self.section.get_display_items() + if display_items: + courseware_context['sequence_title'] = display_items[self.section.position - 1] \ + .display_name_with_default return courseware_context diff --git a/lms/templates/courseware/courseware.html b/lms/templates/courseware/courseware.html index bf2015fcc1..11bebbce7f 100644 --- a/lms/templates/courseware/courseware.html +++ b/lms/templates/courseware/courseware.html @@ -19,13 +19,11 @@ from openedx.core.djangolib.js_utils import js_escaped_string <%block name="bodyclass">view-in-course view-courseware courseware ${course.css_class or ''} -<%block name="title"> - % if section_title: -${static.get_page_title_breadcrumbs(section_title, course_name())} - % else: -${static.get_page_title_breadcrumbs(course_name())} - %endif - +<%block name="title"> + + ${static.get_page_title_breadcrumbs(sequence_title, section_title, course_name())} + + <%block name="header_extras"> diff --git a/openedx/core/djangoapps/site_configuration/helpers.py b/openedx/core/djangoapps/site_configuration/helpers.py index 2ffc3bbb7b..d13083d81f 100644 --- a/openedx/core/djangoapps/site_configuration/helpers.py +++ b/openedx/core/djangoapps/site_configuration/helpers.py @@ -211,6 +211,7 @@ def page_title_breadcrumbs(*crumbs, **kwargs): """ platform_name = get_value('platform_name', settings.PLATFORM_NAME) separator = kwargs.get("separator", " | ") + crumbs = [c for c in crumbs if c is not None] if crumbs: return u'{}{}{}'.format(separator.join(crumbs), separator, platform_name) else: