Skip to content

Commit

Permalink
Merge pull request #488 from ucsd-ets/hasnain/refactor-course-page
Browse files Browse the repository at this point in the history
Refactor course about page
  • Loading branch information
hasnain-saeed authored Sep 21, 2021
2 parents 76a2cf6 + c0e9081 commit 3aa59a8
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 223 deletions.
24 changes: 13 additions & 11 deletions cms/djangoapps/contentstore/courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from xmodule.course_module import CATALOG_VISIBILITY_ABOUT, CATALOG_VISIBILITY_NONE
from xmodule.library_tools import normalize_key_for_search
from xmodule.modulestore import ModuleStoreEnum
from openedx.features.ucsd_features.models import Course
from openedx.features.ucsd_features.models import CourseRun
from openedx.features.ucsd_features.utils import get_course_id

# REINDEX_AGE is the default amount of time that we look back for changes
# that might have happened. If we are provided with a time at which the
Expand Down Expand Up @@ -585,22 +586,23 @@ def index_about_information(cls, modulestore, course):
if not searcher:
return

course_key = f'{course.org}+{course.number}'
course_key = course_key.upper() # making catalog course id case-insensitive
course_run_key = text_type(course.id)

# Fetch latest run in the course
try:
ucsd_course = Course.objects.get(id=course_key)
ucsd_course_run = CourseRun.objects.get(id=course_run_key)
ucsd_course = ucsd_course_run.course
course_key = ucsd_course.id
latest_run = ucsd_course.latest_course_run
except Course.DoesNotExist:
ucsd_course = None
latest_run = None

# Replace current run with the latest run in the given course
if latest_run:
course_run_key = text_type(latest_run.id)
course = modulestore.get_course(latest_run.id)
# Replace current run with the latest run if exists
if latest_run:
course_run_key = text_type(latest_run.id)
course = modulestore.get_course(latest_run.id)

except:
course_key = get_course_id(course)
ucsd_course = None

