From 9bf18b1e23f7cea4f0ff1dd059b9b580cd41a6ab Mon Sep 17 00:00:00 2001 From: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:19:35 -0500 Subject: [PATCH] feat: add url to usage location (#33855) --- .../contentstore/asset_storage_handlers.py | 57 ++++++++++++------- .../rest_api/v1/serializers/videos.py | 4 +- .../contentstore/video_storage_handlers.py | 29 +++++++--- cms/static/js/views/pages/container.js | 6 ++ cms/templates/studio_xblock_wrapper.html | 4 +- 5 files changed, 65 insertions(+), 35 deletions(-) diff --git a/cms/djangoapps/contentstore/asset_storage_handlers.py b/cms/djangoapps/contentstore/asset_storage_handlers.py index 3f77a934f9..281258e03a 100644 --- a/cms/djangoapps/contentstore/asset_storage_handlers.py +++ b/cms/djangoapps/contentstore/asset_storage_handlers.py @@ -126,28 +126,41 @@ def _get_asset_usage_path(course_key, assets): asset_key_string = str(asset_key) static_path = StaticContent.get_static_path_from_location(asset_key) is_video_block = getattr(block, 'category', '') == 'video' - if is_video_block: - handout = getattr(block, 'handout', '') - if handout and asset_key_string in handout: - unit = block.get_parent() - subsection = unit.get_parent() - subsection_display_name = getattr(subsection, 'display_name', '') - unit_display_name = getattr(unit, 'display_name', '') - xblock_display_name = getattr(block, 'display_name', '') - current_locations = usage_locations[asset_key_string] - new_location = f'{subsection_display_name} - {unit_display_name} / {xblock_display_name}' - usage_locations[asset_key_string] = [*current_locations, new_location] - else: - data = getattr(block, 'data', '') - if static_path in data or asset_key_string in data: - unit = block.get_parent() - subsection = unit.get_parent() - subsection_display_name = getattr(subsection, 'display_name', '') - unit_display_name = getattr(unit, 'display_name', '') - xblock_display_name = getattr(block, 'display_name', '') - current_locations = usage_locations[asset_key_string] - new_location = f'{subsection_display_name} - {unit_display_name} / {xblock_display_name}' - usage_locations[asset_key_string] = [*current_locations, new_location] + try: + if is_video_block: + handout = getattr(block, 'handout', '') + if handout and asset_key_string in handout: + usage_dict = {'display_location': '', 'url': ''} + xblock_display_name = getattr(block, 'display_name', '') + xblock_location = str(block.location) + unit = block.get_parent() + unit_location = str(block.parent) + unit_display_name = getattr(unit, 'display_name', '') + subsection = unit.get_parent() + subsection_display_name = getattr(subsection, 'display_name', '') + current_locations = usage_locations[asset_key_string] + usage_dict['display_location'] = (f'{subsection_display_name} - ' + f'{unit_display_name} / {xblock_display_name}') + usage_dict['url'] = f'/container/{unit_location}#{xblock_location}' + usage_locations[asset_key_string] = [*current_locations, usage_dict] + else: + data = getattr(block, 'data', '') + if static_path in data or asset_key_string in data: + usage_dict = {'display_location': '', 'url': ''} + xblock_display_name = getattr(block, 'display_name', '') + xblock_location = str(block.location) + unit = block.get_parent() + unit_location = str(block.parent) + unit_display_name = getattr(unit, 'display_name', '') + subsection = unit.get_parent() + subsection_display_name = getattr(subsection, 'display_name', '') + current_locations = usage_locations[asset_key_string] + usage_dict['display_location'] = (f'{subsection_display_name} - ' + f'{unit_display_name} / {xblock_display_name}') + usage_dict['url'] = f'/container/{unit_location}#{xblock_location}' + usage_locations[asset_key_string] = [*current_locations, usage_dict] + except AttributeError: + continue return usage_locations diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py index c5e730d127..50100f6a2b 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py @@ -57,7 +57,7 @@ class VideoModelSerializer(serializers.Serializer): child=serializers.CharField() ) usage_locations = serializers.ListField( - child=serializers.CharField() + child=serializers.DictField() ) @@ -111,7 +111,7 @@ class CourseVideosSerializer(serializers.Serializer): class VideoUsageSerializer(serializers.Serializer): """Serializer for video usage""" usage_locations = serializers.ListField( - child=serializers.CharField() + child=serializers.DictField() ) diff --git a/cms/djangoapps/contentstore/video_storage_handlers.py b/cms/djangoapps/contentstore/video_storage_handlers.py index 4d546aab3d..f68d71a6bf 100644 --- a/cms/djangoapps/contentstore/video_storage_handlers.py +++ b/cms/djangoapps/contentstore/video_storage_handlers.py @@ -234,15 +234,26 @@ def get_video_usage_path(course_key, edx_video_id): 'category': 'video' }, ) + for video in videos: video_id = getattr(video, 'edx_video_id', '') - if video_id == edx_video_id: - unit = video.get_parent() - subsection = unit.get_parent() - subsection_display_name = getattr(subsection, 'display_name', '') - unit_display_name = getattr(unit, 'display_name', '') - xblock_display_name = getattr(video, 'display_name', '') - usage_locations.append(f'{subsection_display_name} - {unit_display_name} / {xblock_display_name}') + try: + if video_id == edx_video_id: + usage_dict = {'display_location': '', 'url': ''} + video_location = str(video.location) + xblock_display_name = getattr(video, 'display_name', '') + unit = video.get_parent() + unit_location = str(video.parent) + unit_display_name = getattr(unit, 'display_name', '') + subsection = unit.get_parent() + subsection_display_name = getattr(subsection, 'display_name', '') + usage_dict['display_location'] = (f'{subsection_display_name} - ' + f'{unit_display_name} / {xblock_display_name}') + usage_dict['url'] = f'/container/{unit_location}#{video_location}' + usage_locations.append(usage_dict) + except AttributeError: + continue + return {'usage_locations': usage_locations} @@ -666,12 +677,12 @@ def videos_index_html(course, pagination_conf=None): """ Returns an HTML page to display previous video uploads and allow new ones """ + if use_new_video_uploads_page(course.id): + return redirect(get_video_uploads_url(course.id)) context = get_course_videos_context( course, pagination_conf, ) - if use_new_video_uploads_page(course.id): - return redirect(get_video_uploads_url(course.id)) return render_to_response('videos_index.html', context) diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index 9a15c779df..cea6eb856b 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -177,6 +177,12 @@ function($, _, Backbone, gettext, BasePage, self.initializePasteButton(); } + var targetId = window.location.hash.slice(1); + if (targetId) { + var target = document.getElementById(targetId); + target.scrollIntoView({ behavior: 'smooth', inline: 'center' }); + } + }, block_added: options && options.block_added }); diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index 4c73f940b9..19d9c876ed 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -43,9 +43,9 @@ block_is_unit = is_unit(xblock) % if not is_root: % if is_reorderable: -