From 4d9644913436ea442762af59fbf65145e54e2a01 Mon Sep 17 00:00:00 2001 From: Sofia Yoon Date: Mon, 21 Jun 2021 10:38:52 -0400 Subject: [PATCH 1/2] feat: create feature flag for PLS custom pacing --- cms/djangoapps/contentstore/config/waffle.py | 30 ++++++++++++++ cms/djangoapps/contentstore/views/item.py | 2 +- .../spec/views/pages/course_outline_spec.js | 2 +- .../js/views/modals/course_outline_modals.js | 37 +++++++++++++++++- cms/templates/course_outline.html | 2 +- .../js/self-paced-due-date-editor.underscore | 16 ++++++++ .../xmodule/modulestore/xml_importer.py | 2 +- common/lib/xmodule/xmodule/seq_module.py | 7 ++++ .../course_api/blocks/serializers.py | 1 + .../course_date_signals/handlers.py | 39 ++++++++++++++++++- 10 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 cms/templates/js/self-paced-due-date-editor.underscore diff --git a/cms/djangoapps/contentstore/config/waffle.py b/cms/djangoapps/contentstore/config/waffle.py index e9c1bd90cd..b81f731f28 100644 --- a/cms/djangoapps/contentstore/config/waffle.py +++ b/cms/djangoapps/contentstore/config/waffle.py @@ -67,3 +67,33 @@ REDIRECT_TO_LIBRARY_AUTHORING_MICROFRONTEND = LegacyWaffleFlag( flag_name='library_authoring_mfe', module_name=__name__, ) + + +# .. toggle_name: studio.pages_and_resources_mfe +# .. toggle_implementation: CourseWaffleFlag +# .. toggle_default: False +# .. toggle_description: Waffle flag to link existing studio views to the new Pages and Resources experience. +# .. toggle_use_cases: temporary, open_edx +# .. toggle_creation_date: 2021-05-24 +# .. toggle_target_removal_date: 2021-12-31 +# .. toggle_warnings: Also set settings.COURSE_AUTHORING_MICROFRONTEND_URL. +# .. toggle_tickets: None +ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND = CourseWaffleFlag( + waffle_namespace=waffle_flags(), + flag_name='pages_and_resources_mfe', + module_name=__name__, +) + +# .. toggle_name: studio.custom_pls +# .. toggle_implementation: CourseWaffleFlag +# .. toggle_default: False (except for SuperUsers) +# .. toggle_description: Waffle flag to enable custom pacing for PLS +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2021-06-15 +# .. toggle_target_removal_date: 2021-12-31 +# .. toggle_warnings: None +# .. toggle_tickets: None +CUSTOM_PLS = CourseWaffleFlag(WAFFLE_NAMESPACE, 'custom_pls', module_name=__name__,) + +def custom_pls_is_active(course_key): + return CUSTOM_PLS.is_enabled(course_key) diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index 2e65e83532..c429bccee9 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -2,7 +2,7 @@ import logging from collections import OrderedDict -from datetime import datetime +from datetime import datetime, timedelta from functools import partial from uuid import uuid4 diff --git a/cms/static/js/spec/views/pages/course_outline_spec.js b/cms/static/js/spec/views/pages/course_outline_spec.js index afb5d5cfd3..93d245a5df 100644 --- a/cms/static/js/spec/views/pages/course_outline_spec.js +++ b/cms/static/js/spec/views/pages/course_outline_spec.js @@ -294,7 +294,7 @@ describe('CourseOutlinePage', function() { TemplateHelpers.installTemplates([ 'course-outline', 'xblock-string-field-editor', 'modal-button', 'basic-modal', 'course-outline-modal', 'release-date-editor', - 'due-date-editor', 'grading-editor', 'publish-editor', + 'due-date-editor', 'self-paced-due-date-editor', 'grading-editor', 'publish-editor', 'staff-lock-editor', 'unit-access-editor', 'content-visibility-editor', 'settings-modal-tabs', 'timed-examination-preference-editor', 'access-editor', 'show-correctness-editor', 'highlights-editor', 'highlights-enable-editor', diff --git a/cms/static/js/views/modals/course_outline_modals.js b/cms/static/js/views/modals/course_outline_modals.js index 7419a0ae10..eded671fa7 100644 --- a/cms/static/js/views/modals/course_outline_modals.js +++ b/cms/static/js/views/modals/course_outline_modals.js @@ -17,7 +17,8 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', AbstractEditor, BaseDateEditor, ReleaseDateEditor, DueDateEditor, GradingEditor, PublishEditor, AbstractVisibilityEditor, StaffLockEditor, UnitAccessEditor, ContentVisibilityEditor, TimedExaminationPreferenceEditor, - AccessEditor, ShowCorrectnessEditor, HighlightsEditor, HighlightsEnableXBlockModal, HighlightsEnableEditor; + AccessEditor, ShowCorrectnessEditor, HighlightsEditor, HighlightsEnableXBlockModal, HighlightsEnableEditor, + SelfPacedDueDateEditor; CourseOutlineXBlockModal = BaseModal.extend({ events: _.extend({}, BaseModal.prototype.events, { @@ -74,6 +75,7 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', event.preventDefault(); requestData = this.getRequestData(); + console.log(requestData) if (!_.isEqual(requestData, {metadata: {}})) { XBlockViewUtils.updateXBlockFields(this.model, requestData, { success: this.options.onSave @@ -389,6 +391,35 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', } }); + SelfPacedDueDateEditor = BaseDateEditor.extend({ + fieldName: 'due', + templateName: 'self-paced-due-date-editor', + className: 'modal-section-content has-actions due-date-input grading-due-date', + + getValue: function() { + return this.$('#due_date').val(); + }, + + clearValue: function(event) { + event.preventDefault(); + this.$('#due_date').val(''); + }, + + getRequestData: function() { + let currentDate = parseInt(this.getValue()) + if (parseInt(this.getValue())){ + currentDate = new Date() + currentDate.setDate(currentDate.getDate() + parseInt(this.getValue())*7) + }; + // due_num_weeks + return { + metadata: { + due: currentDate + } + }; + } + }); + ReleaseDateEditor = BaseDateEditor.extend({ fieldName: 'start', templateName: 'release-date-editor', @@ -1078,6 +1109,10 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', tabs[0].editors = [ReleaseDateEditor, GradingEditor, DueDateEditor]; tabs[1].editors = [ContentVisibilityEditor, ShowCorrectnessEditor]; + if (course.get('self_paced')) { + tabs[0].editors.push(SelfPacedDueDateEditor) + } + if (options.enable_proctored_exams || options.enable_timed_exams) { advancedTab.editors.push(TimedExaminationPreferenceEditor); } diff --git a/cms/templates/course_outline.html b/cms/templates/course_outline.html index 0bf9ce60d4..e9f6f3ad54 100644 --- a/cms/templates/course_outline.html +++ b/cms/templates/course_outline.html @@ -29,7 +29,7 @@ from django.urls import reverse <%block name="header_extras"> -% for template_name in ['course-outline', 'xblock-string-field-editor', 'basic-modal', 'modal-button', 'course-outline-modal', 'due-date-editor', 'release-date-editor', 'grading-editor', 'publish-editor', 'staff-lock-editor', 'unit-access-editor', 'content-visibility-editor', 'verification-access-editor', 'timed-examination-preference-editor', 'access-editor', 'settings-modal-tabs', 'show-correctness-editor', 'highlights-editor', 'highlights-enable-editor', 'course-highlights-enable']: +% for template_name in ['course-outline', 'xblock-string-field-editor', 'basic-modal', 'modal-button', 'course-outline-modal', 'due-date-editor', 'self-paced-due-date-editor', 'release-date-editor', 'grading-editor', 'publish-editor', 'staff-lock-editor', 'unit-access-editor', 'content-visibility-editor', 'verification-access-editor', 'timed-examination-preference-editor', 'access-editor', 'settings-modal-tabs', 'show-correctness-editor', 'highlights-editor', 'highlights-enable-editor', 'course-highlights-enable']: diff --git a/cms/templates/js/self-paced-due-date-editor.underscore b/cms/templates/js/self-paced-due-date-editor.underscore new file mode 100644 index 0000000000..77ed3fb65c --- /dev/null +++ b/cms/templates/js/self-paced-due-date-editor.underscore @@ -0,0 +1,16 @@ + + + diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 07b184cf6c..57db76be52 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -1051,7 +1051,7 @@ def allowed_metadata_by_category(category): return { 'vertical': [], 'chapter': ['start'], - 'sequential': ['due', 'format', 'start', 'graded'] + 'sequential': ['due', 'due_num_weeks', 'format', 'start', 'graded'] }.get(category, ['*']) diff --git a/common/lib/xmodule/xmodule/seq_module.py b/common/lib/xmodule/xmodule/seq_module.py index 3cd2fd4833..71da55d3bd 100644 --- a/common/lib/xmodule/xmodule/seq_module.py +++ b/common/lib/xmodule/xmodule/seq_module.py @@ -79,6 +79,12 @@ class SequenceFields: # lint-amnesty, pylint: disable=missing-class-docstring scope=Scope.settings, ) + due_num_weeks = Integer( + display_name = _("Number of Weeks Due By"), + help=_("Enter the number of weeks the problems are due by"), + scope = Scope.settings, + ) + hide_after_due = Boolean( display_name=_("Hide sequence content After Due Date"), help=_( @@ -195,6 +201,7 @@ class ProctoringFields: default=False, scope=Scope.settings, ) + def _get_course(self): """ diff --git a/lms/djangoapps/course_api/blocks/serializers.py b/lms/djangoapps/course_api/blocks/serializers.py index 277bf2a668..870f834888 100644 --- a/lms/djangoapps/course_api/blocks/serializers.py +++ b/lms/djangoapps/course_api/blocks/serializers.py @@ -51,6 +51,7 @@ SUPPORTED_FIELDS = [ SupportedFieldType('format'), SupportedFieldType('start'), SupportedFieldType('due'), + SupportedFieldType('due_num_weeks'), SupportedFieldType('contains_gated_content'), SupportedFieldType('has_score'), SupportedFieldType('has_scheduled_content'), diff --git a/openedx/core/djangoapps/course_date_signals/handlers.py b/openedx/core/djangoapps/course_date_signals/handlers.py index 263916c538..e44b130adc 100644 --- a/openedx/core/djangoapps/course_date_signals/handlers.py +++ b/openedx/core/djangoapps/course_date_signals/handlers.py @@ -1,8 +1,11 @@ """Signal handlers for writing course dates into edx_when.""" +from datetime import timedelta, datetime +import datetime import logging +from cms.djangoapps.contentstore.config.waffle import custom_pls_is_active from django.dispatch import receiver from edx_when.api import FIELDS_TO_EXTRACT, set_dates_for_course @@ -27,6 +30,11 @@ def _field_values(fields, xblock): if field_name not in xblock.fields: continue field = xblock.fields[field_name] + if field_name == 'due': + print("THIS IS THE FIELD ", field) + print(xblock) + result[field.name] = field.read_from(xblock) + continue if field.scope == Scope.settings and field.is_set_on(xblock): try: result[field.name] = field.read_from(xblock) @@ -83,7 +91,34 @@ def extract_dates_from_course(course): Extract all dates from the supplied course. """ log.info('Extracting course dates for %s', course.id) - if course.self_paced: + + if course.self_paced and custom_pls_is_active(course.id): + print("This is self paced ") + date_items = [] + store = modulestore() + with store.branch_setting(ModuleStoreEnum.Branch.published_only, course.id): + items = store.get_items(course.id) + log.info('Extracting dates from %d items in %s', len(items), course.id) + print("B4 the items sections") + # new_fields_to_extract = FIELDS_TO_EXTRACT + ('due_num_weeks',) + # print("THe new fields to extract ", new_fields_to_extract) + for item in items: + metadata = _field_values(FIELDS_TO_EXTRACT, item) + print("THIS IS THE METADATA ", metadata) + metadata['due'] = datetime.datetime.now() - metadata['due'] + + # print("TYPE OF DATES: ", metadata) + # print("RIGHT NOW, ", datetime.datetime.now()) + # print(metadata['due']) + # metadata['due'] = datetime.datetime.now() - metadata['due'] + # print('metadata due: ', metadata['due']) + metadata.pop('due_num_weeks',None) + # print("THIS IS THE DUE DATE: ", metadata['due']) + date_items.append((item.location, metadata)) + # date_items.append((item.location, _field_values(FIELDS_TO_EXTRACT, item))) + print("Here are the date items: ", date_items) + + elif course.self_paced and not custom_pls_is_active(course.id): metadata = _field_values(FIELDS_TO_EXTRACT, course) # self-paced courses may accidentally have a course due date metadata.pop('due', None) @@ -94,6 +129,7 @@ def extract_dates_from_course(course): # unless that item already has a relative date set for _, section, weeks_to_complete in spaced_out_sections(course): section_date_items = [] + print("THESE IS THE WEEKS TO COMPLETE ,", weeks_to_complete) for subsection in section.get_children(): section_date_items.extend(_gather_graded_items(subsection, weeks_to_complete)) @@ -108,6 +144,7 @@ def extract_dates_from_course(course): log.info('Extracting dates from %d items in %s', len(items), course.id) for item in items: date_items.append((item.location, _field_values(FIELDS_TO_EXTRACT, item))) + return date_items From 09eb36e55058207a7a862eed37edabdf81d2d4f5 Mon Sep 17 00:00:00 2001 From: Sofia Yoon Date: Wed, 23 Jun 2021 16:04:07 -0400 Subject: [PATCH 2/2] feat: AA-883 basic prototype for custom pacing pls in studio fix: make new field in xblock json serializable and don't assign due dates to ORAs feat: display warning message in Studio if the relative date input is more than 18 weeks for custom pacing in self paced course fix: handle due dates for mix of ORA and non ORA problems under a subsection and other styling fixes feat: add a minimum restriction for self paced courses due date editor input fix: naming of warning id divs to be more specific and exclude children of ORA problems in setting due dates test: extracting dates for a self paced course with custom pacing test: frontend for self paced custom pacing modal in studio and clean up its backend tests fix: remove an unused line when getting children of custom pacing subsection, reorganize testing for custom pacing fix: more specific comments to testing for custom PLS and remove a test case course fix: more cleanup for self paced custom pacing PLS backend tests --- cms/djangoapps/contentstore/config/waffle.py | 26 +- .../contentstore/config/waffle_utils.py | 4 +- cms/djangoapps/contentstore/views/item.py | 3 +- .../spec/views/pages/course_outline_spec.js | 177 +++++++++++++- .../js/views/modals/course_outline_modals.js | 64 +++-- cms/templates/base.html | 4 +- .../js/self-paced-due-date-editor.underscore | 23 +- .../xmodule/modulestore/inheritance.py | 6 + common/lib/xmodule/xmodule/seq_module.py | 9 +- .../course_api/blocks/serializers.py | 1 - .../course_date_signals/handlers.py | 74 +++--- .../djangoapps/course_date_signals/tests.py | 230 +++++++++++++++++- 12 files changed, 506 insertions(+), 115 deletions(-) diff --git a/cms/djangoapps/contentstore/config/waffle.py b/cms/djangoapps/contentstore/config/waffle.py index b81f731f28..4cf7b4a38f 100644 --- a/cms/djangoapps/contentstore/config/waffle.py +++ b/cms/djangoapps/contentstore/config/waffle.py @@ -69,31 +69,13 @@ REDIRECT_TO_LIBRARY_AUTHORING_MICROFRONTEND = LegacyWaffleFlag( ) -# .. toggle_name: studio.pages_and_resources_mfe -# .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False -# .. toggle_description: Waffle flag to link existing studio views to the new Pages and Resources experience. -# .. toggle_use_cases: temporary, open_edx -# .. toggle_creation_date: 2021-05-24 -# .. toggle_target_removal_date: 2021-12-31 -# .. toggle_warnings: Also set settings.COURSE_AUTHORING_MICROFRONTEND_URL. -# .. toggle_tickets: None -ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND = CourseWaffleFlag( - waffle_namespace=waffle_flags(), - flag_name='pages_and_resources_mfe', - module_name=__name__, -) - # .. toggle_name: studio.custom_pls # .. toggle_implementation: CourseWaffleFlag -# .. toggle_default: False (except for SuperUsers) +# .. toggle_default: False # .. toggle_description: Waffle flag to enable custom pacing for PLS # .. toggle_use_cases: temporary -# .. toggle_creation_date: 2021-06-15 +# .. toggle_creation_date: 2021-07-08 # .. toggle_target_removal_date: 2021-12-31 -# .. toggle_warnings: None -# .. toggle_tickets: None +# .. toggle_warnings: For this flag to be active, add flag 'studio.custom_pls' in Django Admin +# .. toggle_tickets: https://openedx.atlassian.net/browse/AA-844 CUSTOM_PLS = CourseWaffleFlag(WAFFLE_NAMESPACE, 'custom_pls', module_name=__name__,) - -def custom_pls_is_active(course_key): - return CUSTOM_PLS.is_enabled(course_key) diff --git a/cms/djangoapps/contentstore/config/waffle_utils.py b/cms/djangoapps/contentstore/config/waffle_utils.py index a63057c62a..eaf9e5e456 100644 --- a/cms/djangoapps/contentstore/config/waffle_utils.py +++ b/cms/djangoapps/contentstore/config/waffle_utils.py @@ -9,6 +9,4 @@ def should_show_checklists_quality(course_key): Determine if the ENABLE_CHECKLISTS_QUALITY waffle flag is set and if the user is able to see it """ - if ENABLE_CHECKLISTS_QUALITY.is_enabled(course_key): - return True - return False + return ENABLE_CHECKLISTS_QUALITY.is_enabled(course_key) diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index c429bccee9..fc660b2d4a 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -2,7 +2,7 @@ import logging from collections import OrderedDict -from datetime import datetime, timedelta +from datetime import datetime from functools import partial from uuid import uuid4 @@ -1230,6 +1230,7 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F 'graded': xblock.graded, 'due_date': get_default_time_display(xblock.due), 'due': xblock.fields['due'].to_json(xblock.due), + 'due_num_weeks': xblock.due_num_weeks, 'format': xblock.format, 'course_graders': [grader.get('type') for grader in graders], 'has_changes': has_changes, diff --git a/cms/static/js/spec/views/pages/course_outline_spec.js b/cms/static/js/spec/views/pages/course_outline_spec.js index 93d245a5df..e8691cc740 100644 --- a/cms/static/js/spec/views/pages/course_outline_spec.js +++ b/cms/static/js/spec/views/pages/course_outline_spec.js @@ -12,7 +12,7 @@ describe('CourseOutlinePage', function() { var createCourseOutlinePage, displayNameInput, model, outlinePage, requests, getItemsOfType, getItemHeaders, verifyItemsExpanded, expandItemsAndVerifyState, collapseItemsAndVerifyState, selectBasicSettings, selectVisibilitySettings, selectAdvancedSettings, createMockCourseJSON, createMockSectionJSON, - createMockSubsectionJSON, verifyTypePublishable, mockCourseJSON, mockEmptyCourseJSON, setSelfPaced, + createMockSubsectionJSON, verifyTypePublishable, mockCourseJSON, mockEmptyCourseJSON, setSelfPaced,setSelfPacedCustomPLS, mockSingleSectionCourseJSON, createMockVerticalJSON, createMockIndexJSON, mockCourseEntranceExamJSON, selectOnboardingExam, createMockCourseJSONWithReviewRules,mockCourseJSONWithReviewRules, mockOutlinePage = readFixtures('templates/mock/mock-course-outline-page.underscore'), @@ -202,6 +202,11 @@ describe('CourseOutlinePage', function() { course.set('self_paced', true); }; + setSelfPacedCustomPLS = function() { + setSelfPaced(); + course.set('is_custom_pls_active', true); + } + createCourseOutlinePage = function(test, courseJSON, createOnly) { requests = AjaxHelpers.requests(test); model = new XBlockOutlineInfo(courseJSON, {parse: true}); @@ -1002,9 +1007,9 @@ describe('CourseOutlinePage', function() { }); describe('Subsection', function() { - var getDisplayNameWrapper, setEditModalValues, setContentVisibility, mockServerValuesJson, - selectDisableSpecialExams, selectTimedExam, selectProctoredExam, selectPracticeExam, - selectPrerequisite, selectLastPrerequisiteSubsection, checkOptionFieldVisibility, + var getDisplayNameWrapper, setEditModalValues, setEditModalValuesForCustomPacing, setContentVisibility, mockServerValuesJson, + mockCustomPacingServerValuesJson, selectDisableSpecialExams, selectTimedExam, selectProctoredExam, selectPracticeExam, + selectPrerequisite, selectLastPrerequisiteSubsection, selectDueNumWeeksSubsection, checkOptionFieldVisibility, defaultModalSettings, modalSettingsWithExamReviewRules, getMockNoPrereqOrExamsCourseJSON, expectShowCorrectness; getDisplayNameWrapper = function() { @@ -2117,6 +2122,170 @@ describe('CourseOutlinePage', function() { ); expect($modalWindow.find('.outline-subsection')).not.toExist(); }); + + describe('Self Paced with Custom Personalized Learner Schedules (PLS)', function () { + beforeEach(function() { + var mockCourseJSON = createMockCourseJSON({}, [ + createMockSectionJSON({}, [ + createMockSubsectionJSON({}, []) + ]) + ]); + createCourseOutlinePage(this, mockCourseJSON, false); + setSelfPacedCustomPLS(); + }); + + setEditModalValuesForCustomPacing = function(due_in, grading_type) { + $('#due_in').val(due_in); + $('#grading_type').val(grading_type); + }; + + selectDueNumWeeksSubsection = function(weeks) { + $('#due_in').val(weeks).trigger('keyup'); + } + + mockCustomPacingServerValuesJson = createMockSectionJSON({ + release_date: 'Jan 01, 2970 at 05:00 UTC' + }, [ + createMockSubsectionJSON({ + graded: true, + due_num_weeks: 3, + format: 'Lab', + has_explicit_staff_lock: true, + staff_only_message: true, + is_prereq: false, + show_correctness: 'never', + is_time_limited: false, + is_practice_exam: false, + is_proctored_exam: false, + default_time_limit_minutes: null, + }, [ + createMockVerticalJSON({ + has_changes: true, + published: false + }) + ]) + ]); + + it('can show correct editors for self_paced course with custom pacing', function (){ + outlinePage.$('.outline-subsection .configure-button').click(); + expect($('.edit-settings-release').length).toBe(0); + // Due date input exists for custom pacing self paced courses + expect($('.grading-due-date').length).toBe(1); + expect($('.edit-settings-grading').length).toBe(1); + expect($('.edit-content-visibility').length).toBe(1); + expect($('.edit-show-correctness').length).toBe(1); + }); + + it('can be edited when custom pacing for self paced course is active', function() { + outlinePage.$('.outline-subsection .configure-button').click(); + setEditModalValuesForCustomPacing('3', 'Lab'); + selectAdvancedSettings(); + $('.wrapper-modal-window .action-save').click(); + AjaxHelpers.expectJsonRequest(requests, 'POST', '/xblock/mock-subsection', { + graderType: 'Lab', + isPrereq: false, + metadata: { + due_num_weeks: 3, + is_time_limited: false, + is_practice_exam: false, + is_proctored_enabled: false, + default_time_limit_minutes: null, + is_onboarding_exam: false, + } + }); + expect(requests[0].requestHeaders['X-HTTP-Method-Override']).toBe('PATCH'); + AjaxHelpers.respondWithJson(requests, {}); + + AjaxHelpers.expectJsonRequest(requests, 'GET', '/xblock/outline/mock-section'); + AjaxHelpers.respondWithJson(requests, mockCustomPacingServerValuesJson); + AjaxHelpers.expectNoRequests(requests); + + expect($('.outline-subsection .status-grading-value')).toContainText( + 'Lab' + ); + expect($('.outline-subsection .status-message-copy')).toContainText( + 'Contains staff only content' + ); + + expect($('.outline-item .outline-subsection .status-grading-value')).toContainText('Lab'); + outlinePage.$('.outline-item .outline-subsection .configure-button').click(); + expect($('#due_in').val()).toBe('3'); + expect($('#grading_type').val()).toBe('Lab'); + expect($('input[name=content-visibility][value=staff_only]').is(':checked')).toBe(true); + expect($('input.timed_exam').is(':checked')).toBe(false); + expect($('input.proctored_exam').is(':checked')).toBe(false); + expect($('input.no_special_exam').is(':checked')).toBe(true); + expect($('input.practice_exam').is(':checked')).toBe(false); + expectShowCorrectness('never'); + }); + + it('shows validation error on due number of weeks', function() { + outlinePage.$('.outline-subsection .configure-button').click(); + + // when due number of weeks goes over 18 + selectDueNumWeeksSubsection('19'); + expect($('#due-num-weeks-warning-max').css('display')).not.toBe('none'); + expect($('.wrapper-modal-window .action-save').prop('disabled')).toBe(true); + expect($('.wrapper-modal-window .action-save').hasClass('is-disabled')).toBe(true); + + // when due number of weeks is less than 1 + selectDueNumWeeksSubsection('-1'); + expect($('#due-num-weeks-warning-min').css('display')).not.toBe('none'); + expect($('.wrapper-modal-window .action-save').prop('disabled')).toBe(true); + expect($('.wrapper-modal-window .action-save').hasClass('is-disabled')).toBe(true); + + // when no validation error should show up + selectDueNumWeeksSubsection('10'); + expect($('#due-num-weeks-warning-max').css('display')).toBe('none'); + expect($('#due-num-weeks-warning-min').css('display')).toBe('none'); + expect($('.wrapper-modal-window .action-save').prop('disabled')).toBe(false); + expect($('.wrapper-modal-window .action-save').hasClass('is-disabled')).toBe(false); + }); + + it('due num weeks (due_in) can be cleared.', function() { + outlinePage.$('.outline-item .outline-subsection .configure-button').click(); + setEditModalValuesForCustomPacing('3', 'Lab'); + setContentVisibility('staff_only'); + $('.wrapper-modal-window .action-save').click(); + + // This is the response for the change operation. + AjaxHelpers.respondWithJson(requests, {}); + // This is the response for the subsequent fetch operation. + AjaxHelpers.respondWithJson(requests, mockCustomPacingServerValuesJson); + + expect($('.outline-subsection .status-grading-value')).toContainText( + 'Lab' + ); + expect($('.outline-subsection .status-message-copy')).toContainText( + 'Contains staff only content' + ); + + outlinePage.$('.outline-subsection .configure-button').click(); + expect($('#due_in').val()).toBe('3'); + expect($('#grading_type').val()).toBe('Lab'); + expect($('input[name=content-visibility][value=staff_only]').is(':checked')).toBe(true); + + $('.wrapper-modal-window .due-date-input .action-clear').click(); + expect($('#due_in').val()).toBe(''); + + $('#grading_type').val('notgraded'); + setContentVisibility('visible'); + + $('.wrapper-modal-window .action-save').click(); + + // This is the response for the change operation. + AjaxHelpers.respondWithJson(requests, {}); + // This is the response for the subsequent fetch operation. + AjaxHelpers.respondWithJson(requests, + createMockSectionJSON({}, [createMockSubsectionJSON()]) + ); + + expect($('.outline-subsection .status-grading-value')).not.toExist(); + expect($('.outline-subsection .status-message-copy')).not.toContainText( + 'Contains staff only content' + ); + }); + }) }); // Note: most tests for units can be found in Bok Choy diff --git a/cms/static/js/views/modals/course_outline_modals.js b/cms/static/js/views/modals/course_outline_modals.js index eded671fa7..164cfe31e9 100644 --- a/cms/static/js/views/modals/course_outline_modals.js +++ b/cms/static/js/views/modals/course_outline_modals.js @@ -15,10 +15,9 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', 'use strict'; var CourseOutlineXBlockModal, SettingsXBlockModal, PublishXBlockModal, HighlightsXBlockModal, AbstractEditor, BaseDateEditor, - ReleaseDateEditor, DueDateEditor, GradingEditor, PublishEditor, AbstractVisibilityEditor, + ReleaseDateEditor, DueDateEditor, SelfPacedDueDateEditor, GradingEditor, PublishEditor, AbstractVisibilityEditor, StaffLockEditor, UnitAccessEditor, ContentVisibilityEditor, TimedExaminationPreferenceEditor, - AccessEditor, ShowCorrectnessEditor, HighlightsEditor, HighlightsEnableXBlockModal, HighlightsEnableEditor, - SelfPacedDueDateEditor; + AccessEditor, ShowCorrectnessEditor, HighlightsEditor, HighlightsEnableXBlockModal, HighlightsEnableEditor; CourseOutlineXBlockModal = BaseModal.extend({ events: _.extend({}, BaseModal.prototype.events, { @@ -75,7 +74,6 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', event.preventDefault(); requestData = this.getRequestData(); - console.log(requestData) if (!_.isEqual(requestData, {metadata: {}})) { XBlockViewUtils.updateXBlockFields(this.model, requestData, { success: this.options.onSave @@ -391,32 +389,55 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', } }); - SelfPacedDueDateEditor = BaseDateEditor.extend({ - fieldName: 'due', + SelfPacedDueDateEditor = AbstractEditor.extend({ + fieldName: 'due_num_weeks', templateName: 'self-paced-due-date-editor', className: 'modal-section-content has-actions due-date-input grading-due-date', + events: { + 'click .clear-date': 'clearValue', + 'keyup #due_in': 'validateDueIn', + 'blur #due_in': 'validateDueIn', + }, + getValue: function() { - return this.$('#due_date').val(); + return parseInt(this.$('#due_in').val()); + }, + + validateDueIn: function() { + if (this.getValue() > 18){ + this.$('#due-num-weeks-warning-max').show(); + BaseModal.prototype.disableActionButton.call(this.parent, 'save'); + } + else if (this.getValue() < 1){ + this.$('#due-num-weeks-warning-min').show() + BaseModal.prototype.disableActionButton.call(this.parent, 'save'); + } + else { + this.$('#due-num-weeks-warning-max').hide(); + this.$('#due-num-weeks-warning-min').hide(); + BaseModal.prototype.enableActionButton.call(this.parent, 'save'); + } }, clearValue: function(event) { event.preventDefault(); - this.$('#due_date').val(''); + this.$('#due_in').val(''); + }, + + afterRender: function() { + AbstractEditor.prototype.afterRender.call(this); + this.$('.field-due-in input').val(this.model.get('due_num_weeks')); }, getRequestData: function() { - let currentDate = parseInt(this.getValue()) - if (parseInt(this.getValue())){ - currentDate = new Date() - currentDate.setDate(currentDate.getDate() + parseInt(this.getValue())*7) - }; - // due_num_weeks - return { - metadata: { - due: currentDate - } - }; + if (this.getValue() < 19 && this.getValue() > 0) { + return { + metadata: { + due_num_weeks: this.getValue() + } + }; + } } }); @@ -1108,9 +1129,8 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview', } else if (xblockInfo.isSequential()) { tabs[0].editors = [ReleaseDateEditor, GradingEditor, DueDateEditor]; tabs[1].editors = [ContentVisibilityEditor, ShowCorrectnessEditor]; - - if (course.get('self_paced')) { - tabs[0].editors.push(SelfPacedDueDateEditor) + if (course.get('self_paced') && course.get('is_custom_pls_active')) { + tabs[0].editors.push(SelfPacedDueDateEditor); } if (options.enable_proctored_exams || options.enable_timed_exams) { diff --git a/cms/templates/base.html b/cms/templates/base.html index abc3ad8677..53da173858 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -10,6 +10,7 @@ <%! from django.utils.translation import ugettext as _ +from cms.djangoapps.contentstore.config.waffle import CUSTOM_PLS from lms.djangoapps.branding import api as branding_api from openedx.core.djangoapps.util.user_messages import PageLevelMessages from openedx.core.djangolib.js_utils import ( @@ -155,7 +156,8 @@ from openedx.core.release import RELEASE_LINE num: "${context_course.location.course | n, js_escaped_string}", display_course_number: "${context_course.display_coursenumber | n, js_escaped_string}", revision: "${context_course.location.branch | n, js_escaped_string}", - self_paced: ${ context_course.self_paced | n, dump_js_escaped_json } + self_paced: ${ context_course.self_paced | n, dump_js_escaped_json }, + is_custom_pls_active: ${CUSTOM_PLS.is_enabled(context_course.id) | n, dump_js_escaped_json} }); % endif diff --git a/cms/templates/js/self-paced-due-date-editor.underscore b/cms/templates/js/self-paced-due-date-editor.underscore index 77ed3fb65c..7d1e894399 100644 --- a/cms/templates/js/self-paced-due-date-editor.underscore +++ b/cms/templates/js/self-paced-due-date-editor.underscore @@ -1,16 +1,25 @@ -