forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
412acc9
commit cf7f366
Showing
7 changed files
with
119 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
""" | ||
Constants for offline mode app. | ||
""" | ||
import os | ||
|
||
from django.conf import settings | ||
|
||
MATHJAX_VERSION = '2.7.5' | ||
MATHJAX_CDN_URL = f'https://cdn.jsdelivr.net/npm/mathjax@{MATHJAX_VERSION}/MathJax.js' | ||
MATHJAX_STATIC_PATH = os.path.join('offline_mode_shared_static', 'js', f'MathJax-{MATHJAX_VERSION}.js') | ||
|
||
OFFLINE_CONTENT_ARCHIVE_NAME = 'offline_content.zip' | ||
|
||
DEFAULT_OFFLINE_SUPPORTED_XBLOCKS = ['html', 'problem'] | ||
OFFLINE_SUPPORTED_XBLOCKS = getattr(settings, 'OFFLINE_SUPPORTED_XBLOCKS', DEFAULT_OFFLINE_SUPPORTED_XBLOCKS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
openedx/features/offline_mode/static/offline_mode/js/bridge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function sendMessageToiOS(message) { | ||
window?.webkit?.messageHandlers?.iOSBridge?.postMessage(message); | ||
} | ||
|
||
function sendMessageToAndroid(message) { | ||
window?.AndroidBridge?.postMessage(message); | ||
} | ||
|
||
function receiveMessageFromiOS(message) { | ||
console.log("Message received from iOS:", message); | ||
} | ||
|
||
function receiveMessageFromAndroid(message) { | ||
console.log("Message received from Android:", message); | ||
} | ||
|
||
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.iOSBridge) { | ||
window.addEventListener("messageFromiOS", function (event) { | ||
receiveMessageFromiOS(event.data); | ||
}); | ||
} | ||
if (window.AndroidBridge) { | ||
window.addEventListener("messageFromAndroid", function (event) { | ||
receiveMessageFromAndroid(event.data); | ||
}); | ||
} | ||
const originalAjax = $.ajax; | ||
$.ajax = function (options) { | ||
sendMessageToiOS(options); | ||
sendMessageToiOS(JSON.stringify(options)); | ||
sendMessageToAndroid(options); | ||
sendMessageToAndroid(JSON.stringify(options)); | ||
console.log(options, JSON.stringify(options)); | ||
return originalAjax.call(this, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
""" | ||
Tasks for offline mode feature. | ||
""" | ||
from celery import shared_task | ||
from edx_django_utils.monitoring import set_code_owner_attribute | ||
from opaque_keys.edx.keys import CourseKey | ||
|
||
from xmodule.modulestore.django import modulestore | ||
|
||
from .constants import OFFLINE_SUPPORTED_XBLOCKS | ||
from .renderer import XBlockRenderer | ||
from .utils import generate_offline_content | ||
from .utils import generate_offline_content, is_offline_supported_block | ||
|
||
|
||
@shared_task | ||
def get_rendered_xblock_from_lms(course_id): | ||
@set_code_owner_attribute | ||
def generate_offline_content_for_course(course_id): | ||
""" | ||
Generates offline content for all supported XBlocks in the course. | ||
""" | ||
course_key = CourseKey.from_string(course_id) | ||
for xblock in modulestore().get_items(course_key, qualifiers={'category': 'problem'}): | ||
# if is_offline_supported(xblock): | ||
# continue | ||
html_data = XBlockRenderer(str(xblock.id)).render_xblock_from_lms() | ||
generate_offline_content(xblock, html_data) | ||
for xblock in modulestore().get_items(course_key, qualifiers={'category': OFFLINE_SUPPORTED_XBLOCKS}): | ||
if is_offline_supported_block(xblock): | ||
html_data = XBlockRenderer(str(xblock.id)).render_xblock_from_lms() | ||
generate_offline_content(xblock, html_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters