diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 376ba56d8dd9..18ec19a12923 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -366,6 +366,7 @@ def test_switch_to_unknown_source_library_preserves_settings(self): self.assertEqual(resp.status_code, 200) lc_block = modulestore().get_item(lc_block.location) + # Source library id should be set to the new bad one... assert lc_block.source_library_id == bad_library_id # ...but old source library version should be preserved... diff --git a/cms/djangoapps/contentstore/toggles.py b/cms/djangoapps/contentstore/toggles.py index ac8469678f78..a71c1c8788bd 100644 --- a/cms/djangoapps/contentstore/toggles.py +++ b/cms/djangoapps/contentstore/toggles.py @@ -178,6 +178,25 @@ def use_add_game_block(): return ENABLE_ADD_GAME_BLOCK_FLAG.is_enabled() +# .. toggle_name: new_core_editors.use_new_library_content_editor +# .. toggle_implementation: WaffleFlag +# .. toggle_default: False +# .. toggle_description: This flag enables the use of the new library xblock editor +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2023-10-30 +# .. toggle_target_removal_date: 2025-1-30 +# .. toggle_tickets: https://github.com/openedx/edx-platform/issues/33640 +# .. toggle_warning: +ENABLE_NEW_LIBRARY_CONTENT_EDITOR_FLAG = WaffleFlag('new_core_editors.use_new_library_content_editor', __name__) + + +def use_new_library_content_editor(): + """ + Returns a boolean if new library content block editor is enabled + """ + return ENABLE_NEW_LIBRARY_CONTENT_EDITOR_FLAG.is_enabled() + + # .. toggle_name: contentstore.individualize_anonymous_user_id # .. toggle_implementation: CourseWaffleFlag # .. toggle_default: False diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 91e85f8df660..05921af92ec3 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -1892,6 +1892,7 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint 'unit': unit, 'is_unit_page': is_unit_page, 'is_collapsible': is_library_xblock, + 'is_library_xblock': is_library_xblock, 'subsection': subsection, 'section': section, 'position': index, diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 8b122d8c8da0..f23712be0c25 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -178,6 +178,16 @@ def handle_xblock(request, usage_key_string=None): xblock, is_concise=True ) return JsonResponse(ancestor_info) + elif "childrenInfo" in fields: + xblock = get_xblock(usage_key, request.user) + children_info = _create_xblock_child_info( + xblock, + course_outline=None, + graders=None, + include_children_predicate=ALWAYS, + is_concise=True + ) + return JsonResponse(children_info) # TODO: pass fields to get_block_info and only return those with modulestore().bulk_operations(usage_key.course_key): response = get_block_info(get_xblock(usage_key, request.user)) @@ -825,7 +835,7 @@ def get_block_info( rewrite_static_links=True, include_ancestor_info=False, include_publishing_info=False, - include_children_predicate=False, + include_children_predicate=NEVER, ): """ metadata, data, id representation of a leaf block fetcher. diff --git a/cms/static/js/views/pages/container.js b/cms/static/js/views/pages/container.js index 3268b60e416a..1b9e91e90e2b 100644 --- a/cms/static/js/views/pages/container.js +++ b/cms/static/js/views/pages/container.js @@ -121,6 +121,11 @@ function($, _, Backbone, gettext, BasePage, this.unitOutlineView.render(); } + if (this.isLibraryContentPage) { + this.selectedLibraryComponents = []; + this.storedSelectedLibraryComponents = []; + this.getSelectedLibraryComponents(); + } this.listenTo(Backbone, 'move:onXBlockMoved', this.onXBlockMoved); }, @@ -370,11 +375,13 @@ function($, _, Backbone, gettext, BasePage, var useNewTextEditor = primaryHeader.attr('use-new-editor-text'), useNewVideoEditor = primaryHeader.attr('use-new-editor-video'), useNewProblemEditor = primaryHeader.attr('use-new-editor-problem'), + useNewLibraryContentEditor = primaryHeader.attr('use-new-editor-library-content'), blockType = primaryHeader.attr('data-block-type'); if((useNewTextEditor === 'True' && blockType === 'html') || (useNewVideoEditor === 'True' && blockType === 'video') || (useNewProblemEditor === 'True' && blockType === 'problem') + || (useNewLibraryContentEditor === 'True' && blockType === 'library_content') ) { var destinationUrl = primaryHeader.attr('authoring_MFE_base_url') + '/' + blockType + '/' + encodeURI(primaryHeader.attr('data-usage-id')); window.location.href = destinationUrl; @@ -639,12 +646,11 @@ function($, _, Backbone, gettext, BasePage, getSelectedLibraryComponents: function() { var self = this; var locator = this.$el.find('.studio-xblock-wrapper').data('locator'); - console.log(ModuleUtils); $.getJSON( ModuleUtils.getUpdateUrl(locator) + '/handler/get_block_ids', function(data) { - self.selectedLibraryComponents = Array.from(data.source_block_ids); - self.storedSelectedLibraryComponents = Array.from(data.source_block_ids); + self.selectedLibraryComponents = Array.from(data.candidates); + self.storedSelectedLibraryComponents = Array.from(data.candidates); } ); }, @@ -655,7 +661,7 @@ function($, _, Backbone, gettext, BasePage, e.preventDefault(); $.postJSON( ModuleUtils.getUpdateUrl(locator) + '/handler/submit_studio_edits', - {values: {source_block_ids: self.storedSelectedLibraryComponents}}, + {values: {candidates: self.storedSelectedLibraryComponents}}, function() { self.selectedLibraryComponents = Array.from(self.storedSelectedLibraryComponents); self.toggleSaveButton(); @@ -665,6 +671,7 @@ function($, _, Backbone, gettext, BasePage, toggleLibraryComponent: function(event) { var componentId = $(event.target).closest('.studio-xblock-wrapper').data('locator'); + var storeIndex = this.storedSelectedLibraryComponents.indexOf(componentId); if (storeIndex > -1) { this.storedSelectedLibraryComponents.splice(storeIndex, 1); diff --git a/cms/templates/container.html b/cms/templates/container.html index d61ce60e9189..2f0728e11210 100644 --- a/cms/templates/container.html +++ b/cms/templates/container.html @@ -176,7 +176,15 @@

${_("Page Actions")}

${_("Preview")} + % else: + % if is_library_xblock: + + % endif