course_info = {
'id': course_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from cms.djangoapps.contentstore.courseware_index import CourseAboutSearchIndexer
from xmodule.modulestore.django import modulestore
from openedx.features.ucsd_features.utils import get_course_id

from .prompt import query_yes_no

Expand Down Expand Up @@ -59,7 +60,7 @@ def handle(self, *args, **options):
return

# remove indices new and old catalog indices
course_keys = ['{}+{}'.format(course.org, course.number).upper() for course in courses]
course_keys = [get_course_id(course) for course in courses]
course_keys = list(set(course_keys))
course_keys += [text_type(course.id) for course in courses]
searcher.remove(doc_type, course_keys)
Expand Down
6 changes: 6 additions & 0 deletions cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,14 @@ def course_index(request, course_key):
raise Http404
lms_link = get_lms_link_for_item(course_module.location)
reindex_link = None
clear_course_page_cache_link = None
if settings.FEATURES.get('ENABLE_COURSEWARE_INDEX', False):
if GlobalStaff().has_user(request.user):
reindex_link = "/course/{course_id}/search_reindex".format(course_id=six.text_type(course_key))
if GlobalStaff().has_user(request.user):
clear_course_page_cache_link = "/course/{course_id}/clear_course_page_cache".format(course_id=six.text_type(course_key))

print(clear_course_page_cache_link)
sections = course_module.get_children()
course_structure = _course_outline_json(request, course_module)
locator_to_show = request.GET.get('show', None)
Expand Down Expand Up @@ -682,6 +687,7 @@ def course_index(request, course_key):
'course_release_date': course_release_date,
'settings_url': settings_url,
'reindex_link': reindex_link,
'clear_course_page_cache_link': clear_course_page_cache_link,
'deprecated_blocks_info': deprecated_blocks_info,
'notification_dismiss_url': reverse_course_url(
'course_notifications_handler',
Expand Down
40 changes: 40 additions & 0 deletions cms/static/js/views/pages/course_outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ define([
this.$('.button.button-reindex').click(function(event) {
self.handleReIndexEvent(event);
});
this.$('.button.button-clear-cache').click(function(event) {
self.handleClearCacheEvent(event);
});
this.model.on('change', this.setCollapseExpandVisibility, this);
$('.dismiss-button').bind('click', ViewUtils.deleteNotificationHandler(function() {
$('.wrapper-alert-announcement').removeClass('is-shown').addClass('is-hidden');
Expand Down Expand Up @@ -167,6 +170,17 @@ define([
.always(function() { $target.css('cursor', 'pointer'); });
},

handleClearCacheEvent: function(event) {
var self = this;
event.preventDefault();
var $target = $(event.currentTarget);
$target.css('cursor', 'wait');
this.clearCache($target.attr('href'))
.done(function(data) { self.onClearCacheSuccess(data); })
.fail(function(data) { self.onClearCacheError(data); })
.always(function() { $target.css('cursor', 'pointer'); });
},

startReIndex: function(reindex_url) {
return $.ajax({
url: reindex_url,
Expand All @@ -177,6 +191,16 @@ define([
});
},

clearCache: function(clear_cache_url) {
return $.ajax({
url: clear_cache_url,
method: 'GET',
global: false,
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});
},

onIndexSuccess: function(data) {
var msg = new AlertView.Announcement({
title: gettext('Course Index'),
Expand All @@ -191,7 +215,23 @@ define([
message: data.user_message
});
msg.show();
},
onClearCacheSuccess: function(data) {
var msg = new AlertView.Announcement({
title: gettext('Clear Course Page Cache'),
message: data.user_message
});
msg.show();
},

onClearCacheError: function(data) {
var msg = new NoteView.Error({
title: gettext('Cache Error'),
message: data.user_message
});
msg.show();
}

});

/**
Expand Down
4 changes: 2 additions & 2 deletions cms/static/sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ dl {
@include float(left);
@include margin-right(flex-gutter());

width: flex-grid(6, 12);
width: flex-grid(5, 12);
}

.nav-actions {
Expand All @@ -295,7 +295,7 @@ dl {

position: relative;
bottom: -($baseline*0.75);
width: flex-grid(6, 12);
width: flex-grid(7, 12);

.nav-item {
display: inline-block;
Expand Down
4 changes: 2 additions & 2 deletions cms/static/sass/bootstrap/_layouts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@

.page-header {
float: left;
width: flex-grid(6, 12);
width: flex-grid(5, 12);
margin-right: flex-gutter();
}

.nav-actions {
position: relative;
bottom: -($baseline*0.75);
float: right;
width: flex-grid(6, 12);
width: flex-grid(7, 12);
text-align: right;

.nav-item {
Expand Down
4 changes: 2 additions & 2 deletions cms/static/sass/elements/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
.page-header {
@include float(left);

width: flex-grid(6, 12);
width: flex-grid(5, 12);

@include margin-right(flex-gutter());
}
Expand All @@ -48,7 +48,7 @@

@include float(right);

width: flex-grid(6, 12);
width: flex-grid(7, 12);

@include text-align(right);

Expand Down
9 changes: 8 additions & 1 deletion cms/templates/course_outline.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h2 class="title title-3 warning-heading-text">${_("This course uses features th
</div>
</div>
%endif

%if proctoring_errors:
<div class="wrapper wrapper-alert wrapper-alert-error is-shown">
<div class="alert announcement has-actions">
Expand Down Expand Up @@ -182,6 +182,13 @@ <h3 class="sr">${_("Page Actions")}</h3>
</a>
</li>
%endif
%if clear_course_page_cache_link:
<li class="nav-item">
<a href="${clear_course_page_cache_link}" class="button button-clear-cache" data-category="clear_course_page_cache" title="${_('Clear course page cache')}">
<span class="icon-arrow-right" aria-hidden="true"></span>${_('Clear Course Page Cache')}
</a>
</li>
%endif
<li class="nav-item">
<a href="#" class="button button-toggle button-toggle-expand-collapse collapse-all is-hidden">
<span class="collapse-all"><span class="icon fa fa-arrow-up" aria-hidden="true"></span> <span class="label">${_("Collapse All Sections")}</span></span>
Expand Down
1 change: 1 addition & 0 deletions cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
name='group_configurations_detail_handler'),
url(r'^api/val/v0/', include('edxval.urls')),
url(r'^api/tasks/v0/', include('user_tasks.urls')),
url(r'^', include('openedx.features.ucsd_features.urls')),
url(r'^accessibility$', contentstore_views.accessibility, name='accessibility'),
]

Expand Down
11 changes: 0 additions & 11 deletions lms/djangoapps/courseware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,3 @@ def can_show_verified_upgrade(user, enrollment, course=None):

# Show the summary if user enrollment is in which allow user to upsell
return enrollment.is_active and enrollment.mode in CourseMode.UPSELL_TO_VERIFIED_MODES


def get_catalog_field_value(catalog_dict, catalog_field):
catalog_fields = catalog_field.split('.')
catalog_value = catalog_dict
for field in catalog_fields:
if isinstance(catalog_value, dict) and field in catalog_value.keys():
catalog_value = catalog_value.get(field)
else:
return None
return catalog_value
Loading

0 comments on commit 3aa59a8

Please sign in to comment.