feat: add url to usage location (#33855)

This commit is contained in:
Kristin Aoki
2023-12-07 11:19:35 -05:00
committed by GitHub
parent ce878a8ad2
commit 9bf18b1e23
5 changed files with 65 additions and 35 deletions

View File

@@ -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

View File

@@ -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()
)

View File

@@ -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)

View File

@@ -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
});

View File

@@ -43,9 +43,9 @@ block_is_unit = is_unit(xblock)
% if not is_root:
% if is_reorderable:
<li class="studio-xblock-wrapper is-draggable" data-locator="${xblock.location}" data-course-key="${xblock.location.course_key}">
<li class="studio-xblock-wrapper is-draggable" id="${xblock.location}" data-locator="${xblock.location}" data-course-key="${xblock.location.course_key}">
% else:
<div class="studio-xblock-wrapper" data-locator="${xblock.location}" data-course-key="${xblock.location.course_key}">
<div class="studio-xblock-wrapper" id="${xblock.location}" data-locator="${xblock.location}" data-course-key="${xblock.location.course_key}">
% endif
<section class="wrapper-xblock is-collapsible ${section_class}