Skip to content

Commit

Permalink
fix: resolve xapi statement tracking for multiple AUs
Browse files Browse the repository at this point in the history
  • Loading branch information
Talha-Rizwan committed Jan 3, 2024
1 parent e122142 commit 3660dae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 52 deletions.
28 changes: 12 additions & 16 deletions openedx_cmi5_xblock/openedx_cmi5_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uuid
import xml.etree.ElementTree as ET
import zipfile
import copy

import pkg_resources
import requests
Expand Down Expand Up @@ -165,7 +166,7 @@ def student_view(self, context=None):
"""The primary view of the CMI5XBlock, shown to students when viewing courses."""
student_context = {
'title': self.display_name,
'index_page_url': self.index_page_url,
'au_urls': self.launch_all_au_urls,
'cmi5_xblock': self,
}
student_context.update(context or {})
Expand All @@ -178,7 +179,6 @@ def student_view(self, context=None):
'CMI5XBlock', json_args={
'popup_width': self.width or 800,
'popup_height': self.height or 800,
'au_urls': self.au_urls,
},
)
return frag
Expand Down Expand Up @@ -268,6 +268,15 @@ def studio_submit(self, request, _suffix):
response['errors'].append(e.args[0])
return json_response(response)

@property
def launch_all_au_urls(self):
temp_au_list = copy.deepcopy(self.au_urls)

for au in temp_au_list:
au['url'] = self.launch_au_url(au['url'])

return temp_au_list

def launch_au_url(self, url):
"""Handles the multiple AUs and append launch params with url."""
if not self.package_meta or not url:
Expand All @@ -276,19 +285,6 @@ def launch_au_url(self, 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):
Expand Down Expand Up @@ -516,7 +512,7 @@ def update_package_fields(self):
launch_method = au.get('launchMethod', 'AnyWindow')

au_data = {
'url': self.launch_au_url(au_url),
'url': au_url,
'launch_method': launch_method
}
au_data_list.append(au_data)
Expand Down
15 changes: 5 additions & 10 deletions openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
<h3 class="xblock-title mb-2">{{title}}</h3>
<br>

{% if index_page_url %}
{% if au_urls %}
<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 %}
{% if not forloop.first %}
{% for au_url in au_urls %}
<li>
<a href="{{ au_url.url }}" target="_blank">
<a href="{{ au_url.url }}">
<span>{% trans "AU No." %}</span> {{ forloop.counter }}
</a>
({%trans "Launch: "%} {{au_url.launch_method}})
</li>
{% endif %}

{% endfor %}
</ol>

Expand Down
39 changes: 13 additions & 26 deletions openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Javascript for CMI5XBlock. */
function CMI5XBlock(runtime, element, settings) {
function CMI5XBlock(runtime, element) {

$(function ($) {
/*
Expand All @@ -9,35 +9,22 @@ 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);
});
event.preventDefault();
var href = $(this).attr('href');
var liText = $(this).closest('li').text().trim();
updateIframeSrc(href, liText);

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;
});

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

0 comments on commit 3660dae

Please sign in to comment.