From 607e4300afbd27b3d0715d2c94faa9396fab6533 Mon Sep 17 00:00:00 2001 From: Talha Date: Mon, 1 Jan 2024 18:30:42 +0500 Subject: [PATCH] fix: code quality --- openedx_cmi5_xblock/openedx_cmi5_xblock.py | 62 +++++++------------ .../static/js/src/openedx_cmi5_xblock.js | 16 +---- 2 files changed, 24 insertions(+), 54 deletions(-) diff --git a/openedx_cmi5_xblock/openedx_cmi5_xblock.py b/openedx_cmi5_xblock/openedx_cmi5_xblock.py index 16305ab..64aea79 100644 --- a/openedx_cmi5_xblock/openedx_cmi5_xblock.py +++ b/openedx_cmi5_xblock/openedx_cmi5_xblock.py @@ -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): @@ -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 @@ -289,7 +273,24 @@ 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: @@ -297,8 +298,8 @@ def launch_au_url(self, url): 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): @@ -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): """ @@ -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 @@ -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') diff --git a/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js b/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js index 11dec21..a5869bb 100644 --- a/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js +++ b/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js @@ -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); @@ -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); } }