Skip to content

Commit

Permalink
fix: xapi issue for single AU
Browse files Browse the repository at this point in the history
  • Loading branch information
Talha-Rizwan committed Jan 2, 2024
1 parent b85776c commit d372cf2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
7 changes: 4 additions & 3 deletions openedx_cmi5_xblock/openedx_cmi5_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,21 +506,22 @@ def update_package_fields(self):

prefix = '{' + namespace + '}' if namespace else ''
self.set_course_detail(prefix, root)

au_elements = root.findall('.//{prefix}au'.format(prefix=prefix))
if au_elements:
self.index_page_path = au_elements[0].find('./{prefix}url'.format(prefix=prefix)).text
au_data_list = []
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),
'url': self.launch_au_url(au_url), #try using index_page_url here
'launch_method': launch_method
}
au_data_list.append(au_data)

self.index_page_path = au_data_list[0]['url']

self.au_urls = au_data_list
else:
self.index_page_path = self.find_relative_file_path('index.html')
Expand Down
15 changes: 12 additions & 3 deletions openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ <h3 class="xblock-title mb-2">{{title}}</h3>
{% if index_page_url %}
<h5 class="xblock-title mb-2"> {% trans "Available Assignables:" %}</h5>
<ol>
<li id="index_url">
<a href="{{ index_page_url }}" target="_blank">
<span>{% trans "AU No. 1" %}</span>
</a>
</li>
{% for au_url in cmi5_xblock.au_urls %}
<li>
<a href="{{ au_url.url }}" target="_blank"><span>{% trans "AU No." %}</span> {{ forloop.counter }}</a>
</li>
{% if not forloop.first %}
<li>
<a href="{{ au_url.url }}" target="_blank">
<span>{% trans "AU No." %}</span> {{ forloop.counter }}
</a>
</li>
{% endif %}
{% endfor %}
</ol>

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

/* Here's where you'd do things on page load. */
setInitialUrl();

$('ol a').click(function (event) {
event.preventDefault();
var href = $(this).attr('href');
updateIframeSrc(href);
});

function setInitialUrl() {
// Get the initial href value from the element with ID "index_url"
var initialUrl = $('#index_url a').attr('href');
// Assign it to the settings.au_urls[0].url
settings.au_urls[0].url = initialUrl;
}

function updateIframeSrc(href) {
var index = settings.au_urls.findIndex(function (au) {
return au.url === href;
Expand Down

0 comments on commit d372cf2

Please sign in to comment.