Skip to content

Commit

Permalink
fix: code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Talha-Rizwan committed Jan 1, 2024
1 parent ef0b2a2 commit 607e430
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 54 deletions.
62 changes: 21 additions & 41 deletions openedx_cmi5_xblock/openedx_cmi5_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,6 @@ class CMI5XBlock(XBlock, CompletableXBlockMixin):
scope=Scope.content,
)

current_au_index = Integer(
display_name=_('Current AU Index'),
help=_('Index of the currently displayed AU URL'),
default=0,
scope=Scope.user_state,
)

total_au_count = Integer(
display_name=_('Total AU Count'),
help=_('Total number of AU URLs'),
default=0,
scope=Scope.content,
)

has_author_view = True

def author_view(self, context=None):
Expand Down Expand Up @@ -193,8 +179,6 @@ def student_view(self, context=None):
'popup_width': self.width or 800,
'popup_height': self.height or 800,
'au_urls': self.au_urls,
'current_au_index': self.current_au_index,
'total_au_count': self.total_au_count,
},
)
return frag
Expand Down Expand Up @@ -289,16 +273,33 @@ def launch_au_url(self, url):
if not self.package_meta or not url:
return ''

lms_cmi5_url = ''
lms_cmi5_url = self.make_launch_url(url)
return lms_cmi5_url

@property
def index_page_url(self):
"""
Gets the URL of the CMI5 index page.
Returns an empty string if the package metadata or index page path is not available.
"""
if not self.package_meta or not self.index_page_path:
return ''

lms_cmi5_url = self.make_launch_url(self.index_page_path)
return lms_cmi5_url

def make_launch_url(self, url):
"""Make the launch url for the AUs of cmi5."""
if is_url(url):
lms_cmi5_url = url
else:
folder = self.extract_folder_path
lms_cmi5_url = requests.utils.unquote(self.storage.url(os.path.join(folder, url)))

params_joining_symbol = '&' if is_params_exist(lms_cmi5_url) else '?'
lms_cmi5_url = lms_cmi5_url + params_joining_symbol + self.get_launch_url_params()
return lms_cmi5_url
lms_cmi5_url = lms_cmi5_url + params_joining_symbol
return lms_cmi5_url + self.get_launch_url_params()

# getters and setters
def get_credentials(self):
Expand Down Expand Up @@ -417,26 +418,6 @@ def get_launch_url_params(self):

return all_parameters

@property
def index_page_url(self):
"""
Gets the URL of the CMI5 index page.
Returns an empty string if the package metadata or index page path is not available.
"""
if not self.package_meta or not self.index_page_path:
return ''

if is_url(self.index_page_path):
lms_cmi5_url = self.index_page_path
else:
folder = self.extract_folder_path
lms_cmi5_url = requests.utils.unquote(self.storage.url(os.path.join(folder, self.index_page_path)))

params_joining_symbol = '&' if is_params_exist(lms_cmi5_url) else '?'
lms_cmi5_url = lms_cmi5_url + params_joining_symbol
return lms_cmi5_url + self.get_launch_url_params()

@property
def extract_folder_path(self):
"""
Expand Down Expand Up @@ -532,7 +513,7 @@ def update_package_fields(self):
for au in au_elements:
au_url = au.find('./{prefix}url'.format(prefix=prefix)).text
launch_method = au.get('launchMethod', 'AnyWindow')

au_data = {
'url': self.launch_au_url(au_url),
'launch_method': launch_method
Expand All @@ -541,7 +522,6 @@ def update_package_fields(self):

self.index_page_path = au_data_list[0]['url']
self.au_urls = au_data_list
self.total_au_count = len(self.au_urls)
else:
self.index_page_path = self.find_relative_file_path('index.html')

Expand Down
16 changes: 3 additions & 13 deletions openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ function CMI5XBlock(runtime, element, settings) {
*/

/* Here's where you'd do things on page load. */
var nextButton = $('#nextButton');
var prevButton = $('#prevButton');
console.log("the au_urls are : ", settings.au_urls)

prevButton.prop('disabled', true)

if(settings.total_au_count === 1){
nextButton.prop('disabled', true)
}


$('ol a').click(function (event) {
$('ol a').click(function (event) {
event.preventDefault();
var href = $(this).attr('href');
updateIframeSrc(href);
Expand All @@ -33,10 +23,10 @@ function CMI5XBlock(runtime, element, settings) {

if (index !== -1) {
if (settings.au_urls[index].launch_method === 'OwnWindow') {
// Open in a new browser window
// Open Au in a new browser window
window.open(href, '_blank');
} else {
// Display in the iframe
// Display Au in the iframe
$('.cmi5-embedded').attr('src', href);
}
}
Expand Down

0 comments on commit 607e430

Please sign in to comment.