diff --git a/lms/djangoapps/edxnotes/decorators.py b/lms/djangoapps/edxnotes/decorators.py index c522ba36bed4..7e058c3a2368 100644 --- a/lms/djangoapps/edxnotes/decorators.py +++ b/lms/djangoapps/edxnotes/decorators.py @@ -7,6 +7,7 @@ from django.conf import settings from xblock.exceptions import NoSuchServiceError +from openedx.core.djangoapps.plugins.plugins_hooks import run_extension_point from common.djangoapps.edxmako.shortcuts import render_to_string from common.djangoapps.student.auth import is_ccx_course @@ -50,6 +51,8 @@ def get_html(self, *args, **kwargs): except NoSuchServiceError: user = None + is_llm_summarize_enabled = run_extension_point('PEARSON_CORE_ENABLE_LLM_SUMMARIZE', course_id=str(course.id)) + if is_studio or not is_feature_enabled(course, user): return original_get_html(self, *args, **kwargs) else: @@ -69,6 +72,10 @@ def get_html(self, *args, **kwargs): "endpoint": get_public_endpoint(), "debug": settings.DEBUG, "eventStringLimit": settings.TRACK_MAX_EVENT / 6, + "llmSummarize": { + "isEnabled": is_llm_summarize_enabled, + "courseId": str(course.id), + }, }, }) diff --git a/lms/static/js/edxnotes/plugins/llm_summarize.js b/lms/static/js/edxnotes/plugins/llm_summarize.js index fff196fa4840..2ee1e636746c 100644 --- a/lms/static/js/edxnotes/plugins/llm_summarize.js +++ b/lms/static/js/edxnotes/plugins/llm_summarize.js @@ -87,17 +87,17 @@ let annotator = this.annotator; document.head.appendChild(style); this.modifyDom(this.annotator); - + annotator.editor.options.llmSummarize = annotator.options.llmSummarize const summarizeButton = document.getElementById('summarizeButton'); summarizeButton.addEventListener('click', function(ev) { - annotator.editor.element[0].setAttribute('is_summarizing', true); + annotator.editor.options.isSummarizing = true; }); annotator.subscribe('annotationEditorShown', this.handleSummarize); annotator.subscribe('annotationEditorHidden', this.cleanupSummarize); }, handleSummarize: function (editor, annotation) { - if (editor.element[0].getAttribute('is_summarizing') !== 'true') return; + if (!editor.options || !editor.options.isSummarizing) return; function toggleLoader() { const saveButton = document.querySelector('.annotator-controls .annotator-save'); @@ -115,6 +115,7 @@ }, body: JSON.stringify({ text_to_summarize: annotation.quote, + course_id: editor.options && editor.options.llmSummarize && editor.options.llmSummarize.courseId, }), }); @@ -140,7 +141,7 @@ textAreaWrapper.children[0].value = ''; textAreaWrapper.children[1].value = ''; - editor.element[0].setAttribute('is_summarizing', 'false'); + editor.options.isSummarizing = false; loaderWrapper.classList.add('d-none'); }, modifyDom: function(annotator) { diff --git a/lms/static/js/edxnotes/views/notes_factory.js b/lms/static/js/edxnotes/views/notes_factory.js index 8d8b5b1dcfec..61344e94e9db 100644 --- a/lms/static/js/edxnotes/views/notes_factory.js +++ b/lms/static/js/edxnotes/views/notes_factory.js @@ -51,7 +51,11 @@ destroy: '/annotations/:id/', search: '/search/' } - } + }, + llmSummarize: { + isEnabled: params && params.llmSummarize && params.llmSummarize.isEnabled, + courseId: params && params.llmSummarize && params.llmSummarize.courseId, + }, }; }; @@ -85,6 +89,9 @@ logger = NotesLogger.getLogger(element.id, params.debug), annotator; + if (options && options.llmSummarize && options.llmSummarize.isEnabled) { + plugins.push('LlmSummarize'); + } annotator = $el.annotator(options).data('annotator'); setupPlugins(annotator, plugins, options); NotesCollector.storeNotesRequestData( @@ -100,4 +107,4 @@ factory: getAnnotator }; }); -}).call(this, define || RequireJS.define); +}).call(this, define || RequireJS.define); \ No newline at end of file