From 543611fbb74bb2bff4f685f1151fb111d33e46c4 Mon Sep 17 00:00:00 2001 From: "Dave St.Germain" Date: Fri, 3 Apr 2020 13:30:47 -0400 Subject: [PATCH] Added edxnotes information to the courseware API. Added notes visibility toggle support for courseware MFE. Removed notes and calculator from chromeless view when rendered in courseware MFE. --- lms/djangoapps/courseware/views/views.py | 3 +- .../views/notes_visibility_factory.js | 23 ++++++++-- .../courseware/courseware-chromeless.html | 44 +++++++++---------- lms/templates/edxnotes/toggle_notes.html | 9 +++- .../content/course_overviews/models.py | 7 +++ .../djangoapps/courseware_api/serializers.py | 11 +++++ 6 files changed, 69 insertions(+), 28 deletions(-) diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index b58a0a5df0..03961b27e1 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -1682,7 +1682,8 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True): 'staff_access': bool(request.user.has_perm(VIEW_XQA_INTERFACE, course)), 'xqa_server': settings.FEATURES.get('XQA_SERVER', 'http://your_xqa_server.com'), 'display_reset_dates_banner': display_reset_dates_banner, - 'web_app_course_url': reverse(COURSE_HOME_VIEW_NAME, args=[course.id]) + 'web_app_course_url': reverse(COURSE_HOME_VIEW_NAME, args=[course.id]), + 'is_learning_mfe': request.META.get('HTTP_REFERER', '').startswith(settings.LEARNING_MICROFRONTEND_URL), } return render_to_response('courseware/courseware-chromeless.html', context) diff --git a/lms/static/js/edxnotes/views/notes_visibility_factory.js b/lms/static/js/edxnotes/views/notes_visibility_factory.js index b7c1051622..80d9b54fc8 100644 --- a/lms/static/js/edxnotes/views/notes_visibility_factory.js +++ b/lms/static/js/edxnotes/views/notes_visibility_factory.js @@ -12,13 +12,17 @@ errorMessage: gettext('An error has occurred. Make sure that you are connected to the Internet, and then try refreshing the page.'), initialize: function(options) { - _.bindAll(this, 'onSuccess', 'onError', 'keyDownToggleHandler'); + _.bindAll(this, 'onSuccess', 'onError', 'keyDownToggleHandler', 'receiveMessage'); this.visibility = options.visibility; this.visibilityUrl = options.visibilityUrl; + this.label = this.$('.utility-control-label'); this.actionLink = this.$('.action-toggle-notes'); this.actionLink.removeClass('is-disabled'); this.actionToggleMessage = this.$('.action-toggle-message'); + if (options.hideUI) { + $(window).on('message', this.receiveMessage); + } this.notification = new Annotator.Notification(); $(document).on('keydown.edxnotes:togglenotes', this.keyDownToggleHandler); }, @@ -28,6 +32,18 @@ Backbone.View.prototype.remove.call(this); }, + receiveMessage: function(event) { + var data = event.originalEvent.data; + if (data === 'tools.toggleNotes') { + event.preventDefault(); + this.visibility = !this.visibility; + if (this.visibility) { + this.enableNotes(); + } else { + this.disableNotes(); + } + } + }, toggleHandler: function(event) { event.preventDefault(); this.visibility = !this.visibility; @@ -94,11 +110,12 @@ }); return { - ToggleVisibilityView: function(visibility, visibilityUrl) { + ToggleVisibilityView: function(visibility, visibilityUrl, hideUI) { return new ToggleVisibilityView({ el: $('.edx-notes-visibility').get(0), visibility: visibility, - visibilityUrl: visibilityUrl + visibilityUrl: visibilityUrl, + hideUI: hideUI }); }, VisibilityDecorator: VisibilityDecorator diff --git a/lms/templates/courseware/courseware-chromeless.html b/lms/templates/courseware/courseware-chromeless.html index eedb182ffb..5e6d5c23f4 100644 --- a/lms/templates/courseware/courseware-chromeless.html +++ b/lms/templates/courseware/courseware-chromeless.html @@ -46,29 +46,23 @@ ${static.get_page_title_breadcrumbs(course_name())} <%static:css group='style-student-notes'/> % endif - - + + - + ${HTML(fragment.head_html())} - +% if is_learning_mfe: + ## If this chromeless view is in an iframe in the learning microfrontend app + ## then add a base tag in the head (of the iframe document) to force links + ## in this iframe to navigate the parent window. + +%endif <%block name="js_extra"> - - + + <%static:js group='courseware'/> @@ -99,7 +93,9 @@ ${HTML(fragment.foot_html())} -% if course.show_calculator or edx_notes_enabled: +% if not is_learning_mfe: + + % if course.show_calculator or edx_notes_enabled: + % endif +% else: + % if edx_notes_enabled: + <%include file="/edxnotes/toggle_notes.html" args="course=course"/> + % endif % endif +% if is_learning_mfe: +% endif diff --git a/lms/templates/edxnotes/toggle_notes.html b/lms/templates/edxnotes/toggle_notes.html index 47533dcee4..ee55a31d4e 100644 --- a/lms/templates/edxnotes/toggle_notes.html +++ b/lms/templates/edxnotes/toggle_notes.html @@ -9,8 +9,12 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str <% edxnotes_visibility = course.edxnotes_visibility edxnotes_visibility_url = reverse("edxnotes_visibility", kwargs={"course_id": course.id}) + if is_learning_mfe is UNDEFINED: + hide_ui = False + else: + hide_ui = is_learning_mfe %> -
+