From 465209951c5ab5ce4c1e59c7573e61e3d1e70140 Mon Sep 17 00:00:00 2001 From: Talha Date: Wed, 27 Dec 2023 18:25:29 +0500 Subject: [PATCH] fix: fix code quality --- openedx_cmi5_xblock/openedx_cmi5_xblock.py | 6 +-- .../static/js/src/openedx_cmi5_xblock.js | 44 ++++++------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/openedx_cmi5_xblock/openedx_cmi5_xblock.py b/openedx_cmi5_xblock/openedx_cmi5_xblock.py index 200e2f7..1ce9827 100644 --- a/openedx_cmi5_xblock/openedx_cmi5_xblock.py +++ b/openedx_cmi5_xblock/openedx_cmi5_xblock.py @@ -198,7 +198,6 @@ def student_view(self, context=None): }, ) return frag - @XBlock.handler def lrs_endpoint(self, request, _suffix): @@ -296,7 +295,7 @@ def launch_au_url(self, 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 @@ -438,7 +437,6 @@ def index_page_url(self): 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 +530,7 @@ def update_package_fields(self): if au_urls is not None: self.index_page_path = au_urls[0].text self.au_urls = [self.launch_au_url(au_url.text) for au_url in au_urls] - self.total_au_count = len(self.au_urls) + 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 ee98851..697b2e8 100644 --- a/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js +++ b/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js @@ -1,7 +1,6 @@ /* Javascript for CMI5XBlock. */ function CMI5XBlock(runtime, element, settings) { - $(function ($) { /* Use `gettext` provided by django-statici18n for static translations @@ -13,52 +12,35 @@ function CMI5XBlock(runtime, element, settings) { var nextButton = $('#nextButton'); var prevButton = $('#prevButton'); prevButton.prop('disabled', true) + if(settings.total_au_count === 1){ nextButton.prop('disabled', true) } nextButton.click(function () { - console.log("the au_urls are : ", settings.au_urls) - console.log("total au count : ", settings.total_au_count) - console.log("current au index: ", settings.current_au_index) - - - if(settings.current_au_index < settings.total_au_count-1){ - settings.current_au_index+=1 - prevButton.prop('disabled', false) - + settings.current_au_index+=1 + prevButton.prop('disabled', false) + if(settings.current_au_index === settings.total_au_count-1){ nextButton.prop('disabled', true) } - } - - $('.cmi5-embedded').attr('src', settings.au_urls[settings.current_au_index]); + }); - }); - - prevButton.click(function () { - - console.log("the au_urls are : ", settings.au_urls) - console.log("total au count : ", settings.total_au_count) - console.log("current au index: ", settings.current_au_index) - - if(settings.current_au_index > 0){ + prevButton.click(function () { + + if(settings.current_au_index > 0){ settings.current_au_index-=1 nextButton.prop('disabled', false) - if(settings.current_au_index === 0){ - prevButton.prop('disabled', true); - } + if(settings.current_au_index === 0){ + prevButton.prop('disabled', true); } - - - $('.cmi5-embedded').attr('src', settings.au_urls[settings.current_au_index]); - - }); - + } + $('.cmi5-embedded').attr('src', settings.au_urls[settings.current_au_index]); + }); }); }